4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * This file contains Kerberos support code, copyright 2006 by
12 * These coded instructions, statements, and computer programs are the
13 * property of Apple Inc. and are protected by Federal copyright
14 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 * which should have been included with this file. If this file is
16 * file is missing or damaged, see the license at "http://www.cups.org/".
20 * cupsdProcessIPPRequest() - Process an incoming IPP request.
21 * cupsdTimeoutJob() - Timeout a job waiting on job files.
22 * accept_jobs() - Accept print jobs to a printer.
23 * add_class() - Add a class to the system.
24 * add_file() - Add a file to a job.
25 * add_job() - Add a job to a print queue.
26 * add_job_state_reasons() - Add the "job-state-reasons" attribute based
27 * upon the job and printer state...
28 * add_job_subscriptions() - Add any subscriptions for a job.
29 * add_job_uuid() - Add job-uuid attribute to a job.
30 * add_printer() - Add a printer to the system.
31 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
32 * based upon the printer state...
33 * add_queued_job_count() - Add the "queued-job-count" attribute for the
34 * specified printer or class.
35 * apple_init_profile() - Initialize a color profile.
36 * apple_register_profiles() - Register color profiles for a printer.
37 * apple_unregister_profiles() - Remove color profiles for the specified
39 * apply_printer_defaults() - Apply printer default options to a job.
40 * authenticate_job() - Set job authentication info.
41 * cancel_all_jobs() - Cancel all or selected print jobs.
42 * cancel_job() - Cancel a print job.
43 * cancel_subscription() - Cancel a subscription.
44 * check_rss_recipient() - Check that we do not have a duplicate RSS
46 * check_quotas() - Check quotas for a printer and user.
47 * close_job() - Close a multi-file job.
48 * copy_attribute() - Copy a single attribute.
49 * copy_attrs() - Copy attributes from one request to another.
50 * copy_banner() - Copy a banner file to the requests directory
51 * for the specified job.
52 * copy_file() - Copy a PPD file or interface script...
53 * copy_model() - Copy a PPD model file, substituting default
55 * copy_job_attrs() - Copy job attributes.
56 * copy_printer_attrs() - Copy printer attributes.
57 * copy_subscription_attrs() - Copy subscription attributes.
58 * create_job() - Print a file to a printer or class.
59 * create_requested_array() - Create an array for the requested-attributes.
60 * create_subscription() - Create a notification subscription.
61 * delete_printer() - Remove a printer or class from the system.
62 * get_default() - Get the default destination.
63 * get_devices() - Get the list of available devices on the
65 * get_document() - Get a copy of a job file.
66 * get_job_attrs() - Get job attributes.
67 * get_jobs() - Get a list of jobs for the specified printer.
68 * get_notifications() - Get events for a subscription.
69 * get_ppd() - Get a named PPD from the local system.
70 * get_ppds() - Get the list of PPD files on the local
72 * get_printer_attrs() - Get printer attributes.
73 * get_printer_supported() - Get printer supported values.
74 * get_printers() - Get a list of printers or classes.
75 * get_subscription_attrs() - Get subscription attributes.
76 * get_subscriptions() - Get subscriptions.
77 * get_username() - Get the username associated with a request.
78 * hold_job() - Hold a print job.
79 * hold_new_jobs() - Hold pending/new jobs on a printer or class.
80 * move_job() - Move a job to a new destination.
81 * ppd_parse_line() - Parse a PPD default line.
82 * print_job() - Print a file to a printer or class.
83 * read_job_ticket() - Read a job ticket embedded in a print file.
84 * reject_jobs() - Reject print jobs to a printer.
85 * release_held_new_jobs() - Release pending/new jobs on a printer or
87 * release_job() - Release a held print job.
88 * renew_subscription() - Renew an existing subscription...
89 * restart_job() - Restart an old print job.
90 * save_auth_info() - Save authentication information for a job.
91 * send_document() - Send a file to a printer or class.
92 * send_http_error() - Send a HTTP error back to the IPP client.
93 * send_ipp_status() - Send a status back to the IPP client.
94 * set_default() - Set the default destination...
95 * set_job_attrs() - Set job attributes.
96 * set_printer_attrs() - Set printer attributes.
97 * set_printer_defaults() - Set printer default options from a request.
98 * start_printer() - Start a printer.
99 * stop_printer() - Stop a printer.
100 * url_encode_attr() - URL-encode a string attribute.
101 * url_encode_string() - URL-encode a string.
102 * user_allowed() - See if a user is allowed to print to a queue.
103 * validate_job() - Validate printer options and destination.
104 * validate_name() - Make sure the printer name only contains
106 * validate_user() - Validate the user for the request.
110 * Include necessary headers...
114 #include <cups/ppd-private.h>
117 # include <ApplicationServices/ApplicationServices.h>
118 # ifdef HAVE_COLORSYNCREGISTERDEVICE
119 extern CFUUIDRef
ColorSyncCreateUUIDFromUInt32(unsigned id
);
120 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
121 # include <CoreFoundation/CoreFoundation.h>
122 # ifdef HAVE_MEMBERSHIP_H
123 # include <membership.h>
124 # endif /* HAVE_MEMBERSHIP_H */
125 # ifdef HAVE_MEMBERSHIPPRIV_H
126 # include <membershipPriv.h>
128 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
129 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
130 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
131 # endif /* HAVE_MEMBERSHIPPRIV_H */
132 #endif /* __APPLE__ */
139 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
140 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
141 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
142 mime_type_t
*filetype
, int compression
);
143 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
144 mime_type_t
*filetype
);
145 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
146 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
147 static void add_job_uuid(cupsd_job_t
*job
);
148 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
149 static void add_printer_state_reasons(cupsd_client_t
*con
,
151 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
153 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
154 # ifdef HAVE_COLORSYNCREGISTERDEVICE
155 CFMutableDictionaryRef profile
,
157 CMDeviceProfileInfo
*profile
,
158 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
159 unsigned id
, const char *name
,
160 const char *text
, const char *iccfile
);
161 static void apple_register_profiles(cupsd_printer_t
*p
);
162 static void apple_unregister_profiles(cupsd_printer_t
*p
);
163 #endif /* __APPLE__ */
164 static void apply_printer_defaults(cupsd_printer_t
*printer
,
166 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
167 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
168 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
169 static void cancel_subscription(cupsd_client_t
*con
, int id
);
170 static int check_rss_recipient(const char *recipient
);
171 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
172 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
174 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
175 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
176 ipp_tag_t group
, int quickcopy
,
177 cups_array_t
*exclude
);
178 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
180 static int copy_file(const char *from
, const char *to
);
181 static int copy_model(cupsd_client_t
*con
, const char *from
,
183 static void copy_job_attrs(cupsd_client_t
*con
,
185 cups_array_t
*ra
, cups_array_t
*exclude
);
186 static void copy_printer_attrs(cupsd_client_t
*con
,
187 cupsd_printer_t
*printer
,
189 static void copy_subscription_attrs(cupsd_client_t
*con
,
190 cupsd_subscription_t
*sub
,
192 cups_array_t
*exclude
);
193 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
194 static cups_array_t
*create_requested_array(ipp_t
*request
);
195 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
196 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
197 static void get_default(cupsd_client_t
*con
);
198 static void get_devices(cupsd_client_t
*con
);
199 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
200 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
201 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
202 static void get_notifications(cupsd_client_t
*con
);
203 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
204 static void get_ppds(cupsd_client_t
*con
);
205 static void get_printers(cupsd_client_t
*con
, int type
);
206 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
207 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
208 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
209 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
210 static const char *get_username(cupsd_client_t
*con
);
211 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
212 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
213 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
214 static int ppd_parse_line(const char *line
, char *option
, int olen
,
215 char *choice
, int clen
);
216 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
217 static void read_job_ticket(cupsd_client_t
*con
);
218 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
219 static void release_held_new_jobs(cupsd_client_t
*con
,
220 ipp_attribute_t
*uri
);
221 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
222 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
223 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
224 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
225 ipp_attribute_t
*auth_info
);
226 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
227 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
228 cupsd_printer_t
*printer
);
229 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
230 const char *message
, ...)
232 __attribute__ ((__format__ (__printf__
, 3, 4)))
233 # endif /* __GNUC__ */
235 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
236 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
237 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
238 static void set_printer_defaults(cupsd_client_t
*con
,
239 cupsd_printer_t
*printer
);
240 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
241 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
242 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
244 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
245 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
246 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
247 static int validate_name(const char *name
);
248 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
249 const char *owner
, char *username
,
254 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
257 int /* O - 1 on success, 0 on failure */
258 cupsdProcessIPPRequest(
259 cupsd_client_t
*con
) /* I - Client connection */
261 ipp_tag_t group
; /* Current group tag */
262 ipp_attribute_t
*attr
; /* Current attribute */
263 ipp_attribute_t
*charset
; /* Character set attribute */
264 ipp_attribute_t
*language
; /* Language attribute */
265 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
266 ipp_attribute_t
*username
; /* requesting-user-name attr */
267 int sub_id
; /* Subscription ID */
270 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
271 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
272 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
275 * First build an empty response message for this request...
278 con
->response
= ippNew();
280 con
->response
->request
.status
.version
[0] =
281 con
->request
->request
.op
.version
[0];
282 con
->response
->request
.status
.version
[1] =
283 con
->request
->request
.op
.version
[1];
284 con
->response
->request
.status
.request_id
=
285 con
->request
->request
.op
.request_id
;
288 * Then validate the request header and required attributes...
291 if (con
->request
->request
.any
.version
[0] != 1 &&
292 con
->request
->request
.any
.version
[0] != 2)
295 * Return an error, since we only support IPP 1.x and 2.x.
298 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
299 "%04X %s Bad request version number %d.%d",
300 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
301 con
->request
->request
.any
.version
[0],
302 con
->request
->request
.any
.version
[1]);
304 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
305 _("Bad request version number %d.%d."),
306 con
->request
->request
.any
.version
[0],
307 con
->request
->request
.any
.version
[1]);
309 else if (con
->request
->request
.any
.request_id
< 1)
312 * Return an error, since request IDs must be between 1 and 2^31-1
315 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
316 "%04X %s Bad request ID %d",
317 IPP_BAD_REQUEST
, con
->http
.hostname
,
318 con
->request
->request
.any
.request_id
);
320 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
321 con
->request
->request
.any
.request_id
);
323 else if (!con
->request
->attrs
)
325 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
326 "%04X %s No attributes in request",
327 IPP_BAD_REQUEST
, con
->http
.hostname
);
329 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
334 * Make sure that the attributes are provided in the correct order and
335 * don't repeat groups...
338 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
341 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
344 * Out of order; return an error...
347 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
348 "%04X %s Attribute groups are out of order",
349 IPP_BAD_REQUEST
, con
->http
.hostname
);
351 send_ipp_status(con
, IPP_BAD_REQUEST
,
352 _("Attribute groups are out of order (%x < %x)."),
353 attr
->group_tag
, group
);
357 group
= attr
->group_tag
;
362 * Then make sure that the first three attributes are:
365 * attributes-natural-language
366 * printer-uri/job-uri
369 attr
= con
->request
->attrs
;
370 if (attr
&& attr
->name
&&
371 !strcmp(attr
->name
, "attributes-charset") &&
372 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
380 if (attr
&& attr
->name
&&
381 !strcmp(attr
->name
, "attributes-natural-language") &&
382 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
387 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
388 IPP_TAG_URI
)) != NULL
)
390 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
391 IPP_TAG_URI
)) != NULL
)
393 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
394 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
399 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
400 "attributes-charset", NULL
,
401 charset
->values
[0].string
.text
);
403 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
404 "attributes-charset", NULL
, "utf-8");
407 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
408 "attributes-natural-language", NULL
,
409 language
->values
[0].string
.text
);
411 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
412 "attributes-natural-language", NULL
, DefaultLanguage
);
415 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
416 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
419 * Bad character set...
422 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
423 charset
->values
[0].string
.text
);
424 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
425 "%04X %s Unsupported attributes-charset value \"%s\"",
426 IPP_CHARSET
, con
->http
.hostname
,
427 charset
->values
[0].string
.text
);
428 send_ipp_status(con
, IPP_BAD_REQUEST
,
429 _("Unsupported character set \"%s\"."),
430 charset
->values
[0].string
.text
);
432 else if (!charset
|| !language
||
434 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
435 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
436 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
437 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
438 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
441 * Return an error, since attributes-charset,
442 * attributes-natural-language, and printer-uri/job-uri are required
443 * for all operations.
448 cupsdLogMessage(CUPSD_LOG_ERROR
,
449 "Missing attributes-charset attribute");
451 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
452 "%04X %s Missing attributes-charset attribute",
453 IPP_BAD_REQUEST
, con
->http
.hostname
);
458 cupsdLogMessage(CUPSD_LOG_ERROR
,
459 "Missing attributes-natural-language attribute");
461 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
462 "%04X %s Missing attributes-natural-language attribute",
463 IPP_BAD_REQUEST
, con
->http
.hostname
);
468 cupsdLogMessage(CUPSD_LOG_ERROR
,
469 "Missing printer-uri, job-uri, or ppd-name "
472 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
473 "%04X %s Missing printer-uri, job-uri, or ppd-name "
474 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
477 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
479 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
480 cupsdLogMessage(CUPSD_LOG_DEBUG
,
481 "attr \"%s\": group_tag = %x, value_tag = %x",
482 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
485 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
487 send_ipp_status(con
, IPP_BAD_REQUEST
,
488 _("Missing required attributes."));
493 * OK, all the checks pass so far; make sure requesting-user-name is
494 * not "root" from a remote host...
497 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
498 IPP_TAG_NAME
)) != NULL
)
501 * Check for root user...
504 if (!strcmp(username
->values
[0].string
.text
, "root") &&
505 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
506 strcmp(con
->username
, "root"))
509 * Remote unauthenticated user masquerading as local root...
512 _cupsStrFree(username
->values
[0].string
.text
);
513 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
517 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
518 IPP_TAG_INTEGER
)) != NULL
)
519 sub_id
= attr
->values
[0].integer
;
524 * Then try processing the operation...
528 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
529 ippOpString(con
->request
->request
.op
.operation_id
),
530 uri
->values
[0].string
.text
);
532 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
533 ippOpString(con
->request
->request
.op
.operation_id
));
535 switch (con
->request
->request
.op
.operation_id
)
541 case IPP_VALIDATE_JOB
:
542 validate_job(con
, uri
);
545 case IPP_CREATE_JOB
:
546 create_job(con
, uri
);
549 case IPP_SEND_DOCUMENT
:
550 send_document(con
, uri
);
553 case IPP_CANCEL_JOB
:
554 cancel_job(con
, uri
);
557 case IPP_GET_JOB_ATTRIBUTES
:
558 get_job_attrs(con
, uri
);
565 case IPP_GET_PRINTER_ATTRIBUTES
:
566 get_printer_attrs(con
, uri
);
569 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
570 get_printer_supported(con
, uri
);
577 case IPP_RELEASE_JOB
:
578 release_job(con
, uri
);
581 case IPP_RESTART_JOB
:
582 restart_job(con
, uri
);
585 case IPP_PAUSE_PRINTER
:
586 stop_printer(con
, uri
);
589 case IPP_RESUME_PRINTER
:
590 start_printer(con
, uri
);
593 case IPP_PURGE_JOBS
:
594 case IPP_CANCEL_JOBS
:
595 case IPP_CANCEL_MY_JOBS
:
596 cancel_all_jobs(con
, uri
);
599 case IPP_SET_JOB_ATTRIBUTES
:
600 set_job_attrs(con
, uri
);
603 case IPP_SET_PRINTER_ATTRIBUTES
:
604 set_printer_attrs(con
, uri
);
607 case IPP_HOLD_NEW_JOBS
:
608 hold_new_jobs(con
, uri
);
611 case IPP_RELEASE_HELD_NEW_JOBS
:
612 release_held_new_jobs(con
, uri
);
619 case CUPS_GET_DEFAULT
:
623 case CUPS_GET_PRINTERS
:
624 get_printers(con
, 0);
627 case CUPS_GET_CLASSES
:
628 get_printers(con
, CUPS_PRINTER_CLASS
);
631 case CUPS_ADD_PRINTER
:
632 add_printer(con
, uri
);
635 case CUPS_DELETE_PRINTER
:
636 delete_printer(con
, uri
);
639 case CUPS_ADD_CLASS
:
643 case CUPS_DELETE_CLASS
:
644 delete_printer(con
, uri
);
647 case CUPS_ACCEPT_JOBS
:
648 case IPP_ENABLE_PRINTER
:
649 accept_jobs(con
, uri
);
652 case CUPS_REJECT_JOBS
:
653 case IPP_DISABLE_PRINTER
:
654 reject_jobs(con
, uri
);
657 case CUPS_SET_DEFAULT
:
658 set_default(con
, uri
);
661 case CUPS_GET_DEVICES
:
665 case CUPS_GET_DOCUMENT
:
666 get_document(con
, uri
);
681 case CUPS_AUTHENTICATE_JOB
:
682 authenticate_job(con
, uri
);
685 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
686 case IPP_CREATE_JOB_SUBSCRIPTION
:
687 create_subscription(con
, uri
);
690 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
691 get_subscription_attrs(con
, sub_id
);
694 case IPP_GET_SUBSCRIPTIONS
:
695 get_subscriptions(con
, uri
);
698 case IPP_RENEW_SUBSCRIPTION
:
699 renew_subscription(con
, sub_id
);
702 case IPP_CANCEL_SUBSCRIPTION
:
703 cancel_subscription(con
, sub_id
);
706 case IPP_GET_NOTIFICATIONS
:
707 get_notifications(con
);
711 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
712 "%04X %s Operation %04X (%s) not supported",
713 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
714 con
->request
->request
.op
.operation_id
,
715 ippOpString(con
->request
->request
.op
.operation_id
));
717 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
718 _("%s not supported."),
720 con
->request
->request
.op
.operation_id
));
730 * Sending data from the scheduler...
733 cupsdLogMessage(con
->response
->request
.status
.status_code
734 >= IPP_BAD_REQUEST
&&
735 con
->response
->request
.status
.status_code
736 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
737 "Returning IPP %s for %s (%s) from %s",
738 ippErrorString(con
->response
->request
.status
.status_code
),
739 ippOpString(con
->request
->request
.op
.operation_id
),
740 uri
? uri
->values
[0].string
.text
: "no URI",
743 if (LogLevel
== CUPSD_LOG_DEBUG2
)
744 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
745 "cupsdProcessIPPRequest: ippLength(response)=%ld",
746 (long)ippLength(con
->response
));
748 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
750 #ifdef CUPSD_USE_CHUNKING
752 * Because older versions of CUPS (1.1.17 and older) and some IPP
753 * clients do not implement chunking properly, we cannot use
754 * chunking by default. This may become the default in future
755 * CUPS releases, or we might add a configuration directive for
759 if (con
->http
.version
== HTTP_1_1
)
761 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
764 if (cupsdFlushHeader(con
) < 0)
767 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
770 #endif /* CUPSD_USE_CHUNKING */
772 size_t length
; /* Length of response */
775 length
= ippLength(con
->response
);
777 if (con
->file
>= 0 && !con
->pipe_pid
)
779 struct stat fileinfo
; /* File information */
782 if (!fstat(con
->file
, &fileinfo
))
783 length
+= fileinfo
.st_size
;
786 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
787 CUPS_LLCAST length
) < 0)
790 if (cupsdFlushHeader(con
) < 0)
793 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
794 con
->http
.data_remaining
= length
;
796 if (con
->http
.data_remaining
<= INT_MAX
)
797 con
->http
._data_remaining
= con
->http
.data_remaining
;
799 con
->http
._data_remaining
= INT_MAX
;
802 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
803 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
806 * Tell the caller the response header was sent successfully...
814 * Tell the caller the response header could not be sent...
823 * Sending data from a subprocess like cups-deviced; tell the caller
824 * everything is A-OK so far...
833 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
836 int /* O - 0 on success, -1 on error */
837 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
839 cupsd_printer_t
*printer
; /* Destination printer or class */
840 ipp_attribute_t
*attr
; /* job-sheets attribute */
841 int kbytes
; /* Kilobytes in banner */
844 job
->pending_timeout
= 0;
847 * See if we need to add the ending sheet...
850 if (!cupsdLoadJob(job
))
853 printer
= cupsdFindDest(job
->dest
);
854 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
857 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
858 attr
&& attr
->num_values
> 1)
864 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
865 attr
->values
[1].string
.text
);
867 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
870 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
878 * 'accept_jobs()' - Accept print jobs to a printer.
882 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
883 ipp_attribute_t
*uri
) /* I - Printer or class URI */
885 http_status_t status
; /* Policy status */
886 cups_ptype_t dtype
; /* Destination type (printer/class) */
887 cupsd_printer_t
*printer
; /* Printer data */
890 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
891 con
->http
.fd
, uri
->values
[0].string
.text
);
894 * Is the destination valid?
897 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
903 send_ipp_status(con
, IPP_NOT_FOUND
,
904 _("The printer or class does not exist."));
912 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
914 send_http_error(con
, status
, printer
);
919 * Accept jobs sent to the printer...
922 printer
->accepting
= 1;
923 printer
->state_message
[0] = '\0';
925 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
926 "Now accepting jobs.");
928 if (dtype
& CUPS_PRINTER_CLASS
)
930 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
932 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
933 printer
->name
, get_username(con
));
937 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
939 cupsdLogMessage(CUPSD_LOG_INFO
,
940 "Printer \"%s\" now accepting jobs (\"%s\").",
941 printer
->name
, get_username(con
));
945 * Everything was ok, so return OK status...
948 con
->response
->request
.status
.status_code
= IPP_OK
;
953 * 'add_class()' - Add a class to the system.
957 add_class(cupsd_client_t
*con
, /* I - Client connection */
958 ipp_attribute_t
*uri
) /* I - URI of class */
960 http_status_t status
; /* Policy status */
961 int i
; /* Looping var */
962 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
963 username
[HTTP_MAX_URI
], /* Username portion of URI */
964 host
[HTTP_MAX_URI
], /* Host portion of URI */
965 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
966 int port
; /* Port portion of URI */
967 cupsd_printer_t
*pclass
, /* Class */
968 *member
; /* Member printer/class */
969 cups_ptype_t dtype
; /* Destination type */
970 ipp_attribute_t
*attr
; /* Printer attribute */
971 int modify
; /* Non-zero if we just modified */
972 char newname
[IPP_MAX_NAME
]; /* New class name */
973 int need_restart_job
; /* Need to restart job? */
976 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
977 con
->http
.fd
, uri
->values
[0].string
.text
);
980 * Do we have a valid URI?
983 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
984 sizeof(scheme
), username
, sizeof(username
), host
,
985 sizeof(host
), &port
, resource
, sizeof(resource
));
988 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
991 * No, return an error...
994 send_ipp_status(con
, IPP_BAD_REQUEST
,
995 _("The printer-uri must be of the form "
996 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
1001 * Do we have a valid printer name?
1004 if (!validate_name(resource
+ 9))
1007 * No, return an error...
1010 send_ipp_status(con
, IPP_BAD_REQUEST
,
1011 _("The printer-uri \"%s\" contains invalid characters."),
1012 uri
->values
[0].string
.text
);
1017 * See if the class already exists; if not, create a new class...
1020 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1023 * Class doesn't exist; see if we have a printer of the same name...
1026 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
1027 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
1030 * Yes, return an error...
1033 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1034 _("A printer named \"%s\" already exists."),
1040 * No, check the default policy and then add the class...
1043 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1045 send_http_error(con
, status
, NULL
);
1049 pclass
= cupsdAddClass(resource
+ 9);
1052 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1055 * Check the default policy, then rename the implicit class to "AnyClass"
1059 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1061 send_http_error(con
, status
, NULL
);
1065 if (ImplicitAnyClasses
)
1067 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1068 cupsdRenamePrinter(pclass
, newname
);
1071 cupsdDeletePrinter(pclass
, 1);
1074 * Add the class as a new local class...
1077 pclass
= cupsdAddClass(resource
+ 9);
1080 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1083 * Check the default policy, then rename the remote class to "Class"...
1086 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1088 send_http_error(con
, status
, NULL
);
1092 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1093 cupsdRenamePrinter(pclass
, newname
);
1096 * Add the class as a new local class...
1099 pclass
= cupsdAddClass(resource
+ 9);
1102 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1105 send_http_error(con
, status
, pclass
);
1112 * Look for attributes and copy them over as needed...
1115 need_restart_job
= 0;
1117 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1118 IPP_TAG_TEXT
)) != NULL
)
1119 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1121 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1122 IPP_TAG_TEXT
)) != NULL
)
1123 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1125 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1126 IPP_TAG_BOOLEAN
)) != NULL
&&
1127 attr
->values
[0].boolean
!= pclass
->accepting
)
1129 cupsdLogMessage(CUPSD_LOG_INFO
,
1130 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1131 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1133 pclass
->accepting
= attr
->values
[0].boolean
;
1135 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1136 pclass
->accepting
? "Now" : "No longer");
1139 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1140 IPP_TAG_BOOLEAN
)) != NULL
)
1142 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1143 cupsdDeregisterPrinter(pclass
, 1);
1145 cupsdLogMessage(CUPSD_LOG_INFO
,
1146 "Setting %s printer-is-shared to %d (was %d.)",
1147 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1149 pclass
->shared
= attr
->values
[0].boolean
;
1152 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1153 IPP_TAG_ENUM
)) != NULL
)
1155 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1156 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1158 send_ipp_status(con
, IPP_BAD_REQUEST
,
1159 _("Attempt to set %s printer-state to bad value %d."),
1160 pclass
->name
, attr
->values
[0].integer
);
1164 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1165 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1167 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1168 cupsdStopPrinter(pclass
, 0);
1171 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1172 need_restart_job
= 1;
1175 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1176 IPP_TAG_TEXT
)) != NULL
)
1178 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1179 sizeof(pclass
->state_message
));
1181 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1182 pclass
->state_message
);
1184 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1185 IPP_TAG_URI
)) != NULL
)
1188 * Clear the printer array as needed...
1191 need_restart_job
= 1;
1193 if (pclass
->num_printers
> 0)
1195 free(pclass
->printers
);
1196 pclass
->num_printers
= 0;
1200 * Add each printer or class that is listed...
1203 for (i
= 0; i
< attr
->num_values
; i
++)
1206 * Search for the printer or class URI...
1209 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1215 send_ipp_status(con
, IPP_NOT_FOUND
,
1216 _("The printer or class does not exist."));
1219 else if (dtype
& CUPS_PRINTER_CLASS
)
1221 send_ipp_status(con
, IPP_BAD_REQUEST
,
1222 _("Nested classes are not allowed."));
1227 * Add it to the class...
1230 cupsdAddPrinterToClass(pclass
, member
);
1234 set_printer_defaults(con
, pclass
);
1236 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1237 IPP_TAG_KEYWORD
)) != NULL
)
1238 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1241 * Update the printer class attributes and return...
1244 cupsdSetPrinterAttrs(pclass
);
1245 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1247 if (need_restart_job
&& pclass
->job
)
1250 * Reset the current job to a "pending" status...
1253 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1254 "Job restarted because the class was modified.");
1257 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1261 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1262 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1263 pclass
->name
, get_username(con
));
1265 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1266 pclass
->name
, get_username(con
));
1270 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1271 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1272 pclass
->name
, get_username(con
));
1274 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1275 pclass
->name
, get_username(con
));
1278 con
->response
->request
.status
.status_code
= IPP_OK
;
1283 * 'add_file()' - Add a file to a job.
1286 static int /* O - 0 on success, -1 on error */
1287 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1288 cupsd_job_t
*job
, /* I - Job to add to */
1289 mime_type_t
*filetype
, /* I - Type of file */
1290 int compression
) /* I - Compression */
1292 mime_type_t
**filetypes
; /* New filetypes array... */
1293 int *compressions
; /* New compressions array... */
1296 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1297 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1298 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1299 filetype
->super
, filetype
->type
, compression
);
1302 * Add the file to the job...
1305 if (job
->num_files
== 0)
1307 compressions
= (int *)malloc(sizeof(int));
1308 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1312 compressions
= (int *)realloc(job
->compressions
,
1313 (job
->num_files
+ 1) * sizeof(int));
1314 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1315 (job
->num_files
+ 1) *
1316 sizeof(mime_type_t
*));
1319 if (!compressions
|| !filetypes
)
1321 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1322 "Job aborted because the scheduler ran out of memory.");
1325 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1326 _("Unable to allocate memory for file types."));
1331 job
->compressions
= compressions
;
1332 job
->compressions
[job
->num_files
] = compression
;
1333 job
->filetypes
= filetypes
;
1334 job
->filetypes
[job
->num_files
] = filetype
;
1339 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1346 * 'add_job()' - Add a job to a print queue.
1349 static cupsd_job_t
* /* O - Job object */
1350 add_job(cupsd_client_t
*con
, /* I - Client connection */
1351 cupsd_printer_t
*printer
, /* I - Destination printer */
1352 mime_type_t
*filetype
) /* I - First print file type, if any */
1354 http_status_t status
; /* Policy status */
1355 ipp_attribute_t
*attr
, /* Current attribute */
1356 *auth_info
; /* auth-info attribute */
1357 const char *val
; /* Default option value */
1358 int priority
; /* Job priority */
1359 cupsd_job_t
*job
; /* Current job */
1360 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1361 int kbytes
; /* Size of print file */
1362 int i
; /* Looping var */
1363 int lowerpagerange
; /* Page range bound */
1364 int exact
; /* Did we have an exact match? */
1365 ipp_attribute_t
*media_col
, /* media-col attribute */
1366 *media_margin
; /* media-*-margin attribute */
1367 ipp_t
*unsup_col
; /* media-col in unsupported response */
1370 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1371 con
, con
->http
.fd
, printer
, printer
->name
,
1372 filetype
, filetype
? filetype
->super
: "none",
1373 filetype
? filetype
->type
: "none");
1376 * Check remote printing to non-shared printer...
1379 if (!printer
->shared
&&
1380 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
1381 _cups_strcasecmp(con
->http
.hostname
, ServerName
))
1383 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1384 _("The printer or class is not shared."));
1392 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1394 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1396 send_http_error(con
, status
, printer
);
1399 else if (printer
->num_auth_info_required
== 1 &&
1400 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1403 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1407 else if (auth_info
&& !con
->http
.tls
&&
1408 !httpAddrLocalhost(con
->http
.hostaddr
))
1411 * Require encryption of auth-info over non-local connections...
1414 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1417 #endif /* HAVE_SSL */
1420 * See if the printer is accepting jobs...
1423 if (!printer
->accepting
)
1425 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1426 _("Destination \"%s\" is not accepting jobs."),
1432 * Validate job template attributes; for now just document-format,
1433 * copies, number-up, and page-ranges...
1436 if (filetype
&& printer
->filetypes
&&
1437 !cupsArrayFind(printer
->filetypes
, filetype
))
1439 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1440 /* MIME media type string */
1443 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1446 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1447 _("Unsupported format \"%s\"."), mimetype
);
1449 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1450 "document-format", NULL
, mimetype
);
1455 if ((attr
= ippFindAttribute(con
->request
, "copies",
1456 IPP_TAG_INTEGER
)) != NULL
)
1458 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1460 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1461 attr
->values
[0].integer
);
1462 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1463 "copies", attr
->values
[0].integer
);
1468 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1469 IPP_TAG_ZERO
)) != NULL
)
1471 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1472 attr
->value_tag
!= IPP_TAG_NAME
)
1474 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1478 if (attr
->num_values
> 2)
1480 send_ipp_status(con
, IPP_BAD_REQUEST
,
1481 _("Too many job-sheets values (%d > 2)."),
1486 for (i
= 0; i
< attr
->num_values
; i
++)
1487 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1488 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1490 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1491 attr
->values
[i
].string
.text
);
1496 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1497 IPP_TAG_INTEGER
)) != NULL
)
1499 if (attr
->values
[0].integer
!= 1 &&
1500 attr
->values
[0].integer
!= 2 &&
1501 attr
->values
[0].integer
!= 4 &&
1502 attr
->values
[0].integer
!= 6 &&
1503 attr
->values
[0].integer
!= 9 &&
1504 attr
->values
[0].integer
!= 16)
1506 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1507 attr
->values
[0].integer
);
1508 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1509 "number-up", attr
->values
[0].integer
);
1514 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1515 IPP_TAG_RANGE
)) != NULL
)
1517 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1519 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1520 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1522 send_ipp_status(con
, IPP_BAD_REQUEST
,
1523 _("Bad page-ranges values %d-%d."),
1524 attr
->values
[i
].range
.lower
,
1525 attr
->values
[i
].range
.upper
);
1529 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1534 * Do media selection as needed...
1537 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1538 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1539 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1542 (media_col
= ippFindAttribute(con
->request
, "media-col",
1543 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1545 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1547 unsup_col
= ippNew();
1548 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1549 "media-bottom-margin",
1550 IPP_TAG_INTEGER
)) != NULL
)
1551 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1552 "media-bottom-margin", media_margin
->values
[0].integer
);
1554 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1555 "media-left-margin",
1556 IPP_TAG_INTEGER
)) != NULL
)
1557 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1558 "media-left-margin", media_margin
->values
[0].integer
);
1560 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1561 "media-right-margin",
1562 IPP_TAG_INTEGER
)) != NULL
)
1563 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1564 "media-right-margin", media_margin
->values
[0].integer
);
1566 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1568 IPP_TAG_INTEGER
)) != NULL
)
1569 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1570 "media-top-margin", media_margin
->values
[0].integer
);
1572 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1574 ippDelete(unsup_col
);
1579 * Make sure we aren't over our limit...
1582 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1585 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1587 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1591 if ((i
= check_quotas(con
, printer
)) < 0)
1593 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1598 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1603 * Create the job and set things up...
1606 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1607 IPP_TAG_INTEGER
)) != NULL
)
1608 priority
= attr
->values
[0].integer
;
1611 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1612 printer
->options
)) != NULL
)
1613 priority
= atoi(val
);
1617 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1621 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1622 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1625 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1627 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1628 _("Unable to add job for destination \"%s\"."),
1633 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1634 CUPS_PRINTER_REMOTE
);
1635 job
->attrs
= con
->request
;
1637 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1639 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1642 apply_printer_defaults(printer
, job
);
1644 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1646 if (con
->username
[0])
1648 cupsdSetString(&job
->username
, con
->username
);
1651 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1655 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1656 "add_job: requesting-user-name=\"%s\"",
1657 attr
->values
[0].string
.text
);
1659 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1662 cupsdSetString(&job
->username
, "anonymous");
1665 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1666 "job-originating-user-name", NULL
, job
->username
);
1669 attr
->group_tag
= IPP_TAG_JOB
;
1670 _cupsStrFree(attr
->name
);
1671 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1674 if (con
->username
[0] || auth_info
)
1676 save_auth_info(con
, job
, auth_info
);
1679 * Remove the auth-info attribute from the attribute data...
1683 ippDeleteAttribute(job
->attrs
, auth_info
);
1686 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1687 IPP_TAG_ZERO
)) != NULL
)
1690 * Request contains a job-originating-host-name attribute; validate it...
1693 if (attr
->value_tag
!= IPP_TAG_NAME
||
1694 attr
->num_values
!= 1 ||
1695 strcmp(con
->http
.hostname
, "localhost"))
1698 * Can't override the value if we aren't connected via localhost.
1699 * Also, we can only have 1 value and it must be a name value.
1702 switch (attr
->value_tag
)
1704 case IPP_TAG_STRING
:
1705 case IPP_TAG_TEXTLANG
:
1706 case IPP_TAG_NAMELANG
:
1709 case IPP_TAG_KEYWORD
:
1711 case IPP_TAG_URISCHEME
:
1712 case IPP_TAG_CHARSET
:
1713 case IPP_TAG_LANGUAGE
:
1714 case IPP_TAG_MIMETYPE
:
1716 * Free old strings...
1719 for (i
= 0; i
< attr
->num_values
; i
++)
1721 _cupsStrFree(attr
->values
[i
].string
.text
);
1722 attr
->values
[i
].string
.text
= NULL
;
1723 if (attr
->values
[i
].string
.charset
)
1725 _cupsStrFree(attr
->values
[i
].string
.charset
);
1726 attr
->values
[i
].string
.charset
= NULL
;
1735 * Use the default connection hostname instead...
1738 attr
->value_tag
= IPP_TAG_NAME
;
1739 attr
->num_values
= 1;
1740 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1743 attr
->group_tag
= IPP_TAG_JOB
;
1748 * No job-originating-host-name attribute, so use the hostname from
1752 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1753 "job-originating-host-name", NULL
, con
->http
.hostname
);
1756 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1758 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1759 "time-at-processing", 0);
1760 attr
->value_tag
= IPP_TAG_NOVALUE
;
1761 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1762 "time-at-completed", 0);
1763 attr
->value_tag
= IPP_TAG_NOVALUE
;
1766 * Add remaining job attributes...
1769 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1770 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1771 "job-state", IPP_JOB_STOPPED
);
1772 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1773 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1774 "job-media-sheets-completed", 0);
1775 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1778 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1779 IPP_TAG_INTEGER
)) != NULL
)
1780 attr
->values
[0].integer
= 0;
1782 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1784 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1785 IPP_TAG_KEYWORD
)) == NULL
)
1786 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1789 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1790 printer
->options
)) == NULL
)
1793 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1794 "job-hold-until", NULL
, val
);
1796 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1799 * Hold job until specified time...
1802 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1804 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1805 job
->state_value
= IPP_JOB_HELD
;
1807 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1809 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1810 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1811 job
->state_value
= IPP_JOB_HELD
;
1815 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1816 job
->state_value
= IPP_JOB_PENDING
;
1819 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1823 * Add job sheets options...
1826 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1827 IPP_TAG_ZERO
)) == NULL
)
1829 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1830 "Adding default job-sheets values \"%s,%s\"...",
1831 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1833 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1835 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1836 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1839 job
->job_sheets
= attr
;
1842 * Enforce classification level if set...
1847 cupsdLogMessage(CUPSD_LOG_INFO
,
1848 "Classification=\"%s\", ClassifyOverride=%d",
1849 Classification
? Classification
: "(null)",
1852 if (ClassifyOverride
)
1854 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1855 (attr
->num_values
== 1 ||
1856 !strcmp(attr
->values
[1].string
.text
, "none")))
1859 * Force the leading banner to have the classification on it...
1862 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1864 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1865 "job-sheets=\"%s,none\", "
1866 "job-originating-user-name=\"%s\"",
1867 Classification
, job
->username
);
1869 else if (attr
->num_values
== 2 &&
1870 strcmp(attr
->values
[0].string
.text
,
1871 attr
->values
[1].string
.text
) &&
1872 strcmp(attr
->values
[0].string
.text
, "none") &&
1873 strcmp(attr
->values
[1].string
.text
, "none"))
1876 * Can't put two different security markings on the same document!
1879 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1881 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1882 "job-sheets=\"%s,%s\", "
1883 "job-originating-user-name=\"%s\"",
1884 attr
->values
[0].string
.text
,
1885 attr
->values
[1].string
.text
, job
->username
);
1887 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1888 strcmp(attr
->values
[0].string
.text
, "none") &&
1889 (attr
->num_values
== 1 ||
1890 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1891 strcmp(attr
->values
[1].string
.text
, "none"))))
1893 if (attr
->num_values
== 1)
1894 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1895 "CLASSIFICATION OVERRIDDEN "
1896 "job-sheets=\"%s\", "
1897 "job-originating-user-name=\"%s\"",
1898 attr
->values
[0].string
.text
, job
->username
);
1900 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1901 "CLASSIFICATION OVERRIDDEN "
1902 "job-sheets=\"%s,%s\",fffff "
1903 "job-originating-user-name=\"%s\"",
1904 attr
->values
[0].string
.text
,
1905 attr
->values
[1].string
.text
, job
->username
);
1908 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1909 (attr
->num_values
== 1 ||
1910 strcmp(attr
->values
[1].string
.text
, Classification
)))
1913 * Force the banner to have the classification on it...
1916 if (attr
->num_values
> 1 &&
1917 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1919 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1920 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1924 if (attr
->num_values
== 1 ||
1925 strcmp(attr
->values
[0].string
.text
, "none"))
1926 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1928 if (attr
->num_values
> 1 &&
1929 strcmp(attr
->values
[1].string
.text
, "none"))
1930 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1933 if (attr
->num_values
> 1)
1934 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1935 "CLASSIFICATION FORCED "
1936 "job-sheets=\"%s,%s\", "
1937 "job-originating-user-name=\"%s\"",
1938 attr
->values
[0].string
.text
,
1939 attr
->values
[1].string
.text
, job
->username
);
1941 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1942 "CLASSIFICATION FORCED "
1943 "job-sheets=\"%s\", "
1944 "job-originating-user-name=\"%s\"",
1945 Classification
, job
->username
);
1950 * See if we need to add the starting sheet...
1953 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1955 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1956 attr
->values
[0].string
.text
);
1958 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1960 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1961 "Aborting job because the start banner could not be "
1966 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1969 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1970 IPP_TAG_ZERO
)) != NULL
)
1971 job
->job_sheets
= attr
;
1974 * Fill in the response info...
1977 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1978 LocalPort
, job
->id
);
1980 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1983 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1985 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1987 add_job_state_reasons(con
, job
);
1989 con
->response
->request
.status
.status_code
= IPP_OK
;
1992 * Add any job subscriptions...
1995 add_job_subscriptions(con
, job
);
1998 * Set all but the first two attributes to the job attributes group...
2001 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
2002 attr
->group_tag
= IPP_TAG_JOB
;
2005 * Fire the "job created" event...
2008 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
2011 * Return the new job...
2019 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
2020 * upon the job and printer state...
2024 add_job_state_reasons(
2025 cupsd_client_t
*con
, /* I - Client connection */
2026 cupsd_job_t
*job
) /* I - Job info */
2028 cupsd_printer_t
*dest
; /* Destination printer */
2031 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
2032 con
, con
->http
.fd
, job
? job
->id
: 0);
2034 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
2036 case IPP_JOB_PENDING
:
2037 dest
= cupsdFindDest(job
->dest
);
2039 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
2040 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2041 "job-state-reasons", NULL
, "printer-stopped");
2043 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2044 "job-state-reasons", NULL
, "none");
2048 if (ippFindAttribute(job
->attrs
, "job-hold-until",
2049 IPP_TAG_KEYWORD
) != NULL
||
2050 ippFindAttribute(job
->attrs
, "job-hold-until",
2051 IPP_TAG_NAME
) != NULL
)
2052 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2053 "job-state-reasons", NULL
, "job-hold-until-specified");
2055 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2056 "job-state-reasons", NULL
, "job-incoming");
2059 case IPP_JOB_PROCESSING
:
2060 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2061 "job-state-reasons", NULL
, "job-printing");
2064 case IPP_JOB_STOPPED
:
2065 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2066 "job-state-reasons", NULL
, "job-stopped");
2069 case IPP_JOB_CANCELED
:
2070 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2071 "job-state-reasons", NULL
, "job-canceled-by-user");
2074 case IPP_JOB_ABORTED
:
2075 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2076 "job-state-reasons", NULL
, "aborted-by-system");
2079 case IPP_JOB_COMPLETED
:
2080 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2081 "job-state-reasons", NULL
, "job-completed-successfully");
2088 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2092 add_job_subscriptions(
2093 cupsd_client_t
*con
, /* I - Client connection */
2094 cupsd_job_t
*job
) /* I - Newly created job */
2096 int i
; /* Looping var */
2097 ipp_attribute_t
*prev
, /* Previous attribute */
2098 *next
, /* Next attribute */
2099 *attr
; /* Current attribute */
2100 cupsd_subscription_t
*sub
; /* Subscription object */
2101 const char *recipient
, /* notify-recipient-uri */
2102 *pullmethod
; /* notify-pull-method */
2103 ipp_attribute_t
*user_data
; /* notify-user-data */
2104 int interval
; /* notify-time-interval */
2105 unsigned mask
; /* notify-events */
2109 * Find the first subscription group attribute; return if we have
2113 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2114 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2121 * Process the subscription attributes in the request...
2130 mask
= CUPSD_EVENT_NONE
;
2132 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2134 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2135 attr
->value_tag
== IPP_TAG_URI
)
2138 * Validate the recipient scheme against the ServerBin/notifier
2142 char notifier
[1024], /* Notifier filename */
2143 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2144 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2145 host
[HTTP_MAX_URI
], /* Host portion of URI */
2146 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2147 int port
; /* Port portion of URI */
2150 recipient
= attr
->values
[0].string
.text
;
2152 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2153 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2154 host
, sizeof(host
), &port
,
2155 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2157 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2158 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2159 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2160 "notify-status-code", IPP_URI_SCHEME
);
2164 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2166 if (access(notifier
, X_OK
))
2168 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2169 _("notify-recipient-uri URI \"%s\" uses unknown "
2170 "scheme."), recipient
);
2171 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2172 "notify-status-code", IPP_URI_SCHEME
);
2176 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2178 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2179 _("notify-recipient-uri URI \"%s\" is already used."),
2181 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2182 "notify-status-code", IPP_ATTRIBUTES
);
2186 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2187 attr
->value_tag
== IPP_TAG_KEYWORD
)
2189 pullmethod
= attr
->values
[0].string
.text
;
2191 if (strcmp(pullmethod
, "ippget"))
2193 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2194 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2195 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2196 "notify-status-code", IPP_ATTRIBUTES
);
2200 else if (!strcmp(attr
->name
, "notify-charset") &&
2201 attr
->value_tag
== IPP_TAG_CHARSET
&&
2202 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2203 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2205 send_ipp_status(con
, IPP_CHARSET
,
2206 _("Character set \"%s\" not supported."),
2207 attr
->values
[0].string
.text
);
2210 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2211 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2212 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2214 send_ipp_status(con
, IPP_CHARSET
,
2215 _("Language \"%s\" not supported."),
2216 attr
->values
[0].string
.text
);
2219 else if (!strcmp(attr
->name
, "notify-user-data") &&
2220 attr
->value_tag
== IPP_TAG_STRING
)
2222 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2224 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2225 _("The notify-user-data value is too large "
2226 "(%d > 63 octets)."),
2227 attr
->values
[0].unknown
.length
);
2233 else if (!strcmp(attr
->name
, "notify-events") &&
2234 attr
->value_tag
== IPP_TAG_KEYWORD
)
2236 for (i
= 0; i
< attr
->num_values
; i
++)
2237 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2239 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2241 send_ipp_status(con
, IPP_BAD_REQUEST
,
2242 _("The notify-lease-duration attribute cannot be "
2243 "used with job subscriptions."));
2246 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2247 attr
->value_tag
== IPP_TAG_INTEGER
)
2248 interval
= attr
->values
[0].integer
;
2253 if (!recipient
&& !pullmethod
)
2256 if (mask
== CUPSD_EVENT_NONE
)
2257 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2259 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2260 recipient
, 0)) != NULL
)
2262 sub
->interval
= interval
;
2264 cupsdSetString(&sub
->owner
, job
->username
);
2268 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2269 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2270 sub
->user_data_len
);
2273 ippAddSeparator(con
->response
);
2274 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2275 "notify-subscription-id", sub
->id
);
2277 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2285 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2288 * Remove all of the subscription attributes from the job request...
2290 * TODO: Optimize this since subscription groups have to come at the
2291 * end of the request...
2294 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2298 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2299 attr
->group_tag
== IPP_TAG_ZERO
)
2302 * Free and remove this attribute...
2310 job
->attrs
->attrs
= next
;
2316 job
->attrs
->last
= prev
;
2317 job
->attrs
->current
= prev
;
2322 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2324 * See RFC 4122 for the definition of UUIDs and the format.
2328 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2330 char uuid
[64]; /* job-uuid string */
2334 * Add a job-uuid attribute if none exists...
2337 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2338 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2339 _httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2340 uuid
, sizeof(uuid
)));
2345 * 'add_printer()' - Add a printer to the system.
2349 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2350 ipp_attribute_t
*uri
) /* I - URI of printer */
2352 http_status_t status
; /* Policy status */
2353 int i
; /* Looping var */
2354 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2355 username
[HTTP_MAX_URI
], /* Username portion of URI */
2356 host
[HTTP_MAX_URI
], /* Host portion of URI */
2357 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2358 int port
; /* Port portion of URI */
2359 cupsd_printer_t
*printer
; /* Printer/class */
2360 ipp_attribute_t
*attr
; /* Printer attribute */
2361 cups_file_t
*fp
; /* Script/PPD file */
2362 char line
[1024]; /* Line from file... */
2363 char srcfile
[1024], /* Source Script/PPD file */
2364 dstfile
[1024]; /* Destination Script/PPD file */
2365 int modify
; /* Non-zero if we are modifying */
2366 char newname
[IPP_MAX_NAME
]; /* New printer name */
2367 int changed_driver
, /* Changed the PPD/interface script? */
2368 need_restart_job
, /* Need to restart job? */
2369 set_device_uri
, /* Did we set the device URI? */
2370 set_port_monitor
; /* Did we set the port monitor? */
2373 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2374 con
->http
.fd
, uri
->values
[0].string
.text
);
2377 * Do we have a valid URI?
2380 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2381 sizeof(scheme
), username
, sizeof(username
), host
,
2382 sizeof(host
), &port
, resource
, sizeof(resource
));
2384 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2387 * No, return an error...
2390 send_ipp_status(con
, IPP_BAD_REQUEST
,
2391 _("The printer-uri must be of the form "
2392 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2397 * Do we have a valid printer name?
2400 if (!validate_name(resource
+ 10))
2403 * No, return an error...
2406 send_ipp_status(con
, IPP_BAD_REQUEST
,
2407 _("The printer-uri \"%s\" contains invalid characters."),
2408 uri
->values
[0].string
.text
);
2413 * See if the printer already exists; if not, create a new printer...
2416 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2419 * Printer doesn't exist; see if we have a class of the same name...
2422 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2423 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2426 * Yes, return an error...
2429 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2430 _("A class named \"%s\" already exists."),
2436 * No, check the default policy then add the printer...
2439 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2441 send_http_error(con
, status
, NULL
);
2445 printer
= cupsdAddPrinter(resource
+ 10);
2448 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2451 * Check the default policy, then rename the implicit printer to
2452 * "AnyPrinter" or delete it...
2455 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2457 send_http_error(con
, status
, NULL
);
2461 if (ImplicitAnyClasses
)
2463 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2464 cupsdRenamePrinter(printer
, newname
);
2467 cupsdDeletePrinter(printer
, 1);
2470 * Add the printer as a new local printer...
2473 printer
= cupsdAddPrinter(resource
+ 10);
2476 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2479 * Check the default policy, then rename the remote printer to
2480 * "Printer@server"...
2483 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2485 send_http_error(con
, status
, NULL
);
2489 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2491 cupsdRenamePrinter(printer
, newname
);
2494 * Add the printer as a new local printer...
2497 printer
= cupsdAddPrinter(resource
+ 10);
2500 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2503 send_http_error(con
, status
, printer
);
2510 * Look for attributes and copy them over as needed...
2514 need_restart_job
= 0;
2516 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2517 IPP_TAG_TEXT
)) != NULL
)
2518 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2520 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2521 IPP_TAG_TEXT
)) != NULL
)
2522 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2526 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2527 IPP_TAG_URI
)) != NULL
)
2530 * Do we have a valid device URI?
2533 http_uri_status_t uri_status
; /* URI separation status */
2534 char old_device_uri
[1024];
2535 /* Old device URI */
2538 need_restart_job
= 1;
2540 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2541 attr
->values
[0].string
.text
,
2542 scheme
, sizeof(scheme
),
2543 username
, sizeof(username
),
2544 host
, sizeof(host
), &port
,
2545 resource
, sizeof(resource
));
2547 if (uri_status
< HTTP_URI_OK
)
2549 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2550 attr
->values
[0].string
.text
);
2551 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2552 "add_printer: httpSeparateURI returned %d", uri_status
);
2556 if (!strcmp(scheme
, "file"))
2559 * See if the administrator has enabled file devices...
2562 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2565 * File devices are disabled and the URL is not file:/dev/null...
2568 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2569 _("File device URIs have been disabled. "
2570 "To enable, see the FileDevice directive in "
2571 "\"%s/cupsd.conf\"."),
2579 * See if the backend exists and is executable...
2582 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2583 if (access(srcfile
, X_OK
))
2586 * Could not find device in list!
2589 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2590 _("Bad device-uri scheme \"%s\"."), scheme
);
2595 if (printer
->sanitized_device_uri
)
2596 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2597 sizeof(old_device_uri
));
2599 old_device_uri
[0] = '\0';
2601 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2603 cupsdLogMessage(CUPSD_LOG_INFO
,
2604 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2605 printer
->name
, printer
->sanitized_device_uri
,
2611 set_port_monitor
= 0;
2613 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2614 IPP_TAG_NAME
)) != NULL
)
2616 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2619 need_restart_job
= 1;
2621 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2625 for (i
= 0; i
< supported
->num_values
; i
++)
2626 if (!strcmp(supported
->values
[i
].string
.text
,
2627 attr
->values
[0].string
.text
))
2631 if (!supported
|| i
>= supported
->num_values
)
2633 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2634 attr
->values
[0].string
.text
);
2638 cupsdLogMessage(CUPSD_LOG_INFO
,
2639 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2640 printer
->name
, attr
->values
[0].string
.text
,
2641 printer
->port_monitor
? printer
->port_monitor
: "none");
2643 if (strcmp(attr
->values
[0].string
.text
, "none"))
2644 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2646 cupsdClearString(&printer
->port_monitor
);
2648 set_port_monitor
= 1;
2651 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2652 IPP_TAG_BOOLEAN
)) != NULL
&&
2653 attr
->values
[0].boolean
!= printer
->accepting
)
2655 cupsdLogMessage(CUPSD_LOG_INFO
,
2656 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2657 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2659 printer
->accepting
= attr
->values
[0].boolean
;
2661 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2662 "%s accepting jobs.",
2663 printer
->accepting
? "Now" : "No longer");
2666 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2667 IPP_TAG_BOOLEAN
)) != NULL
)
2669 if (attr
->values
[0].boolean
&&
2670 printer
->num_auth_info_required
== 1 &&
2671 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2673 send_ipp_status(con
, IPP_BAD_REQUEST
,
2674 _("Cannot share a remote Kerberized printer."));
2678 if (printer
->shared
&& !attr
->values
[0].boolean
)
2679 cupsdDeregisterPrinter(printer
, 1);
2681 cupsdLogMessage(CUPSD_LOG_INFO
,
2682 "Setting %s printer-is-shared to %d (was %d.)",
2683 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2685 printer
->shared
= attr
->values
[0].boolean
;
2688 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2689 IPP_TAG_ENUM
)) != NULL
)
2691 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2692 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2694 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2695 attr
->values
[0].integer
);
2699 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2700 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2702 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2703 cupsdStopPrinter(printer
, 0);
2706 need_restart_job
= 1;
2707 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2711 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2712 IPP_TAG_TEXT
)) != NULL
)
2714 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2715 sizeof(printer
->state_message
));
2717 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2718 printer
->state_message
);
2721 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2722 IPP_TAG_KEYWORD
)) != NULL
)
2724 if (attr
->num_values
>
2725 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2727 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2728 _("Too many printer-state-reasons values (%d > %d)."),
2730 (int)(sizeof(printer
->reasons
) /
2731 sizeof(printer
->reasons
[0])));
2735 for (i
= 0; i
< printer
->num_reasons
; i
++)
2736 _cupsStrFree(printer
->reasons
[i
]);
2738 printer
->num_reasons
= 0;
2739 for (i
= 0; i
< attr
->num_values
; i
++)
2741 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2744 printer
->reasons
[printer
->num_reasons
] =
2745 _cupsStrRetain(attr
->values
[i
].string
.text
);
2746 printer
->num_reasons
++;
2748 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2749 printer
->state
!= IPP_PRINTER_STOPPED
)
2751 cupsdLogMessage(CUPSD_LOG_INFO
,
2752 "Setting %s printer-state to %d (was %d.)",
2753 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2754 cupsdStopPrinter(printer
, 0);
2758 if (PrintcapFormat
== PRINTCAP_PLIST
)
2759 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2761 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2762 "Printer \"%s\" state changed.", printer
->name
);
2765 set_printer_defaults(con
, printer
);
2767 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2768 IPP_TAG_KEYWORD
)) != NULL
)
2769 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2772 * See if we have all required attributes...
2775 if (!printer
->device_uri
)
2776 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2779 * See if we have an interface script or PPD file attached to the request...
2784 need_restart_job
= 1;
2787 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2789 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2792 * Yes; get the first line from it...
2796 cupsFileGets(fp
, line
, sizeof(line
));
2800 * Then see what kind of file it is...
2803 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2806 if (!strncmp(line
, "*PPD-Adobe", 10))
2809 * The new file is a PPD file, so remove any old interface script
2810 * that might be lying around...
2818 * This must be an interface script, so move the file over to the
2819 * interfaces directory and make it executable...
2822 if (copy_file(srcfile
, dstfile
))
2824 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2825 _("Unable to copy interface script - %s"),
2830 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2831 "Copied interface script successfully");
2832 chmod(dstfile
, 0755);
2835 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2838 if (!strncmp(line
, "*PPD-Adobe", 10))
2841 * The new file is a PPD file, so move the file over to the
2842 * ppd directory and make it readable by all...
2845 if (copy_file(srcfile
, dstfile
))
2847 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2848 _("Unable to copy PPD file - %s"),
2853 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2854 "Copied PPD file successfully");
2855 chmod(dstfile
, 0644);
2860 * This must be an interface script, so remove any old PPD file that
2861 * may be lying around...
2868 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2869 IPP_TAG_NAME
)) != NULL
)
2871 need_restart_job
= 1;
2874 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2877 * Raw driver, remove any existing PPD or interface script files.
2880 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2884 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2894 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2898 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2901 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2903 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2907 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2908 "Copied PPD file successfully");
2909 chmod(dstfile
, 0644);
2916 * If we changed the PPD/interface script, then remove the printer's cache
2917 * file and clear the printer-state-reasons...
2920 char cache_name
[1024]; /* Cache filename for printer attrs */
2922 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2926 cupsdSetPrinterReasons(printer
, "none");
2930 * (Re)register color profiles...
2935 apple_unregister_profiles(printer
);
2936 apple_register_profiles(printer
);
2938 #endif /* __APPLE__ */
2942 * If we set the device URI but not the port monitor, check which port
2943 * monitor to use by default...
2946 if (set_device_uri
&& !set_port_monitor
)
2948 ppd_file_t
*ppd
; /* PPD file */
2949 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2952 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2953 sizeof(scheme
), username
, sizeof(username
), host
,
2954 sizeof(host
), &port
, resource
, sizeof(resource
));
2956 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2958 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2960 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2962 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2963 if (!strcmp(scheme
, ppdattr
->spec
))
2965 cupsdLogMessage(CUPSD_LOG_INFO
,
2966 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2967 printer
->name
, ppdattr
->value
,
2968 printer
->port_monitor
? printer
->port_monitor
2971 if (strcmp(ppdattr
->value
, "none"))
2972 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2974 cupsdClearString(&printer
->port_monitor
);
2984 * Update the printer attributes and return...
2987 cupsdSetPrinterAttrs(printer
);
2988 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2990 if (need_restart_job
&& printer
->job
)
2993 * Restart the current job...
2996 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2997 "Job restarted because the printer was modified.");
3000 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3004 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
3005 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
3006 printer
->name
, get_username(con
));
3008 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
3009 printer
->name
, get_username(con
));
3013 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
3014 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
3015 printer
->name
, get_username(con
));
3017 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
3018 printer
->name
, get_username(con
));
3021 con
->response
->request
.status
.status_code
= IPP_OK
;
3026 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
3027 * based upon the printer state...
3031 add_printer_state_reasons(
3032 cupsd_client_t
*con
, /* I - Client connection */
3033 cupsd_printer_t
*p
) /* I - Printer info */
3035 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3036 "add_printer_state_reasons(%p[%d], %p[%s])",
3037 con
, con
->http
.fd
, p
, p
->name
);
3039 if (p
->num_reasons
== 0)
3040 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3041 "printer-state-reasons", NULL
, "none");
3043 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3044 "printer-state-reasons", p
->num_reasons
, NULL
,
3045 (const char * const *)p
->reasons
);
3050 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
3051 * the specified printer or class.
3055 add_queued_job_count(
3056 cupsd_client_t
*con
, /* I - Client connection */
3057 cupsd_printer_t
*p
) /* I - Printer or class */
3059 int count
; /* Number of jobs on destination */
3062 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3063 con
, con
->http
.fd
, p
, p
->name
);
3065 count
= cupsdGetPrinterJobCount(p
->name
);
3067 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3068 "queued-job-count", count
);
3074 * 'apple_init_profile()' - Initialize a color profile.
3079 ppd_file_t
*ppd
, /* I - PPD file */
3080 cups_array_t
*languages
, /* I - Languages in the PPD file */
3081 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3082 CFMutableDictionaryRef profile
, /* I - Profile dictionary */
3084 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3085 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3086 unsigned id
, /* I - Profile ID */
3087 const char *name
, /* I - Profile name */
3088 const char *text
, /* I - Profile UI text */
3089 const char *iccfile
) /* I - ICC filename */
3091 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3092 CFURLRef url
; /* URL for profile filename */
3093 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3094 CFMutableDictionaryRef dict
; /* Dictionary for name */
3095 char *language
; /* Current language */
3096 ppd_attr_t
*attr
; /* Profile attribute */
3097 CFStringRef cflang
, /* Language string */
3098 cftext
; /* Localized text */
3104 * Build the profile name dictionary...
3107 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3108 &kCFTypeDictionaryKeyCallBacks
,
3109 &kCFTypeDictionaryValueCallBacks
);
3112 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to initialize profile \"%s\".",
3117 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3118 kCFStringEncodingUTF8
);
3122 CFDictionarySetValue(dict
, CFSTR("en_US"), cftext
);
3129 * Find localized names for the color profiles...
3132 cupsArraySave(ppd
->sorted_attrs
);
3134 for (language
= (char *)cupsArrayFirst(languages
);
3136 language
= (char *)cupsArrayNext(languages
))
3140 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3142 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3145 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3147 if (attr
&& attr
->text
[0])
3149 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3150 kCFStringEncodingUTF8
);
3151 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3152 kCFStringEncodingUTF8
);
3154 if (cflang
&& cftext
)
3155 CFDictionarySetValue(dict
, cflang
, cftext
);
3165 cupsArrayRestore(ppd
->sorted_attrs
);
3169 * Fill in the profile data...
3172 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3175 url
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
3176 (const UInt8
*)iccfile
,
3177 strlen(iccfile
), false);
3181 CFDictionarySetValue(profile
, kColorSyncDeviceProfileURL
, url
);
3186 CFDictionarySetValue(profile
, kColorSyncDeviceModeDescriptions
, dict
);
3190 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3191 profile
->profileID
= id
;
3192 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3193 profile
->profileName
= dict
;
3196 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3197 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3198 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3203 * 'apple_register_profiles()' - Register color profiles for a printer.
3207 apple_register_profiles(
3208 cupsd_printer_t
*p
) /* I - Printer */
3210 int i
; /* Looping var */
3211 char ppdfile
[1024], /* PPD filename */
3212 iccfile
[1024], /* ICC filename */
3213 selector
[PPD_MAX_NAME
];
3214 /* Profile selection string */
3215 ppd_file_t
*ppd
; /* PPD file */
3216 ppd_attr_t
*attr
, /* Profile attributes */
3217 *profileid_attr
,/* cupsProfileID attribute */
3218 *q1_attr
, /* ColorModel (or other) qualifier */
3219 *q2_attr
, /* MediaType (or other) qualifier */
3220 *q3_attr
; /* Resolution (or other) qualifier */
3221 char q_keyword
[PPD_MAX_NAME
];
3222 /* Qualifier keyword */
3223 const char *q1_choice
, /* ColorModel (or other) choice */
3224 *q2_choice
, /* MediaType (or other) choice */
3225 *q3_choice
; /* Resolution (or other) choice */
3226 const char *profile_key
; /* Profile keyword */
3227 ppd_option_t
*cm_option
; /* Color model option */
3228 ppd_choice_t
*cm_choice
; /* Color model choice */
3229 int num_profiles
; /* Number of profiles */
3230 OSStatus error
= 0; /* Last error */
3231 unsigned device_id
, /* Printer device ID */
3232 profile_id
= 0, /* Profile ID */
3233 default_profile_id
= 0;
3234 /* Default profile ID */
3235 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3236 CFStringRef printer_name
; /* Printer name string */
3237 cups_array_t
*languages
; /* Languages array */
3238 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3239 CFMutableDictionaryRef profiles
, /* Dictionary of profiles */
3240 profile
; /* Current profile info dictionary */
3241 CFStringRef dict_key
; /* Key in factory profile dictionary */
3243 CMDeviceScope scope
= /* Scope of the registration */
3245 kCFPreferencesAnyUser
,
3246 kCFPreferencesCurrentHost
3248 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3249 CMDeviceProfileInfo
*profile
; /* Current profile */
3250 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3254 * Make sure ColorSync is available...
3257 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3258 if (ColorSyncRegisterDevice
== NULL
)
3262 if (CMRegisterColorDevice
== NULL
)
3264 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3267 * Try opening the PPD file for this printer...
3270 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3271 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3275 * See if we have any profiles...
3278 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3279 profile_key
= "APTiogaProfile";
3282 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3283 profile_key
= "cupsICCProfile";
3286 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3287 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3289 if (attr
->value
[0] != '/')
3290 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3293 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3295 if (access(iccfile
, 0))
3297 cupsdLogMessage(CUPSD_LOG_ERROR
,
3298 "%s: ICC Profile \"%s\" does not exist.", p
->name
,
3306 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3308 * Create a dictionary for the factory profiles...
3311 profiles
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3312 &kCFTypeDictionaryKeyCallBacks
,
3313 &kCFTypeDictionaryValueCallBacks
);
3316 cupsdLogMessage(CUPSD_LOG_ERROR
,
3317 "Unable to allocate memory for factory profiles.");
3321 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3324 * If we have profiles, add them...
3327 if (num_profiles
> 0)
3329 if (profile_key
[0] == 'A')
3332 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3336 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3338 default_profile_id
= atoi(attr
->value
);
3340 q1_choice
= q2_choice
= q3_choice
= NULL
;
3345 * For CUPS PPDs, figure out the default profile selector values...
3348 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3349 attr
->value
&& attr
->value
[0])
3351 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3352 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3354 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3355 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3357 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3358 q1_choice
= q1_attr
->value
;
3362 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3363 attr
->value
&& attr
->value
[0])
3365 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3366 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3369 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3371 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3372 q2_choice
= q2_attr
->value
;
3376 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3377 attr
->value
&& attr
->value
[0])
3379 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3380 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3383 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3385 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3386 q3_choice
= q3_attr
->value
;
3391 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3393 * Build the array of profiles...
3395 * Note: This calloc actually requests slightly more memory than needed.
3398 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3400 cupsdLogMessage(CUPSD_LOG_ERROR
,
3401 "Unable to allocate memory for factory profiles.");
3406 profiles
->profileCount
= num_profiles
;
3407 profile
= profiles
->profiles
;
3408 # endif /* !HAVE_COLORSYNCREGISTERDEVICE */
3411 * Loop through the profiles listed in the PPD...
3414 languages
= _ppdGetLanguages(ppd
);
3416 for (attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3418 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3419 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3422 * Add this profile...
3425 if (attr
->value
[0] != '/')
3426 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3429 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3431 if (_cupsFileCheck(iccfile
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
3432 cupsdLogFCMessage
, p
))
3435 if (profile_key
[0] == 'c')
3437 cupsArraySave(ppd
->sorted_attrs
);
3439 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3440 attr
->spec
)) != NULL
&&
3441 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3442 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3444 profile_id
= _ppdHashName(attr
->spec
);
3446 cupsArrayRestore(ppd
->sorted_attrs
);
3449 profile_id
= atoi(attr
->spec
);
3451 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3452 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3453 &kCFTypeDictionaryKeyCallBacks
,
3454 &kCFTypeDictionaryValueCallBacks
);
3457 cupsdLogMessage(CUPSD_LOG_ERROR
,
3458 "Unable to allocate memory for color profile.");
3459 CFRelease(profiles
);
3464 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3465 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3467 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3468 CFSTR("%u"), profile_id
);
3471 CFDictionarySetValue(profiles
, dict_key
, profile
);
3472 CFRelease(dict_key
);
3478 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3479 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3482 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3485 * See if this is the default profile...
3488 if (!default_profile_id
&& q1_choice
&& q2_choice
&& q3_choice
)
3490 snprintf(selector
, sizeof(selector
), "%s.%s.%s", q1_choice
, q2_choice
,
3492 if (!strcmp(selector
, attr
->spec
))
3493 default_profile_id
= profile_id
;
3496 if (!default_profile_id
&& q1_choice
&& q2_choice
)
3498 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
, q2_choice
);
3499 if (!strcmp(selector
, attr
->spec
))
3500 default_profile_id
= profile_id
;
3503 if (!default_profile_id
&& q1_choice
&& q3_choice
)
3505 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
, q3_choice
);
3506 if (!strcmp(selector
, attr
->spec
))
3507 default_profile_id
= profile_id
;
3510 if (!default_profile_id
&& q1_choice
)
3512 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3513 if (!strcmp(selector
, attr
->spec
))
3514 default_profile_id
= profile_id
;
3517 if (!default_profile_id
&& q2_choice
&& q3_choice
)
3519 snprintf(selector
, sizeof(selector
), ".%s.%s", q2_choice
, q3_choice
);
3520 if (!strcmp(selector
, attr
->spec
))
3521 default_profile_id
= profile_id
;
3524 if (!default_profile_id
&& q2_choice
)
3526 snprintf(selector
, sizeof(selector
), ".%s.", q2_choice
);
3527 if (!strcmp(selector
, attr
->spec
))
3528 default_profile_id
= profile_id
;
3531 if (!default_profile_id
&& q3_choice
)
3533 snprintf(selector
, sizeof(selector
), "..%s", q3_choice
);
3534 if (!strcmp(selector
, attr
->spec
))
3535 default_profile_id
= profile_id
;
3539 _ppdFreeLanguages(languages
);
3541 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3544 * Extract profiles from ColorModel option...
3547 const char *profile_name
; /* Name of generic profile */
3550 num_profiles
= cm_option
->num_choices
;
3552 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3554 * Create an array for the factory profiles...
3557 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3559 cupsdLogMessage(CUPSD_LOG_ERROR
,
3560 "Unable to allocate memory for factory profiles.");
3565 profiles
->profileCount
= num_profiles
;
3566 profile
= profiles
->profiles
;
3567 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3569 for (i
= cm_option
->num_choices
, cm_choice
= cm_option
->choices
;
3573 if (!strcmp(cm_choice
->choice
, "Gray") ||
3574 !strcmp(cm_choice
->choice
, "Black"))
3575 profile_name
= "Gray";
3576 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3577 !strcmp(cm_choice
->choice
, "CMY"))
3578 profile_name
= "RGB";
3579 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3580 !strcmp(cm_choice
->choice
, "KCMY"))
3581 profile_name
= "CMYK";
3583 profile_name
= "DeviceN";
3585 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3586 profile_id
= _ppdHashName(selector
);
3588 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3589 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3590 &kCFTypeDictionaryKeyCallBacks
,
3591 &kCFTypeDictionaryValueCallBacks
);
3594 cupsdLogMessage(CUPSD_LOG_ERROR
,
3595 "Unable to allocate memory for color profile.");
3596 CFRelease(profiles
);
3601 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3602 cm_choice
->text
, NULL
);
3604 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3605 CFSTR("%u"), profile_id
);
3608 CFDictionarySetValue(profiles
, dict_key
, profile
);
3609 CFRelease(dict_key
);
3615 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3616 cm_choice
->text
, NULL
);
3618 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3620 if (cm_choice
->marked
)
3621 default_profile_id
= profile_id
;
3627 * Use the default colorspace...
3630 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3632 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3634 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3636 * Add the grayscale profile first. We always have a grayscale profile.
3639 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3640 &kCFTypeDictionaryKeyCallBacks
,
3641 &kCFTypeDictionaryValueCallBacks
);
3645 cupsdLogMessage(CUPSD_LOG_ERROR
,
3646 "Unable to allocate memory for color profile.");
3647 CFRelease(profiles
);
3652 profile_id
= _ppdHashName("Gray..");
3653 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "Gray", "Gray", NULL
);
3655 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3659 CFDictionarySetValue(profiles
, dict_key
, profile
);
3660 CFRelease(dict_key
);
3666 * Then add the RGB/CMYK/DeviceN color profile...
3669 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3670 &kCFTypeDictionaryKeyCallBacks
,
3671 &kCFTypeDictionaryValueCallBacks
);
3675 cupsdLogMessage(CUPSD_LOG_ERROR
,
3676 "Unable to allocate memory for color profile.");
3677 CFRelease(profiles
);
3682 switch (ppd
->colorspace
)
3687 profile_id
= _ppdHashName("RGB..");
3688 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "RGB", "RGB",
3694 profile_id
= _ppdHashName("CMYK..");
3695 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "CMYK", "CMYK",
3704 profile_id
= _ppdHashName("DeviceN..");
3705 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "DeviceN",
3710 if (CFDictionaryGetCount(profile
) > 0)
3712 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3713 CFSTR("%u"), profile_id
);
3716 CFDictionarySetValue(profiles
, dict_key
, profile
);
3717 CFRelease(dict_key
);
3725 * Create an array for the factory profiles...
3728 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3730 cupsdLogMessage(CUPSD_LOG_ERROR
,
3731 "Unable to allocate memory for factory profiles.");
3736 profiles
->profileCount
= num_profiles
;
3739 * Add the grayscale profile first. We always have a grayscale profile.
3742 profile_id
= _ppdHashName("Gray..");
3743 apple_init_profile(ppd
, NULL
, profiles
->profiles
, profile_id
, "Gray",
3747 * Then add the RGB/CMYK/DeviceN color profile...
3750 switch (ppd
->colorspace
)
3755 profile_id
= _ppdHashName("RGB..");
3756 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3757 "RGB", "RGB", NULL
);
3761 profile_id
= _ppdHashName("CMYK..");
3762 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3763 "CMYK", "CMYK", NULL
);
3771 profile_id
= _ppdHashName("DeviceN..");
3772 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3773 "DeviceN", "DeviceN", NULL
);
3776 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3779 if (num_profiles
> 0)
3782 * Make sure we have a default profile ID...
3785 if (!default_profile_id
)
3786 default_profile_id
= profile_id
; /* Last profile */
3788 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3789 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3790 default_profile_id
);
3793 CFDictionarySetValue(profiles
, kColorSyncDeviceDefaultProfileID
,
3795 CFRelease(dict_key
);
3797 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3800 * Get the device ID hash and pathelogical name dictionary.
3803 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3806 device_id
= _ppdHashName(p
->name
);
3807 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3808 &kCFTypeDictionaryKeyCallBacks
,
3809 &kCFTypeDictionaryValueCallBacks
);
3810 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3811 p
->name
, kCFStringEncodingUTF8
);
3813 if (device_name
&& printer_name
)
3815 CFDictionarySetValue(device_name
, CFSTR("en_US"), printer_name
);
3818 * Register the device with ColorSync...
3821 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3822 CFTypeRef deviceDictKeys
[] =
3824 kColorSyncDeviceDescriptions
,
3825 kColorSyncFactoryProfiles
,
3826 kColorSyncDeviceUserScope
,
3827 kColorSyncDeviceHostScope
3829 CFTypeRef deviceDictVals
[] =
3830 { /* Device values */
3833 kCFPreferencesAnyUser
,
3834 kCFPreferencesCurrentHost
3836 CFDictionaryRef deviceDict
; /* Device dictionary */
3837 CFUUIDRef deviceUUID
; /* Device UUID */
3839 deviceDict
= CFDictionaryCreate(kCFAllocatorDefault
,
3840 (const void **)deviceDictKeys
,
3841 (const void **)deviceDictVals
,
3842 sizeof(deviceDictKeys
) /
3843 sizeof(deviceDictKeys
[0]),
3844 &kCFTypeDictionaryKeyCallBacks
,
3845 &kCFTypeDictionaryValueCallBacks
);
3846 deviceUUID
= ColorSyncCreateUUIDFromUInt32(device_id
);
3848 if (!deviceDict
|| !deviceUUID
||
3849 !ColorSyncRegisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
,
3854 CFRelease(deviceUUID
);
3857 CFRelease(deviceDict
);
3860 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3861 device_name
, &scope
);
3864 * Register the profiles...
3868 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3869 default_profile_id
, profiles
);
3870 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3880 cupsdLogMessage(CUPSD_LOG_ERROR
,
3881 "Unable to register ICC color profiles for \"%s\": %d",
3882 p
->name
, (int)error
);
3885 CFRelease(printer_name
);
3888 CFRelease(device_name
);
3892 * Free any memory we used...
3895 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3896 CFRelease(profiles
);
3899 if (num_profiles
> 0)
3901 for (profile
= profiles
->profiles
;
3903 profile
++, num_profiles
--)
3904 CFRelease(profile
->profileName
);
3908 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3915 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3920 apple_unregister_profiles(
3921 cupsd_printer_t
*p
) /* I - Printer */
3924 * Make sure ColorSync is available...
3927 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3928 if (ColorSyncUnregisterDevice
!= NULL
)
3931 * Because we may have registered the printer profiles using a prior device
3932 * ID-based UUID, remove both the old style UUID and current UUID for the
3936 CFUUIDRef deviceUUID
; /* Device UUID */
3938 deviceUUID
= ColorSyncCreateUUIDFromUInt32(_ppdHashName(p
->name
));
3941 ColorSyncUnregisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
);
3942 CFRelease(deviceUUID
);
3947 if (CMUnregisterColorDevice
!= NULL
)
3948 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3949 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3951 #endif /* __APPLE__ */
3955 * 'apply_printer_defaults()' - Apply printer default options to a job.
3959 apply_printer_defaults(
3960 cupsd_printer_t
*printer
, /* I - Printer */
3961 cupsd_job_t
*job
) /* I - Job */
3963 int i
, /* Looping var */
3964 num_options
; /* Number of default options */
3965 cups_option_t
*options
, /* Default options */
3966 *option
; /* Current option */
3970 * Collect all of the default options and add the missing ones to the
3974 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3975 option
= printer
->options
;
3978 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3980 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3985 * Encode these options as attributes in the job object...
3988 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3989 cupsFreeOptions(num_options
, options
);
3994 * 'authenticate_job()' - Set job authentication info.
3998 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3999 ipp_attribute_t
*uri
) /* I - Job URI */
4001 ipp_attribute_t
*attr
, /* job-id attribute */
4002 *auth_info
; /* auth-info attribute */
4003 int jobid
; /* Job ID */
4004 cupsd_job_t
*job
; /* Current job */
4005 char scheme
[HTTP_MAX_URI
],
4006 /* Method portion of URI */
4007 username
[HTTP_MAX_URI
],
4008 /* Username portion of URI */
4010 /* Host portion of URI */
4011 resource
[HTTP_MAX_URI
];
4012 /* Resource portion of URI */
4013 int port
; /* Port portion of URI */
4016 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
4017 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
4020 * Start with "everything is OK" status...
4023 con
->response
->request
.status
.status_code
= IPP_OK
;
4026 * See if we have a job URI or a printer URI...
4029 if (!strcmp(uri
->name
, "printer-uri"))
4032 * Got a printer URI; see if we also have a job-id attribute...
4035 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4036 IPP_TAG_INTEGER
)) == NULL
)
4038 send_ipp_status(con
, IPP_BAD_REQUEST
,
4039 _("Got a printer-uri attribute but no job-id."));
4043 jobid
= attr
->values
[0].integer
;
4048 * Got a job URI; parse it to get the job ID...
4051 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4052 sizeof(scheme
), username
, sizeof(username
), host
,
4053 sizeof(host
), &port
, resource
, sizeof(resource
));
4055 if (strncmp(resource
, "/jobs/", 6))
4061 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
4062 uri
->values
[0].string
.text
);
4066 jobid
= atoi(resource
+ 6);
4070 * See if the job exists...
4073 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4076 * Nope - return a "not found" error...
4079 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
4084 * See if the job has been completed...
4087 if (job
->state_value
!= IPP_JOB_HELD
)
4090 * Return a "not-possible" error...
4093 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4094 _("Job #%d is not held for authentication."),
4100 * See if we have already authenticated...
4103 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
4105 if (!con
->username
[0] && !auth_info
)
4107 cupsd_printer_t
*printer
; /* Job destination */
4111 * No auth data. If we need to authenticate via Kerberos, send a
4112 * HTTP auth challenge, otherwise just return an IPP error...
4115 printer
= cupsdFindDest(job
->dest
);
4117 if (printer
&& printer
->num_auth_info_required
> 0 &&
4118 !strcmp(printer
->auth_info_required
[0], "negotiate"))
4119 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
4121 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
4122 _("No authentication information provided."));
4127 * See if the job is owned by the requesting user...
4130 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4132 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4133 cupsdFindDest(job
->dest
));
4138 * Save the authentication information for this job...
4141 save_auth_info(con
, job
, auth_info
);
4144 * Reset the job-hold-until value to "no-hold"...
4147 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4148 IPP_TAG_KEYWORD
)) == NULL
)
4149 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4153 attr
->value_tag
= IPP_TAG_KEYWORD
;
4154 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
4158 * Release the job and return...
4161 cupsdReleaseJob(job
);
4163 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
4165 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
4172 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
4176 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
4177 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4179 int i
; /* Looping var */
4180 http_status_t status
; /* Policy status */
4181 cups_ptype_t dtype
; /* Destination type */
4182 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4183 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
4184 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
4185 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4186 int port
; /* Port portion of URI */
4187 ipp_attribute_t
*attr
; /* Attribute in request */
4188 const char *username
= NULL
; /* Username */
4189 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
4191 cupsd_printer_t
*printer
; /* Printer */
4192 ipp_attribute_t
*job_ids
; /* job-ids attribute */
4193 cupsd_job_t
*job
; /* Job */
4196 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
4197 con
->http
.fd
, uri
->values
[0].string
.text
);
4200 * Get the jobs to cancel/purge...
4203 switch (con
->request
->request
.op
.operation_id
)
4205 case IPP_PURGE_JOBS
:
4207 * Get the username (if any) for the jobs we want to cancel (only if
4208 * "my-jobs" is specified...
4211 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
4212 IPP_TAG_BOOLEAN
)) != NULL
&&
4213 attr
->values
[0].boolean
)
4215 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4216 IPP_TAG_NAME
)) != NULL
)
4217 username
= attr
->values
[0].string
.text
;
4220 send_ipp_status(con
, IPP_BAD_REQUEST
,
4221 _("Missing requesting-user-name attribute."));
4227 * Look for the "purge-jobs" attribute...
4230 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
4231 IPP_TAG_BOOLEAN
)) != NULL
)
4232 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4234 purge
= CUPSD_JOB_PURGE
;
4237 case IPP_CANCEL_MY_JOBS
:
4238 if (con
->username
[0])
4239 username
= con
->username
;
4240 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4241 IPP_TAG_NAME
)) != NULL
)
4242 username
= attr
->values
[0].string
.text
;
4245 send_ipp_status(con
, IPP_BAD_REQUEST
,
4246 _("Missing requesting-user-name attribute."));
4254 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
4257 * See if we have a printer URI...
4260 if (strcmp(uri
->name
, "printer-uri"))
4262 send_ipp_status(con
, IPP_BAD_REQUEST
,
4263 _("The printer-uri attribute is required."));
4268 * And if the destination is valid...
4271 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4277 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
4278 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
4279 hostname
, sizeof(hostname
), &port
,
4280 resource
, sizeof(resource
));
4282 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
4283 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
4285 send_ipp_status(con
, IPP_NOT_FOUND
,
4286 _("The printer or class does not exist."));
4294 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
4296 send_http_error(con
, status
, NULL
);
4302 for (i
= 0; i
< job_ids
->num_values
; i
++)
4304 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
4308 if (i
< job_ids
->num_values
)
4310 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4311 job_ids
->values
[i
].integer
);
4315 for (i
= 0; i
< job_ids
->num_values
; i
++)
4317 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4319 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4320 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4321 "Job canceled by user.");
4324 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4325 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4331 * Cancel all jobs on all printers...
4334 cupsdCancelJobs(NULL
, username
, purge
);
4336 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
4337 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4347 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4350 send_http_error(con
, status
, printer
);
4356 for (i
= 0; i
< job_ids
->num_values
; i
++)
4358 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
4359 _cups_strcasecmp(job
->dest
, printer
->name
))
4363 if (i
< job_ids
->num_values
)
4365 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4366 job_ids
->values
[i
].integer
);
4370 for (i
= 0; i
< job_ids
->num_values
; i
++)
4372 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4374 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4375 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4376 "Job canceled by user.");
4379 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4380 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4386 * Cancel all of the jobs on the named printer...
4389 cupsdCancelJobs(printer
->name
, username
, purge
);
4391 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
4393 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4398 con
->response
->request
.status
.status_code
= IPP_OK
;
4403 * 'cancel_job()' - Cancel a print job.
4407 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
4408 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4410 ipp_attribute_t
*attr
; /* Current attribute */
4411 int jobid
; /* Job ID */
4412 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4413 username
[HTTP_MAX_URI
], /* Username portion of URI */
4414 host
[HTTP_MAX_URI
], /* Host portion of URI */
4415 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4416 int port
; /* Port portion of URI */
4417 cupsd_job_t
*job
; /* Job information */
4418 cups_ptype_t dtype
; /* Destination type (printer/class) */
4419 cupsd_printer_t
*printer
; /* Printer data */
4420 cupsd_jobaction_t purge
; /* Purge the job? */
4423 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
4424 con
->http
.fd
, uri
->values
[0].string
.text
);
4427 * See if we have a job URI or a printer URI...
4430 if (!strcmp(uri
->name
, "printer-uri"))
4433 * Got a printer URI; see if we also have a job-id attribute...
4436 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4437 IPP_TAG_INTEGER
)) == NULL
)
4439 send_ipp_status(con
, IPP_BAD_REQUEST
,
4440 _("Got a printer-uri attribute but no job-id."));
4444 if ((jobid
= attr
->values
[0].integer
) == 0)
4447 * Find the current job on the specified printer...
4450 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4456 send_ipp_status(con
, IPP_NOT_FOUND
,
4457 _("The printer or class does not exist."));
4462 * See if there are any pending jobs...
4465 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4467 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4468 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
4469 !_cups_strcasecmp(job
->dest
, printer
->name
))
4477 * No, try stopped jobs...
4480 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4482 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4483 if (job
->state_value
== IPP_JOB_STOPPED
&&
4484 !_cups_strcasecmp(job
->dest
, printer
->name
))
4491 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
4501 * Got a job URI; parse it to get the job ID...
4504 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4505 sizeof(scheme
), username
, sizeof(username
), host
,
4506 sizeof(host
), &port
, resource
, sizeof(resource
));
4508 if (strncmp(resource
, "/jobs/", 6))
4514 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
4515 uri
->values
[0].string
.text
);
4519 jobid
= atoi(resource
+ 6);
4523 * Look for the "purge-job" attribute...
4526 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4527 IPP_TAG_BOOLEAN
)) != NULL
)
4528 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4530 purge
= CUPSD_JOB_DEFAULT
;
4533 * See if the job exists...
4536 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4539 * Nope - return a "not found" error...
4542 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
4547 * See if the job is owned by the requesting user...
4550 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4552 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4553 cupsdFindDest(job
->dest
));
4558 * See if the job is already completed, canceled, or aborted; if so,
4559 * we can't cancel...
4562 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4564 switch (job
->state_value
)
4566 case IPP_JOB_CANCELED
:
4567 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4568 _("Job #%d is already canceled - can\'t cancel."),
4572 case IPP_JOB_ABORTED
:
4573 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4574 _("Job #%d is already aborted - can\'t cancel."),
4579 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4580 _("Job #%d is already completed - can\'t cancel."),
4589 * Cancel the job and return...
4592 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4593 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4594 "Job canceled by \"%s\"",
4598 if (purge
== CUPSD_JOB_PURGE
)
4599 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4602 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4605 con
->response
->request
.status
.status_code
= IPP_OK
;
4610 * 'cancel_subscription()' - Cancel a subscription.
4614 cancel_subscription(
4615 cupsd_client_t
*con
, /* I - Client connection */
4616 int sub_id
) /* I - Subscription ID */
4618 http_status_t status
; /* Policy status */
4619 cupsd_subscription_t
*sub
; /* Subscription */
4622 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4623 "cancel_subscription(con=%p[%d], sub_id=%d)",
4624 con
, con
->http
.fd
, sub_id
);
4627 * Is the subscription ID valid?
4630 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4633 * Bad subscription ID...
4636 send_ipp_status(con
, IPP_NOT_FOUND
,
4637 _("Subscription #%d does not exist."), sub_id
);
4645 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4647 con
, sub
->owner
)) != HTTP_OK
)
4649 send_http_error(con
, status
, sub
->dest
);
4654 * Cancel the subscription...
4657 cupsdDeleteSubscription(sub
, 1);
4659 con
->response
->request
.status
.status_code
= IPP_OK
;
4664 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4667 static int /* O - 1 if OK, 0 if not */
4668 check_rss_recipient(
4669 const char *recipient
) /* I - Recipient URI */
4671 cupsd_subscription_t
*sub
; /* Current subscription */
4674 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4676 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4680 * Compare the URIs up to the first ?...
4683 const char *r1
, *r2
;
4685 for (r1
= recipient
, r2
= sub
->recipient
;
4686 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4698 * 'check_quotas()' - Check quotas for a printer and user.
4701 static int /* O - 1 if OK, 0 if forbidden,
4702 -1 if limit reached */
4703 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4704 cupsd_printer_t
*p
) /* I - Printer or class */
4706 char username
[33], /* Username */
4707 *name
; /* Current user name */
4708 cupsd_quota_t
*q
; /* Quota data */
4709 #ifdef HAVE_MBR_UID_TO_UUID
4711 * Use Apple membership APIs which require that all names represent
4712 * valid user account or group records accessible by the server.
4715 uuid_t usr_uuid
; /* UUID for job requesting user */
4716 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4717 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4718 int mbr_err
; /* Error from membership function */
4719 int is_member
; /* Is this user a member? */
4722 * Use standard POSIX APIs for checking users and groups...
4725 struct passwd
*pw
; /* User password data */
4726 #endif /* HAVE_MBR_UID_TO_UUID */
4729 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4730 con
, con
->http
.fd
, p
, p
->name
);
4733 * Figure out who is printing...
4736 strlcpy(username
, get_username(con
), sizeof(username
));
4739 * Check global active job limits for printers and users...
4742 if (MaxJobsPerPrinter
)
4745 * Check if there are too many pending jobs on this printer...
4748 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4750 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4759 * Check if there are too many pending jobs for this user...
4762 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4764 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4771 * Check against users...
4774 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4777 if (cupsArrayCount(p
->users
))
4779 #ifdef HAVE_MBR_UID_TO_UUID
4781 * Get UUID for job requesting user...
4784 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4790 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4791 "check_quotas: UUID lookup failed for user \"%s\"",
4793 cupsdLogMessage(CUPSD_LOG_INFO
,
4794 "Denying user \"%s\" access to printer \"%s\" "
4795 "(unknown user)...",
4801 * Get UID and GID of requesting user...
4804 pw
= getpwnam(username
);
4806 #endif /* HAVE_MBR_UID_TO_UUID */
4808 for (name
= (char *)cupsArrayFirst(p
->users
);
4810 name
= (char *)cupsArrayNext(p
->users
))
4814 * Check group membership...
4817 #ifdef HAVE_MBR_UID_TO_UUID
4820 if (uuid_parse(name
+ 2, grp_uuid
))
4821 uuid_clear(grp_uuid
);
4823 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
4826 * Invalid ACL entries are ignored for matching; just record a
4827 * warning in the log...
4830 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4831 "check_quotas: UUID lookup failed for ACL entry "
4832 "\"%s\" (err=%d)", name
, mbr_err
);
4833 cupsdLogMessage(CUPSD_LOG_WARN
,
4834 "Access control entry \"%s\" not a valid group name; "
4835 "entry ignored", name
);
4838 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4842 * At this point, there should be no errors, but check anyways...
4845 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4846 "check_quotas: group \"%s\" membership check "
4847 "failed (err=%d)", name
+ 1, mbr_err
);
4852 * Stop if we found a match...
4859 if (cupsdCheckGroup(username
, pw
, name
+ 1))
4861 #endif /* HAVE_MBR_UID_TO_UUID */
4863 #ifdef HAVE_MBR_UID_TO_UUID
4868 if (uuid_parse(name
+ 1, usr2_uuid
))
4869 uuid_clear(usr2_uuid
);
4871 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
4874 * Invalid ACL entries are ignored for matching; just record a
4875 * warning in the log...
4878 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4879 "check_quotas: UUID lookup failed for ACL entry "
4880 "\"%s\" (err=%d)", name
, mbr_err
);
4881 cupsdLogMessage(CUPSD_LOG_WARN
,
4882 "Access control entry \"%s\" not a valid user name; "
4883 "entry ignored", name
);
4886 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4890 else if (!_cups_strcasecmp(username
, name
))
4892 #endif /* HAVE_MBR_UID_TO_UUID */
4894 if ((name
!= NULL
) == p
->deny_users
)
4896 cupsdLogMessage(CUPSD_LOG_INFO
,
4897 "Denying user \"%s\" access to printer \"%s\"...",
4907 if (p
->k_limit
|| p
->page_limit
)
4909 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4911 cupsdLogMessage(CUPSD_LOG_ERROR
,
4912 "Unable to allocate quota data for user \"%s\"",
4917 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4918 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4920 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4927 * If we have gotten this far, we're done!
4935 * 'close_job()' - Close a multi-file job.
4939 close_job(cupsd_client_t
*con
, /* I - Client connection */
4940 ipp_attribute_t
*uri
) /* I - Printer URI */
4942 cupsd_job_t
*job
; /* Job */
4943 ipp_attribute_t
*attr
; /* Attribute */
4944 char job_uri
[HTTP_MAX_URI
],
4946 username
[256]; /* User name */
4949 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4950 con
->http
.fd
, uri
->values
[0].string
.text
);
4953 * See if we have a job URI or a printer URI...
4956 if (strcmp(uri
->name
, "printer-uri"))
4959 * job-uri is not supported by Close-Job!
4962 send_ipp_status(con
, IPP_BAD_REQUEST
,
4963 _("Close-Job doesn't support the job-uri attribute."));
4968 * Got a printer URI; see if we also have a job-id attribute...
4971 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4972 IPP_TAG_INTEGER
)) == NULL
)
4974 send_ipp_status(con
, IPP_BAD_REQUEST
,
4975 _("Got a printer-uri attribute but no job-id."));
4979 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4982 * Nope - return a "not found" error...
4985 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4986 attr
->values
[0].integer
);
4991 * See if the job is owned by the requesting user...
4994 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4996 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4997 cupsdFindDest(job
->dest
));
5002 * Add any ending sheet...
5005 if (cupsdTimeoutJob(job
))
5008 if (job
->state_value
== IPP_JOB_STOPPED
)
5010 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5011 job
->state_value
= IPP_JOB_PENDING
;
5013 else if (job
->state_value
== IPP_JOB_HELD
)
5015 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
5016 IPP_TAG_KEYWORD
)) == NULL
)
5017 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
5019 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
5021 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5022 job
->state_value
= IPP_JOB_PENDING
;
5027 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
5030 * Fill in the response info...
5033 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
5034 LocalPort
, job
->id
);
5035 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
5038 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
5040 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
5043 add_job_state_reasons(con
, job
);
5045 con
->response
->request
.status
.status_code
= IPP_OK
;
5048 * Start the job if necessary...
5056 * 'copy_attribute()' - Copy a single attribute.
5059 static ipp_attribute_t
* /* O - New attribute */
5061 ipp_t
*to
, /* O - Destination request/response */
5062 ipp_attribute_t
*attr
, /* I - Attribute to copy */
5063 int quickcopy
) /* I - Do a quick copy? */
5065 int i
; /* Looping var */
5066 ipp_attribute_t
*toattr
; /* Destination attribute */
5069 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5070 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
5071 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
5074 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
5077 toattr
= ippAddSeparator(to
);
5080 case IPP_TAG_INTEGER
:
5082 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5083 attr
->name
, attr
->num_values
, NULL
);
5085 for (i
= 0; i
< attr
->num_values
; i
++)
5086 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
5089 case IPP_TAG_BOOLEAN
:
5090 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
5091 attr
->num_values
, NULL
);
5093 for (i
= 0; i
< attr
->num_values
; i
++)
5094 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
5097 case IPP_TAG_STRING
:
5100 case IPP_TAG_KEYWORD
:
5102 case IPP_TAG_URISCHEME
:
5103 case IPP_TAG_CHARSET
:
5104 case IPP_TAG_LANGUAGE
:
5105 case IPP_TAG_MIMETYPE
:
5106 toattr
= ippAddStrings(to
, attr
->group_tag
,
5107 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5108 attr
->name
, attr
->num_values
, NULL
, NULL
);
5112 for (i
= 0; i
< attr
->num_values
; i
++)
5113 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5115 else if (attr
->value_tag
& IPP_TAG_COPY
)
5117 for (i
= 0; i
< attr
->num_values
; i
++)
5118 toattr
->values
[i
].string
.text
=
5119 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5123 for (i
= 0; i
< attr
->num_values
; i
++)
5124 toattr
->values
[i
].string
.text
=
5125 _cupsStrRetain(attr
->values
[i
].string
.text
);
5130 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
5131 attr
->values
[0].date
);
5134 case IPP_TAG_RESOLUTION
:
5135 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
5136 attr
->num_values
, IPP_RES_PER_INCH
,
5139 for (i
= 0; i
< attr
->num_values
; i
++)
5141 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
5142 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
5143 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
5147 case IPP_TAG_RANGE
:
5148 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
5149 attr
->num_values
, NULL
, NULL
);
5151 for (i
= 0; i
< attr
->num_values
; i
++)
5153 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
5154 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
5158 case IPP_TAG_TEXTLANG
:
5159 case IPP_TAG_NAMELANG
:
5160 toattr
= ippAddStrings(to
, attr
->group_tag
,
5161 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5162 attr
->name
, attr
->num_values
, NULL
, NULL
);
5166 for (i
= 0; i
< attr
->num_values
; i
++)
5168 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
5169 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5172 else if (attr
->value_tag
& IPP_TAG_COPY
)
5174 for (i
= 0; i
< attr
->num_values
; i
++)
5177 toattr
->values
[i
].string
.charset
=
5178 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
5180 toattr
->values
[i
].string
.charset
=
5181 toattr
->values
[0].string
.charset
;
5183 toattr
->values
[i
].string
.text
=
5184 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5189 for (i
= 0; i
< attr
->num_values
; i
++)
5192 toattr
->values
[i
].string
.charset
=
5193 _cupsStrRetain(attr
->values
[i
].string
.charset
);
5195 toattr
->values
[i
].string
.charset
=
5196 toattr
->values
[0].string
.charset
;
5198 toattr
->values
[i
].string
.text
=
5199 _cupsStrRetain(attr
->values
[i
].string
.text
);
5204 case IPP_TAG_BEGIN_COLLECTION
:
5205 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
5206 attr
->num_values
, NULL
);
5208 for (i
= 0; i
< attr
->num_values
; i
++)
5210 toattr
->values
[i
].collection
= attr
->values
[i
].collection
;
5211 attr
->values
[i
].collection
->use
++;
5216 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5217 attr
->name
, attr
->num_values
, NULL
);
5219 for (i
= 0; i
< attr
->num_values
; i
++)
5221 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
5223 if (toattr
->values
[i
].unknown
.length
> 0)
5225 if ((toattr
->values
[i
].unknown
.data
=
5226 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
5227 toattr
->values
[i
].unknown
.length
= 0;
5229 memcpy(toattr
->values
[i
].unknown
.data
,
5230 attr
->values
[i
].unknown
.data
,
5231 toattr
->values
[i
].unknown
.length
);
5234 break; /* anti-compiler-warning-code */
5242 * 'copy_attrs()' - Copy attributes from one request to another.
5246 copy_attrs(ipp_t
*to
, /* I - Destination request */
5247 ipp_t
*from
, /* I - Source request */
5248 cups_array_t
*ra
, /* I - Requested attributes */
5249 ipp_tag_t group
, /* I - Group to copy */
5250 int quickcopy
, /* I - Do a quick copy? */
5251 cups_array_t
*exclude
) /* I - Attributes to exclude? */
5253 ipp_attribute_t
*fromattr
; /* Source attribute */
5256 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5257 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
5258 to
, from
, ra
, group
, quickcopy
);
5263 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
5266 * Filter attributes as needed...
5269 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
5270 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
5273 if (!strcmp(fromattr
->name
, "job-printer-uri"))
5277 (cupsArrayFind(exclude
, fromattr
->name
) ||
5278 cupsArrayFind(exclude
, "all")))
5281 * We need to exclude this attribute for security reasons; we require the
5282 * job-id attribute regardless of the security settings for IPP
5285 * The job-printer-uri attribute is handled by copy_job_attrs().
5287 * Subscription attribute security is handled by copy_subscription_attrs().
5290 if (strcmp(fromattr
->name
, "job-id"))
5294 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
5297 * Don't send collection attributes by default to IPP/1.x clients
5298 * since many do not support collections. Also don't send
5299 * media-col-database unless specifically requested by the client.
5302 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
5304 (to
->request
.status
.version
[0] == 1 ||
5305 !strcmp(fromattr
->name
, "media-col-database")))
5308 copy_attribute(to
, fromattr
, quickcopy
);
5315 * 'copy_banner()' - Copy a banner file to the requests directory for the
5319 static int /* O - Size of banner file in kbytes */
5320 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
5321 cupsd_job_t
*job
, /* I - Job information */
5322 const char *name
) /* I - Name of banner */
5324 int i
; /* Looping var */
5325 int kbytes
; /* Size of banner file in kbytes */
5326 char filename
[1024]; /* Job filename */
5327 cupsd_banner_t
*banner
; /* Pointer to banner */
5328 cups_file_t
*in
; /* Input file */
5329 cups_file_t
*out
; /* Output file */
5330 int ch
; /* Character from file */
5331 char attrname
[255], /* Name of attribute */
5332 *s
; /* Pointer into name */
5333 ipp_attribute_t
*attr
; /* Attribute */
5336 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5337 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
5338 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
5339 name
? name
: "(null)");
5342 * Find the banner; return if not found or "none"...
5345 if (!name
|| !strcmp(name
, "none") ||
5346 (banner
= cupsdFindBanner(name
)) == NULL
)
5350 * Open the banner and job files...
5353 if (add_file(con
, job
, banner
->filetype
, 0))
5356 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
5358 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
5360 cupsdLogMessage(CUPSD_LOG_ERROR
,
5361 "Unable to create banner job file %s - %s",
5362 filename
, strerror(errno
));
5367 fchmod(cupsFileNumber(out
), 0640);
5368 fchown(cupsFileNumber(out
), RunUser
, Group
);
5371 * Try the localized banner file under the subdirectory...
5374 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5376 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5379 * Convert ll-cc to ll_CC...
5383 attrname
[3] = toupper(attrname
[3] & 255);
5384 attrname
[4] = toupper(attrname
[4] & 255);
5387 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5390 if (access(filename
, 0) && strlen(attrname
) > 2)
5393 * Wasn't able to find "ll_CC" locale file; try the non-national
5394 * localization banner directory.
5399 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5403 if (access(filename
, 0))
5406 * Use the non-localized banner file.
5409 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5412 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5416 cupsdLogMessage(CUPSD_LOG_ERROR
,
5417 "Unable to open banner template file %s - %s",
5418 filename
, strerror(errno
));
5424 * Parse the file to the end...
5427 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5431 * Get an attribute name...
5434 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5435 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5437 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5447 * Ignore { followed by stuff that is not an attribute name...
5450 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5455 * See if it is defined...
5458 if (attrname
[0] == '?')
5463 if (!strcmp(s
, "printer-name"))
5465 cupsFilePuts(out
, job
->dest
);
5468 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5471 * See if we have a leading question mark...
5474 if (attrname
[0] != '?')
5477 * Nope, write to file as-is; probably a PostScript procedure...
5480 cupsFilePrintf(out
, "{%s}", attrname
);
5487 * Output value(s)...
5490 for (i
= 0; i
< attr
->num_values
; i
++)
5493 cupsFilePutChar(out
, ',');
5495 switch (attr
->value_tag
)
5497 case IPP_TAG_INTEGER
:
5499 if (!strncmp(s
, "time-at-", 8))
5501 struct timeval tv
; /* Time value */
5503 tv
.tv_sec
= attr
->values
[i
].integer
;
5506 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5509 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5512 case IPP_TAG_BOOLEAN
:
5513 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5516 case IPP_TAG_NOVALUE
:
5517 cupsFilePuts(out
, "novalue");
5520 case IPP_TAG_RANGE
:
5521 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5522 attr
->values
[i
].range
.upper
);
5525 case IPP_TAG_RESOLUTION
:
5526 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5527 attr
->values
[i
].resolution
.yres
,
5528 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5533 case IPP_TAG_STRING
:
5536 case IPP_TAG_KEYWORD
:
5537 case IPP_TAG_CHARSET
:
5538 case IPP_TAG_LANGUAGE
:
5539 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
5542 * Need to quote strings for PS banners...
5547 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5549 if (*p
== '(' || *p
== ')' || *p
== '\\')
5551 cupsFilePutChar(out
, '\\');
5552 cupsFilePutChar(out
, *p
);
5554 else if (*p
< 32 || *p
> 126)
5555 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5557 cupsFilePutChar(out
, *p
);
5561 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5565 break; /* anti-compiler-warning-code */
5569 else if (ch
== '\\') /* Quoted char */
5571 ch
= cupsFileGetChar(in
);
5573 if (ch
!= '{') /* Only do special handling for \{ */
5574 cupsFilePutChar(out
, '\\');
5576 cupsFilePutChar(out
, ch
);
5579 cupsFilePutChar(out
, ch
);
5583 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5585 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5586 IPP_TAG_INTEGER
)) != NULL
)
5587 attr
->values
[0].integer
+= kbytes
;
5596 * 'copy_file()' - Copy a PPD file or interface script...
5599 static int /* O - 0 = success, -1 = error */
5600 copy_file(const char *from
, /* I - Source file */
5601 const char *to
) /* I - Destination file */
5603 cups_file_t
*src
, /* Source file */
5604 *dst
; /* Destination file */
5605 int bytes
; /* Bytes to read/write */
5606 char buffer
[2048]; /* Copy buffer */
5609 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5612 * Open the source and destination file for a copy...
5615 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5618 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5625 * Copy the source file to the destination...
5628 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5629 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5637 * Close both files and return...
5642 return (cupsFileClose(dst
));
5647 * 'copy_model()' - Copy a PPD model file, substituting default values
5651 static int /* O - 0 = success, -1 = error */
5652 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5653 const char *from
, /* I - Source file */
5654 const char *to
) /* I - Destination file */
5656 fd_set input
; /* select() input set */
5657 struct timeval timeout
; /* select() timeout */
5658 int maxfd
; /* Max file descriptor for select() */
5659 char tempfile
[1024]; /* Temporary PPD file */
5660 int tempfd
; /* Temporary PPD file descriptor */
5661 int temppid
; /* Process ID of cups-driverd */
5662 int temppipe
[2]; /* Temporary pipes */
5663 char *argv
[4], /* Command-line arguments */
5664 *envp
[MAX_ENV
]; /* Environment */
5665 cups_file_t
*src
, /* Source file */
5666 *dst
; /* Destination file */
5667 ppd_file_t
*ppd
; /* PPD file */
5668 int bytes
, /* Bytes from pipe */
5669 total
; /* Total bytes from pipe */
5670 char buffer
[2048]; /* Copy buffer */
5671 int i
; /* Looping var */
5672 char option
[PPD_MAX_NAME
], /* Option name */
5673 choice
[PPD_MAX_NAME
]; /* Choice name */
5674 ppd_size_t
*size
; /* Default size */
5675 int num_defaults
; /* Number of default options */
5676 cups_option_t
*defaults
; /* Default options */
5677 char cups_protocol
[PPD_MAX_LINE
];
5678 /* cupsProtocol attribute */
5681 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5682 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5686 * Run cups-driverd to get the PPD file...
5689 argv
[0] = "cups-driverd";
5691 argv
[2] = (char *)from
;
5694 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5696 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5697 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5698 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5699 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
5702 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5703 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5705 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5706 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5717 * Wait up to 30 seconds for the PPD file to be copied...
5722 if (temppipe
[0] > CGIPipes
[0])
5723 maxfd
= temppipe
[0] + 1;
5725 maxfd
= CGIPipes
[0] + 1;
5730 * See if we have data ready...
5734 FD_SET(temppipe
[0], &input
);
5735 FD_SET(CGIPipes
[0], &input
);
5737 timeout
.tv_sec
= 30;
5738 timeout
.tv_usec
= 0;
5740 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5750 * We have timed out...
5756 if (FD_ISSET(temppipe
[0], &input
))
5759 * Read the PPD file from the pipe, and write it to the PPD file.
5762 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5764 if (write(tempfd
, buffer
, bytes
) < bytes
)
5773 if (FD_ISSET(CGIPipes
[0], &input
))
5783 * No data from cups-deviced...
5786 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5792 * Read the source file and see what page sizes are supported...
5795 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5802 * Open the destination (if possible) and set the default options...
5807 cups_protocol
[0] = '\0';
5809 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5812 * Read all of the default lines from the old PPD...
5815 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5816 if (!strncmp(buffer
, "*Default", 8))
5819 * Add the default option...
5822 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5823 choice
, sizeof(choice
)))
5825 ppd_option_t
*ppdo
; /* PPD option */
5829 * Only add the default if the default hasn't already been
5830 * set and the choice exists in the new PPD...
5833 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5834 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5835 ppdFindChoice(ppdo
, choice
))
5836 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5840 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5841 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5845 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5848 * Add the default media sizes...
5851 num_defaults
= cupsAddOption("PageSize", size
->name
,
5852 num_defaults
, &defaults
);
5853 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5854 num_defaults
, &defaults
);
5855 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5856 num_defaults
, &defaults
);
5857 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5858 num_defaults
, &defaults
);
5864 * Open the source file for a copy...
5867 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5869 cupsFreeOptions(num_defaults
, defaults
);
5875 * Open the destination file for a copy...
5878 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5880 cupsFreeOptions(num_defaults
, defaults
);
5887 * Copy the source file to the destination...
5890 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5892 if (!strncmp(buffer
, "*Default", 8))
5895 * Check for an previous default option choice...
5898 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5899 choice
, sizeof(choice
)))
5901 const char *val
; /* Default option value */
5904 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5907 * Substitute the previous choice...
5910 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5915 cupsFilePrintf(dst
, "%s\n", buffer
);
5918 if (cups_protocol
[0])
5919 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5921 cupsFreeOptions(num_defaults
, defaults
);
5924 * Close both files and return...
5931 return (cupsFileClose(dst
));
5936 * 'copy_job_attrs()' - Copy job attributes.
5940 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5941 cupsd_job_t
*job
, /* I - Job */
5942 cups_array_t
*ra
, /* I - Requested attributes array */
5943 cups_array_t
*exclude
) /* I - Private attributes array */
5945 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5949 * Send the requested attributes for each job...
5952 if (!cupsArrayFind(exclude
, "all"))
5954 if ((!exclude
|| !cupsArrayFind(exclude
, "document-count")) &&
5955 (!ra
|| cupsArrayFind(ra
, "document-count")))
5956 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5957 "document-count", job
->num_files
);
5959 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
5960 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
5961 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5962 "job-media-progress", job
->progress
);
5964 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
5965 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
5967 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
5968 NULL
, con
->servername
, con
->serverport
, "/jobs/%d",
5970 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5971 "job-more-info", NULL
, job_uri
);
5974 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5975 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
5976 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5977 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5978 job
->num_files
> 0);
5980 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
5981 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
5982 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5983 "job-printer-up-time", time(NULL
));
5986 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
5988 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5989 con
->servername
, con
->serverport
,
5990 job
->dtype
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
) ?
5991 "/classes/%s" : "/printers/%s",
5993 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5994 "job-printer-uri", NULL
, job_uri
);
5997 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5998 add_job_state_reasons(con
, job
);
6000 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
6002 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
6003 con
->servername
, con
->serverport
, "/jobs/%d",
6005 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
6006 "job-uri", NULL
, job_uri
);
6009 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
6014 * 'copy_printer_attrs()' - Copy printer attributes.
6019 cupsd_client_t
*con
, /* I - Client connection */
6020 cupsd_printer_t
*printer
, /* I - Printer */
6021 cups_array_t
*ra
) /* I - Requested attributes array */
6023 char printer_uri
[HTTP_MAX_URI
];
6025 char printer_icons
[HTTP_MAX_URI
];
6027 time_t curtime
; /* Current time */
6028 int i
; /* Looping var */
6032 * Copy the printer attributes to the response using requested-attributes
6033 * and document-format attributes that may be provided by the client.
6036 curtime
= time(NULL
);
6038 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
6039 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6040 "marker-change-time", printer
->marker_time
);
6042 if (printer
->num_printers
> 0 &&
6043 (!ra
|| cupsArrayFind(ra
, "member-uris")))
6045 ipp_attribute_t
*member_uris
; /* member-uris attribute */
6046 cupsd_printer_t
*p2
; /* Printer in class */
6047 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
6050 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
6051 IPP_TAG_URI
, "member-uris",
6052 printer
->num_printers
, NULL
,
6055 for (i
= 0; i
< printer
->num_printers
; i
++)
6057 p2
= printer
->printers
[i
];
6059 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
6060 IPP_TAG_URI
)) != NULL
)
6061 member_uris
->values
[i
].string
.text
=
6062 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
6065 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
6066 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
6068 (p2
->type
& CUPS_PRINTER_CLASS
) ?
6069 "/classes/%s" : "/printers/%s", p2
->name
);
6070 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
6076 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
6077 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
6078 "printer-alert", NULL
, printer
->alert
);
6080 if (printer
->alert_description
&&
6081 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
6082 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
6083 "printer-alert-description", NULL
,
6084 printer
->alert_description
);
6086 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
6087 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
6088 ippTimeToDate(curtime
));
6091 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
6093 if (printer
->reg_name
)
6094 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6095 "printer-dns-sd-name", NULL
, printer
->reg_name
);
6097 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
6098 "printer-dns-sd-name", 0);
6100 #endif /* HAVE_DNSSD */
6102 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
6103 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6104 "printer-error-policy", NULL
, printer
->error_policy
);
6106 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
6108 static const char * const errors
[] =/* printer-error-policy-supported values */
6111 "retry-current-job",
6116 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
6117 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6118 "printer-error-policy-supported", NULL
, "retry-current-job");
6120 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6121 "printer-error-policy-supported",
6122 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
6125 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
6127 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
6128 "http", NULL
, con
->servername
, con
->serverport
,
6129 "/icons/%s.png", printer
->name
);
6130 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
6131 NULL
, printer_icons
);
6132 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
6135 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
6136 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
6137 printer
->accepting
);
6139 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
6140 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
6143 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
6144 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6146 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6147 "http", NULL
, con
->servername
, con
->serverport
,
6148 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6149 "/classes/%s" : "/printers/%s", printer
->name
);
6150 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6151 "printer-more-info", NULL
, printer_uri
);
6154 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
6155 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6156 "printer-op-policy", NULL
, printer
->op_policy
);
6158 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
6159 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
6162 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
6163 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6164 "printer-state-change-time", printer
->state_time
);
6166 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
6167 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
6168 "printer-state-message", NULL
, printer
->state_message
);
6170 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
6171 add_printer_state_reasons(con
, printer
);
6173 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
6175 int type
; /* printer-type value */
6178 * Add the CUPS-specific printer-type attribute...
6181 type
= printer
->type
;
6183 if (printer
== DefaultPrinter
)
6184 type
|= CUPS_PRINTER_DEFAULT
;
6186 if (!printer
->accepting
)
6187 type
|= CUPS_PRINTER_REJECTING
;
6189 if (!printer
->shared
)
6190 type
|= CUPS_PRINTER_NOT_SHARED
;
6192 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
6196 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
6197 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6198 "printer-up-time", curtime
);
6200 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
6201 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6203 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6204 "ipp", NULL
, con
->servername
, con
->serverport
,
6205 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6206 "/classes/%s" : "/printers/%s", printer
->name
);
6207 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6208 "printer-uri-supported", NULL
, printer_uri
);
6209 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
6213 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
6214 add_queued_job_count(con
, printer
);
6216 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6217 if (printer
->ppd_attrs
)
6218 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6219 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
6224 * 'copy_subscription_attrs()' - Copy subscription attributes.
6228 copy_subscription_attrs(
6229 cupsd_client_t
*con
, /* I - Client connection */
6230 cupsd_subscription_t
*sub
, /* I - Subscription */
6231 cups_array_t
*ra
, /* I - Requested attributes array */
6232 cups_array_t
*exclude
) /* I - Private attributes array */
6234 ipp_attribute_t
*attr
; /* Current attribute */
6235 char printer_uri
[HTTP_MAX_URI
];
6237 int count
; /* Number of events */
6238 unsigned mask
; /* Current event mask */
6239 const char *name
; /* Current event name */
6242 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6243 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
6244 con
, sub
, ra
, exclude
);
6247 * Copy the subscription attributes to the response using the
6248 * requested-attributes attribute that may be provided by the client.
6251 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
6253 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
6254 (!ra
|| cupsArrayFind(ra
, "notify-events")))
6256 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
6258 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
6261 * Simple event list...
6264 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
6265 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6266 "notify-events", NULL
, name
);
6271 * Complex event list...
6274 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6275 if (sub
->mask
& mask
)
6278 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
6279 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6280 "notify-events", count
, NULL
, NULL
);
6282 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6283 if (sub
->mask
& mask
)
6285 attr
->values
[count
].string
.text
=
6286 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
6293 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
6294 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
6295 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6296 "notify-lease-duration", sub
->lease
);
6298 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
6299 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
6300 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6301 "notify-recipient-uri", NULL
, sub
->recipient
);
6302 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
6303 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
6304 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
6305 "notify-pull-method", NULL
, "ippget");
6307 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
6308 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
6309 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
6310 "notify-subscriber-user-name", NULL
, sub
->owner
);
6312 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
6313 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
6314 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6315 "notify-time-interval", sub
->interval
);
6317 if (sub
->user_data_len
> 0 &&
6318 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
6319 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
6320 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
6321 sub
->user_data
, sub
->user_data_len
);
6324 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
6325 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6326 "notify-job-id", sub
->job
->id
);
6328 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
6330 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6331 "ipp", NULL
, con
->servername
, con
->serverport
,
6332 "/printers/%s", sub
->dest
->name
);
6333 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6334 "notify-printer-uri", NULL
, printer_uri
);
6337 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
6338 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6339 "notify-subscription-id", sub
->id
);
6344 * 'create_job()' - Print a file to a printer or class.
6348 create_job(cupsd_client_t
*con
, /* I - Client connection */
6349 ipp_attribute_t
*uri
) /* I - Printer URI */
6351 cupsd_printer_t
*printer
; /* Printer */
6352 cupsd_job_t
*job
; /* New job */
6355 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
6356 con
->http
.fd
, uri
->values
[0].string
.text
);
6359 * Is the destination valid?
6362 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6368 send_ipp_status(con
, IPP_NOT_FOUND
,
6369 _("The printer or class does not exist."));
6374 * Create the job object...
6377 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6380 job
->pending_timeout
= 1;
6383 * Save and log the job...
6386 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6387 job
->dest
, job
->username
);
6392 * 'create_requested_array()' - Create an array for the requested-attributes.
6395 static cups_array_t
* /* O - Array of attributes or NULL */
6396 create_requested_array(ipp_t
*request
) /* I - IPP request */
6398 int i
; /* Looping var */
6399 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6400 cups_array_t
*ra
; /* Requested attributes array */
6401 char *value
; /* Current value */
6405 * Get the requested-attributes attribute, and return NULL if we don't
6409 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6410 IPP_TAG_KEYWORD
)) == NULL
)
6414 * If the attribute contains a single "all" keyword, return NULL...
6417 if (requested
->num_values
== 1 &&
6418 !strcmp(requested
->values
[0].string
.text
, "all"))
6422 * Create an array using "strcmp" as the comparison function...
6425 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6427 for (i
= 0; i
< requested
->num_values
; i
++)
6429 value
= requested
->values
[i
].string
.text
;
6431 if (!strcmp(value
, "job-template"))
6433 cupsArrayAdd(ra
, "copies");
6434 cupsArrayAdd(ra
, "copies-default");
6435 cupsArrayAdd(ra
, "copies-supported");
6436 cupsArrayAdd(ra
, "finishings");
6437 cupsArrayAdd(ra
, "finishings-default");
6438 cupsArrayAdd(ra
, "finishings-supported");
6439 cupsArrayAdd(ra
, "job-hold-until");
6440 cupsArrayAdd(ra
, "job-hold-until-default");
6441 cupsArrayAdd(ra
, "job-hold-until-supported");
6442 cupsArrayAdd(ra
, "job-priority");
6443 cupsArrayAdd(ra
, "job-priority-default");
6444 cupsArrayAdd(ra
, "job-priority-supported");
6445 cupsArrayAdd(ra
, "job-sheets");
6446 cupsArrayAdd(ra
, "job-sheets-default");
6447 cupsArrayAdd(ra
, "job-sheets-supported");
6448 cupsArrayAdd(ra
, "media");
6449 cupsArrayAdd(ra
, "media-default");
6450 cupsArrayAdd(ra
, "media-supported");
6451 cupsArrayAdd(ra
, "multiple-document-handling");
6452 cupsArrayAdd(ra
, "multiple-document-handling-default");
6453 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6454 cupsArrayAdd(ra
, "number-up");
6455 cupsArrayAdd(ra
, "number-up-default");
6456 cupsArrayAdd(ra
, "number-up-supported");
6457 cupsArrayAdd(ra
, "orientation-requested");
6458 cupsArrayAdd(ra
, "orientation-requested-default");
6459 cupsArrayAdd(ra
, "orientation-requested-supported");
6460 cupsArrayAdd(ra
, "page-ranges");
6461 cupsArrayAdd(ra
, "page-ranges-supported");
6462 cupsArrayAdd(ra
, "printer-resolution");
6463 cupsArrayAdd(ra
, "printer-resolution-default");
6464 cupsArrayAdd(ra
, "printer-resolution-supported");
6465 cupsArrayAdd(ra
, "print-quality");
6466 cupsArrayAdd(ra
, "print-quality-default");
6467 cupsArrayAdd(ra
, "print-quality-supported");
6468 cupsArrayAdd(ra
, "sides");
6469 cupsArrayAdd(ra
, "sides-default");
6470 cupsArrayAdd(ra
, "sides-supported");
6472 else if (!strcmp(value
, "job-description"))
6474 cupsArrayAdd(ra
, "date-time-at-completed");
6475 cupsArrayAdd(ra
, "date-time-at-creation");
6476 cupsArrayAdd(ra
, "date-time-at-processing");
6477 cupsArrayAdd(ra
, "job-detailed-status-message");
6478 cupsArrayAdd(ra
, "job-document-access-errors");
6479 cupsArrayAdd(ra
, "job-id");
6480 cupsArrayAdd(ra
, "job-impressions");
6481 cupsArrayAdd(ra
, "job-impressions-completed");
6482 cupsArrayAdd(ra
, "job-k-octets");
6483 cupsArrayAdd(ra
, "job-k-octets-processed");
6484 cupsArrayAdd(ra
, "job-media-progress");
6485 cupsArrayAdd(ra
, "job-media-sheets");
6486 cupsArrayAdd(ra
, "job-media-sheets-completed");
6487 cupsArrayAdd(ra
, "job-message-from-operator");
6488 cupsArrayAdd(ra
, "job-more-info");
6489 cupsArrayAdd(ra
, "job-name");
6490 cupsArrayAdd(ra
, "job-originating-user-name");
6491 cupsArrayAdd(ra
, "job-printer-up-time");
6492 cupsArrayAdd(ra
, "job-printer-uri");
6493 cupsArrayAdd(ra
, "job-state");
6494 cupsArrayAdd(ra
, "job-state-message");
6495 cupsArrayAdd(ra
, "job-state-reasons");
6496 cupsArrayAdd(ra
, "job-uri");
6497 cupsArrayAdd(ra
, "number-of-documents");
6498 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6499 cupsArrayAdd(ra
, "output-device-assigned");
6500 cupsArrayAdd(ra
, "time-at-completed");
6501 cupsArrayAdd(ra
, "time-at-creation");
6502 cupsArrayAdd(ra
, "time-at-processing");
6504 else if (!strcmp(value
, "printer-description"))
6506 cupsArrayAdd(ra
, "charset-configured");
6507 cupsArrayAdd(ra
, "charset-supported");
6508 cupsArrayAdd(ra
, "color-supported");
6509 cupsArrayAdd(ra
, "compression-supported");
6510 cupsArrayAdd(ra
, "document-format-default");
6511 cupsArrayAdd(ra
, "document-format-supported");
6512 cupsArrayAdd(ra
, "generated-natural-language-supported");
6513 cupsArrayAdd(ra
, "ipp-versions-supported");
6514 cupsArrayAdd(ra
, "job-impressions-supported");
6515 cupsArrayAdd(ra
, "job-k-octets-supported");
6516 cupsArrayAdd(ra
, "job-media-sheets-supported");
6517 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6518 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6519 cupsArrayAdd(ra
, "multiple-operation-time-out");
6520 cupsArrayAdd(ra
, "natural-language-configured");
6521 cupsArrayAdd(ra
, "notify-attributes-supported");
6522 cupsArrayAdd(ra
, "notify-lease-duration-default");
6523 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6524 cupsArrayAdd(ra
, "notify-max-events-supported");
6525 cupsArrayAdd(ra
, "notify-events-default");
6526 cupsArrayAdd(ra
, "notify-events-supported");
6527 cupsArrayAdd(ra
, "notify-pull-method-supported");
6528 cupsArrayAdd(ra
, "notify-schemes-supported");
6529 cupsArrayAdd(ra
, "operations-supported");
6530 cupsArrayAdd(ra
, "pages-per-minute");
6531 cupsArrayAdd(ra
, "pages-per-minute-color");
6532 cupsArrayAdd(ra
, "pdl-override-supported");
6533 cupsArrayAdd(ra
, "printer-alert");
6534 cupsArrayAdd(ra
, "printer-alert-description");
6535 cupsArrayAdd(ra
, "printer-commands");
6536 cupsArrayAdd(ra
, "printer-current-time");
6537 cupsArrayAdd(ra
, "printer-driver-installer");
6538 cupsArrayAdd(ra
, "printer-dns-sd-name");
6539 cupsArrayAdd(ra
, "printer-info");
6540 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6541 cupsArrayAdd(ra
, "printer-location");
6542 cupsArrayAdd(ra
, "printer-make-and-model");
6543 cupsArrayAdd(ra
, "printer-message-from-operator");
6544 cupsArrayAdd(ra
, "printer-more-info");
6545 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6546 cupsArrayAdd(ra
, "printer-name");
6547 cupsArrayAdd(ra
, "printer-state");
6548 cupsArrayAdd(ra
, "printer-state-message");
6549 cupsArrayAdd(ra
, "printer-state-reasons");
6550 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6551 cupsArrayAdd(ra
, "printer-type");
6552 cupsArrayAdd(ra
, "printer-up-time");
6553 cupsArrayAdd(ra
, "printer-uri-supported");
6554 cupsArrayAdd(ra
, "queued-job-count");
6555 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6556 cupsArrayAdd(ra
, "uri-authentication-supported");
6557 cupsArrayAdd(ra
, "uri-security-supported");
6559 else if (!strcmp(value
, "printer-defaults"))
6561 char *name
; /* Option name */
6564 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6566 name
= (char *)cupsArrayNext(CommonDefaults
))
6567 cupsArrayAdd(ra
, name
);
6569 else if (!strcmp(value
, "subscription-template"))
6571 cupsArrayAdd(ra
, "notify-attributes");
6572 cupsArrayAdd(ra
, "notify-charset");
6573 cupsArrayAdd(ra
, "notify-events");
6574 cupsArrayAdd(ra
, "notify-lease-duration");
6575 cupsArrayAdd(ra
, "notify-natural-language");
6576 cupsArrayAdd(ra
, "notify-pull-method");
6577 cupsArrayAdd(ra
, "notify-recipient-uri");
6578 cupsArrayAdd(ra
, "notify-time-interval");
6579 cupsArrayAdd(ra
, "notify-user-data");
6582 cupsArrayAdd(ra
, value
);
6590 * 'create_subscription()' - Create a notification subscription.
6594 create_subscription(
6595 cupsd_client_t
*con
, /* I - Client connection */
6596 ipp_attribute_t
*uri
) /* I - Printer URI */
6598 http_status_t status
; /* Policy status */
6599 int i
; /* Looping var */
6600 ipp_attribute_t
*attr
; /* Current attribute */
6601 cups_ptype_t dtype
; /* Destination type (printer/class) */
6602 char scheme
[HTTP_MAX_URI
],
6603 /* Scheme portion of URI */
6604 userpass
[HTTP_MAX_URI
],
6605 /* Username portion of URI */
6607 /* Host portion of URI */
6608 resource
[HTTP_MAX_URI
];
6609 /* Resource portion of URI */
6610 int port
; /* Port portion of URI */
6611 cupsd_printer_t
*printer
; /* Printer/class */
6612 cupsd_job_t
*job
; /* Job */
6613 int jobid
; /* Job ID */
6614 cupsd_subscription_t
*sub
; /* Subscription object */
6615 const char *username
, /* requesting-user-name or
6616 authenticated username */
6617 *recipient
, /* notify-recipient-uri */
6618 *pullmethod
; /* notify-pull-method */
6619 ipp_attribute_t
*user_data
; /* notify-user-data */
6620 int interval
, /* notify-time-interval */
6621 lease
; /* notify-lease-duration */
6622 unsigned mask
; /* notify-events */
6623 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6624 *notify_lease
; /* notify-lease-duration(-default) */
6628 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6630 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6631 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6632 attr
->value_tag
, attr
->name
);
6634 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6639 * Is the destination valid?
6642 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6643 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6644 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6646 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6647 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6648 sizeof(host
), &port
, resource
, sizeof(resource
));
6650 if (!strcmp(resource
, "/"))
6652 dtype
= (cups_ptype_t
)0;
6655 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6657 dtype
= (cups_ptype_t
)0;
6660 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6662 dtype
= CUPS_PRINTER_CLASS
;
6665 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6671 send_ipp_status(con
, IPP_NOT_FOUND
,
6672 _("The printer or class does not exist."));
6682 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6685 send_http_error(con
, status
, printer
);
6689 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6691 send_http_error(con
, status
, NULL
);
6696 * Get the user that is requesting the subscription...
6699 username
= get_username(con
);
6702 * Find the first subscription group attribute; return if we have
6706 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6707 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6712 send_ipp_status(con
, IPP_BAD_REQUEST
,
6713 _("No subscription attributes in request."));
6718 * Process the subscription attributes in the request...
6721 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6729 lease
= DefaultLeaseDuration
;
6731 mask
= CUPSD_EVENT_NONE
;
6735 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6737 notify_lease
= ippFindAttribute(printer
->attrs
,
6738 "notify-lease-duration-default",
6742 lease
= notify_lease
->values
[0].integer
;
6746 notify_events
= NULL
;
6747 notify_lease
= NULL
;
6750 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6752 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6753 attr
->value_tag
== IPP_TAG_URI
)
6756 * Validate the recipient scheme against the ServerBin/notifier
6760 char notifier
[1024]; /* Notifier filename */
6763 recipient
= attr
->values
[0].string
.text
;
6765 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6766 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6767 host
, sizeof(host
), &port
,
6768 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6770 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6771 _("Bad notify-recipient-uri \"%s\"."), recipient
);
6772 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6773 "notify-status-code", IPP_URI_SCHEME
);
6777 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6779 if (access(notifier
, X_OK
))
6781 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6782 _("notify-recipient-uri URI \"%s\" uses unknown "
6783 "scheme."), recipient
);
6784 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6785 "notify-status-code", IPP_URI_SCHEME
);
6789 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6791 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6792 _("notify-recipient-uri URI \"%s\" is already used."),
6794 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6795 "notify-status-code", IPP_ATTRIBUTES
);
6799 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6800 attr
->value_tag
== IPP_TAG_KEYWORD
)
6802 pullmethod
= attr
->values
[0].string
.text
;
6804 if (strcmp(pullmethod
, "ippget"))
6806 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6807 _("Bad notify-pull-method \"%s\"."), pullmethod
);
6808 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6809 "notify-status-code", IPP_ATTRIBUTES
);
6813 else if (!strcmp(attr
->name
, "notify-charset") &&
6814 attr
->value_tag
== IPP_TAG_CHARSET
&&
6815 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6816 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6818 send_ipp_status(con
, IPP_CHARSET
,
6819 _("Character set \"%s\" not supported."),
6820 attr
->values
[0].string
.text
);
6823 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6824 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6825 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6827 send_ipp_status(con
, IPP_CHARSET
,
6828 _("Language \"%s\" not supported."),
6829 attr
->values
[0].string
.text
);
6832 else if (!strcmp(attr
->name
, "notify-user-data") &&
6833 attr
->value_tag
== IPP_TAG_STRING
)
6835 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6837 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6838 _("The notify-user-data value is too large "
6839 "(%d > 63 octets)."),
6840 attr
->values
[0].unknown
.length
);
6846 else if (!strcmp(attr
->name
, "notify-events") &&
6847 attr
->value_tag
== IPP_TAG_KEYWORD
)
6848 notify_events
= attr
;
6849 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6850 attr
->value_tag
== IPP_TAG_INTEGER
)
6851 lease
= attr
->values
[0].integer
;
6852 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6853 attr
->value_tag
== IPP_TAG_INTEGER
)
6854 interval
= attr
->values
[0].integer
;
6855 else if (!strcmp(attr
->name
, "notify-job-id") &&
6856 attr
->value_tag
== IPP_TAG_INTEGER
)
6857 jobid
= attr
->values
[0].integer
;
6864 for (i
= 0; i
< notify_events
->num_values
; i
++)
6865 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6869 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6871 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6872 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6873 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6875 if (!recipient
&& !pullmethod
)
6878 if (mask
== CUPSD_EVENT_NONE
)
6881 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6883 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6886 send_ipp_status(con
, IPP_BAD_REQUEST
,
6887 _("notify-events not specified."));
6892 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6894 cupsdLogMessage(CUPSD_LOG_INFO
,
6895 "create_subscription: Limiting notify-lease-duration to "
6898 lease
= MaxLeaseDuration
;
6903 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6905 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6913 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6915 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6916 _("There are too many subscriptions."));
6921 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
6924 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6925 "Added subscription #%d for printer \"%s\".",
6926 sub
->id
, printer
->name
);
6928 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
6931 sub
->interval
= interval
;
6933 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6935 cupsdSetString(&sub
->owner
, username
);
6939 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6940 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6941 sub
->user_data_len
);
6944 ippAddSeparator(con
->response
);
6945 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6946 "notify-subscription-id", sub
->id
);
6948 con
->response
->request
.status
.status_code
= IPP_OK
;
6954 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6959 * 'delete_printer()' - Remove a printer or class from the system.
6963 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6964 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6966 http_status_t status
; /* Policy status */
6967 cups_ptype_t dtype
; /* Destination type (printer/class) */
6968 cupsd_printer_t
*printer
; /* Printer/class */
6969 char filename
[1024]; /* Script/PPD filename */
6972 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6973 con
->http
.fd
, uri
->values
[0].string
.text
);
6976 * Do we have a valid URI?
6979 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6985 send_ipp_status(con
, IPP_NOT_FOUND
,
6986 _("The printer or class does not exist."));
6994 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6996 send_http_error(con
, status
, NULL
);
7001 * Remove old jobs...
7004 cupsdCancelJobs(printer
->name
, NULL
, 1);
7007 * Remove old subscriptions and send a "deleted printer" event...
7010 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
7011 "%s \"%s\" deleted by \"%s\".",
7012 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
7013 printer
->name
, get_username(con
));
7015 cupsdExpireSubscriptions(printer
, NULL
);
7018 * Remove any old PPD or script files...
7021 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
7025 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7029 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
7032 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
7037 * Unregister color profiles...
7040 apple_unregister_profiles(printer
);
7041 #endif /* __APPLE__ */
7043 if (dtype
& CUPS_PRINTER_CLASS
)
7045 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
7046 printer
->name
, get_username(con
));
7048 cupsdDeletePrinter(printer
, 0);
7049 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7053 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
7054 printer
->name
, get_username(con
));
7056 if (cupsdDeletePrinter(printer
, 0))
7057 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7059 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
7062 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
7065 * Return with no errors...
7068 con
->response
->request
.status
.status_code
= IPP_OK
;
7073 * 'get_default()' - Get the default destination.
7077 get_default(cupsd_client_t
*con
) /* I - Client connection */
7079 http_status_t status
; /* Policy status */
7080 cups_array_t
*ra
; /* Requested attributes array */
7083 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
7089 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7091 send_http_error(con
, status
, NULL
);
7097 ra
= create_requested_array(con
->request
);
7099 copy_printer_attrs(con
, DefaultPrinter
, ra
);
7101 cupsArrayDelete(ra
);
7103 con
->response
->request
.status
.status_code
= IPP_OK
;
7106 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
7111 * 'get_devices()' - Get the list of available devices on the local system.
7115 get_devices(cupsd_client_t
*con
) /* I - Client connection */
7117 http_status_t status
; /* Policy status */
7118 ipp_attribute_t
*limit
, /* limit attribute */
7119 *timeout
, /* timeout attribute */
7120 *requested
, /* requested-attributes attribute */
7121 *exclude
, /* exclude-schemes attribute */
7122 *include
; /* include-schemes attribute */
7123 char command
[1024], /* cups-deviced command */
7124 options
[2048], /* Options to pass to command */
7126 /* String for requested attributes */
7128 /* String for excluded schemes */
7130 /* String for included schemes */
7133 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
7139 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7141 send_http_error(con
, status
, NULL
);
7146 * Run cups-deviced command with the given options...
7149 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7150 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
7151 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7153 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
7154 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
7157 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7159 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7162 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7164 exclude_str
[0] = '\0';
7167 url_encode_attr(include
, include_str
, sizeof(include_str
));
7169 include_str
[0] = '\0';
7171 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
7172 snprintf(options
, sizeof(options
),
7173 "%d+%d+%d+%d+%s%s%s%s%s",
7174 con
->request
->request
.op
.request_id
,
7175 limit
? limit
->values
[0].integer
: 0,
7176 timeout
? timeout
->values
[0].integer
: 15,
7179 exclude_str
[0] ? "%20" : "", exclude_str
,
7180 include_str
[0] ? "%20" : "", include_str
);
7182 if (cupsdSendCommand(con
, command
, options
, 1))
7185 * Command started successfully, don't send an IPP response here...
7188 ippDelete(con
->response
);
7189 con
->response
= NULL
;
7194 * Command failed, return "internal error" so the user knows something
7198 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7199 _("cups-deviced failed to execute."));
7205 * 'get_document()' - Get a copy of a job file.
7209 get_document(cupsd_client_t
*con
, /* I - Client connection */
7210 ipp_attribute_t
*uri
) /* I - Job URI */
7212 http_status_t status
; /* Policy status */
7213 ipp_attribute_t
*attr
; /* Current attribute */
7214 int jobid
; /* Job ID */
7215 int docnum
; /* Document number */
7216 cupsd_job_t
*job
; /* Current job */
7217 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7218 username
[HTTP_MAX_URI
], /* Username portion of URI */
7219 host
[HTTP_MAX_URI
], /* Host portion of URI */
7220 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7221 int port
; /* Port portion of URI */
7222 char filename
[1024], /* Filename for document */
7223 format
[1024]; /* Format for document */
7226 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
7227 con
->http
.fd
, uri
->values
[0].string
.text
);
7230 * See if we have a job URI or a printer URI...
7233 if (!strcmp(uri
->name
, "printer-uri"))
7236 * Got a printer URI; see if we also have a job-id attribute...
7239 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7240 IPP_TAG_INTEGER
)) == NULL
)
7242 send_ipp_status(con
, IPP_BAD_REQUEST
,
7243 _("Got a printer-uri attribute but no job-id."));
7247 jobid
= attr
->values
[0].integer
;
7252 * Got a job URI; parse it to get the job ID...
7255 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7256 sizeof(scheme
), username
, sizeof(username
), host
,
7257 sizeof(host
), &port
, resource
, sizeof(resource
));
7259 if (strncmp(resource
, "/jobs/", 6))
7265 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7266 uri
->values
[0].string
.text
);
7270 jobid
= atoi(resource
+ 6);
7274 * See if the job exists...
7277 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7280 * Nope - return a "not found" error...
7283 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7291 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
7292 job
->username
)) != HTTP_OK
)
7294 send_http_error(con
, status
, NULL
);
7299 * Get the document number...
7302 if ((attr
= ippFindAttribute(con
->request
, "document-number",
7303 IPP_TAG_INTEGER
)) == NULL
)
7305 send_ipp_status(con
, IPP_BAD_REQUEST
,
7306 _("Missing document-number attribute."));
7310 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
7311 attr
->num_values
> 1)
7313 send_ipp_status(con
, IPP_NOT_FOUND
,
7314 _("Document #%d does not exist in job #%d."), docnum
,
7319 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
7321 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
7323 cupsdLogMessage(CUPSD_LOG_ERROR
,
7324 "Unable to open document %d in job %d - %s", docnum
, jobid
,
7326 send_ipp_status(con
, IPP_NOT_FOUND
,
7327 _("Unable to open document #%d in job #%d."), docnum
,
7332 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7336 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
7337 job
->filetypes
[docnum
- 1]->type
);
7339 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
7341 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
7343 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
7344 IPP_TAG_NAME
)) != NULL
)
7345 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
7346 NULL
, attr
->values
[0].string
.text
);
7351 * 'get_job_attrs()' - Get job attributes.
7355 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
7356 ipp_attribute_t
*uri
) /* I - Job URI */
7358 http_status_t status
; /* Policy status */
7359 ipp_attribute_t
*attr
; /* Current attribute */
7360 int jobid
; /* Job ID */
7361 cupsd_job_t
*job
; /* Current job */
7362 cupsd_printer_t
*printer
; /* Current printer */
7363 cupsd_policy_t
*policy
; /* Current security policy */
7364 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7365 username
[HTTP_MAX_URI
], /* Username portion of URI */
7366 host
[HTTP_MAX_URI
], /* Host portion of URI */
7367 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7368 int port
; /* Port portion of URI */
7369 cups_array_t
*ra
, /* Requested attributes array */
7370 *exclude
; /* Private attributes array */
7373 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7374 con
->http
.fd
, uri
->values
[0].string
.text
);
7377 * See if we have a job URI or a printer URI...
7380 if (!strcmp(uri
->name
, "printer-uri"))
7383 * Got a printer URI; see if we also have a job-id attribute...
7386 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7387 IPP_TAG_INTEGER
)) == NULL
)
7389 send_ipp_status(con
, IPP_BAD_REQUEST
,
7390 _("Got a printer-uri attribute but no job-id."));
7394 jobid
= attr
->values
[0].integer
;
7399 * Got a job URI; parse it to get the job ID...
7402 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7403 sizeof(scheme
), username
, sizeof(username
), host
,
7404 sizeof(host
), &port
, resource
, sizeof(resource
));
7406 if (strncmp(resource
, "/jobs/", 6))
7412 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7413 uri
->values
[0].string
.text
);
7417 jobid
= atoi(resource
+ 6);
7421 * See if the job exists...
7424 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7427 * Nope - return a "not found" error...
7430 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7438 if ((printer
= job
->printer
) == NULL
)
7439 printer
= cupsdFindDest(job
->dest
);
7442 policy
= printer
->op_policy_ptr
;
7444 policy
= DefaultPolicyPtr
;
7446 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
7448 send_http_error(con
, status
, NULL
);
7452 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
7455 * Copy attributes...
7460 ra
= create_requested_array(con
->request
);
7461 copy_job_attrs(con
, job
, ra
, exclude
);
7462 cupsArrayDelete(ra
);
7464 con
->response
->request
.status
.status_code
= IPP_OK
;
7469 * 'get_jobs()' - Get a list of jobs for the specified printer.
7473 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7474 ipp_attribute_t
*uri
) /* I - Printer URI */
7476 http_status_t status
; /* Policy status */
7477 ipp_attribute_t
*attr
; /* Current attribute */
7478 const char *dest
; /* Destination */
7479 cups_ptype_t dtype
; /* Destination type (printer/class) */
7480 cups_ptype_t dmask
; /* Destination type mask */
7481 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7482 username
[HTTP_MAX_URI
], /* Username portion of URI */
7483 host
[HTTP_MAX_URI
], /* Host portion of URI */
7484 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7485 int port
; /* Port portion of URI */
7486 int job_comparison
; /* Job comparison */
7487 ipp_jstate_t job_state
; /* job-state value */
7488 int first_job_id
; /* First job ID */
7489 int limit
; /* Maximum number of jobs to return */
7490 int count
; /* Number of jobs that match */
7491 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7492 cupsd_job_t
*job
; /* Current job pointer */
7493 cupsd_printer_t
*printer
; /* Printer */
7494 cups_array_t
*list
; /* Which job list... */
7495 cups_array_t
*ra
, /* Requested attributes array */
7496 *exclude
; /* Private attributes array */
7497 cupsd_policy_t
*policy
; /* Current policy */
7500 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7501 uri
->values
[0].string
.text
);
7504 * Is the destination valid?
7507 if (strcmp(uri
->name
, "printer-uri"))
7509 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
7513 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7514 sizeof(scheme
), username
, sizeof(username
), host
,
7515 sizeof(host
), &port
, resource
, sizeof(resource
));
7517 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7520 dtype
= (cups_ptype_t
)0;
7521 dmask
= (cups_ptype_t
)0;
7524 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7527 dtype
= (cups_ptype_t
)0;
7528 dmask
= CUPS_PRINTER_CLASS
;
7531 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7534 dtype
= CUPS_PRINTER_CLASS
;
7535 dmask
= CUPS_PRINTER_CLASS
;
7538 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7545 send_ipp_status(con
, IPP_NOT_FOUND
,
7546 _("The printer or class does not exist."));
7551 dtype
&= CUPS_PRINTER_CLASS
;
7552 dmask
= CUPS_PRINTER_CLASS
;
7560 policy
= printer
->op_policy_ptr
;
7562 policy
= DefaultPolicyPtr
;
7564 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7566 send_http_error(con
, status
, NULL
);
7570 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7573 * See if the "which-jobs" attribute have been specified...
7576 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7577 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7579 send_ipp_status(con
, IPP_CONFLICT
,
7580 _("The %s attribute cannot be provided with job-ids."),
7584 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7586 job_comparison
= -1;
7587 job_state
= IPP_JOB_STOPPED
;
7590 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7593 job_state
= IPP_JOB_CANCELED
;
7596 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7599 job_state
= IPP_JOB_ABORTED
;
7602 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7605 job_state
= IPP_JOB_PENDING
;
7608 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7611 job_state
= IPP_JOB_CANCELED
;
7614 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7617 job_state
= IPP_JOB_PENDING
;
7620 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7623 job_state
= IPP_JOB_HELD
;
7626 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7629 job_state
= IPP_JOB_PROCESSING
;
7630 list
= PrintingJobs
;
7632 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7635 job_state
= IPP_JOB_STOPPED
;
7640 send_ipp_status(con
, IPP_ATTRIBUTES
,
7641 _("The which-jobs value \"%s\" is not supported."),
7642 attr
->values
[0].string
.text
);
7643 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7644 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7649 * See if they want to limit the number of jobs reported...
7652 if ((attr
= ippFindAttribute(con
->request
, "limit",
7653 IPP_TAG_INTEGER
)) != NULL
)
7657 send_ipp_status(con
, IPP_CONFLICT
,
7658 _("The %s attribute cannot be provided with job-ids."),
7663 limit
= attr
->values
[0].integer
;
7668 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7669 IPP_TAG_INTEGER
)) != NULL
)
7673 send_ipp_status(con
, IPP_CONFLICT
,
7674 _("The %s attribute cannot be provided with job-ids."),
7679 first_job_id
= attr
->values
[0].integer
;
7685 * See if we only want to see jobs for a specific user...
7688 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7689 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7691 send_ipp_status(con
, IPP_CONFLICT
,
7692 _("The %s attribute cannot be provided with job-ids."),
7696 else if (attr
&& attr
->values
[0].boolean
)
7697 strlcpy(username
, get_username(con
), sizeof(username
));
7701 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7702 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7705 * IPP conformance - Get-Jobs has a default requested-attributes value of
7706 * "job-id" and "job-uri".
7709 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7710 cupsArrayAdd(ra
, "job-id");
7711 cupsArrayAdd(ra
, "job-uri");
7715 * OK, build a list of jobs for this printer...
7720 int i
; /* Looping var */
7722 for (i
= 0; i
< job_ids
->num_values
; i
++)
7724 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
7728 if (i
< job_ids
->num_values
)
7730 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7731 job_ids
->values
[i
].integer
);
7735 for (i
= 0; i
< job_ids
->num_values
; i
++)
7737 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7743 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7749 ippAddSeparator(con
->response
);
7751 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7752 job
->printer
->op_policy_ptr
:
7753 policy
, con
, job
->printer
,
7756 copy_job_attrs(con
, job
, ra
, exclude
);
7761 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7762 (limit
<= 0 || count
< limit
) && job
;
7763 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7766 * Filter out jobs that don't match...
7769 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7770 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7771 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7772 job
->username
, job
->state_value
, job
->attrs
);
7774 if (!job
->dest
|| !job
->username
)
7777 if (!job
->dest
|| !job
->username
)
7780 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7781 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7783 if ((job
->dtype
& dmask
) != dtype
&&
7784 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7787 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7788 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7789 (job_comparison
> 0 && job
->state_value
< job_state
))
7792 if (job
->id
< first_job_id
)
7799 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7804 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
7808 ippAddSeparator(con
->response
);
7812 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7813 job
->printer
->op_policy_ptr
:
7814 policy
, con
, job
->printer
,
7817 copy_job_attrs(con
, job
, ra
, exclude
);
7820 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7823 cupsArrayDelete(ra
);
7825 con
->response
->request
.status
.status_code
= IPP_OK
;
7830 * 'get_notifications()' - Get events for a subscription.
7834 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7836 int i
, j
; /* Looping vars */
7837 http_status_t status
; /* Policy status */
7838 cupsd_subscription_t
*sub
; /* Subscription */
7839 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7840 *sequences
; /* notify-sequence-numbers */
7841 int min_seq
; /* Minimum sequence number */
7842 int interval
; /* Poll interval */
7845 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7849 * Get subscription attributes...
7852 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7854 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7859 send_ipp_status(con
, IPP_BAD_REQUEST
,
7860 _("Missing notify-subscription-ids attribute."));
7865 * Are the subscription IDs valid?
7868 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7870 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7873 * Bad subscription ID...
7876 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7877 ids
->values
[i
].integer
);
7885 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7887 con
, sub
->owner
)) != HTTP_OK
)
7889 send_http_error(con
, status
, sub
->dest
);
7894 * Check the subscription type and update the interval accordingly.
7897 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7900 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7902 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7908 * Tell the client to poll again in N seconds...
7912 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7913 "notify-get-interval", interval
);
7915 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7916 "printer-up-time", time(NULL
));
7919 * Copy the subscription event attributes to the response.
7922 con
->response
->request
.status
.status_code
=
7923 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7925 for (i
= 0; i
< ids
->num_values
; i
++)
7928 * Get the subscription and sequence number...
7931 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7933 if (sequences
&& i
< sequences
->num_values
)
7934 min_seq
= sequences
->values
[i
].integer
;
7939 * If we don't have any new events, nothing to do here...
7942 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
7946 * Otherwise copy all of the new events...
7949 if (sub
->first_event_id
> min_seq
)
7952 j
= min_seq
- sub
->first_event_id
;
7954 for (; j
< cupsArrayCount(sub
->events
); j
++)
7956 ippAddSeparator(con
->response
);
7958 copy_attrs(con
->response
,
7959 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7960 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7967 * 'get_ppd()' - Get a named PPD from the local system.
7971 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7972 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7974 http_status_t status
; /* Policy status */
7975 cupsd_printer_t
*dest
; /* Destination */
7976 cups_ptype_t dtype
; /* Destination type */
7979 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7980 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7982 if (!strcmp(uri
->name
, "ppd-name"))
7985 * Return a PPD file from cups-driverd...
7988 char command
[1024], /* cups-driverd command */
7989 options
[1024], /* Options to pass to command */
7990 ppd_name
[1024]; /* ppd-name */
7997 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7999 send_http_error(con
, status
, NULL
);
8004 * Run cups-driverd command with the given options...
8007 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
8008 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
8009 snprintf(options
, sizeof(options
), "get+%d+%s",
8010 con
->request
->request
.op
.request_id
, ppd_name
);
8012 if (cupsdSendCommand(con
, command
, options
, 0))
8015 * Command started successfully, don't send an IPP response here...
8018 ippDelete(con
->response
);
8019 con
->response
= NULL
;
8024 * Command failed, return "internal error" so the user knows something
8028 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8029 _("cups-driverd failed to execute."));
8032 else if (!strcmp(uri
->name
, "printer-uri") &&
8033 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
8035 int i
; /* Looping var */
8036 char filename
[1024]; /* PPD filename */
8043 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8045 send_http_error(con
, status
, dest
);
8050 * See if we need the PPD for a class or remote printer...
8053 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8056 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
8058 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8059 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8060 "printer-uri", NULL
, dest
->uri
);
8063 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
8065 for (i
= 0; i
< dest
->num_printers
; i
++)
8066 if (!(dest
->printers
[i
]->type
&
8067 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
8069 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8070 dest
->printers
[i
]->name
);
8072 if (!access(filename
, 0))
8076 if (i
< dest
->num_printers
)
8077 dest
= dest
->printers
[i
];
8080 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8081 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8082 "printer-uri", NULL
, dest
->printers
[0]->uri
);
8088 * Found the printer with the PPD file, now see if there is one...
8091 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
8093 send_ipp_status(con
, IPP_NOT_FOUND
,
8094 _("The PPD file \"%s\" could not be opened: %s"),
8095 uri
->values
[0].string
.text
, strerror(errno
));
8099 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
8103 con
->response
->request
.status
.status_code
= IPP_OK
;
8106 send_ipp_status(con
, IPP_NOT_FOUND
,
8107 _("The PPD file \"%s\" could not be found."),
8108 uri
->values
[0].string
.text
);
8113 * 'get_ppds()' - Get the list of PPD files on the local system.
8117 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
8119 http_status_t status
; /* Policy status */
8120 ipp_attribute_t
*limit
, /* Limit attribute */
8121 *device
, /* ppd-device-id attribute */
8122 *language
, /* ppd-natural-language attribute */
8123 *make
, /* ppd-make attribute */
8124 *model
, /* ppd-make-and-model attribute */
8125 *model_number
, /* ppd-model-number attribute */
8126 *product
, /* ppd-product attribute */
8127 *psversion
, /* ppd-psverion attribute */
8128 *type
, /* ppd-type attribute */
8129 *requested
, /* requested-attributes attribute */
8130 *exclude
, /* exclude-schemes attribute */
8131 *include
; /* include-schemes attribute */
8132 char command
[1024], /* cups-driverd command */
8133 options
[4096], /* Options to pass to command */
8134 device_str
[256],/* Escaped ppd-device-id string */
8136 /* Escaped ppd-natural-language */
8137 make_str
[256], /* Escaped ppd-make string */
8138 model_str
[256], /* Escaped ppd-make-and-model string */
8139 model_number_str
[256],
8140 /* ppd-model-number string */
8142 /* Escaped ppd-product string */
8144 /* Escaped ppd-psversion string */
8145 type_str
[256], /* Escaped ppd-type string */
8147 /* String for requested attributes */
8149 /* String for excluded schemes */
8151 /* String for included schemes */
8154 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
8160 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8162 send_http_error(con
, status
, NULL
);
8167 * Run cups-driverd command with the given options...
8170 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
8171 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
8172 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
8174 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
8175 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
8177 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
8179 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
8180 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
8181 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
8182 requested
= ippFindAttribute(con
->request
, "requested-attributes",
8184 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
8186 include
= ippFindAttribute(con
->request
, "include-schemes",
8190 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
8192 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
8195 url_encode_attr(device
, device_str
, sizeof(device_str
));
8197 device_str
[0] = '\0';
8200 url_encode_attr(language
, language_str
, sizeof(language_str
));
8202 language_str
[0] = '\0';
8205 url_encode_attr(make
, make_str
, sizeof(make_str
));
8210 url_encode_attr(model
, model_str
, sizeof(model_str
));
8212 model_str
[0] = '\0';
8215 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
8216 model_number
->values
[0].integer
);
8218 model_number_str
[0] = '\0';
8221 url_encode_attr(product
, product_str
, sizeof(product_str
));
8223 product_str
[0] = '\0';
8226 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
8228 psversion_str
[0] = '\0';
8231 url_encode_attr(type
, type_str
, sizeof(type_str
));
8236 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
8238 exclude_str
[0] = '\0';
8241 url_encode_attr(include
, include_str
, sizeof(include_str
));
8243 include_str
[0] = '\0';
8245 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
8246 snprintf(options
, sizeof(options
),
8247 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
8248 con
->request
->request
.op
.request_id
,
8249 limit
? limit
->values
[0].integer
: 0,
8251 device
? "%20" : "", device_str
,
8252 language
? "%20" : "", language_str
,
8253 make
? "%20" : "", make_str
,
8254 model
? "%20" : "", model_str
,
8255 model_number
? "%20" : "", model_number_str
,
8256 product
? "%20" : "", product_str
,
8257 psversion
? "%20" : "", psversion_str
,
8258 type
? "%20" : "", type_str
,
8259 exclude_str
[0] ? "%20" : "", exclude_str
,
8260 include_str
[0] ? "%20" : "", include_str
);
8262 if (cupsdSendCommand(con
, command
, options
, 0))
8265 * Command started successfully, don't send an IPP response here...
8268 ippDelete(con
->response
);
8269 con
->response
= NULL
;
8274 * Command failed, return "internal error" so the user knows something
8278 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8279 _("cups-driverd failed to execute."));
8285 * 'get_printer_attrs()' - Get printer attributes.
8289 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
8290 ipp_attribute_t
*uri
) /* I - Printer URI */
8292 http_status_t status
; /* Policy status */
8293 cups_ptype_t dtype
; /* Destination type (printer/class) */
8294 cupsd_printer_t
*printer
; /* Printer/class */
8295 cups_array_t
*ra
; /* Requested attributes array */
8298 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
8299 con
->http
.fd
, uri
->values
[0].string
.text
);
8302 * Is the destination valid?
8305 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8311 send_ipp_status(con
, IPP_NOT_FOUND
,
8312 _("The printer or class does not exist."));
8320 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8322 send_http_error(con
, status
, printer
);
8327 * Send the attributes...
8330 ra
= create_requested_array(con
->request
);
8332 copy_printer_attrs(con
, printer
, ra
);
8334 cupsArrayDelete(ra
);
8336 con
->response
->request
.status
.status_code
= IPP_OK
;
8341 * 'get_printer_supported()' - Get printer supported values.
8345 get_printer_supported(
8346 cupsd_client_t
*con
, /* I - Client connection */
8347 ipp_attribute_t
*uri
) /* I - Printer URI */
8349 http_status_t status
; /* Policy status */
8350 cups_ptype_t dtype
; /* Destination type (printer/class) */
8351 cupsd_printer_t
*printer
; /* Printer/class */
8354 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
8355 con
->http
.fd
, uri
->values
[0].string
.text
);
8358 * Is the destination valid?
8361 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8367 send_ipp_status(con
, IPP_NOT_FOUND
,
8368 _("The printer or class does not exist."));
8376 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8378 send_http_error(con
, status
, printer
);
8383 * Return a list of attributes that can be set via Set-Printer-Attributes.
8386 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8388 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8389 "printer-location", 0);
8391 con
->response
->request
.status
.status_code
= IPP_OK
;
8396 * 'get_printers()' - Get a list of printers or classes.
8400 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8401 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8403 http_status_t status
; /* Policy status */
8404 ipp_attribute_t
*attr
; /* Current attribute */
8405 int limit
; /* Max number of printers to return */
8406 int count
; /* Number of printers that match */
8407 cupsd_printer_t
*printer
; /* Current printer pointer */
8408 int printer_type
, /* printer-type attribute */
8409 printer_mask
; /* printer-type-mask attribute */
8410 char *location
; /* Location string */
8411 const char *username
; /* Current user */
8412 char *first_printer_name
; /* first-printer-name attribute */
8413 cups_array_t
*ra
; /* Requested attributes array */
8414 int local
; /* Local connection? */
8417 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8418 con
->http
.fd
, type
);
8424 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8426 send_http_error(con
, status
, NULL
);
8431 * Check for printers...
8434 if (!Printers
|| !cupsArrayCount(Printers
))
8436 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8441 * See if they want to limit the number of printers reported...
8444 if ((attr
= ippFindAttribute(con
->request
, "limit",
8445 IPP_TAG_INTEGER
)) != NULL
)
8446 limit
= attr
->values
[0].integer
;
8450 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8451 IPP_TAG_NAME
)) != NULL
)
8452 first_printer_name
= attr
->values
[0].string
.text
;
8454 first_printer_name
= NULL
;
8457 * Support filtering...
8460 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8461 IPP_TAG_ENUM
)) != NULL
)
8462 printer_type
= attr
->values
[0].integer
;
8466 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8467 IPP_TAG_ENUM
)) != NULL
)
8468 printer_mask
= attr
->values
[0].integer
;
8472 local
= httpAddrLocalhost(&(con
->clientaddr
));
8474 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8475 IPP_TAG_TEXT
)) != NULL
)
8476 location
= attr
->values
[0].string
.text
;
8480 if (con
->username
[0])
8481 username
= con
->username
;
8482 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8483 IPP_TAG_NAME
)) != NULL
)
8484 username
= attr
->values
[0].string
.text
;
8488 ra
= create_requested_array(con
->request
);
8491 * OK, build a list of printers for this printer...
8494 if (first_printer_name
)
8496 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8497 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8500 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8503 count
< limit
&& printer
;
8504 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8506 if (!local
&& !printer
->shared
)
8509 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8510 (printer
->type
& printer_mask
) == printer_type
&&
8512 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
8515 * If HideImplicitMembers is enabled, see if this printer or class
8516 * is a member of an implicit class...
8519 if (ImplicitClasses
&& HideImplicitMembers
&&
8520 printer
->in_implicit_class
)
8524 * If a username is specified, see if it is allowed or denied
8528 if (cupsArrayCount(printer
->users
) && username
&&
8529 !user_allowed(printer
, username
))
8533 * Add the group separator as needed...
8537 ippAddSeparator(con
->response
);
8542 * Send the attributes...
8545 copy_printer_attrs(con
, printer
, ra
);
8549 cupsArrayDelete(ra
);
8551 con
->response
->request
.status
.status_code
= IPP_OK
;
8556 * 'get_subscription_attrs()' - Get subscription attributes.
8560 get_subscription_attrs(
8561 cupsd_client_t
*con
, /* I - Client connection */
8562 int sub_id
) /* I - Subscription ID */
8564 http_status_t status
; /* Policy status */
8565 cupsd_subscription_t
*sub
; /* Subscription */
8566 cupsd_policy_t
*policy
; /* Current security policy */
8567 cups_array_t
*ra
, /* Requested attributes array */
8568 *exclude
; /* Private attributes array */
8571 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8572 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8573 con
, con
->http
.fd
, sub_id
);
8576 * Is the subscription ID valid?
8579 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8582 * Bad subscription ID...
8585 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8595 policy
= sub
->dest
->op_policy_ptr
;
8597 policy
= DefaultPolicyPtr
;
8599 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
8601 send_http_error(con
, status
, sub
->dest
);
8605 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
8608 * Copy the subscription attributes to the response using the
8609 * requested-attributes attribute that may be provided by the client.
8612 ra
= create_requested_array(con
->request
);
8614 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8616 cupsArrayDelete(ra
);
8618 con
->response
->request
.status
.status_code
= IPP_OK
;
8623 * 'get_subscriptions()' - Get subscriptions.
8627 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8628 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8630 http_status_t status
; /* Policy status */
8631 int count
; /* Number of subscriptions */
8632 int limit
; /* Limit */
8633 cupsd_subscription_t
*sub
; /* Subscription */
8634 cups_array_t
*ra
; /* Requested attributes array */
8635 ipp_attribute_t
*attr
; /* Attribute */
8636 cups_ptype_t dtype
; /* Destination type (printer/class) */
8637 char scheme
[HTTP_MAX_URI
],
8638 /* Scheme portion of URI */
8639 username
[HTTP_MAX_URI
],
8640 /* Username portion of URI */
8642 /* Host portion of URI */
8643 resource
[HTTP_MAX_URI
];
8644 /* Resource portion of URI */
8645 int port
; /* Port portion of URI */
8646 cupsd_job_t
*job
; /* Job pointer */
8647 cupsd_printer_t
*printer
; /* Printer */
8648 cupsd_policy_t
*policy
; /* Policy */
8649 cups_array_t
*exclude
; /* Private attributes array */
8652 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8653 "get_subscriptions(con=%p[%d], uri=%s)",
8654 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8657 * Is the destination valid?
8660 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8661 sizeof(scheme
), username
, sizeof(username
), host
,
8662 sizeof(host
), &port
, resource
, sizeof(resource
));
8664 if (!strcmp(resource
, "/") ||
8665 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8666 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8667 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8672 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8675 job
= cupsdFindJob(atoi(resource
+ 6));
8679 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
8680 atoi(resource
+ 6));
8684 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8690 send_ipp_status(con
, IPP_NOT_FOUND
,
8691 _("The printer or class does not exist."));
8694 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8695 IPP_TAG_INTEGER
)) != NULL
)
8697 job
= cupsdFindJob(attr
->values
[0].integer
);
8701 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
8702 attr
->values
[0].integer
);
8714 policy
= printer
->op_policy_ptr
;
8716 policy
= DefaultPolicyPtr
;
8718 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
8720 send_http_error(con
, status
, printer
);
8725 * Copy the subscription attributes to the response using the
8726 * requested-attributes attribute that may be provided by the client.
8729 ra
= create_requested_array(con
->request
);
8731 if ((attr
= ippFindAttribute(con
->request
, "limit",
8732 IPP_TAG_INTEGER
)) != NULL
)
8733 limit
= attr
->values
[0].integer
;
8738 * See if we only want to see subscriptions for a specific user...
8741 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8742 IPP_TAG_BOOLEAN
)) != NULL
&&
8743 attr
->values
[0].boolean
)
8744 strlcpy(username
, get_username(con
), sizeof(username
));
8748 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8750 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8751 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8752 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
8754 ippAddSeparator(con
->response
);
8756 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
8757 policy
, con
, sub
->dest
,
8760 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8763 if (limit
&& count
>= limit
)
8767 cupsArrayDelete(ra
);
8770 con
->response
->request
.status
.status_code
= IPP_OK
;
8772 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8777 * 'get_username()' - Get the username associated with a request.
8780 static const char * /* O - Username */
8781 get_username(cupsd_client_t
*con
) /* I - Connection */
8783 ipp_attribute_t
*attr
; /* Attribute */
8786 if (con
->username
[0])
8787 return (con
->username
);
8788 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8789 IPP_TAG_NAME
)) != NULL
)
8790 return (attr
->values
[0].string
.text
);
8792 return ("anonymous");
8797 * 'hold_job()' - Hold a print job.
8801 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8802 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8804 ipp_attribute_t
*attr
; /* Current job-hold-until */
8805 const char *when
; /* New value */
8806 int jobid
; /* Job ID */
8807 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8808 username
[HTTP_MAX_URI
], /* Username portion of URI */
8809 host
[HTTP_MAX_URI
], /* Host portion of URI */
8810 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8811 int port
; /* Port portion of URI */
8812 cupsd_job_t
*job
; /* Job information */
8815 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8816 uri
->values
[0].string
.text
);
8819 * See if we have a job URI or a printer URI...
8822 if (!strcmp(uri
->name
, "printer-uri"))
8825 * Got a printer URI; see if we also have a job-id attribute...
8828 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8829 IPP_TAG_INTEGER
)) == NULL
)
8831 send_ipp_status(con
, IPP_BAD_REQUEST
,
8832 _("Got a printer-uri attribute but no job-id."));
8836 jobid
= attr
->values
[0].integer
;
8841 * Got a job URI; parse it to get the job ID...
8844 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8845 sizeof(scheme
), username
, sizeof(username
), host
,
8846 sizeof(host
), &port
, resource
, sizeof(resource
));
8848 if (strncmp(resource
, "/jobs/", 6))
8854 send_ipp_status(con
, IPP_BAD_REQUEST
,
8855 _("Bad job-uri \"%s\"."),
8856 uri
->values
[0].string
.text
);
8860 jobid
= atoi(resource
+ 6);
8864 * See if the job exists...
8867 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8870 * Nope - return a "not found" error...
8873 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8878 * See if the job is owned by the requesting user...
8881 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8883 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8884 cupsdFindDest(job
->dest
));
8889 * See if the job is in a state that allows holding...
8892 if (job
->state_value
> IPP_JOB_STOPPED
)
8895 * Return a "not-possible" error...
8898 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8899 _("Job #%d is finished and cannot be altered."),
8905 * Hold the job and return...
8908 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8909 IPP_TAG_KEYWORD
)) == NULL
)
8910 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8914 when
= attr
->values
[0].string
.text
;
8916 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8917 "Job job-hold-until value changed by user.");
8920 when
= "indefinite";
8922 cupsdSetJobHoldUntil(job
, when
, 1);
8923 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8926 con
->response
->request
.status
.status_code
= IPP_OK
;
8931 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8935 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8936 ipp_attribute_t
*uri
) /* I - Printer URI */
8938 http_status_t status
; /* Policy status */
8939 cups_ptype_t dtype
; /* Destination type (printer/class) */
8940 cupsd_printer_t
*printer
; /* Printer data */
8943 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8944 con
->http
.fd
, uri
->values
[0].string
.text
);
8947 * Is the destination valid?
8950 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8956 send_ipp_status(con
, IPP_NOT_FOUND
,
8957 _("The printer or class does not exist."));
8965 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8967 send_http_error(con
, status
, printer
);
8972 * Hold pending/new jobs sent to the printer...
8975 printer
->holding_new_jobs
= 1;
8977 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8979 if (dtype
& CUPS_PRINTER_CLASS
)
8980 cupsdLogMessage(CUPSD_LOG_INFO
,
8981 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8982 printer
->name
, get_username(con
));
8984 cupsdLogMessage(CUPSD_LOG_INFO
,
8985 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8986 printer
->name
, get_username(con
));
8989 * Everything was ok, so return OK status...
8992 con
->response
->request
.status
.status_code
= IPP_OK
;
8997 * 'move_job()' - Move a job to a new destination.
9001 move_job(cupsd_client_t
*con
, /* I - Client connection */
9002 ipp_attribute_t
*uri
) /* I - Job URI */
9004 http_status_t status
; /* Policy status */
9005 ipp_attribute_t
*attr
; /* Current attribute */
9006 int jobid
; /* Job ID */
9007 cupsd_job_t
*job
; /* Current job */
9008 const char *src
; /* Source printer/class */
9009 cups_ptype_t stype
, /* Source type (printer or class) */
9010 dtype
; /* Destination type (printer/class) */
9011 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
9012 username
[HTTP_MAX_URI
], /* Username portion of URI */
9013 host
[HTTP_MAX_URI
], /* Host portion of URI */
9014 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9015 int port
; /* Port portion of URI */
9016 cupsd_printer_t
*sprinter
, /* Source printer */
9017 *dprinter
; /* Destination printer */
9020 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
9021 uri
->values
[0].string
.text
);
9024 * Get the new printer or class...
9027 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
9028 IPP_TAG_URI
)) == NULL
)
9031 * Need job-printer-uri...
9034 send_ipp_status(con
, IPP_BAD_REQUEST
,
9035 _("job-printer-uri attribute missing."));
9039 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
9045 send_ipp_status(con
, IPP_NOT_FOUND
,
9046 _("The printer or class does not exist."));
9051 * See if we have a job URI or a printer URI...
9054 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9055 sizeof(scheme
), username
, sizeof(username
), host
,
9056 sizeof(host
), &port
, resource
, sizeof(resource
));
9058 if (!strcmp(uri
->name
, "printer-uri"))
9061 * Got a printer URI; see if we also have a job-id attribute...
9064 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9065 IPP_TAG_INTEGER
)) == NULL
)
9071 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
9072 &sprinter
)) == NULL
)
9078 send_ipp_status(con
, IPP_NOT_FOUND
,
9079 _("The printer or class does not exist."));
9088 * Otherwise, just move a single job...
9091 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
9094 * Nope - return a "not found" error...
9097 send_ipp_status(con
, IPP_NOT_FOUND
,
9098 _("Job #%d does not exist."), attr
->values
[0].integer
);
9104 * Job found, initialize source pointers...
9115 * Got a job URI; parse it to get the job ID...
9118 if (strncmp(resource
, "/jobs/", 6))
9124 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9125 uri
->values
[0].string
.text
);
9130 * See if the job exists...
9133 jobid
= atoi(resource
+ 6);
9135 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9138 * Nope - return a "not found" error...
9141 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9147 * Job found, initialize source pointers...
9156 * Check the policy of the destination printer...
9159 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
9160 job
? job
->username
: NULL
)) != HTTP_OK
)
9162 send_http_error(con
, status
, dprinter
);
9167 * Now move the job or jobs...
9173 * See if the job has been completed...
9176 if (job
->state_value
> IPP_JOB_STOPPED
)
9179 * Return a "not-possible" error...
9182 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9183 _("Job #%d is finished and cannot be altered."),
9189 * See if the job is owned by the requesting user...
9192 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9194 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9195 cupsdFindDest(job
->dest
));
9200 * Move the job to a different printer or class...
9203 cupsdMoveJob(job
, dprinter
);
9208 * Got the source printer, now look through the jobs...
9211 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
9213 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
9216 * See if the job is pointing at the source printer or has not been
9220 if (_cups_strcasecmp(job
->dest
, src
) ||
9221 job
->state_value
> IPP_JOB_STOPPED
)
9225 * See if the job can be moved by the requesting user...
9228 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9232 * Move the job to a different printer or class...
9235 cupsdMoveJob(job
, dprinter
);
9240 * Start jobs if possible...
9246 * Return with "everything is OK" status...
9249 con
->response
->request
.status
.status_code
= IPP_OK
;
9254 * 'ppd_parse_line()' - Parse a PPD default line.
9257 static int /* O - 0 on success, -1 on failure */
9258 ppd_parse_line(const char *line
, /* I - Line */
9259 char *option
, /* O - Option name */
9260 int olen
, /* I - Size of option name */
9261 char *choice
, /* O - Choice name */
9262 int clen
) /* I - Size of choice name */
9265 * Verify this is a default option line...
9268 if (strncmp(line
, "*Default", 8))
9272 * Read the option name...
9275 for (line
+= 8, olen
--;
9276 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9287 * Skip everything else up to the colon (:)...
9290 while (*line
&& *line
!= ':')
9299 * Now grab the option choice, skipping leading whitespace...
9302 while (isspace(*line
& 255))
9306 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9317 * Return with no errors...
9325 * 'print_job()' - Print a file to a printer or class.
9329 print_job(cupsd_client_t
*con
, /* I - Client connection */
9330 ipp_attribute_t
*uri
) /* I - Printer URI */
9332 ipp_attribute_t
*attr
; /* Current attribute */
9333 ipp_attribute_t
*format
; /* Document-format attribute */
9334 const char *default_format
; /* document-format-default value */
9335 cupsd_job_t
*job
; /* New job */
9336 char filename
[1024]; /* Job filename */
9337 mime_type_t
*filetype
; /* Type of file */
9338 char super
[MIME_MAX_SUPER
], /* Supertype of file */
9339 type
[MIME_MAX_TYPE
], /* Subtype of file */
9340 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9341 /* Textual name of mime type */
9342 cupsd_printer_t
*printer
; /* Printer data */
9343 struct stat fileinfo
; /* File information */
9344 int kbytes
; /* Size of file */
9345 int compression
; /* Document compression */
9348 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
9349 uri
->values
[0].string
.text
);
9352 * Validate print file attributes, for now just document-format and
9353 * compression (CUPS only supports "none" and "gzip")...
9356 compression
= CUPS_FILE_NONE
;
9358 if ((attr
= ippFindAttribute(con
->request
, "compression",
9359 IPP_TAG_KEYWORD
)) != NULL
)
9361 if (strcmp(attr
->values
[0].string
.text
, "none")
9363 && strcmp(attr
->values
[0].string
.text
, "gzip")
9364 #endif /* HAVE_LIBZ */
9367 send_ipp_status(con
, IPP_ATTRIBUTES
,
9368 _("Unsupported compression \"%s\"."),
9369 attr
->values
[0].string
.text
);
9370 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9371 "compression", NULL
, attr
->values
[0].string
.text
);
9376 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9377 compression
= CUPS_FILE_GZIP
;
9378 #endif /* HAVE_LIBZ */
9382 * Do we have a file to print?
9387 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9392 * Is the destination valid?
9395 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
9401 send_ipp_status(con
, IPP_NOT_FOUND
,
9402 _("The printer or class does not exist."));
9407 * Is it a format we support?
9410 if ((format
= ippFindAttribute(con
->request
, "document-format",
9411 IPP_TAG_MIMETYPE
)) != NULL
)
9414 * Grab format from client...
9417 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9420 send_ipp_status(con
, IPP_BAD_REQUEST
,
9421 _("Bad document-format \"%s\"."),
9422 format
->values
[0].string
.text
);
9426 else if ((default_format
= cupsGetOption("document-format",
9427 printer
->num_options
,
9428 printer
->options
)) != NULL
)
9431 * Use default document format...
9434 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9436 send_ipp_status(con
, IPP_BAD_REQUEST
,
9437 _("Bad document-format \"%s\"."),
9448 strcpy(super
, "application");
9449 strcpy(type
, "octet-stream");
9452 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9455 * Auto-type the file...
9458 ipp_attribute_t
*doc_name
; /* document-name attribute */
9461 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9463 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9464 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9465 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9469 filetype
= mimeType(MimeDatabase
, super
, type
);
9471 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9472 filetype
->super
, filetype
->type
);
9475 filetype
= mimeType(MimeDatabase
, super
, type
);
9479 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9482 * Replace the document-format attribute value with the auto-typed or
9486 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9491 _cupsStrFree(format
->values
[0].string
.text
);
9493 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9496 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9497 "document-format", NULL
, mimetype
);
9501 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9502 _("Unsupported document-format \"%s\"."),
9503 format
? format
->values
[0].string
.text
:
9504 "application/octet-stream");
9505 cupsdLogMessage(CUPSD_LOG_INFO
,
9506 "Hint: Do you have the raw file printing rules enabled?");
9509 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9510 "document-format", NULL
, format
->values
[0].string
.text
);
9516 * Read any embedded job ticket info from PS files...
9519 if (!_cups_strcasecmp(filetype
->super
, "application") &&
9520 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
9521 !_cups_strcasecmp(filetype
->type
, "pdf")))
9522 read_job_ticket(con
);
9525 * Create the job object...
9528 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9532 * Update quota data...
9535 if (stat(con
->filename
, &fileinfo
))
9538 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9540 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9542 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9543 IPP_TAG_INTEGER
)) != NULL
)
9544 attr
->values
[0].integer
+= kbytes
;
9547 * Add the job file...
9550 if (add_file(con
, job
, filetype
, compression
))
9553 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9555 rename(con
->filename
, filename
);
9556 cupsdClearString(&con
->filename
);
9559 * See if we need to add the ending sheet...
9562 if (cupsdTimeoutJob(job
))
9566 * Log and save the job...
9569 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9570 "File of type %s/%s queued by \"%s\".",
9571 filetype
->super
, filetype
->type
, job
->username
);
9572 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9573 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9574 job
->dest
, job
->username
);
9577 * Start the job if possible...
9585 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9587 * This function only gets called when printing a single PDF or PostScript
9588 * file using the Print-Job operation. It doesn't work for Create-Job +
9589 * Send-File, since the job attributes need to be set at job creation
9590 * time for banners to work. The embedded job ticket stuff is here
9591 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9592 * options and IPP attributes which otherwise would be lost.
9594 * The format of a job ticket is simple:
9596 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9598 * %cupsJobTicket: attr1=value1
9599 * %cupsJobTicket: attr2=value2
9601 * %cupsJobTicket: attrN=valueN
9603 * Job ticket lines must appear immediately after the first line that
9604 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9605 * stops looking for job ticket info when it finds a line that does not begin
9606 * with "%cupsJobTicket:".
9608 * The maximum length of a job ticket line, including the prefix, is
9609 * 255 characters to conform with the Adobe DSC.
9611 * Read-only attributes are rejected with a notice to the error log in
9612 * case a malicious user tries anything. Since the job ticket is read
9613 * prior to attribute validation in print_job(), job ticket attributes
9614 * will go through the same validation as IPP attributes...
9618 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9620 cups_file_t
*fp
; /* File to read from */
9621 char line
[256]; /* Line data */
9622 int num_options
; /* Number of options */
9623 cups_option_t
*options
; /* Options */
9624 ipp_t
*ticket
; /* New attributes */
9625 ipp_attribute_t
*attr
, /* Current attribute */
9626 *attr2
, /* Job attribute */
9627 *prev2
; /* Previous job attribute */
9631 * First open the print file...
9634 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9636 cupsdLogMessage(CUPSD_LOG_ERROR
,
9637 "Unable to open print file for job ticket - %s",
9643 * Skip the first line...
9646 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9648 cupsdLogMessage(CUPSD_LOG_ERROR
,
9649 "Unable to read from print file for job ticket - %s",
9655 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9658 * Not a DSC-compliant file, so no job ticket info will be available...
9666 * Read job ticket info from the file...
9672 while (cupsFileGets(fp
, line
, sizeof(line
)))
9675 * Stop at the first non-ticket line...
9678 if (strncmp(line
, "%cupsJobTicket:", 15))
9682 * Add the options to the option array...
9685 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9689 * Done with the file; see if we have any options...
9694 if (num_options
== 0)
9698 * OK, convert the options to an attribute list, and apply them to
9703 cupsEncodeOptions(ticket
, num_options
, options
);
9706 * See what the user wants to change.
9709 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9711 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9714 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9715 !strcmp(attr
->name
, "job-originating-user-name") ||
9716 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9717 !strcmp(attr
->name
, "job-k-octets") ||
9718 !strcmp(attr
->name
, "job-id") ||
9719 !strncmp(attr
->name
, "job-state", 9) ||
9720 !strncmp(attr
->name
, "time-at-", 8))
9721 continue; /* Read-only attrs */
9723 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9724 IPP_TAG_ZERO
)) != NULL
)
9727 * Some other value; first free the old value...
9730 if (con
->request
->attrs
== attr2
)
9732 con
->request
->attrs
= attr2
->next
;
9737 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9738 if (prev2
->next
== attr2
)
9740 prev2
->next
= attr2
->next
;
9745 if (con
->request
->last
== attr2
)
9746 con
->request
->last
= prev2
;
9748 _ippFreeAttr(attr2
);
9752 * Add new option by copying it...
9755 copy_attribute(con
->request
, attr
, 0);
9759 * Then free the attribute list and option array...
9763 cupsFreeOptions(num_options
, options
);
9768 * 'reject_jobs()' - Reject print jobs to a printer.
9772 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9773 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9775 http_status_t status
; /* Policy status */
9776 cups_ptype_t dtype
; /* Destination type (printer/class) */
9777 cupsd_printer_t
*printer
; /* Printer data */
9778 ipp_attribute_t
*attr
; /* printer-state-message text */
9781 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9782 con
->http
.fd
, uri
->values
[0].string
.text
);
9785 * Is the destination valid?
9788 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9794 send_ipp_status(con
, IPP_NOT_FOUND
,
9795 _("The printer or class does not exist."));
9803 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9805 send_http_error(con
, status
, printer
);
9810 * Reject jobs sent to the printer...
9813 printer
->accepting
= 0;
9815 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9816 IPP_TAG_TEXT
)) == NULL
)
9817 strcpy(printer
->state_message
, "Rejecting Jobs");
9819 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9820 sizeof(printer
->state_message
));
9822 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9823 "No longer accepting jobs.");
9825 if (dtype
& CUPS_PRINTER_CLASS
)
9827 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9829 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9830 printer
->name
, get_username(con
));
9834 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9836 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9837 printer
->name
, get_username(con
));
9841 * Everything was ok, so return OK status...
9844 con
->response
->request
.status
.status_code
= IPP_OK
;
9849 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9853 release_held_new_jobs(
9854 cupsd_client_t
*con
, /* I - Connection */
9855 ipp_attribute_t
*uri
) /* I - Printer URI */
9857 http_status_t status
; /* Policy status */
9858 cups_ptype_t dtype
; /* Destination type (printer/class) */
9859 cupsd_printer_t
*printer
; /* Printer data */
9862 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9863 con
->http
.fd
, uri
->values
[0].string
.text
);
9866 * Is the destination valid?
9869 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9875 send_ipp_status(con
, IPP_NOT_FOUND
,
9876 _("The printer or class does not exist."));
9884 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9886 send_http_error(con
, status
, printer
);
9891 * Hold pending/new jobs sent to the printer...
9894 printer
->holding_new_jobs
= 0;
9896 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9898 if (dtype
& CUPS_PRINTER_CLASS
)
9899 cupsdLogMessage(CUPSD_LOG_INFO
,
9900 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9901 printer
->name
, get_username(con
));
9903 cupsdLogMessage(CUPSD_LOG_INFO
,
9904 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9905 printer
->name
, get_username(con
));
9908 * Everything was ok, so return OK status...
9911 con
->response
->request
.status
.status_code
= IPP_OK
;
9916 * 'release_job()' - Release a held print job.
9920 release_job(cupsd_client_t
*con
, /* I - Client connection */
9921 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9923 ipp_attribute_t
*attr
; /* Current attribute */
9924 int jobid
; /* Job ID */
9925 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9926 username
[HTTP_MAX_URI
], /* Username portion of URI */
9927 host
[HTTP_MAX_URI
], /* Host portion of URI */
9928 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9929 int port
; /* Port portion of URI */
9930 cupsd_job_t
*job
; /* Job information */
9933 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9934 con
->http
.fd
, uri
->values
[0].string
.text
);
9937 * See if we have a job URI or a printer URI...
9940 if (!strcmp(uri
->name
, "printer-uri"))
9943 * Got a printer URI; see if we also have a job-id attribute...
9946 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9947 IPP_TAG_INTEGER
)) == NULL
)
9949 send_ipp_status(con
, IPP_BAD_REQUEST
,
9950 _("Got a printer-uri attribute but no job-id."));
9954 jobid
= attr
->values
[0].integer
;
9959 * Got a job URI; parse it to get the job ID...
9962 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9963 sizeof(scheme
), username
, sizeof(username
), host
,
9964 sizeof(host
), &port
, resource
, sizeof(resource
));
9966 if (strncmp(resource
, "/jobs/", 6))
9972 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9973 uri
->values
[0].string
.text
);
9977 jobid
= atoi(resource
+ 6);
9981 * See if the job exists...
9984 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9987 * Nope - return a "not found" error...
9990 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9995 * See if job is "held"...
9998 if (job
->state_value
!= IPP_JOB_HELD
)
10001 * Nope - return a "not possible" error...
10004 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
10009 * See if the job is owned by the requesting user...
10012 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10014 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10015 cupsdFindDest(job
->dest
));
10020 * Reset the job-hold-until value to "no-hold"...
10023 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10024 IPP_TAG_KEYWORD
)) == NULL
)
10025 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10029 _cupsStrFree(attr
->values
[0].string
.text
);
10031 attr
->value_tag
= IPP_TAG_KEYWORD
;
10032 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
10034 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10035 "Job job-hold-until value changed by user.");
10039 * Release the job and return...
10042 cupsdReleaseJob(job
);
10044 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10045 "Job released by user.");
10047 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
10049 con
->response
->request
.status
.status_code
= IPP_OK
;
10056 * 'renew_subscription()' - Renew an existing subscription...
10060 renew_subscription(
10061 cupsd_client_t
*con
, /* I - Client connection */
10062 int sub_id
) /* I - Subscription ID */
10064 http_status_t status
; /* Policy status */
10065 cupsd_subscription_t
*sub
; /* Subscription */
10066 ipp_attribute_t
*lease
; /* notify-lease-duration */
10069 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
10070 "renew_subscription(con=%p[%d], sub_id=%d)",
10071 con
, con
->http
.fd
, sub_id
);
10074 * Is the subscription ID valid?
10077 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
10080 * Bad subscription ID...
10083 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
10091 * Job subscriptions cannot be renewed...
10094 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10095 _("Job subscriptions cannot be renewed."));
10103 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
10105 con
, sub
->owner
)) != HTTP_OK
)
10107 send_http_error(con
, status
, sub
->dest
);
10112 * Renew the subscription...
10115 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
10118 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
10120 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
10122 cupsdLogMessage(CUPSD_LOG_INFO
,
10123 "renew_subscription: Limiting notify-lease-duration to "
10126 sub
->lease
= MaxLeaseDuration
;
10129 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
10131 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
10133 con
->response
->request
.status
.status_code
= IPP_OK
;
10135 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
10136 "notify-lease-duration", sub
->lease
);
10141 * 'restart_job()' - Restart an old print job.
10145 restart_job(cupsd_client_t
*con
, /* I - Client connection */
10146 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
10148 ipp_attribute_t
*attr
; /* Current attribute */
10149 int jobid
; /* Job ID */
10150 cupsd_job_t
*job
; /* Job information */
10151 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
10152 username
[HTTP_MAX_URI
], /* Username portion of URI */
10153 host
[HTTP_MAX_URI
], /* Host portion of URI */
10154 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10155 int port
; /* Port portion of URI */
10158 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
10159 con
->http
.fd
, uri
->values
[0].string
.text
);
10162 * See if we have a job URI or a printer URI...
10165 if (!strcmp(uri
->name
, "printer-uri"))
10168 * Got a printer URI; see if we also have a job-id attribute...
10171 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10172 IPP_TAG_INTEGER
)) == NULL
)
10174 send_ipp_status(con
, IPP_BAD_REQUEST
,
10175 _("Got a printer-uri attribute but no job-id."));
10179 jobid
= attr
->values
[0].integer
;
10184 * Got a job URI; parse it to get the job ID...
10187 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10188 sizeof(scheme
), username
, sizeof(username
), host
,
10189 sizeof(host
), &port
, resource
, sizeof(resource
));
10191 if (strncmp(resource
, "/jobs/", 6))
10197 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10198 uri
->values
[0].string
.text
);
10202 jobid
= atoi(resource
+ 6);
10206 * See if the job exists...
10209 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10212 * Nope - return a "not found" error...
10215 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10220 * See if job is in any of the "completed" states...
10223 if (job
->state_value
<= IPP_JOB_PROCESSING
)
10226 * Nope - return a "not possible" error...
10229 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
10235 * See if we have retained the job files...
10240 if (!job
->attrs
|| job
->num_files
== 0)
10243 * Nope - return a "not possible" error...
10246 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10247 _("Job #%d cannot be restarted - no files."), jobid
);
10252 * See if the job is owned by the requesting user...
10255 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10257 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10258 cupsdFindDest(job
->dest
));
10263 * See if the job-hold-until attribute is specified...
10266 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
10267 IPP_TAG_KEYWORD
)) == NULL
)
10268 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
10270 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
10273 * Return the job to a held state...
10276 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
10277 "Restarted by \"%s\" with job-hold-until=%s.",
10278 username
, attr
->values
[0].string
.text
);
10279 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10281 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
10282 NULL
, job
, "Job restarted by user with job-hold-until=%s",
10283 attr
->values
[0].string
.text
);
10288 * Restart the job...
10291 cupsdRestartJob(job
);
10295 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
10297 con
->response
->request
.status
.status_code
= IPP_OK
;
10302 * 'save_auth_info()' - Save authentication information for a job.
10307 cupsd_client_t
*con
, /* I - Client connection */
10308 cupsd_job_t
*job
, /* I - Job */
10309 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
10311 int i
; /* Looping var */
10312 char filename
[1024]; /* Job authentication filename */
10313 cups_file_t
*fp
; /* Job authentication file */
10314 char line
[2048]; /* Line for file */
10315 cupsd_printer_t
*dest
; /* Destination printer/class */
10319 * This function saves the in-memory authentication information for
10320 * a job so that it can be used to authenticate with a remote host.
10321 * The information is stored in a file that is readable only by the
10322 * root user. The fields are Base-64 encoded, each on a separate line,
10323 * followed by random number (up to 1024) of newlines to limit the
10324 * amount of information that is exposed.
10326 * Because of the potential for exposing of authentication information,
10327 * this functionality is only enabled when running cupsd as root.
10329 * This caching only works for the Basic and BasicDigest authentication
10330 * types. Digest authentication cannot be cached this way, and in
10331 * the future Kerberos authentication may make all of this obsolete.
10333 * Authentication information is saved whenever an authenticated
10334 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
10337 * This information is deleted after a job is completed or canceled,
10338 * so reprints may require subsequent re-authentication.
10344 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
10348 * Create the authentication file and change permissions...
10351 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
10352 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
10354 cupsdLogMessage(CUPSD_LOG_ERROR
,
10355 "Unable to save authentication info to \"%s\" - %s",
10356 filename
, strerror(errno
));
10360 fchown(cupsFileNumber(fp
), 0, 0);
10361 fchmod(cupsFileNumber(fp
), 0400);
10364 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
10366 cupsdClearString(job
->auth_env
+ i
);
10368 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
10371 * Write 1 to 3 auth values...
10375 i
< auth_info
->num_values
&&
10376 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
10379 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
10380 strlen(auth_info
->values
[i
].string
.text
));
10381 cupsFilePrintf(fp
, "%s\n", line
);
10383 if (!strcmp(dest
->auth_info_required
[i
], "username"))
10384 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
10385 auth_info
->values
[i
].string
.text
);
10386 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
10387 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
10388 auth_info
->values
[i
].string
.text
);
10389 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
10390 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
10391 auth_info
->values
[i
].string
.text
);
10392 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
10393 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
10394 auth_info
->values
[i
].string
.text
);
10396 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_%s=%s",
10397 dest
->auth_info_required
[i
],
10398 auth_info
->values
[i
].string
.text
);
10401 else if (con
->username
[0])
10404 * Write the authenticated username...
10407 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
10408 cupsFilePrintf(fp
, "%s\n", line
);
10410 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
10413 * Write the authenticated password...
10416 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10417 cupsFilePrintf(fp
, "%s\n", line
);
10419 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
10423 if (con
->gss_uid
> 0)
10425 cupsFilePrintf(fp
, "%d\n", (int)con
->gss_uid
);
10426 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
10428 #endif /* HAVE_GSSAPI */
10431 * Write a random number of newlines to the end of the file...
10434 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10435 cupsFilePutChar(fp
, '\n');
10438 * Close the file and return...
10446 * 'send_document()' - Send a file to a printer or class.
10450 send_document(cupsd_client_t
*con
, /* I - Client connection */
10451 ipp_attribute_t
*uri
) /* I - Printer URI */
10453 ipp_attribute_t
*attr
; /* Current attribute */
10454 ipp_attribute_t
*format
; /* Request's document-format attribute */
10455 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10456 const char *default_format
;/* document-format-default value */
10457 int jobid
; /* Job ID number */
10458 cupsd_job_t
*job
; /* Current job */
10459 char job_uri
[HTTP_MAX_URI
],
10461 scheme
[HTTP_MAX_URI
],
10462 /* Method portion of URI */
10463 username
[HTTP_MAX_URI
],
10464 /* Username portion of URI */
10465 host
[HTTP_MAX_URI
],
10466 /* Host portion of URI */
10467 resource
[HTTP_MAX_URI
];
10468 /* Resource portion of URI */
10469 int port
; /* Port portion of URI */
10470 mime_type_t
*filetype
; /* Type of file */
10471 char super
[MIME_MAX_SUPER
],
10472 /* Supertype of file */
10473 type
[MIME_MAX_TYPE
],
10474 /* Subtype of file */
10475 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10476 /* Textual name of mime type */
10477 char filename
[1024]; /* Job filename */
10478 cupsd_printer_t
*printer
; /* Current printer */
10479 struct stat fileinfo
; /* File information */
10480 int kbytes
; /* Size of file */
10481 int compression
; /* Type of compression */
10482 int start_job
; /* Start the job? */
10485 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10486 con
->http
.fd
, uri
->values
[0].string
.text
);
10489 * See if we have a job URI or a printer URI...
10492 if (!strcmp(uri
->name
, "printer-uri"))
10495 * Got a printer URI; see if we also have a job-id attribute...
10498 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10499 IPP_TAG_INTEGER
)) == NULL
)
10501 send_ipp_status(con
, IPP_BAD_REQUEST
,
10502 _("Got a printer-uri attribute but no job-id."));
10506 jobid
= attr
->values
[0].integer
;
10511 * Got a job URI; parse it to get the job ID...
10514 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10515 sizeof(scheme
), username
, sizeof(username
), host
,
10516 sizeof(host
), &port
, resource
, sizeof(resource
));
10518 if (strncmp(resource
, "/jobs/", 6))
10524 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10525 uri
->values
[0].string
.text
);
10529 jobid
= atoi(resource
+ 6);
10533 * See if the job exists...
10536 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10539 * Nope - return a "not found" error...
10542 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10546 printer
= cupsdFindDest(job
->dest
);
10549 * See if the job is owned by the requesting user...
10552 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10554 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10555 cupsdFindDest(job
->dest
));
10560 * OK, see if the client is sending the document compressed - CUPS
10561 * only supports "none" and "gzip".
10564 compression
= CUPS_FILE_NONE
;
10566 if ((attr
= ippFindAttribute(con
->request
, "compression",
10567 IPP_TAG_KEYWORD
)) != NULL
)
10569 if (strcmp(attr
->values
[0].string
.text
, "none")
10571 && strcmp(attr
->values
[0].string
.text
, "gzip")
10572 #endif /* HAVE_LIBZ */
10575 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
10576 attr
->values
[0].string
.text
);
10577 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10578 "compression", NULL
, attr
->values
[0].string
.text
);
10583 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10584 compression
= CUPS_FILE_GZIP
;
10585 #endif /* HAVE_LIBZ */
10589 * Do we have a file to print?
10592 if (!con
->filename
)
10595 * Check for an empty request with "last-document" set to true, which is
10596 * used to close an "open" job by RFC 2911, section 3.3.2.
10599 if (job
->num_files
> 0 &&
10600 (attr
= ippFindAttribute(con
->request
, "last-document",
10601 IPP_TAG_BOOLEAN
)) != NULL
&&
10602 attr
->values
[0].boolean
)
10603 goto last_document
;
10605 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
10610 * Is it a format we support?
10613 if ((format
= ippFindAttribute(con
->request
, "document-format",
10614 IPP_TAG_MIMETYPE
)) != NULL
)
10617 * Grab format from client...
10620 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10623 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
10624 format
->values
[0].string
.text
);
10628 else if ((default_format
= cupsGetOption("document-format",
10629 printer
->num_options
,
10630 printer
->options
)) != NULL
)
10633 * Use default document format...
10636 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10638 send_ipp_status(con
, IPP_BAD_REQUEST
,
10639 _("Bad document-format-default \"%s\"."), default_format
);
10646 * No document format attribute? Auto-type it!
10649 strcpy(super
, "application");
10650 strcpy(type
, "octet-stream");
10653 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10656 * Auto-type the file...
10659 ipp_attribute_t
*doc_name
; /* document-name attribute */
10662 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10664 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10665 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10666 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10670 filetype
= mimeType(MimeDatabase
, super
, type
);
10673 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10674 filetype
->super
, filetype
->type
);
10677 filetype
= mimeType(MimeDatabase
, super
, type
);
10682 * Replace the document-format attribute value with the auto-typed or
10686 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10689 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10690 IPP_TAG_MIMETYPE
)) != NULL
)
10692 _cupsStrFree(jformat
->values
[0].string
.text
);
10694 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10697 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10698 "document-format", NULL
, mimetype
);
10700 else if (!filetype
)
10702 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10703 _("Unsupported document-format \"%s/%s\"."), super
, type
);
10704 cupsdLogMessage(CUPSD_LOG_INFO
,
10705 "Hint: Do you have the raw file printing rules enabled?");
10708 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10709 "document-format", NULL
, format
->values
[0].string
.text
);
10714 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10716 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10719 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10720 _("Unsupported document-format \"%s\"."), mimetype
);
10722 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10723 "document-format", NULL
, mimetype
);
10729 * Add the file to the job...
10734 if (add_file(con
, job
, filetype
, compression
))
10737 if (stat(con
->filename
, &fileinfo
))
10740 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10742 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10744 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10745 IPP_TAG_INTEGER
)) != NULL
)
10746 attr
->values
[0].integer
+= kbytes
;
10748 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10750 rename(con
->filename
, filename
);
10752 cupsdClearString(&con
->filename
);
10754 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10755 filetype
->super
, filetype
->type
, job
->username
);
10758 * Start the job if this is the last document...
10763 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10764 IPP_TAG_BOOLEAN
)) != NULL
&&
10765 attr
->values
[0].boolean
)
10768 * See if we need to add the ending sheet...
10771 if (cupsdTimeoutJob(job
))
10774 if (job
->state_value
== IPP_JOB_STOPPED
)
10776 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10777 job
->state_value
= IPP_JOB_PENDING
;
10779 else if (job
->state_value
== IPP_JOB_HELD
)
10781 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10782 IPP_TAG_KEYWORD
)) == NULL
)
10783 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10785 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10787 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10788 job
->state_value
= IPP_JOB_PENDING
;
10793 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10799 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10800 IPP_TAG_KEYWORD
)) == NULL
)
10801 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10803 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10805 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10806 job
->state_value
= IPP_JOB_HELD
;
10807 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10810 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10817 * Fill in the response info...
10820 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10823 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10826 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10828 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10830 add_job_state_reasons(con
, job
);
10832 con
->response
->request
.status
.status_code
= IPP_OK
;
10835 * Start the job if necessary...
10844 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10849 cupsd_client_t
*con
, /* I - Client connection */
10850 http_status_t status
, /* I - HTTP status code */
10851 cupsd_printer_t
*printer
) /* I - Printer, if any */
10853 ipp_attribute_t
*uri
; /* Request URI, if any */
10856 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10857 IPP_TAG_URI
)) == NULL
)
10858 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10860 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10861 "Returning HTTP %s for %s (%s) from %s",
10862 httpStatus(status
),
10864 ippOpString(con
->request
->request
.op
.operation_id
) :
10866 uri
? uri
->values
[0].string
.text
: "no URI",
10867 con
->http
.hostname
);
10871 int auth_type
; /* Type of authentication required */
10874 auth_type
= CUPSD_AUTH_NONE
;
10876 if (status
== HTTP_UNAUTHORIZED
&&
10877 printer
->num_auth_info_required
> 0 &&
10878 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10880 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10881 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10882 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10885 * Creating and authenticating jobs requires Kerberos...
10888 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10893 * Use policy/location-defined authentication requirements...
10896 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10897 cupsd_location_t
*auth
; /* Pointer to authentication element */
10900 if (printer
->type
& CUPS_PRINTER_CLASS
)
10901 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10903 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10905 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10906 auth
->type
== CUPSD_AUTH_NONE
)
10907 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10909 con
->request
->request
.op
.operation_id
:
10914 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10915 auth_type
= DefaultAuthType
;
10917 auth_type
= auth
->type
;
10921 cupsdSendError(con
, status
, auth_type
);
10924 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10926 ippDelete(con
->response
);
10927 con
->response
= NULL
;
10934 * 'send_ipp_status()' - Send a status back to the IPP client.
10938 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10939 ipp_status_t status
, /* I - IPP status code */
10940 const char *message
,/* I - Status message */
10941 ...) /* I - Additional args as needed */
10943 va_list ap
; /* Pointer to additional args */
10944 char formatted
[1024]; /* Formatted errror message */
10947 va_start(ap
, message
);
10948 vsnprintf(formatted
, sizeof(formatted
),
10949 _cupsLangString(con
->language
, message
), ap
);
10952 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10953 ippOpString(con
->request
->request
.op
.operation_id
),
10954 ippErrorString(status
), formatted
);
10956 con
->response
->request
.status
.status_code
= status
;
10958 if (ippFindAttribute(con
->response
, "attributes-charset",
10959 IPP_TAG_ZERO
) == NULL
)
10960 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10961 "attributes-charset", NULL
, "utf-8");
10963 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10964 IPP_TAG_ZERO
) == NULL
)
10965 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10966 "attributes-natural-language", NULL
, DefaultLanguage
);
10968 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10969 "status-message", NULL
, formatted
);
10974 * 'set_default()' - Set the default destination...
10978 set_default(cupsd_client_t
*con
, /* I - Client connection */
10979 ipp_attribute_t
*uri
) /* I - Printer URI */
10981 http_status_t status
; /* Policy status */
10982 cups_ptype_t dtype
; /* Destination type (printer/class) */
10983 cupsd_printer_t
*printer
, /* Printer */
10984 *oldprinter
; /* Old default printer */
10987 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10988 con
->http
.fd
, uri
->values
[0].string
.text
);
10991 * Is the destination valid?
10994 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11000 send_ipp_status(con
, IPP_NOT_FOUND
,
11001 _("The printer or class does not exist."));
11009 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
11011 send_http_error(con
, status
, NULL
);
11016 * Set it as the default...
11019 oldprinter
= DefaultPrinter
;
11020 DefaultPrinter
= printer
;
11023 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
11024 "%s is no longer the default printer.", oldprinter
->name
);
11026 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
11027 "%s is now the default printer.", printer
->name
);
11029 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
11030 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
11032 cupsdLogMessage(CUPSD_LOG_INFO
,
11033 "Default destination set to \"%s\" by \"%s\".",
11034 printer
->name
, get_username(con
));
11037 * Everything was ok, so return OK status...
11040 con
->response
->request
.status
.status_code
= IPP_OK
;
11045 * 'set_job_attrs()' - Set job attributes.
11049 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
11050 ipp_attribute_t
*uri
) /* I - Job URI */
11052 ipp_attribute_t
*attr
, /* Current attribute */
11053 *attr2
; /* Job attribute */
11054 int jobid
; /* Job ID */
11055 cupsd_job_t
*job
; /* Current job */
11056 char scheme
[HTTP_MAX_URI
],
11057 /* Method portion of URI */
11058 username
[HTTP_MAX_URI
],
11059 /* Username portion of URI */
11060 host
[HTTP_MAX_URI
],
11061 /* Host portion of URI */
11062 resource
[HTTP_MAX_URI
];
11063 /* Resource portion of URI */
11064 int port
; /* Port portion of URI */
11065 int event
; /* Events? */
11066 int check_jobs
; /* Check jobs? */
11069 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
11070 con
->http
.fd
, uri
->values
[0].string
.text
);
11073 * Start with "everything is OK" status...
11076 con
->response
->request
.status
.status_code
= IPP_OK
;
11079 * See if we have a job URI or a printer URI...
11082 if (!strcmp(uri
->name
, "printer-uri"))
11085 * Got a printer URI; see if we also have a job-id attribute...
11088 if ((attr
= ippFindAttribute(con
->request
, "job-id",
11089 IPP_TAG_INTEGER
)) == NULL
)
11091 send_ipp_status(con
, IPP_BAD_REQUEST
,
11092 _("Got a printer-uri attribute but no job-id."));
11096 jobid
= attr
->values
[0].integer
;
11101 * Got a job URI; parse it to get the job ID...
11104 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
11105 sizeof(scheme
), username
, sizeof(username
), host
,
11106 sizeof(host
), &port
, resource
, sizeof(resource
));
11108 if (strncmp(resource
, "/jobs/", 6))
11114 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
11115 uri
->values
[0].string
.text
);
11119 jobid
= atoi(resource
+ 6);
11123 * See if the job exists...
11126 if ((job
= cupsdFindJob(jobid
)) == NULL
)
11129 * Nope - return a "not found" error...
11132 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
11137 * See if the job has been completed...
11140 if (job
->state_value
> IPP_JOB_STOPPED
)
11143 * Return a "not-possible" error...
11146 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11147 _("Job #%d is finished and cannot be altered."), jobid
);
11152 * See if the job is owned by the requesting user...
11155 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
11157 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
11158 cupsdFindDest(job
->dest
));
11163 * See what the user wants to change.
11171 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11173 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
11176 if (!strcmp(attr
->name
, "attributes-charset") ||
11177 !strcmp(attr
->name
, "attributes-natural-language") ||
11178 !strcmp(attr
->name
, "document-compression") ||
11179 !strcmp(attr
->name
, "document-format") ||
11180 !strcmp(attr
->name
, "job-detailed-status-messages") ||
11181 !strcmp(attr
->name
, "job-document-access-errors") ||
11182 !strcmp(attr
->name
, "job-id") ||
11183 !strcmp(attr
->name
, "job-impressions-completed") ||
11184 !strcmp(attr
->name
, "job-k-octets") ||
11185 !strcmp(attr
->name
, "job-originating-host-name") ||
11186 !strcmp(attr
->name
, "job-originating-user-name") ||
11187 !strcmp(attr
->name
, "job-printer-up-time") ||
11188 !strcmp(attr
->name
, "job-printer-uri") ||
11189 !strcmp(attr
->name
, "job-sheets") ||
11190 !strcmp(attr
->name
, "job-state-message") ||
11191 !strcmp(attr
->name
, "job-state-reasons") ||
11192 !strcmp(attr
->name
, "job-uri") ||
11193 !strcmp(attr
->name
, "number-of-documents") ||
11194 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
11195 !strcmp(attr
->name
, "output-device-assigned") ||
11196 !strncmp(attr
->name
, "date-time-at-", 13) ||
11197 !strncmp(attr
->name
, "job-k-octets", 12) ||
11198 !strncmp(attr
->name
, "job-media-sheets", 16) ||
11199 !strncmp(attr
->name
, "time-at-", 8))
11205 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
11206 _("%s cannot be changed."), attr
->name
);
11208 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11209 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11214 if (!strcmp(attr
->name
, "job-priority"))
11217 * Change the job priority...
11220 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11222 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
11224 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11225 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11227 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
11229 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11230 _("Job is completed and cannot be changed."));
11233 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11235 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
11236 attr
->values
[0].integer
);
11237 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
11240 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
11241 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
11244 else if (!strcmp(attr
->name
, "job-state"))
11247 * Change the job state...
11250 if (attr
->value_tag
!= IPP_TAG_ENUM
)
11252 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
11254 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11255 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11259 switch (attr
->values
[0].integer
)
11261 case IPP_JOB_PENDING
:
11262 case IPP_JOB_HELD
:
11263 if (job
->state_value
> IPP_JOB_HELD
)
11265 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11266 _("Job state cannot be changed."));
11269 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11271 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11272 attr
->values
[0].integer
);
11273 cupsdSetJobState(job
, attr
->values
[0].integer
,
11275 "Job state changed by \"%s\"", username
);
11280 case IPP_JOB_PROCESSING
:
11281 case IPP_JOB_STOPPED
:
11282 if (job
->state_value
!= attr
->values
[0].integer
)
11284 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11285 _("Job state cannot be changed."));
11290 case IPP_JOB_CANCELED
:
11291 case IPP_JOB_ABORTED
:
11292 case IPP_JOB_COMPLETED
:
11293 if (job
->state_value
> IPP_JOB_PROCESSING
)
11295 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11296 _("Job state cannot be changed."));
11299 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11301 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11302 attr
->values
[0].integer
);
11303 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
11305 "Job state changed by \"%s\"", username
);
11312 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
11314 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11315 IPP_TAG_ZERO
)) != NULL
)
11318 * Some other value; first free the old value...
11321 if (job
->attrs
->prev
)
11322 job
->attrs
->prev
->next
= attr2
->next
;
11324 job
->attrs
->attrs
= attr2
->next
;
11326 if (job
->attrs
->last
== attr2
)
11327 job
->attrs
->last
= job
->attrs
->prev
;
11329 _ippFreeAttr(attr2
);
11332 * Then copy the attribute...
11335 copy_attribute(job
->attrs
, attr
, 0);
11338 * See if the job-name or job-hold-until is being changed.
11341 if (!strcmp(attr
->name
, "job-hold-until"))
11343 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
11344 attr
->values
[0].string
.text
);
11345 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
11347 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
11349 cupsdReleaseJob(job
);
11353 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
11354 "Job held by \"%s\".", username
);
11356 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
11359 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
11362 * Delete the attribute...
11365 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11366 IPP_TAG_ZERO
)) != NULL
)
11368 if (job
->attrs
->prev
)
11369 job
->attrs
->prev
->next
= attr2
->next
;
11371 job
->attrs
->attrs
= attr2
->next
;
11373 if (attr2
== job
->attrs
->last
)
11374 job
->attrs
->last
= job
->attrs
->prev
;
11376 _ippFreeAttr(attr2
);
11378 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11384 * Add new option by copying it...
11387 copy_attribute(job
->attrs
, attr
, 0);
11389 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11398 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11401 * Send events as needed...
11404 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11405 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11406 cupsdFindDest(job
->dest
), job
,
11407 "Job priority changed by user.");
11409 if (event
& CUPSD_EVENT_JOB_STATE
)
11410 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11411 job
->state_value
== IPP_JOB_HELD
?
11412 "Job held by user." : "Job restarted by user.");
11414 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11415 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11416 "Job options changed by user.");
11419 * Start jobs if possible...
11428 * 'set_printer_attrs()' - Set printer attributes.
11432 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11433 ipp_attribute_t
*uri
) /* I - Printer */
11435 http_status_t status
; /* Policy status */
11436 cups_ptype_t dtype
; /* Destination type (printer/class) */
11437 cupsd_printer_t
*printer
; /* Printer/class */
11438 ipp_attribute_t
*attr
; /* Printer attribute */
11439 int changed
= 0; /* Was anything changed? */
11442 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11443 con
->http
.fd
, uri
->values
[0].string
.text
);
11446 * Is the destination valid?
11449 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11455 send_ipp_status(con
, IPP_NOT_FOUND
,
11456 _("The printer or class does not exist."));
11464 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11466 send_http_error(con
, status
, printer
);
11471 * Return a list of attributes that can be set via Set-Printer-Attributes.
11474 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11475 IPP_TAG_TEXT
)) != NULL
)
11477 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11481 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11482 IPP_TAG_TEXT
)) != NULL
)
11484 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11489 * Update the printer attributes and return...
11494 cupsdSetPrinterAttrs(printer
);
11495 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11497 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11498 "Printer \"%s\" description or location changed by \"%s\".",
11499 printer
->name
, get_username(con
));
11501 cupsdLogMessage(CUPSD_LOG_INFO
,
11502 "Printer \"%s\" description or location changed by \"%s\".",
11503 printer
->name
, get_username(con
));
11506 con
->response
->request
.status
.status_code
= IPP_OK
;
11511 * 'set_printer_defaults()' - Set printer default options from a request.
11515 set_printer_defaults(
11516 cupsd_client_t
*con
, /* I - Client connection */
11517 cupsd_printer_t
*printer
) /* I - Printer */
11519 int i
; /* Looping var */
11520 ipp_attribute_t
*attr
; /* Current attribute */
11521 int namelen
; /* Length of attribute name */
11522 char name
[256], /* New attribute name */
11523 value
[256]; /* String version of integer attrs */
11526 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11529 * Skip non-printer attributes...
11532 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11535 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11537 if (!strcmp(attr
->name
, "job-sheets-default"))
11540 * Only allow keywords and names...
11543 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11547 * Only allow job-sheets-default to be set when running without a
11548 * system high classification level...
11551 if (Classification
)
11554 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11556 if (attr
->num_values
> 1)
11557 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11559 cupsdSetString(&printer
->job_sheets
[1], "none");
11561 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11563 cupsdFreeStrings(&(printer
->users
));
11565 printer
->deny_users
= 0;
11567 if (attr
->value_tag
== IPP_TAG_NAME
&&
11568 (attr
->num_values
> 1 ||
11569 strcmp(attr
->values
[0].string
.text
, "all")))
11571 for (i
= 0; i
< attr
->num_values
; i
++)
11572 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11575 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11577 cupsdFreeStrings(&(printer
->users
));
11579 printer
->deny_users
= 1;
11581 if (attr
->value_tag
== IPP_TAG_NAME
&&
11582 (attr
->num_values
> 1 ||
11583 strcmp(attr
->values
[0].string
.text
, "none")))
11585 for (i
= 0; i
< attr
->num_values
; i
++)
11586 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11589 else if (!strcmp(attr
->name
, "job-quota-period"))
11591 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11594 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11595 attr
->values
[0].integer
);
11596 cupsdFreeQuotas(printer
);
11598 printer
->quota_period
= attr
->values
[0].integer
;
11600 else if (!strcmp(attr
->name
, "job-k-limit"))
11602 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11605 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11606 attr
->values
[0].integer
);
11607 cupsdFreeQuotas(printer
);
11609 printer
->k_limit
= attr
->values
[0].integer
;
11611 else if (!strcmp(attr
->name
, "job-page-limit"))
11613 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11616 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11617 attr
->values
[0].integer
);
11618 cupsdFreeQuotas(printer
);
11620 printer
->page_limit
= attr
->values
[0].integer
;
11622 else if (!strcmp(attr
->name
, "printer-op-policy"))
11624 cupsd_policy_t
*p
; /* Policy */
11627 if (attr
->value_tag
!= IPP_TAG_NAME
)
11630 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11632 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11633 "Setting printer-op-policy to \"%s\"...",
11634 attr
->values
[0].string
.text
);
11635 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11636 printer
->op_policy_ptr
= p
;
11640 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11641 _("Unknown printer-op-policy \"%s\"."),
11642 attr
->values
[0].string
.text
);
11646 else if (!strcmp(attr
->name
, "printer-error-policy"))
11648 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11651 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11652 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
11653 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11654 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11655 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11657 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11658 _("Unknown printer-error-policy \"%s\"."),
11659 attr
->values
[0].string
.text
);
11663 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11664 "Setting printer-error-policy to \"%s\"...",
11665 attr
->values
[0].string
.text
);
11666 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11670 * Skip any other non-default attributes...
11673 namelen
= strlen(attr
->name
);
11674 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11675 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11679 * OK, anything else must be a user-defined default...
11682 strlcpy(name
, attr
->name
, sizeof(name
));
11683 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11685 switch (attr
->value_tag
)
11687 case IPP_TAG_DELETEATTR
:
11688 printer
->num_options
= cupsRemoveOption(name
,
11689 printer
->num_options
,
11690 &(printer
->options
));
11691 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11692 "Deleting %s", attr
->name
);
11695 case IPP_TAG_NAME
:
11696 case IPP_TAG_KEYWORD
:
11698 printer
->num_options
= cupsAddOption(name
,
11699 attr
->values
[0].string
.text
,
11700 printer
->num_options
,
11701 &(printer
->options
));
11702 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11703 "Setting %s to \"%s\"...", attr
->name
,
11704 attr
->values
[0].string
.text
);
11707 case IPP_TAG_BOOLEAN
:
11708 printer
->num_options
= cupsAddOption(name
,
11709 attr
->values
[0].boolean
?
11711 printer
->num_options
,
11712 &(printer
->options
));
11713 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11714 "Setting %s to %s...", attr
->name
,
11715 attr
->values
[0].boolean
? "true" : "false");
11718 case IPP_TAG_INTEGER
:
11719 case IPP_TAG_ENUM
:
11720 sprintf(value
, "%d", attr
->values
[0].integer
);
11721 printer
->num_options
= cupsAddOption(name
, value
,
11722 printer
->num_options
,
11723 &(printer
->options
));
11724 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11725 "Setting %s to %s...", attr
->name
, value
);
11728 case IPP_TAG_RANGE
:
11729 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11730 attr
->values
[0].range
.upper
);
11731 printer
->num_options
= cupsAddOption(name
, value
,
11732 printer
->num_options
,
11733 &(printer
->options
));
11734 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11735 "Setting %s to %s...", attr
->name
, value
);
11738 case IPP_TAG_RESOLUTION
:
11739 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11740 attr
->values
[0].resolution
.yres
,
11741 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11743 printer
->num_options
= cupsAddOption(name
, value
,
11744 printer
->num_options
,
11745 &(printer
->options
));
11746 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11747 "Setting %s to %s...", attr
->name
, value
);
11751 /* Do nothing for other values */
11759 * 'start_printer()' - Start a printer.
11763 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11764 ipp_attribute_t
*uri
) /* I - Printer URI */
11766 int i
; /* Temporary variable */
11767 http_status_t status
; /* Policy status */
11768 cups_ptype_t dtype
; /* Destination type (printer/class) */
11769 cupsd_printer_t
*printer
; /* Printer data */
11772 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11773 con
->http
.fd
, uri
->values
[0].string
.text
);
11776 * Is the destination valid?
11779 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11785 send_ipp_status(con
, IPP_NOT_FOUND
,
11786 _("The printer or class does not exist."));
11794 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11796 send_http_error(con
, status
, printer
);
11801 * Start the printer...
11804 printer
->state_message
[0] = '\0';
11806 cupsdStartPrinter(printer
, 1);
11808 if (dtype
& CUPS_PRINTER_CLASS
)
11809 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11810 printer
->name
, get_username(con
));
11812 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11813 printer
->name
, get_username(con
));
11821 if ((i
= check_quotas(con
, printer
)) < 0)
11823 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
11828 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
11833 * Everything was ok, so return OK status...
11836 con
->response
->request
.status
.status_code
= IPP_OK
;
11841 * 'stop_printer()' - Stop a printer.
11845 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11846 ipp_attribute_t
*uri
) /* I - Printer URI */
11848 http_status_t status
; /* Policy status */
11849 cups_ptype_t dtype
; /* Destination type (printer/class) */
11850 cupsd_printer_t
*printer
; /* Printer data */
11851 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11854 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11855 con
->http
.fd
, uri
->values
[0].string
.text
);
11858 * Is the destination valid?
11861 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11867 send_ipp_status(con
, IPP_NOT_FOUND
,
11868 _("The printer or class does not exist."));
11876 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11878 send_http_error(con
, status
, printer
);
11883 * Stop the printer...
11886 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11887 IPP_TAG_TEXT
)) == NULL
)
11888 strcpy(printer
->state_message
, "Paused");
11891 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11892 sizeof(printer
->state_message
));
11895 cupsdStopPrinter(printer
, 1);
11897 if (dtype
& CUPS_PRINTER_CLASS
)
11898 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11899 printer
->name
, get_username(con
));
11901 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11902 printer
->name
, get_username(con
));
11905 * Everything was ok, so return OK status...
11908 con
->response
->request
.status
.status_code
= IPP_OK
;
11913 * 'url_encode_attr()' - URL-encode a string attribute.
11917 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11918 char *buffer
,/* I - String buffer */
11919 int bufsize
)/* I - Size of buffer */
11921 int i
; /* Looping var */
11922 char *bufptr
, /* Pointer into buffer */
11923 *bufend
; /* End of buffer */
11926 strlcpy(buffer
, attr
->name
, bufsize
);
11927 bufptr
= buffer
+ strlen(buffer
);
11928 bufend
= buffer
+ bufsize
- 1;
11930 for (i
= 0; i
< attr
->num_values
; i
++)
11932 if (bufptr
>= bufend
)
11940 if (bufptr
>= bufend
)
11945 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11946 bufptr
, bufend
- bufptr
+ 1);
11948 if (bufptr
>= bufend
)
11959 * 'url_encode_string()' - URL-encode a string.
11962 static char * /* O - End of string */
11963 url_encode_string(const char *s
, /* I - String */
11964 char *buffer
, /* I - String buffer */
11965 int bufsize
) /* I - Size of buffer */
11967 char *bufptr
, /* Pointer into buffer */
11968 *bufend
; /* End of buffer */
11969 static const char *hex
= "0123456789ABCDEF";
11974 bufend
= buffer
+ bufsize
- 1;
11976 while (*s
&& bufptr
< bufend
)
11978 if (*s
== ' ' || *s
== '%' || *s
== '+')
11980 if (bufptr
>= (bufend
- 2))
11984 *bufptr
++ = hex
[(*s
>> 4) & 15];
11985 *bufptr
++ = hex
[*s
& 15];
11989 else if (*s
== '\'' || *s
== '\\')
11991 if (bufptr
>= (bufend
- 1))
12008 * 'user_allowed()' - See if a user is allowed to print to a queue.
12011 static int /* O - 0 if not allowed, 1 if allowed */
12012 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
12013 const char *username
) /* I - Username */
12015 struct passwd
*pw
; /* User password data */
12016 char baseuser
[256], /* Base username */
12017 *baseptr
, /* Pointer to "@" in base username */
12018 *name
; /* Current user name */
12021 if (cupsArrayCount(p
->users
) == 0)
12024 if (!strcmp(username
, "root"))
12027 if (strchr(username
, '@'))
12030 * Strip @REALM for username check...
12033 strlcpy(baseuser
, username
, sizeof(baseuser
));
12035 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
12038 username
= baseuser
;
12041 pw
= getpwnam(username
);
12044 for (name
= (char *)cupsArrayFirst(p
->users
);
12046 name
= (char *)cupsArrayNext(p
->users
))
12048 if (name
[0] == '@')
12051 * Check group membership...
12054 if (cupsdCheckGroup(username
, pw
, name
+ 1))
12057 else if (name
[0] == '#')
12063 if (cupsdCheckGroup(username
, pw
, name
))
12066 else if (!_cups_strcasecmp(username
, name
))
12070 return ((name
!= NULL
) != p
->deny_users
);
12075 * 'validate_job()' - Validate printer options and destination.
12079 validate_job(cupsd_client_t
*con
, /* I - Client connection */
12080 ipp_attribute_t
*uri
) /* I - Printer URI */
12082 http_status_t status
; /* Policy status */
12083 ipp_attribute_t
*attr
, /* Current attribute */
12084 *auth_info
; /* auth-info attribute */
12085 ipp_attribute_t
*format
; /* Document-format attribute */
12086 cups_ptype_t dtype
; /* Destination type (printer/class) */
12087 char super
[MIME_MAX_SUPER
],
12088 /* Supertype of file */
12089 type
[MIME_MAX_TYPE
];
12090 /* Subtype of file */
12091 cupsd_printer_t
*printer
; /* Printer */
12094 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
12095 con
->http
.fd
, uri
->values
[0].string
.text
);
12098 * OK, see if the client is sending the document compressed - CUPS
12099 * doesn't support compression yet...
12102 if ((attr
= ippFindAttribute(con
->request
, "compression",
12103 IPP_TAG_KEYWORD
)) != NULL
)
12105 if (strcmp(attr
->values
[0].string
.text
, "none")
12107 && strcmp(attr
->values
[0].string
.text
, "gzip")
12108 #endif /* HAVE_LIBZ */
12111 send_ipp_status(con
, IPP_ATTRIBUTES
,
12112 _("Unsupported compression \"%s\"."),
12113 attr
->values
[0].string
.text
);
12114 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
12115 "compression", NULL
, attr
->values
[0].string
.text
);
12121 * Is it a format we support?
12124 if ((format
= ippFindAttribute(con
->request
, "document-format",
12125 IPP_TAG_MIMETYPE
)) != NULL
)
12127 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
12130 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
12131 format
->values
[0].string
.text
);
12135 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
12136 !mimeType(MimeDatabase
, super
, type
))
12138 cupsdLogMessage(CUPSD_LOG_INFO
,
12139 "Hint: Do you have the raw file printing rules enabled?");
12140 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
12141 _("Unsupported document-format \"%s\"."),
12142 format
->values
[0].string
.text
);
12143 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
12144 "document-format", NULL
, format
->values
[0].string
.text
);
12150 * Is the destination valid?
12153 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
12159 send_ipp_status(con
, IPP_NOT_FOUND
,
12160 _("The printer or class does not exist."));
12168 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
12170 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
12172 send_http_error(con
, status
, printer
);
12175 else if (printer
->num_auth_info_required
== 1 &&
12176 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
12179 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
12183 else if (auth_info
&& !con
->http
.tls
&&
12184 !httpAddrLocalhost(con
->http
.hostaddr
))
12187 * Require encryption of auth-info over non-local connections...
12190 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
12193 #endif /* HAVE_SSL */
12196 * Everything was ok, so return OK status...
12199 con
->response
->request
.status
.status_code
= IPP_OK
;
12204 * 'validate_name()' - Make sure the printer name only contains valid chars.
12207 static int /* O - 0 if name is no good, 1 if good */
12208 validate_name(const char *name
) /* I - Name to check */
12210 const char *ptr
; /* Pointer into name */
12214 * Scan the whole name...
12217 for (ptr
= name
; *ptr
; ptr
++)
12218 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
12222 * All the characters are good; validate the length, too...
12225 return ((ptr
- name
) < 128);
12230 * 'validate_user()' - Validate the user for the request.
12233 static int /* O - 1 if permitted, 0 otherwise */
12234 validate_user(cupsd_job_t
*job
, /* I - Job */
12235 cupsd_client_t
*con
, /* I - Client connection */
12236 const char *owner
, /* I - Owner of job/resource */
12237 char *username
, /* O - Authenticated username */
12238 int userlen
) /* I - Length of username */
12240 cupsd_printer_t
*printer
; /* Printer for job */
12243 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
12244 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
12246 job
->id
, con
? con
->http
.fd
: 0,
12247 owner
? owner
: "(null)", username
, userlen
);
12250 * Validate input...
12253 if (!con
|| !owner
|| !username
|| userlen
<= 0)
12257 * Get the best authenticated username that is available.
12260 strlcpy(username
, get_username(con
), userlen
);
12263 * Check the username against the owner...
12266 printer
= cupsdFindDest(job
->dest
);
12268 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
12269 con
, owner
) == HTTP_OK
);