2 * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * This file contains Kerberos support code, copyright 2006 by
12 * These coded instructions, statements, and computer programs are the
13 * property of Apple Inc. and are protected by Federal copyright
14 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 * which should have been included with this file. If this file is
16 * file is missing or damaged, see the license at "http://www.cups.org/".
20 * cupsdProcessIPPRequest() - Process an incoming IPP request.
21 * cupsdTimeoutJob() - Timeout a job waiting on job files.
22 * accept_jobs() - Accept print jobs to a printer.
23 * add_class() - Add a class to the system.
24 * add_file() - Add a file to a job.
25 * add_job() - Add a job to a print queue.
26 * add_job_state_reasons() - Add the "job-state-reasons" attribute based
27 * upon the job and printer state...
28 * add_job_subscriptions() - Add any subscriptions for a job.
29 * add_job_uuid() - Add job-uuid attribute to a job.
30 * add_printer() - Add a printer to the system.
31 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
32 * based upon the printer state...
33 * add_queued_job_count() - Add the "queued-job-count" attribute for the
34 * specified printer or class.
35 * apple_init_profile() - Initialize a color profile.
36 * apple_register_profiles() - Register color profiles for a printer.
37 * apple_unregister_profiles() - Remove color profiles for the specified
39 * apply_printer_defaults() - Apply printer default options to a job.
40 * authenticate_job() - Set job authentication info.
41 * cancel_all_jobs() - Cancel all or selected print jobs.
42 * cancel_job() - Cancel a print job.
43 * cancel_subscription() - Cancel a subscription.
44 * check_rss_recipient() - Check that we do not have a duplicate RSS
46 * check_quotas() - Check quotas for a printer and user.
47 * close_job() - Close a multi-file job.
48 * copy_attribute() - Copy a single attribute.
49 * copy_attrs() - Copy attributes from one request to another.
50 * copy_banner() - Copy a banner file to the requests directory
51 * for the specified job.
52 * copy_file() - Copy a PPD file or interface script...
53 * copy_model() - Copy a PPD model file, substituting default
55 * copy_job_attrs() - Copy job attributes.
56 * copy_printer_attrs() - Copy printer attributes.
57 * copy_subscription_attrs() - Copy subscription attributes.
58 * create_job() - Print a file to a printer or class.
59 * create_requested_array() - Create an array for the requested-attributes.
60 * create_subscription() - Create a notification subscription.
61 * delete_printer() - Remove a printer or class from the system.
62 * get_default() - Get the default destination.
63 * get_devices() - Get the list of available devices on the
65 * get_document() - Get a copy of a job file.
66 * get_job_attrs() - Get job attributes.
67 * get_jobs() - Get a list of jobs for the specified printer.
68 * get_notifications() - Get events for a subscription.
69 * get_ppd() - Get a named PPD from the local system.
70 * get_ppds() - Get the list of PPD files on the local
72 * get_printer_attrs() - Get printer attributes.
73 * get_printer_supported() - Get printer supported values.
74 * get_printers() - Get a list of printers or classes.
75 * get_subscription_attrs() - Get subscription attributes.
76 * get_subscriptions() - Get subscriptions.
77 * get_username() - Get the username associated with a request.
78 * hold_job() - Hold a print job.
79 * hold_new_jobs() - Hold pending/new jobs on a printer or class.
80 * move_job() - Move a job to a new destination.
81 * ppd_parse_line() - Parse a PPD default line.
82 * print_job() - Print a file to a printer or class.
83 * read_job_ticket() - Read a job ticket embedded in a print file.
84 * reject_jobs() - Reject print jobs to a printer.
85 * release_held_new_jobs() - Release pending/new jobs on a printer or
87 * release_job() - Release a held print job.
88 * renew_subscription() - Renew an existing subscription...
89 * restart_job() - Restart an old print job.
90 * save_auth_info() - Save authentication information for a job.
91 * save_krb5_creds() - Save Kerberos credentials for the job.
92 * send_document() - Send a file to a printer or class.
93 * send_http_error() - Send a HTTP error back to the IPP client.
94 * send_ipp_status() - Send a status back to the IPP client.
95 * set_default() - Set the default destination...
96 * set_job_attrs() - Set job attributes.
97 * set_printer_attrs() - Set printer attributes.
98 * set_printer_defaults() - Set printer default options from a request.
99 * start_printer() - Start a printer.
100 * stop_printer() - Stop a printer.
101 * url_encode_attr() - URL-encode a string attribute.
102 * url_encode_string() - URL-encode a string.
103 * user_allowed() - See if a user is allowed to print to a queue.
104 * validate_job() - Validate printer options and destination.
105 * validate_name() - Make sure the printer name only contains
107 * validate_user() - Validate the user for the request.
111 * Include necessary headers...
115 #include <cups/ppd-private.h>
118 # include <ApplicationServices/ApplicationServices.h>
119 # ifdef HAVE_COLORSYNCREGISTERDEVICE
120 extern CFUUIDRef
ColorSyncCreateUUIDFromUInt32(unsigned id
);
121 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
122 # include <CoreFoundation/CoreFoundation.h>
123 # ifdef HAVE_MEMBERSHIP_H
124 # include <membership.h>
125 # endif /* HAVE_MEMBERSHIP_H */
126 # ifdef HAVE_MEMBERSHIPPRIV_H
127 # include <membershipPriv.h>
129 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
130 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
131 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
132 # endif /* HAVE_MEMBERSHIPPRIV_H */
133 #endif /* __APPLE__ */
140 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
141 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
142 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
143 mime_type_t
*filetype
, int compression
);
144 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
145 mime_type_t
*filetype
);
146 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
147 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
148 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
149 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
150 static void add_printer_state_reasons(cupsd_client_t
*con
,
152 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
154 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
155 # ifdef HAVE_COLORSYNCREGISTERDEVICE
156 CFMutableDictionaryRef profile
,
158 CMDeviceProfileInfo
*profile
,
159 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
160 unsigned id
, const char *name
,
161 const char *text
, const char *iccfile
);
162 static void apple_register_profiles(cupsd_printer_t
*p
);
163 static void apple_unregister_profiles(cupsd_printer_t
*p
);
164 #endif /* __APPLE__ */
165 static void apply_printer_defaults(cupsd_printer_t
*printer
,
167 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
168 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
169 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
170 static void cancel_subscription(cupsd_client_t
*con
, int id
);
171 static int check_rss_recipient(const char *recipient
);
172 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
173 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
175 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
176 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
177 ipp_tag_t group
, int quickcopy
,
178 cups_array_t
*exclude
);
179 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
181 static int copy_file(const char *from
, const char *to
);
182 static int copy_model(cupsd_client_t
*con
, const char *from
,
184 static void copy_job_attrs(cupsd_client_t
*con
,
186 cups_array_t
*ra
, cups_array_t
*exclude
);
187 static void copy_printer_attrs(cupsd_client_t
*con
,
188 cupsd_printer_t
*printer
,
190 static void copy_subscription_attrs(cupsd_client_t
*con
,
191 cupsd_subscription_t
*sub
,
193 cups_array_t
*exclude
);
194 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
195 static cups_array_t
*create_requested_array(ipp_t
*request
);
196 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
197 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static void get_default(cupsd_client_t
*con
);
199 static void get_devices(cupsd_client_t
*con
);
200 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
201 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
202 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
203 static void get_notifications(cupsd_client_t
*con
);
204 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
205 static void get_ppds(cupsd_client_t
*con
);
206 static void get_printers(cupsd_client_t
*con
, int type
);
207 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
208 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
209 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
210 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
211 static const char *get_username(cupsd_client_t
*con
);
212 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
213 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
214 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
215 static int ppd_parse_line(const char *line
, char *option
, int olen
,
216 char *choice
, int clen
);
217 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
218 static void read_job_ticket(cupsd_client_t
*con
);
219 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
220 static void release_held_new_jobs(cupsd_client_t
*con
,
221 ipp_attribute_t
*uri
);
222 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
223 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
224 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
225 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
226 ipp_attribute_t
*auth_info
);
227 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
228 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
229 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
230 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
231 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
232 cupsd_printer_t
*printer
);
233 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
234 const char *message
, ...)
236 __attribute__ ((__format__ (__printf__
, 3, 4)))
237 # endif /* __GNUC__ */
239 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
240 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
241 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
242 static void set_printer_defaults(cupsd_client_t
*con
,
243 cupsd_printer_t
*printer
);
244 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
245 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
246 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
248 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
249 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
250 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
251 static int validate_name(const char *name
);
252 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
253 const char *owner
, char *username
,
258 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
261 int /* O - 1 on success, 0 on failure */
262 cupsdProcessIPPRequest(
263 cupsd_client_t
*con
) /* I - Client connection */
265 ipp_tag_t group
; /* Current group tag */
266 ipp_attribute_t
*attr
; /* Current attribute */
267 ipp_attribute_t
*charset
; /* Character set attribute */
268 ipp_attribute_t
*language
; /* Language attribute */
269 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
270 ipp_attribute_t
*username
; /* requesting-user-name attr */
271 int sub_id
; /* Subscription ID */
274 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
275 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
276 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
279 * First build an empty response message for this request...
282 con
->response
= ippNew();
284 con
->response
->request
.status
.version
[0] =
285 con
->request
->request
.op
.version
[0];
286 con
->response
->request
.status
.version
[1] =
287 con
->request
->request
.op
.version
[1];
288 con
->response
->request
.status
.request_id
=
289 con
->request
->request
.op
.request_id
;
292 * Then validate the request header and required attributes...
295 if (con
->request
->request
.any
.version
[0] != 1 &&
296 con
->request
->request
.any
.version
[0] != 2)
299 * Return an error, since we only support IPP 1.x and 2.x.
302 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
303 "%04X %s Bad request version number %d.%d",
304 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
305 con
->request
->request
.any
.version
[0],
306 con
->request
->request
.any
.version
[1]);
308 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
309 _("Bad request version number %d.%d"),
310 con
->request
->request
.any
.version
[0],
311 con
->request
->request
.any
.version
[1]);
313 else if (con
->request
->request
.any
.request_id
< 1)
316 * Return an error, since request IDs must be between 1 and 2^31-1
319 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
320 "%04X %s Bad request ID %d",
321 IPP_BAD_REQUEST
, con
->http
.hostname
,
322 con
->request
->request
.any
.request_id
);
324 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d"),
325 con
->request
->request
.any
.request_id
);
327 else if (!con
->request
->attrs
)
329 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
330 "%04X %s No attributes in request",
331 IPP_BAD_REQUEST
, con
->http
.hostname
);
333 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request"));
338 * Make sure that the attributes are provided in the correct order and
339 * don't repeat groups...
342 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
345 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
348 * Out of order; return an error...
351 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
352 "%04X %s Attribute groups are out of order",
353 IPP_BAD_REQUEST
, con
->http
.hostname
);
355 send_ipp_status(con
, IPP_BAD_REQUEST
,
356 _("Attribute groups are out of order (%x < %x)"),
357 attr
->group_tag
, group
);
361 group
= attr
->group_tag
;
366 * Then make sure that the first three attributes are:
369 * attributes-natural-language
370 * printer-uri/job-uri
373 attr
= con
->request
->attrs
;
374 if (attr
&& attr
->name
&&
375 !strcmp(attr
->name
, "attributes-charset") &&
376 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
384 if (attr
&& attr
->name
&&
385 !strcmp(attr
->name
, "attributes-natural-language") &&
386 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
391 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
392 IPP_TAG_URI
)) != NULL
)
394 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
395 IPP_TAG_URI
)) != NULL
)
397 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
398 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
403 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
404 "attributes-charset", NULL
,
405 charset
->values
[0].string
.text
);
407 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
408 "attributes-charset", NULL
, "utf-8");
411 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
412 "attributes-natural-language", NULL
,
413 language
->values
[0].string
.text
);
415 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
416 "attributes-natural-language", NULL
, DefaultLanguage
);
419 strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
420 strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
423 * Bad character set...
426 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
427 charset
->values
[0].string
.text
);
428 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
429 "%04X %s Unsupported attributes-charset value \"%s\"",
430 IPP_CHARSET
, con
->http
.hostname
,
431 charset
->values
[0].string
.text
);
432 send_ipp_status(con
, IPP_BAD_REQUEST
,
433 _("Unsupported character set \"%s\""),
434 charset
->values
[0].string
.text
);
436 else if (!charset
|| !language
||
438 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
439 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
440 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
441 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
442 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
445 * Return an error, since attributes-charset,
446 * attributes-natural-language, and printer-uri/job-uri are required
447 * for all operations.
452 cupsdLogMessage(CUPSD_LOG_ERROR
,
453 "Missing attributes-charset attribute");
455 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
456 "%04X %s Missing attributes-charset attribute",
457 IPP_BAD_REQUEST
, con
->http
.hostname
);
462 cupsdLogMessage(CUPSD_LOG_ERROR
,
463 "Missing attributes-natural-language attribute");
465 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
466 "%04X %s Missing attributes-natural-language attribute",
467 IPP_BAD_REQUEST
, con
->http
.hostname
);
472 cupsdLogMessage(CUPSD_LOG_ERROR
,
473 "Missing printer-uri, job-uri, or ppd-name "
476 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
477 "%04X %s Missing printer-uri, job-uri, or ppd-name "
478 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
481 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
483 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
484 cupsdLogMessage(CUPSD_LOG_DEBUG
,
485 "attr \"%s\": group_tag = %x, value_tag = %x",
486 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
489 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
491 send_ipp_status(con
, IPP_BAD_REQUEST
,
492 _("Missing required attributes"));
497 * OK, all the checks pass so far; make sure requesting-user-name is
498 * not "root" from a remote host...
501 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
502 IPP_TAG_NAME
)) != NULL
)
505 * Check for root user...
508 if (!strcmp(username
->values
[0].string
.text
, "root") &&
509 strcasecmp(con
->http
.hostname
, "localhost") &&
510 strcmp(con
->username
, "root"))
513 * Remote unauthenticated user masquerading as local root...
516 _cupsStrFree(username
->values
[0].string
.text
);
517 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
521 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
522 IPP_TAG_INTEGER
)) != NULL
)
523 sub_id
= attr
->values
[0].integer
;
528 * Then try processing the operation...
532 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
533 ippOpString(con
->request
->request
.op
.operation_id
),
534 uri
->values
[0].string
.text
);
536 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
537 ippOpString(con
->request
->request
.op
.operation_id
));
539 switch (con
->request
->request
.op
.operation_id
)
545 case IPP_VALIDATE_JOB
:
546 validate_job(con
, uri
);
549 case IPP_CREATE_JOB
:
550 create_job(con
, uri
);
553 case IPP_SEND_DOCUMENT
:
554 send_document(con
, uri
);
557 case IPP_CANCEL_JOB
:
558 cancel_job(con
, uri
);
561 case IPP_GET_JOB_ATTRIBUTES
:
562 get_job_attrs(con
, uri
);
569 case IPP_GET_PRINTER_ATTRIBUTES
:
570 get_printer_attrs(con
, uri
);
573 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
574 get_printer_supported(con
, uri
);
581 case IPP_RELEASE_JOB
:
582 release_job(con
, uri
);
585 case IPP_RESTART_JOB
:
586 restart_job(con
, uri
);
589 case IPP_PAUSE_PRINTER
:
590 stop_printer(con
, uri
);
593 case IPP_RESUME_PRINTER
:
594 start_printer(con
, uri
);
597 case IPP_PURGE_JOBS
:
598 case IPP_CANCEL_JOBS
:
599 case IPP_CANCEL_MY_JOBS
:
600 cancel_all_jobs(con
, uri
);
603 case IPP_SET_JOB_ATTRIBUTES
:
604 set_job_attrs(con
, uri
);
607 case IPP_SET_PRINTER_ATTRIBUTES
:
608 set_printer_attrs(con
, uri
);
611 case IPP_HOLD_NEW_JOBS
:
612 hold_new_jobs(con
, uri
);
615 case IPP_RELEASE_HELD_NEW_JOBS
:
616 release_held_new_jobs(con
, uri
);
623 case CUPS_GET_DEFAULT
:
627 case CUPS_GET_PRINTERS
:
628 get_printers(con
, 0);
631 case CUPS_GET_CLASSES
:
632 get_printers(con
, CUPS_PRINTER_CLASS
);
635 case CUPS_ADD_PRINTER
:
636 add_printer(con
, uri
);
639 case CUPS_DELETE_PRINTER
:
640 delete_printer(con
, uri
);
643 case CUPS_ADD_CLASS
:
647 case CUPS_DELETE_CLASS
:
648 delete_printer(con
, uri
);
651 case CUPS_ACCEPT_JOBS
:
652 case IPP_ENABLE_PRINTER
:
653 accept_jobs(con
, uri
);
656 case CUPS_REJECT_JOBS
:
657 case IPP_DISABLE_PRINTER
:
658 reject_jobs(con
, uri
);
661 case CUPS_SET_DEFAULT
:
662 set_default(con
, uri
);
665 case CUPS_GET_DEVICES
:
669 case CUPS_GET_DOCUMENT
:
670 get_document(con
, uri
);
685 case CUPS_AUTHENTICATE_JOB
:
686 authenticate_job(con
, uri
);
689 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
690 case IPP_CREATE_JOB_SUBSCRIPTION
:
691 create_subscription(con
, uri
);
694 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
695 get_subscription_attrs(con
, sub_id
);
698 case IPP_GET_SUBSCRIPTIONS
:
699 get_subscriptions(con
, uri
);
702 case IPP_RENEW_SUBSCRIPTION
:
703 renew_subscription(con
, sub_id
);
706 case IPP_CANCEL_SUBSCRIPTION
:
707 cancel_subscription(con
, sub_id
);
710 case IPP_GET_NOTIFICATIONS
:
711 get_notifications(con
);
715 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
716 "%04X %s Operation %04X (%s) not supported",
717 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
718 con
->request
->request
.op
.operation_id
,
719 ippOpString(con
->request
->request
.op
.operation_id
));
721 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
722 _("%s not supported"),
724 con
->request
->request
.op
.operation_id
));
734 * Sending data from the scheduler...
737 cupsdLogMessage(con
->response
->request
.status
.status_code
738 >= IPP_BAD_REQUEST
&&
739 con
->response
->request
.status
.status_code
740 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
741 "Returning IPP %s for %s (%s) from %s",
742 ippErrorString(con
->response
->request
.status
.status_code
),
743 ippOpString(con
->request
->request
.op
.operation_id
),
744 uri
? uri
->values
[0].string
.text
: "no URI",
747 if (LogLevel
== CUPSD_LOG_DEBUG2
)
748 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
749 "cupsdProcessIPPRequest: ippLength(response)=%ld",
750 (long)ippLength(con
->response
));
752 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
754 #ifdef CUPSD_USE_CHUNKING
756 * Because older versions of CUPS (1.1.17 and older) and some IPP
757 * clients do not implement chunking properly, we cannot use
758 * chunking by default. This may become the default in future
759 * CUPS releases, or we might add a configuration directive for
763 if (con
->http
.version
== HTTP_1_1
)
765 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
768 if (cupsdFlushHeader(con
) < 0)
771 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
774 #endif /* CUPSD_USE_CHUNKING */
776 size_t length
; /* Length of response */
779 length
= ippLength(con
->response
);
781 if (con
->file
>= 0 && !con
->pipe_pid
)
783 struct stat fileinfo
; /* File information */
786 if (!fstat(con
->file
, &fileinfo
))
787 length
+= fileinfo
.st_size
;
790 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
791 CUPS_LLCAST length
) < 0)
794 if (cupsdFlushHeader(con
) < 0)
797 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
798 con
->http
.data_remaining
= length
;
800 if (con
->http
.data_remaining
<= INT_MAX
)
801 con
->http
._data_remaining
= con
->http
.data_remaining
;
803 con
->http
._data_remaining
= INT_MAX
;
806 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
807 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
810 * Tell the caller the response header was sent successfully...
818 * Tell the caller the response header could not be sent...
827 * Sending data from a subprocess like cups-deviced; tell the caller
828 * everything is A-OK so far...
837 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
840 int /* O - 0 on success, -1 on error */
841 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
843 cupsd_printer_t
*printer
; /* Destination printer or class */
844 ipp_attribute_t
*attr
; /* job-sheets attribute */
845 int kbytes
; /* Kilobytes in banner */
848 job
->pending_timeout
= 0;
851 * See if we need to add the ending sheet...
854 if (!cupsdLoadJob(job
))
857 printer
= cupsdFindDest(job
->dest
);
858 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
861 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
862 attr
&& attr
->num_values
> 1)
868 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
869 attr
->values
[1].string
.text
);
871 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
874 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
882 * 'accept_jobs()' - Accept print jobs to a printer.
886 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
887 ipp_attribute_t
*uri
) /* I - Printer or class URI */
889 http_status_t status
; /* Policy status */
890 cups_ptype_t dtype
; /* Destination type (printer/class) */
891 cupsd_printer_t
*printer
; /* Printer data */
894 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
895 con
->http
.fd
, uri
->values
[0].string
.text
);
898 * Is the destination valid?
901 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
907 send_ipp_status(con
, IPP_NOT_FOUND
,
908 _("The printer or class was not found."));
916 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
918 send_http_error(con
, status
, printer
);
923 * Accept jobs sent to the printer...
926 printer
->accepting
= 1;
927 printer
->state_message
[0] = '\0';
929 cupsdAddPrinterHistory(printer
);
931 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
932 "Now accepting jobs.");
934 if (dtype
& CUPS_PRINTER_CLASS
)
936 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
938 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
939 printer
->name
, get_username(con
));
943 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
945 cupsdLogMessage(CUPSD_LOG_INFO
,
946 "Printer \"%s\" now accepting jobs (\"%s\").",
947 printer
->name
, get_username(con
));
951 * Everything was ok, so return OK status...
954 con
->response
->request
.status
.status_code
= IPP_OK
;
959 * 'add_class()' - Add a class to the system.
963 add_class(cupsd_client_t
*con
, /* I - Client connection */
964 ipp_attribute_t
*uri
) /* I - URI of class */
966 http_status_t status
; /* Policy status */
967 int i
; /* Looping var */
968 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
969 username
[HTTP_MAX_URI
], /* Username portion of URI */
970 host
[HTTP_MAX_URI
], /* Host portion of URI */
971 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
972 int port
; /* Port portion of URI */
973 cupsd_printer_t
*pclass
, /* Class */
974 *member
; /* Member printer/class */
975 cups_ptype_t dtype
; /* Destination type */
976 ipp_attribute_t
*attr
; /* Printer attribute */
977 int modify
; /* Non-zero if we just modified */
978 char newname
[IPP_MAX_NAME
]; /* New class name */
979 int need_restart_job
; /* Need to restart job? */
982 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
983 con
->http
.fd
, uri
->values
[0].string
.text
);
986 * Do we have a valid URI?
989 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
990 sizeof(scheme
), username
, sizeof(username
), host
,
991 sizeof(host
), &port
, resource
, sizeof(resource
));
994 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
997 * No, return an error...
1000 send_ipp_status(con
, IPP_BAD_REQUEST
,
1001 _("The printer-uri must be of the form "
1002 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
1007 * Do we have a valid printer name?
1010 if (!validate_name(resource
+ 9))
1013 * No, return an error...
1016 send_ipp_status(con
, IPP_BAD_REQUEST
,
1017 _("The printer-uri \"%s\" contains invalid characters."),
1018 uri
->values
[0].string
.text
);
1023 * See if the class already exists; if not, create a new class...
1026 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1029 * Class doesn't exist; see if we have a printer of the same name...
1032 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
1033 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
1036 * Yes, return an error...
1039 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1040 _("A printer named \"%s\" already exists"),
1046 * No, check the default policy and then add the class...
1049 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1051 send_http_error(con
, status
, NULL
);
1055 pclass
= cupsdAddClass(resource
+ 9);
1058 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1061 * Check the default policy, then rename the implicit class to "AnyClass"
1065 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1067 send_http_error(con
, status
, NULL
);
1071 if (ImplicitAnyClasses
)
1073 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1074 cupsdRenamePrinter(pclass
, newname
);
1077 cupsdDeletePrinter(pclass
, 1);
1080 * Add the class as a new local class...
1083 pclass
= cupsdAddClass(resource
+ 9);
1086 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1089 * Check the default policy, then rename the remote class to "Class"...
1092 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1094 send_http_error(con
, status
, NULL
);
1098 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1099 cupsdRenamePrinter(pclass
, newname
);
1102 * Add the class as a new local class...
1105 pclass
= cupsdAddClass(resource
+ 9);
1108 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1111 send_http_error(con
, status
, pclass
);
1118 * Look for attributes and copy them over as needed...
1121 need_restart_job
= 0;
1123 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1124 IPP_TAG_TEXT
)) != NULL
)
1125 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1127 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1128 IPP_TAG_TEXT
)) != NULL
)
1129 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1131 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1132 IPP_TAG_BOOLEAN
)) != NULL
&&
1133 attr
->values
[0].boolean
!= pclass
->accepting
)
1135 cupsdLogMessage(CUPSD_LOG_INFO
,
1136 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1137 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1139 pclass
->accepting
= attr
->values
[0].boolean
;
1140 cupsdAddPrinterHistory(pclass
);
1142 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1143 pclass
->accepting
? "Now" : "No longer");
1146 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1147 IPP_TAG_BOOLEAN
)) != NULL
)
1149 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1150 cupsdDeregisterPrinter(pclass
, 1);
1152 cupsdLogMessage(CUPSD_LOG_INFO
,
1153 "Setting %s printer-is-shared to %d (was %d.)",
1154 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1156 pclass
->shared
= attr
->values
[0].boolean
;
1159 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1160 IPP_TAG_ENUM
)) != NULL
)
1162 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1163 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1165 send_ipp_status(con
, IPP_BAD_REQUEST
,
1166 _("Attempt to set %s printer-state to bad value %d"),
1167 pclass
->name
, attr
->values
[0].integer
);
1171 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1172 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1174 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1175 cupsdStopPrinter(pclass
, 0);
1178 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1179 need_restart_job
= 1;
1182 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1183 IPP_TAG_TEXT
)) != NULL
)
1185 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1186 sizeof(pclass
->state_message
));
1187 cupsdAddPrinterHistory(pclass
);
1189 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1190 pclass
->state_message
);
1192 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1193 IPP_TAG_URI
)) != NULL
)
1196 * Clear the printer array as needed...
1199 need_restart_job
= 1;
1201 if (pclass
->num_printers
> 0)
1203 free(pclass
->printers
);
1204 pclass
->num_printers
= 0;
1208 * Add each printer or class that is listed...
1211 for (i
= 0; i
< attr
->num_values
; i
++)
1214 * Search for the printer or class URI...
1217 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1223 send_ipp_status(con
, IPP_NOT_FOUND
,
1224 _("The printer or class was not found."));
1227 else if (dtype
& CUPS_PRINTER_CLASS
)
1229 send_ipp_status(con
, IPP_BAD_REQUEST
,
1230 _("Nested classes are not allowed"));
1235 * Add it to the class...
1238 cupsdAddPrinterToClass(pclass
, member
);
1242 set_printer_defaults(con
, pclass
);
1244 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1245 IPP_TAG_KEYWORD
)) != NULL
)
1246 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1249 * Update the printer class attributes and return...
1252 cupsdSetPrinterAttrs(pclass
);
1253 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1255 if (need_restart_job
&& pclass
->job
)
1258 * Reset the current job to a "pending" status...
1261 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1262 "Job restarted because the class was modified.");
1265 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1269 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1270 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1271 pclass
->name
, get_username(con
));
1273 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1274 pclass
->name
, get_username(con
));
1278 cupsdAddPrinterHistory(pclass
);
1280 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1281 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1282 pclass
->name
, get_username(con
));
1284 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1285 pclass
->name
, get_username(con
));
1288 con
->response
->request
.status
.status_code
= IPP_OK
;
1293 * 'add_file()' - Add a file to a job.
1296 static int /* O - 0 on success, -1 on error */
1297 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1298 cupsd_job_t
*job
, /* I - Job to add to */
1299 mime_type_t
*filetype
, /* I - Type of file */
1300 int compression
) /* I - Compression */
1302 mime_type_t
**filetypes
; /* New filetypes array... */
1303 int *compressions
; /* New compressions array... */
1306 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1307 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1308 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1309 filetype
->super
, filetype
->type
, compression
);
1312 * Add the file to the job...
1315 if (job
->num_files
== 0)
1317 compressions
= (int *)malloc(sizeof(int));
1318 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1322 compressions
= (int *)realloc(job
->compressions
,
1323 (job
->num_files
+ 1) * sizeof(int));
1324 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1325 (job
->num_files
+ 1) *
1326 sizeof(mime_type_t
*));
1329 if (!compressions
|| !filetypes
)
1331 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1332 "Job aborted because the scheduler ran out of memory.");
1335 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1336 _("Unable to allocate memory for file types"));
1341 job
->compressions
= compressions
;
1342 job
->compressions
[job
->num_files
] = compression
;
1343 job
->filetypes
= filetypes
;
1344 job
->filetypes
[job
->num_files
] = filetype
;
1349 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1356 * 'add_job()' - Add a job to a print queue.
1359 static cupsd_job_t
* /* O - Job object */
1360 add_job(cupsd_client_t
*con
, /* I - Client connection */
1361 cupsd_printer_t
*printer
, /* I - Destination printer */
1362 mime_type_t
*filetype
) /* I - First print file type, if any */
1364 http_status_t status
; /* Policy status */
1365 ipp_attribute_t
*attr
, /* Current attribute */
1366 *auth_info
; /* auth-info attribute */
1367 const char *val
; /* Default option value */
1368 int priority
; /* Job priority */
1369 cupsd_job_t
*job
; /* Current job */
1370 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1371 int kbytes
; /* Size of print file */
1372 int i
; /* Looping var */
1373 int lowerpagerange
; /* Page range bound */
1374 int exact
; /* Did we have an exact match? */
1375 ipp_attribute_t
*media_col
, /* media-col attribute */
1376 *media_margin
; /* media-*-margin attribute */
1377 ipp_t
*unsup_col
; /* media-col in unsupported response */
1380 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1381 con
, con
->http
.fd
, printer
, printer
->name
,
1382 filetype
, filetype
? filetype
->super
: "none",
1383 filetype
? filetype
->type
: "none");
1386 * Check remote printing to non-shared printer...
1389 if (!printer
->shared
&&
1390 strcasecmp(con
->http
.hostname
, "localhost") &&
1391 strcasecmp(con
->http
.hostname
, ServerName
))
1393 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1394 _("The printer or class is not shared"));
1402 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1404 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1406 send_http_error(con
, status
, printer
);
1409 else if (printer
->num_auth_info_required
== 1 &&
1410 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1413 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1417 else if (auth_info
&& !con
->http
.tls
&&
1418 !httpAddrLocalhost(con
->http
.hostaddr
))
1421 * Require encryption of auth-info over non-local connections...
1424 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1427 #endif /* HAVE_SSL */
1430 * See if the printer is accepting jobs...
1433 if (!printer
->accepting
)
1435 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1436 _("Destination \"%s\" is not accepting jobs."),
1442 * Validate job template attributes; for now just document-format,
1443 * copies, number-up, and page-ranges...
1446 if (filetype
&& printer
->filetypes
&&
1447 !cupsArrayFind(printer
->filetypes
, filetype
))
1449 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1450 /* MIME media type string */
1453 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1456 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1457 _("Unsupported format \'%s\'"), mimetype
);
1459 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1460 "document-format", NULL
, mimetype
);
1465 if ((attr
= ippFindAttribute(con
->request
, "copies",
1466 IPP_TAG_INTEGER
)) != NULL
)
1468 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1470 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1471 attr
->values
[0].integer
);
1472 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1473 "copies", attr
->values
[0].integer
);
1478 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1479 IPP_TAG_ZERO
)) != NULL
)
1481 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1482 attr
->value_tag
!= IPP_TAG_NAME
)
1484 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type"));
1488 if (attr
->num_values
> 2)
1490 send_ipp_status(con
, IPP_BAD_REQUEST
,
1491 _("Too many job-sheets values (%d > 2)"),
1496 for (i
= 0; i
< attr
->num_values
; i
++)
1497 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1498 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1500 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\""),
1501 attr
->values
[i
].string
.text
);
1506 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1507 IPP_TAG_INTEGER
)) != NULL
)
1509 if (attr
->values
[0].integer
!= 1 &&
1510 attr
->values
[0].integer
!= 2 &&
1511 attr
->values
[0].integer
!= 4 &&
1512 attr
->values
[0].integer
!= 6 &&
1513 attr
->values
[0].integer
!= 9 &&
1514 attr
->values
[0].integer
!= 16)
1516 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1517 attr
->values
[0].integer
);
1518 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1519 "number-up", attr
->values
[0].integer
);
1524 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1525 IPP_TAG_RANGE
)) != NULL
)
1527 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1529 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1530 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1532 send_ipp_status(con
, IPP_BAD_REQUEST
,
1533 _("Bad page-ranges values %d-%d."),
1534 attr
->values
[i
].range
.lower
,
1535 attr
->values
[i
].range
.upper
);
1539 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1544 * Do media selection as needed...
1547 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1548 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1549 _pwgGetPageSize(printer
->pwg
, con
->request
, NULL
, &exact
))
1552 (media_col
= ippFindAttribute(con
->request
, "media-col",
1553 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1555 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1557 unsup_col
= ippNew();
1558 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1559 "media-bottom-margin",
1560 IPP_TAG_INTEGER
)) != NULL
)
1561 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1562 "media-bottom-margin", media_margin
->values
[0].integer
);
1564 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1565 "media-left-margin",
1566 IPP_TAG_INTEGER
)) != NULL
)
1567 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1568 "media-left-margin", media_margin
->values
[0].integer
);
1570 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1571 "media-right-margin",
1572 IPP_TAG_INTEGER
)) != NULL
)
1573 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1574 "media-right-margin", media_margin
->values
[0].integer
);
1576 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1578 IPP_TAG_INTEGER
)) != NULL
)
1579 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1580 "media-top-margin", media_margin
->values
[0].integer
);
1582 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1584 ippDelete(unsup_col
);
1589 * Make sure we aren't over our limit...
1592 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1595 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1597 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1598 _("Too many active jobs."));
1602 if ((i
= check_quotas(con
, printer
)) < 0)
1604 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1609 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1614 * Create the job and set things up...
1617 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1618 IPP_TAG_INTEGER
)) != NULL
)
1619 priority
= attr
->values
[0].integer
;
1622 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1623 printer
->options
)) != NULL
)
1624 priority
= atoi(val
);
1628 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1632 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1633 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1636 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1638 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1639 _("Unable to add job for destination \"%s\""),
1644 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1645 CUPS_PRINTER_REMOTE
);
1646 job
->attrs
= con
->request
;
1648 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1650 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1652 add_job_uuid(con
, job
);
1653 apply_printer_defaults(printer
, job
);
1655 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1657 if (con
->username
[0])
1659 cupsdSetString(&job
->username
, con
->username
);
1662 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1666 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1667 "add_job: requesting-user-name=\"%s\"",
1668 attr
->values
[0].string
.text
);
1670 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1673 cupsdSetString(&job
->username
, "anonymous");
1676 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1677 "job-originating-user-name", NULL
, job
->username
);
1680 attr
->group_tag
= IPP_TAG_JOB
;
1681 _cupsStrFree(attr
->name
);
1682 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1685 if (con
->username
[0] || auth_info
)
1687 save_auth_info(con
, job
, auth_info
);
1690 * Remove the auth-info attribute from the attribute data...
1694 ippDeleteAttribute(job
->attrs
, auth_info
);
1697 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1698 IPP_TAG_ZERO
)) != NULL
)
1701 * Request contains a job-originating-host-name attribute; validate it...
1704 if (attr
->value_tag
!= IPP_TAG_NAME
||
1705 attr
->num_values
!= 1 ||
1706 strcmp(con
->http
.hostname
, "localhost"))
1709 * Can't override the value if we aren't connected via localhost.
1710 * Also, we can only have 1 value and it must be a name value.
1713 switch (attr
->value_tag
)
1715 case IPP_TAG_STRING
:
1716 case IPP_TAG_TEXTLANG
:
1717 case IPP_TAG_NAMELANG
:
1720 case IPP_TAG_KEYWORD
:
1722 case IPP_TAG_URISCHEME
:
1723 case IPP_TAG_CHARSET
:
1724 case IPP_TAG_LANGUAGE
:
1725 case IPP_TAG_MIMETYPE
:
1727 * Free old strings...
1730 for (i
= 0; i
< attr
->num_values
; i
++)
1732 _cupsStrFree(attr
->values
[i
].string
.text
);
1733 attr
->values
[i
].string
.text
= NULL
;
1734 if (attr
->values
[i
].string
.charset
)
1736 _cupsStrFree(attr
->values
[i
].string
.charset
);
1737 attr
->values
[i
].string
.charset
= NULL
;
1746 * Use the default connection hostname instead...
1749 attr
->value_tag
= IPP_TAG_NAME
;
1750 attr
->num_values
= 1;
1751 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1754 attr
->group_tag
= IPP_TAG_JOB
;
1759 * No job-originating-host-name attribute, so use the hostname from
1763 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1764 "job-originating-host-name", NULL
, con
->http
.hostname
);
1767 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1769 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1770 "time-at-processing", 0);
1771 attr
->value_tag
= IPP_TAG_NOVALUE
;
1772 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1773 "time-at-completed", 0);
1774 attr
->value_tag
= IPP_TAG_NOVALUE
;
1777 * Add remaining job attributes...
1780 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1781 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1782 "job-state", IPP_JOB_STOPPED
);
1783 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1784 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1785 "job-media-sheets-completed", 0);
1786 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1789 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1790 IPP_TAG_INTEGER
)) != NULL
)
1791 attr
->values
[0].integer
= 0;
1793 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1795 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1796 IPP_TAG_KEYWORD
)) == NULL
)
1797 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1800 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1801 printer
->options
)) == NULL
)
1804 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1805 "job-hold-until", NULL
, val
);
1807 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1810 * Hold job until specified time...
1813 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1815 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1816 job
->state_value
= IPP_JOB_HELD
;
1818 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1820 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1821 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1822 job
->state_value
= IPP_JOB_HELD
;
1826 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1827 job
->state_value
= IPP_JOB_PENDING
;
1830 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1834 * Add job sheets options...
1837 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1838 IPP_TAG_ZERO
)) == NULL
)
1840 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1841 "Adding default job-sheets values \"%s,%s\"...",
1842 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1844 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1846 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1847 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1850 job
->job_sheets
= attr
;
1853 * Enforce classification level if set...
1858 cupsdLogMessage(CUPSD_LOG_INFO
,
1859 "Classification=\"%s\", ClassifyOverride=%d",
1860 Classification
? Classification
: "(null)",
1863 if (ClassifyOverride
)
1865 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1866 (attr
->num_values
== 1 ||
1867 !strcmp(attr
->values
[1].string
.text
, "none")))
1870 * Force the leading banner to have the classification on it...
1873 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1875 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1876 "job-sheets=\"%s,none\", "
1877 "job-originating-user-name=\"%s\"",
1878 Classification
, job
->username
);
1880 else if (attr
->num_values
== 2 &&
1881 strcmp(attr
->values
[0].string
.text
,
1882 attr
->values
[1].string
.text
) &&
1883 strcmp(attr
->values
[0].string
.text
, "none") &&
1884 strcmp(attr
->values
[1].string
.text
, "none"))
1887 * Can't put two different security markings on the same document!
1890 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1892 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1893 "job-sheets=\"%s,%s\", "
1894 "job-originating-user-name=\"%s\"",
1895 attr
->values
[0].string
.text
,
1896 attr
->values
[1].string
.text
, job
->username
);
1898 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1899 strcmp(attr
->values
[0].string
.text
, "none") &&
1900 (attr
->num_values
== 1 ||
1901 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1902 strcmp(attr
->values
[1].string
.text
, "none"))))
1904 if (attr
->num_values
== 1)
1905 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1906 "CLASSIFICATION OVERRIDDEN "
1907 "job-sheets=\"%s\", "
1908 "job-originating-user-name=\"%s\"",
1909 attr
->values
[0].string
.text
, job
->username
);
1911 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1912 "CLASSIFICATION OVERRIDDEN "
1913 "job-sheets=\"%s,%s\",fffff "
1914 "job-originating-user-name=\"%s\"",
1915 attr
->values
[0].string
.text
,
1916 attr
->values
[1].string
.text
, job
->username
);
1919 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1920 (attr
->num_values
== 1 ||
1921 strcmp(attr
->values
[1].string
.text
, Classification
)))
1924 * Force the banner to have the classification on it...
1927 if (attr
->num_values
> 1 &&
1928 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1930 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1931 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1935 if (attr
->num_values
== 1 ||
1936 strcmp(attr
->values
[0].string
.text
, "none"))
1937 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1939 if (attr
->num_values
> 1 &&
1940 strcmp(attr
->values
[1].string
.text
, "none"))
1941 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1944 if (attr
->num_values
> 1)
1945 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1946 "CLASSIFICATION FORCED "
1947 "job-sheets=\"%s,%s\", "
1948 "job-originating-user-name=\"%s\"",
1949 attr
->values
[0].string
.text
,
1950 attr
->values
[1].string
.text
, job
->username
);
1952 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1953 "CLASSIFICATION FORCED "
1954 "job-sheets=\"%s\", "
1955 "job-originating-user-name=\"%s\"",
1956 Classification
, job
->username
);
1961 * See if we need to add the starting sheet...
1964 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1966 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1967 attr
->values
[0].string
.text
);
1969 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1971 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1972 "Aborting job because the start banner could not be "
1977 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1980 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1981 IPP_TAG_ZERO
)) != NULL
)
1985 * Fill in the response info...
1988 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1989 LocalPort
, job
->id
);
1991 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1994 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1996 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1998 add_job_state_reasons(con
, job
);
2000 con
->response
->request
.status
.status_code
= IPP_OK
;
2003 * Add any job subscriptions...
2006 add_job_subscriptions(con
, job
);
2009 * Set all but the first two attributes to the job attributes group...
2012 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
2013 attr
->group_tag
= IPP_TAG_JOB
;
2016 * Fire the "job created" event...
2019 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
2022 * Return the new job...
2030 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
2031 * upon the job and printer state...
2035 add_job_state_reasons(
2036 cupsd_client_t
*con
, /* I - Client connection */
2037 cupsd_job_t
*job
) /* I - Job info */
2039 cupsd_printer_t
*dest
; /* Destination printer */
2042 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
2043 con
, con
->http
.fd
, job
? job
->id
: 0);
2045 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
2047 case IPP_JOB_PENDING
:
2048 dest
= cupsdFindDest(job
->dest
);
2050 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
2051 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2052 "job-state-reasons", NULL
, "printer-stopped");
2054 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2055 "job-state-reasons", NULL
, "none");
2059 if (ippFindAttribute(job
->attrs
, "job-hold-until",
2060 IPP_TAG_KEYWORD
) != NULL
||
2061 ippFindAttribute(job
->attrs
, "job-hold-until",
2062 IPP_TAG_NAME
) != NULL
)
2063 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2064 "job-state-reasons", NULL
, "job-hold-until-specified");
2066 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2067 "job-state-reasons", NULL
, "job-incoming");
2070 case IPP_JOB_PROCESSING
:
2071 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2072 "job-state-reasons", NULL
, "job-printing");
2075 case IPP_JOB_STOPPED
:
2076 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2077 "job-state-reasons", NULL
, "job-stopped");
2080 case IPP_JOB_CANCELED
:
2081 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2082 "job-state-reasons", NULL
, "job-canceled-by-user");
2085 case IPP_JOB_ABORTED
:
2086 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2087 "job-state-reasons", NULL
, "aborted-by-system");
2090 case IPP_JOB_COMPLETED
:
2091 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2092 "job-state-reasons", NULL
, "job-completed-successfully");
2099 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2103 add_job_subscriptions(
2104 cupsd_client_t
*con
, /* I - Client connection */
2105 cupsd_job_t
*job
) /* I - Newly created job */
2107 int i
; /* Looping var */
2108 ipp_attribute_t
*prev
, /* Previous attribute */
2109 *next
, /* Next attribute */
2110 *attr
; /* Current attribute */
2111 cupsd_subscription_t
*sub
; /* Subscription object */
2112 const char *recipient
, /* notify-recipient-uri */
2113 *pullmethod
; /* notify-pull-method */
2114 ipp_attribute_t
*user_data
; /* notify-user-data */
2115 int interval
; /* notify-time-interval */
2116 unsigned mask
; /* notify-events */
2120 * Find the first subscription group attribute; return if we have
2124 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2125 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2132 * Process the subscription attributes in the request...
2141 mask
= CUPSD_EVENT_NONE
;
2143 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2145 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2146 attr
->value_tag
== IPP_TAG_URI
)
2149 * Validate the recipient scheme against the ServerBin/notifier
2153 char notifier
[1024], /* Notifier filename */
2154 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2155 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2156 host
[HTTP_MAX_URI
], /* Host portion of URI */
2157 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2158 int port
; /* Port portion of URI */
2161 recipient
= attr
->values
[0].string
.text
;
2163 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2164 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2165 host
, sizeof(host
), &port
,
2166 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2168 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2169 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
2170 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2171 "notify-status-code", IPP_URI_SCHEME
);
2175 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2177 if (access(notifier
, X_OK
))
2179 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2180 _("notify-recipient-uri URI \"%s\" uses unknown "
2181 "scheme"), recipient
);
2182 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2183 "notify-status-code", IPP_URI_SCHEME
);
2187 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2189 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2190 _("notify-recipient-uri URI \"%s\" is already used"),
2192 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2193 "notify-status-code", IPP_ATTRIBUTES
);
2197 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2198 attr
->value_tag
== IPP_TAG_KEYWORD
)
2200 pullmethod
= attr
->values
[0].string
.text
;
2202 if (strcmp(pullmethod
, "ippget"))
2204 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2205 _("Bad notify-pull-method \"%s\""), pullmethod
);
2206 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2207 "notify-status-code", IPP_ATTRIBUTES
);
2211 else if (!strcmp(attr
->name
, "notify-charset") &&
2212 attr
->value_tag
== IPP_TAG_CHARSET
&&
2213 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2214 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2216 send_ipp_status(con
, IPP_CHARSET
,
2217 _("Character set \"%s\" not supported"),
2218 attr
->values
[0].string
.text
);
2221 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2222 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2223 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2225 send_ipp_status(con
, IPP_CHARSET
,
2226 _("Language \"%s\" not supported"),
2227 attr
->values
[0].string
.text
);
2230 else if (!strcmp(attr
->name
, "notify-user-data") &&
2231 attr
->value_tag
== IPP_TAG_STRING
)
2233 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2235 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2236 _("The notify-user-data value is too large "
2237 "(%d > 63 octets)"),
2238 attr
->values
[0].unknown
.length
);
2244 else if (!strcmp(attr
->name
, "notify-events") &&
2245 attr
->value_tag
== IPP_TAG_KEYWORD
)
2247 for (i
= 0; i
< attr
->num_values
; i
++)
2248 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2250 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2252 send_ipp_status(con
, IPP_BAD_REQUEST
,
2253 _("The notify-lease-duration attribute cannot be "
2254 "used with job subscriptions."));
2257 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2258 attr
->value_tag
== IPP_TAG_INTEGER
)
2259 interval
= attr
->values
[0].integer
;
2264 if (!recipient
&& !pullmethod
)
2267 if (mask
== CUPSD_EVENT_NONE
)
2268 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2270 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2271 recipient
, 0)) != NULL
)
2273 sub
->interval
= interval
;
2275 cupsdSetString(&sub
->owner
, job
->username
);
2279 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2280 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2281 sub
->user_data_len
);
2284 ippAddSeparator(con
->response
);
2285 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2286 "notify-subscription-id", sub
->id
);
2288 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2296 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2299 * Remove all of the subscription attributes from the job request...
2301 * TODO: Optimize this since subscription groups have to come at the
2302 * end of the request...
2305 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2309 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2310 attr
->group_tag
== IPP_TAG_ZERO
)
2313 * Free and remove this attribute...
2321 job
->attrs
->attrs
= next
;
2327 job
->attrs
->last
= prev
;
2328 job
->attrs
->current
= prev
;
2333 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2335 * See RFC 4122 for the definition of UUIDs and the format.
2339 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2340 cupsd_job_t
*job
) /* I - Job */
2342 char uuid
[1024]; /* job-uuid string */
2343 _cups_md5_state_t md5state
; /* MD5 state */
2344 unsigned char md5sum
[16]; /* MD5 digest/sum */
2348 * First see if the job already has a job-uuid attribute; if so, return...
2351 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2355 * No job-uuid attribute, so build a version 3 UUID with the local job
2356 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2357 * the ServerName, server name and port that the client connected to,
2358 * and local job ID...
2361 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2362 con
->serverport
, job
->id
);
2364 _cupsMD5Init(&md5state
);
2365 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2366 _cupsMD5Finish(&md5state
, md5sum
);
2369 * Format the UUID URI using the MD5 sum and job ID.
2372 snprintf(uuid
, sizeof(uuid
),
2373 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2374 "%02x%02x%02x%02x%02x%02x",
2375 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2376 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2377 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2378 md5sum
[14], md5sum
[15]);
2380 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2385 * 'add_printer()' - Add a printer to the system.
2389 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2390 ipp_attribute_t
*uri
) /* I - URI of printer */
2392 http_status_t status
; /* Policy status */
2393 int i
; /* Looping var */
2394 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2395 username
[HTTP_MAX_URI
], /* Username portion of URI */
2396 host
[HTTP_MAX_URI
], /* Host portion of URI */
2397 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2398 int port
; /* Port portion of URI */
2399 cupsd_printer_t
*printer
; /* Printer/class */
2400 ipp_attribute_t
*attr
; /* Printer attribute */
2401 cups_file_t
*fp
; /* Script/PPD file */
2402 char line
[1024]; /* Line from file... */
2403 char srcfile
[1024], /* Source Script/PPD file */
2404 dstfile
[1024]; /* Destination Script/PPD file */
2405 int modify
; /* Non-zero if we are modifying */
2406 char newname
[IPP_MAX_NAME
]; /* New printer name */
2407 int changed_driver
, /* Changed the PPD/interface script? */
2408 need_restart_job
, /* Need to restart job? */
2409 set_device_uri
, /* Did we set the device URI? */
2410 set_port_monitor
; /* Did we set the port monitor? */
2413 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2414 con
->http
.fd
, uri
->values
[0].string
.text
);
2417 * Do we have a valid URI?
2420 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2421 sizeof(scheme
), username
, sizeof(username
), host
,
2422 sizeof(host
), &port
, resource
, sizeof(resource
));
2424 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2427 * No, return an error...
2430 send_ipp_status(con
, IPP_BAD_REQUEST
,
2431 _("The printer-uri must be of the form "
2432 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2437 * Do we have a valid printer name?
2440 if (!validate_name(resource
+ 10))
2443 * No, return an error...
2446 send_ipp_status(con
, IPP_BAD_REQUEST
,
2447 _("The printer-uri \"%s\" contains invalid characters."),
2448 uri
->values
[0].string
.text
);
2453 * See if the printer already exists; if not, create a new printer...
2456 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2459 * Printer doesn't exist; see if we have a class of the same name...
2462 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2463 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2466 * Yes, return an error...
2469 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2470 _("A class named \"%s\" already exists"),
2476 * No, check the default policy then add the printer...
2479 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2481 send_http_error(con
, status
, NULL
);
2485 printer
= cupsdAddPrinter(resource
+ 10);
2488 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2491 * Check the default policy, then rename the implicit printer to
2492 * "AnyPrinter" or delete it...
2495 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2497 send_http_error(con
, status
, NULL
);
2501 if (ImplicitAnyClasses
)
2503 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2504 cupsdRenamePrinter(printer
, newname
);
2507 cupsdDeletePrinter(printer
, 1);
2510 * Add the printer as a new local printer...
2513 printer
= cupsdAddPrinter(resource
+ 10);
2516 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2519 * Check the default policy, then rename the remote printer to
2520 * "Printer@server"...
2523 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2525 send_http_error(con
, status
, NULL
);
2529 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2531 cupsdRenamePrinter(printer
, newname
);
2534 * Add the printer as a new local printer...
2537 printer
= cupsdAddPrinter(resource
+ 10);
2540 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2543 send_http_error(con
, status
, printer
);
2550 * Look for attributes and copy them over as needed...
2554 need_restart_job
= 0;
2556 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2557 IPP_TAG_TEXT
)) != NULL
)
2558 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2560 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2561 IPP_TAG_TEXT
)) != NULL
)
2562 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2566 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2567 IPP_TAG_URI
)) != NULL
)
2570 * Do we have a valid device URI?
2573 http_uri_status_t uri_status
; /* URI separation status */
2574 char old_device_uri
[1024];
2575 /* Old device URI */
2578 need_restart_job
= 1;
2580 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2581 attr
->values
[0].string
.text
,
2582 scheme
, sizeof(scheme
),
2583 username
, sizeof(username
),
2584 host
, sizeof(host
), &port
,
2585 resource
, sizeof(resource
));
2587 if (uri_status
< HTTP_URI_OK
)
2589 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\""),
2590 attr
->values
[0].string
.text
);
2591 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2592 "add_printer: httpSeparateURI returned %d", uri_status
);
2596 if (!strcmp(scheme
, "file"))
2599 * See if the administrator has enabled file devices...
2602 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2605 * File devices are disabled and the URL is not file:/dev/null...
2608 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2609 _("File device URIs have been disabled! "
2610 "To enable, see the FileDevice directive in "
2611 "\"%s/cupsd.conf\"."),
2619 * See if the backend exists and is executable...
2622 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2623 if (access(srcfile
, X_OK
))
2626 * Could not find device in list!
2629 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\""),
2635 if (printer
->sanitized_device_uri
)
2636 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2637 sizeof(old_device_uri
));
2639 old_device_uri
[0] = '\0';
2641 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2643 cupsdLogMessage(CUPSD_LOG_INFO
,
2644 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2645 printer
->name
, printer
->sanitized_device_uri
,
2651 set_port_monitor
= 0;
2653 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2654 IPP_TAG_NAME
)) != NULL
)
2656 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2659 need_restart_job
= 1;
2661 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2665 for (i
= 0; i
< supported
->num_values
; i
++)
2666 if (!strcmp(supported
->values
[i
].string
.text
,
2667 attr
->values
[0].string
.text
))
2671 if (!supported
|| i
>= supported
->num_values
)
2673 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\""),
2674 attr
->values
[0].string
.text
);
2678 cupsdLogMessage(CUPSD_LOG_INFO
,
2679 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2680 printer
->name
, attr
->values
[0].string
.text
,
2681 printer
->port_monitor
? printer
->port_monitor
: "none");
2683 if (strcmp(attr
->values
[0].string
.text
, "none"))
2684 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2686 cupsdClearString(&printer
->port_monitor
);
2688 set_port_monitor
= 1;
2691 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2692 IPP_TAG_BOOLEAN
)) != NULL
&&
2693 attr
->values
[0].boolean
!= printer
->accepting
)
2695 cupsdLogMessage(CUPSD_LOG_INFO
,
2696 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2697 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2699 printer
->accepting
= attr
->values
[0].boolean
;
2700 cupsdAddPrinterHistory(printer
);
2702 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2703 "%s accepting jobs.",
2704 printer
->accepting
? "Now" : "No longer");
2707 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2708 IPP_TAG_BOOLEAN
)) != NULL
)
2710 if (printer
->shared
&& !attr
->values
[0].boolean
)
2711 cupsdDeregisterPrinter(printer
, 1);
2713 cupsdLogMessage(CUPSD_LOG_INFO
,
2714 "Setting %s printer-is-shared to %d (was %d.)",
2715 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2717 printer
->shared
= attr
->values
[0].boolean
;
2720 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2721 IPP_TAG_ENUM
)) != NULL
)
2723 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2724 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2726 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d"),
2727 attr
->values
[0].integer
);
2731 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2732 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2734 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2735 cupsdStopPrinter(printer
, 0);
2738 need_restart_job
= 1;
2739 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2743 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2744 IPP_TAG_TEXT
)) != NULL
)
2746 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2747 sizeof(printer
->state_message
));
2748 cupsdAddPrinterHistory(printer
);
2750 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2751 printer
->state_message
);
2754 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2755 IPP_TAG_KEYWORD
)) != NULL
)
2757 if (attr
->num_values
>
2758 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2760 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2761 _("Too many printer-state-reasons values (%d > %d)"),
2763 (int)(sizeof(printer
->reasons
) /
2764 sizeof(printer
->reasons
[0])));
2768 for (i
= 0; i
< printer
->num_reasons
; i
++)
2769 _cupsStrFree(printer
->reasons
[i
]);
2771 printer
->num_reasons
= 0;
2772 for (i
= 0; i
< attr
->num_values
; i
++)
2774 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2777 printer
->reasons
[printer
->num_reasons
] =
2778 _cupsStrRetain(attr
->values
[i
].string
.text
);
2779 printer
->num_reasons
++;
2781 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2782 printer
->state
!= IPP_PRINTER_STOPPED
)
2784 cupsdLogMessage(CUPSD_LOG_INFO
,
2785 "Setting %s printer-state to %d (was %d.)",
2786 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2787 cupsdStopPrinter(printer
, 0);
2791 if (PrintcapFormat
== PRINTCAP_PLIST
)
2792 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2794 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2795 "Printer \"%s\" state changed.", printer
->name
);
2798 set_printer_defaults(con
, printer
);
2800 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2801 IPP_TAG_KEYWORD
)) != NULL
)
2802 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2805 * See if we have all required attributes...
2808 if (!printer
->device_uri
)
2809 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2812 * See if we have an interface script or PPD file attached to the request...
2817 need_restart_job
= 1;
2820 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2822 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2825 * Yes; get the first line from it...
2829 cupsFileGets(fp
, line
, sizeof(line
));
2833 * Then see what kind of file it is...
2836 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2839 if (!strncmp(line
, "*PPD-Adobe", 10))
2842 * The new file is a PPD file, so remove any old interface script
2843 * that might be lying around...
2851 * This must be an interface script, so move the file over to the
2852 * interfaces directory and make it executable...
2855 if (copy_file(srcfile
, dstfile
))
2857 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2858 _("Unable to copy interface script - %s"),
2863 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2864 "Copied interface script successfully");
2865 chmod(dstfile
, 0755);
2868 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2871 if (!strncmp(line
, "*PPD-Adobe", 10))
2874 * The new file is a PPD file, so move the file over to the
2875 * ppd directory and make it readable by all...
2878 if (copy_file(srcfile
, dstfile
))
2880 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2881 _("Unable to copy PPD file - %s"),
2886 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2887 "Copied PPD file successfully");
2888 chmod(dstfile
, 0644);
2893 * This must be an interface script, so remove any old PPD file that
2894 * may be lying around...
2901 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2902 IPP_TAG_NAME
)) != NULL
)
2904 need_restart_job
= 1;
2907 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2910 * Raw driver, remove any existing PPD or interface script files.
2913 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2917 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2927 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2931 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2934 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2936 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file"));
2940 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2941 "Copied PPD file successfully");
2942 chmod(dstfile
, 0644);
2949 * If we changed the PPD/interface script, then remove the printer's cache
2950 * file and clear the printer-state-reasons...
2953 char cache_name
[1024]; /* Cache filename for printer attrs */
2955 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp4", CacheDir
,
2959 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.pwg3", CacheDir
,
2963 cupsdSetPrinterReasons(printer
, "none");
2967 * (Re)register color profiles...
2972 apple_unregister_profiles(printer
);
2973 apple_register_profiles(printer
);
2975 #endif /* __APPLE__ */
2979 * If we set the device URI but not the port monitor, check which port
2980 * monitor to use by default...
2983 if (set_device_uri
&& !set_port_monitor
)
2985 ppd_file_t
*ppd
; /* PPD file */
2986 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2989 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2990 sizeof(scheme
), username
, sizeof(username
), host
,
2991 sizeof(host
), &port
, resource
, sizeof(resource
));
2993 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2995 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2997 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2999 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
3000 if (!strcmp(scheme
, ppdattr
->spec
))
3002 cupsdLogMessage(CUPSD_LOG_INFO
,
3003 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
3004 printer
->name
, ppdattr
->value
,
3005 printer
->port_monitor
? printer
->port_monitor
3008 if (strcmp(ppdattr
->value
, "none"))
3009 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
3011 cupsdClearString(&printer
->port_monitor
);
3021 * Update the printer attributes and return...
3024 cupsdSetPrinterAttrs(printer
);
3025 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3027 if (need_restart_job
&& printer
->job
)
3030 * Restart the current job...
3033 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
3034 "Job restarted because the printer was modified.");
3037 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3041 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
3042 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
3043 printer
->name
, get_username(con
));
3045 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
3046 printer
->name
, get_username(con
));
3050 cupsdAddPrinterHistory(printer
);
3052 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
3053 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
3054 printer
->name
, get_username(con
));
3056 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
3057 printer
->name
, get_username(con
));
3060 con
->response
->request
.status
.status_code
= IPP_OK
;
3065 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
3066 * based upon the printer state...
3070 add_printer_state_reasons(
3071 cupsd_client_t
*con
, /* I - Client connection */
3072 cupsd_printer_t
*p
) /* I - Printer info */
3074 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3075 "add_printer_state_reasons(%p[%d], %p[%s])",
3076 con
, con
->http
.fd
, p
, p
->name
);
3078 if (p
->num_reasons
== 0)
3079 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3080 "printer-state-reasons", NULL
, "none");
3082 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3083 "printer-state-reasons", p
->num_reasons
, NULL
,
3084 (const char * const *)p
->reasons
);
3089 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
3090 * the specified printer or class.
3094 add_queued_job_count(
3095 cupsd_client_t
*con
, /* I - Client connection */
3096 cupsd_printer_t
*p
) /* I - Printer or class */
3098 int count
; /* Number of jobs on destination */
3101 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3102 con
, con
->http
.fd
, p
, p
->name
);
3104 count
= cupsdGetPrinterJobCount(p
->name
);
3106 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3107 "queued-job-count", count
);
3113 * 'apple_init_profile()' - Initialize a color profile.
3118 ppd_file_t
*ppd
, /* I - PPD file */
3119 cups_array_t
*languages
, /* I - Languages in the PPD file */
3120 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3121 CFMutableDictionaryRef profile
, /* I - Profile dictionary */
3123 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3124 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3125 unsigned id
, /* I - Profile ID */
3126 const char *name
, /* I - Profile name */
3127 const char *text
, /* I - Profile UI text */
3128 const char *iccfile
) /* I - ICC filename */
3130 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3131 CFURLRef url
; /* URL for profile filename */
3132 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3133 CFMutableDictionaryRef dict
; /* Dictionary for name */
3134 char *language
; /* Current language */
3135 ppd_attr_t
*attr
; /* Profile attribute */
3136 CFStringRef cflang
, /* Language string */
3137 cftext
; /* Localized text */
3141 * Build the profile name dictionary...
3144 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3145 &kCFTypeDictionaryKeyCallBacks
,
3146 &kCFTypeDictionaryValueCallBacks
);
3148 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3149 kCFStringEncodingUTF8
);
3153 CFDictionarySetValue(dict
, CFSTR("en_US"), cftext
);
3160 * Find localized names for the color profiles...
3163 cupsArraySave(ppd
->sorted_attrs
);
3165 for (language
= (char *)cupsArrayFirst(languages
);
3167 language
= (char *)cupsArrayNext(languages
))
3171 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3173 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3176 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3178 if (attr
&& attr
->text
[0])
3180 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3181 kCFStringEncodingUTF8
);
3182 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3183 kCFStringEncodingUTF8
);
3185 if (cflang
&& cftext
)
3186 CFDictionarySetValue(dict
, cflang
, cftext
);
3196 cupsArrayRestore(ppd
->sorted_attrs
);
3200 * Fill in the profile data...
3203 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3206 url
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
3207 (const UInt8
*)iccfile
,
3208 strlen(iccfile
), false);
3212 CFDictionarySetValue(profile
, kColorSyncDeviceProfileURL
, url
);
3217 CFDictionarySetValue(profile
, kColorSyncDeviceModeDescriptions
, dict
);
3221 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3222 profile
->profileID
= id
;
3223 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3224 profile
->profileName
= dict
;
3227 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3228 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3229 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3234 * 'apple_register_profiles()' - Register color profiles for a printer.
3238 apple_register_profiles(
3239 cupsd_printer_t
*p
) /* I - Printer */
3241 int i
; /* Looping var */
3242 char ppdfile
[1024], /* PPD filename */
3243 iccfile
[1024], /* ICC filename */
3244 selector
[PPD_MAX_NAME
];
3245 /* Profile selection string */
3246 ppd_file_t
*ppd
; /* PPD file */
3247 ppd_attr_t
*attr
, /* Profile attributes */
3248 *profileid_attr
,/* cupsProfileID attribute */
3249 *q1_attr
, /* ColorModel (or other) qualifier */
3250 *q2_attr
, /* MediaType (or other) qualifier */
3251 *q3_attr
; /* Resolution (or other) qualifier */
3252 char q_keyword
[PPD_MAX_NAME
];
3253 /* Qualifier keyword */
3254 const char *q1_choice
, /* ColorModel (or other) choice */
3255 *q2_choice
, /* MediaType (or other) choice */
3256 *q3_choice
; /* Resolution (or other) choice */
3257 const char *profile_key
; /* Profile keyword */
3258 ppd_option_t
*cm_option
; /* Color model option */
3259 ppd_choice_t
*cm_choice
; /* Color model choice */
3260 int num_profiles
; /* Number of profiles */
3261 CMError error
= 0; /* Last error */
3262 unsigned device_id
, /* Printer device ID */
3263 profile_id
, /* Profile ID */
3264 default_profile_id
= 0;
3265 /* Default profile ID */
3266 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3267 CFStringRef printer_name
; /* Printer name string */
3268 cups_array_t
*languages
; /* Languages array */
3269 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3270 CFMutableDictionaryRef profiles
, /* Dictionary of profiles */
3271 profile
; /* Current profile info dictionary */
3272 CFStringRef dict_key
; /* Key in factory profile dictionary */
3274 CMDeviceScope scope
= /* Scope of the registration */
3276 kCFPreferencesAnyUser
,
3277 kCFPreferencesCurrentHost
3279 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3280 CMDeviceProfileInfo
*profile
; /* Current profile */
3281 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3285 * Make sure ColorSync is available...
3288 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3289 if (ColorSyncRegisterDevice
== NULL
)
3293 if (CMRegisterColorDevice
== NULL
)
3295 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3298 * Try opening the PPD file for this printer...
3301 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3302 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3306 * See if we have any profiles...
3309 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3310 profile_key
= "APTiogaProfile";
3313 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3314 profile_key
= "cupsICCProfile";
3317 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3318 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3320 if (attr
->value
[0] != '/')
3321 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3324 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3326 if (access(iccfile
, 0))
3332 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3334 * Create a dictionary for the factory profiles...
3337 profiles
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3338 &kCFTypeDictionaryKeyCallBacks
,
3339 &kCFTypeDictionaryValueCallBacks
);
3342 cupsdLogMessage(CUPSD_LOG_ERROR
,
3343 "Unable to allocate memory for factory profiles.");
3347 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3350 * If we have profiles, add them...
3353 if (num_profiles
> 0)
3355 if (profile_key
[0] == 'A')
3358 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3362 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3364 default_profile_id
= atoi(attr
->value
);
3366 q1_choice
= q2_choice
= q3_choice
= NULL
;
3371 * For CUPS PPDs, figure out the default profile selector values...
3374 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3375 attr
->value
&& attr
->value
[0])
3377 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3378 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3380 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3381 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3383 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3384 q1_choice
= q1_attr
->value
;
3388 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3389 attr
->value
&& attr
->value
[0])
3391 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3392 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3395 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3397 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3398 q2_choice
= q2_attr
->value
;
3402 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3403 attr
->value
&& attr
->value
[0])
3405 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3406 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3409 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3411 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3412 q3_choice
= q3_attr
->value
;
3417 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3419 * Build the array of profiles...
3421 * Note: This calloc actually requests slightly more memory than needed.
3424 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3426 cupsdLogMessage(CUPSD_LOG_ERROR
,
3427 "Unable to allocate memory for factory profiles.");
3432 profiles
->profileCount
= num_profiles
;
3433 profile
= profiles
->profiles
;
3434 # endif /* !HAVE_COLORSYNCREGISTERDEVICE */
3437 * Loop through the profiles listed in the PPD...
3440 languages
= _ppdGetLanguages(ppd
);
3442 for (attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3444 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3445 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3448 * Add this profile...
3451 if (attr
->value
[0] != '/')
3452 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3455 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3457 if (access(iccfile
, 0))
3460 if (profile_key
[0] == 'c')
3462 cupsArraySave(ppd
->sorted_attrs
);
3464 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3465 attr
->spec
)) != NULL
&&
3466 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3467 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3469 profile_id
= _ppdHashName(attr
->spec
);
3471 cupsArrayRestore(ppd
->sorted_attrs
);
3474 profile_id
= atoi(attr
->spec
);
3476 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3477 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3478 &kCFTypeDictionaryKeyCallBacks
,
3479 &kCFTypeDictionaryValueCallBacks
);
3482 cupsdLogMessage(CUPSD_LOG_ERROR
,
3483 "Unable to allocate memory for color profile.");
3484 CFRelease(profiles
);
3489 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3490 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3492 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3493 CFSTR("%u"), profile_id
);
3496 CFDictionarySetValue(profiles
, dict_key
, profile
);
3497 CFRelease(dict_key
);
3503 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3504 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3507 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3510 * See if this is the default profile...
3513 if (!default_profile_id
)
3519 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3520 q1_choice
, q2_choice
, q3_choice
);
3521 if (!strcmp(selector
, attr
->spec
))
3522 default_profile_id
= profile_id
;
3525 if (!default_profile_id
)
3527 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3529 if (!strcmp(selector
, attr
->spec
))
3530 default_profile_id
= profile_id
;
3534 if (!default_profile_id
&& q3_choice
)
3536 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3538 if (!strcmp(selector
, attr
->spec
))
3539 default_profile_id
= profile_id
;
3542 if (!default_profile_id
)
3544 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3545 if (!strcmp(selector
, attr
->spec
))
3546 default_profile_id
= profile_id
;
3551 _ppdFreeLanguages(languages
);
3553 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3556 * Extract profiles from ColorModel option...
3559 const char *profile_name
; /* Name of generic profile */
3562 num_profiles
= cm_option
->num_choices
;
3564 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3566 * Create an array for the factory profiles...
3569 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3571 cupsdLogMessage(CUPSD_LOG_ERROR
,
3572 "Unable to allocate memory for factory profiles.");
3577 profiles
->profileCount
= num_profiles
;
3578 profile
= profiles
->profiles
;
3579 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3581 for (i
= cm_option
->num_choices
, cm_choice
= cm_option
->choices
;
3585 if (!strcmp(cm_choice
->choice
, "Gray") ||
3586 !strcmp(cm_choice
->choice
, "Black"))
3587 profile_name
= "Gray";
3588 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3589 !strcmp(cm_choice
->choice
, "CMY"))
3590 profile_name
= "RGB";
3591 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3592 !strcmp(cm_choice
->choice
, "KCMY"))
3593 profile_name
= "CMYK";
3595 profile_name
= "DeviceN";
3597 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3598 profile_id
= _ppdHashName(selector
);
3600 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3601 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3602 &kCFTypeDictionaryKeyCallBacks
,
3603 &kCFTypeDictionaryValueCallBacks
);
3606 cupsdLogMessage(CUPSD_LOG_ERROR
,
3607 "Unable to allocate memory for color profile.");
3608 CFRelease(profiles
);
3613 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3614 cm_choice
->text
, NULL
);
3616 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3617 CFSTR("%u"), profile_id
);
3620 CFDictionarySetValue(profiles
, dict_key
, profile
);
3621 CFRelease(dict_key
);
3627 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3628 cm_choice
->text
, NULL
);
3630 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3632 if (cm_choice
->marked
)
3633 default_profile_id
= profile_id
;
3639 * Use the default colorspace...
3642 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3644 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3646 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3648 * Add the grayscale profile first. We always have a grayscale profile.
3651 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3652 &kCFTypeDictionaryKeyCallBacks
,
3653 &kCFTypeDictionaryValueCallBacks
);
3657 cupsdLogMessage(CUPSD_LOG_ERROR
,
3658 "Unable to allocate memory for color profile.");
3659 CFRelease(profiles
);
3664 profile_id
= _ppdHashName("Gray..");
3665 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "Gray", "Gray", NULL
);
3667 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3671 CFDictionarySetValue(profiles
, dict_key
, profile
);
3672 CFRelease(dict_key
);
3678 * Then add the RGB/CMYK/DeviceN color profile...
3681 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3682 &kCFTypeDictionaryKeyCallBacks
,
3683 &kCFTypeDictionaryValueCallBacks
);
3687 cupsdLogMessage(CUPSD_LOG_ERROR
,
3688 "Unable to allocate memory for color profile.");
3689 CFRelease(profiles
);
3694 switch (ppd
->colorspace
)
3698 profile_id
= _ppdHashName("RGB..");
3699 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "RGB", "RGB",
3704 profile_id
= _ppdHashName("CMYK..");
3705 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "CMYK", "CMYK",
3714 profile_id
= _ppdHashName("DeviceN..");
3715 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "DeviceN",
3720 if (CFDictionaryGetCount(profile
) > 0)
3722 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3723 CFSTR("%u"), profile_id
);
3726 CFDictionarySetValue(profiles
, dict_key
, profile
);
3727 CFRelease(dict_key
);
3735 * Create an array for the factory profiles...
3738 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3740 cupsdLogMessage(CUPSD_LOG_ERROR
,
3741 "Unable to allocate memory for factory profiles.");
3746 profiles
->profileCount
= num_profiles
;
3749 * Add the grayscale profile first. We always have a grayscale profile.
3752 profile_id
= _ppdHashName("Gray..");
3753 apple_init_profile(ppd
, NULL
, profiles
->profiles
, profile_id
, "Gray",
3757 * Then add the RGB/CMYK/DeviceN color profile...
3760 switch (ppd
->colorspace
)
3764 profile_id
= _ppdHashName("RGB..");
3765 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3766 "RGB", "RGB", NULL
);
3770 profile_id
= _ppdHashName("CMYK..");
3771 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3772 "CMYK", "CMYK", NULL
);
3780 profile_id
= _ppdHashName("DeviceN..");
3781 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3782 "DeviceN", "DeviceN", NULL
);
3785 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3788 if (num_profiles
> 0)
3791 * Make sure we have a default profile ID...
3794 if (!default_profile_id
)
3795 default_profile_id
= profile_id
; /* Last profile */
3797 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3798 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3799 default_profile_id
);
3802 CFDictionarySetValue(profiles
, kColorSyncDeviceDefaultProfileID
,
3804 CFRelease(dict_key
);
3806 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3809 * Get the device ID hash and pathelogical name dictionary.
3812 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3815 device_id
= _ppdHashName(p
->name
);
3816 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3817 &kCFTypeDictionaryKeyCallBacks
,
3818 &kCFTypeDictionaryValueCallBacks
);
3819 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3820 p
->name
, kCFStringEncodingUTF8
);
3822 if (device_name
&& printer_name
)
3824 CFDictionarySetValue(device_name
, CFSTR("en_US"), printer_name
);
3827 * Register the device with ColorSync...
3830 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3831 CFTypeRef deviceDictKeys
[] =
3833 kColorSyncDeviceDescriptions
,
3834 kColorSyncFactoryProfiles
,
3835 kColorSyncDeviceUserScope
,
3836 kColorSyncDeviceHostScope
3838 CFTypeRef deviceDictVals
[] =
3839 { /* Device values */
3842 kCFPreferencesAnyUser
,
3843 kCFPreferencesCurrentHost
3845 CFDictionaryRef deviceDict
; /* Device dictionary */
3846 CFUUIDRef deviceUUID
; /* Device UUID (TODO: use printer-uuid value) */
3848 deviceDict
= CFDictionaryCreate(kCFAllocatorDefault
,
3849 (const void **)deviceDictKeys
,
3850 (const void **)deviceDictVals
,
3851 sizeof(deviceDictKeys
) /
3852 sizeof(deviceDictKeys
[0]),
3853 &kCFTypeDictionaryKeyCallBacks
,
3854 &kCFTypeDictionaryValueCallBacks
);
3855 deviceUUID
= ColorSyncCreateUUIDFromUInt32(device_id
);
3856 if (deviceDict
&& deviceUUID
&&
3857 !ColorSyncRegisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
,
3862 CFRelease(deviceUUID
);
3865 CFRelease(deviceDict
);
3868 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3869 device_name
, &scope
);
3872 * Register the profiles...
3876 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3877 default_profile_id
, profiles
);
3878 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3888 cupsdLogMessage(CUPSD_LOG_ERROR
,
3889 "Unable to register ICC color profiles for \"%s\": %d",
3890 p
->name
, (int)error
);
3893 CFRelease(printer_name
);
3896 CFRelease(device_name
);
3900 * Free any memory we used...
3903 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3904 CFRelease(profiles
);
3907 if (num_profiles
> 0)
3909 for (profile
= profiles
->profiles
;
3911 profile
++, num_profiles
--)
3912 CFRelease(profile
->profileName
);
3916 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3923 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3928 apple_unregister_profiles(
3929 cupsd_printer_t
*p
) /* I - Printer */
3932 * Make sure ColorSync is available...
3935 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3936 if (ColorSyncUnregisterDevice
!= NULL
)
3938 CFUUIDRef deviceUUID
; /* Printer UUID */
3940 deviceUUID
= ColorSyncCreateUUIDFromUInt32(_ppdHashName(p
->name
));
3941 /* TODO: Use printer-uuid value */
3945 ColorSyncUnregisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
);
3946 CFRelease(deviceUUID
);
3951 if (CMUnregisterColorDevice
!= NULL
)
3952 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3953 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3955 #endif /* __APPLE__ */
3958 * 'apply_printer_defaults()' - Apply printer default options to a job.
3962 apply_printer_defaults(
3963 cupsd_printer_t
*printer
, /* I - Printer */
3964 cupsd_job_t
*job
) /* I - Job */
3966 int i
, /* Looping var */
3967 num_options
; /* Number of default options */
3968 cups_option_t
*options
, /* Default options */
3969 *option
; /* Current option */
3973 * Collect all of the default options and add the missing ones to the
3977 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3978 option
= printer
->options
;
3981 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3983 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3988 * Encode these options as attributes in the job object...
3991 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3992 cupsFreeOptions(num_options
, options
);
3997 * 'authenticate_job()' - Set job authentication info.
4001 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
4002 ipp_attribute_t
*uri
) /* I - Job URI */
4004 ipp_attribute_t
*attr
, /* job-id attribute */
4005 *auth_info
; /* auth-info attribute */
4006 int jobid
; /* Job ID */
4007 cupsd_job_t
*job
; /* Current job */
4008 char scheme
[HTTP_MAX_URI
],
4009 /* Method portion of URI */
4010 username
[HTTP_MAX_URI
],
4011 /* Username portion of URI */
4013 /* Host portion of URI */
4014 resource
[HTTP_MAX_URI
];
4015 /* Resource portion of URI */
4016 int port
; /* Port portion of URI */
4019 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
4020 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
4023 * Start with "everything is OK" status...
4026 con
->response
->request
.status
.status_code
= IPP_OK
;
4029 * See if we have a job URI or a printer URI...
4032 if (!strcmp(uri
->name
, "printer-uri"))
4035 * Got a printer URI; see if we also have a job-id attribute...
4038 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4039 IPP_TAG_INTEGER
)) == NULL
)
4041 send_ipp_status(con
, IPP_BAD_REQUEST
,
4042 _("Got a printer-uri attribute but no job-id"));
4046 jobid
= attr
->values
[0].integer
;
4051 * Got a job URI; parse it to get the job ID...
4054 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4055 sizeof(scheme
), username
, sizeof(username
), host
,
4056 sizeof(host
), &port
, resource
, sizeof(resource
));
4058 if (strncmp(resource
, "/jobs/", 6))
4064 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\""),
4065 uri
->values
[0].string
.text
);
4069 jobid
= atoi(resource
+ 6);
4073 * See if the job exists...
4076 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4079 * Nope - return a "not found" error...
4082 send_ipp_status(con
, IPP_NOT_FOUND
,
4083 _("Job #%d does not exist"), jobid
);
4088 * See if the job has been completed...
4091 if (job
->state_value
!= IPP_JOB_HELD
)
4094 * Return a "not-possible" error...
4097 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4098 _("Job #%d is not held for authentication"),
4104 * See if we have already authenticated...
4107 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
4109 if (!con
->username
[0] && !auth_info
)
4111 cupsd_printer_t
*printer
; /* Job destination */
4115 * No auth data. If we need to authenticate via Kerberos, send a
4116 * HTTP auth challenge, otherwise just return an IPP error...
4119 printer
= cupsdFindDest(job
->dest
);
4121 if (printer
&& printer
->num_auth_info_required
> 0 &&
4122 !strcmp(printer
->auth_info_required
[0], "negotiate"))
4123 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
4125 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
4126 _("No authentication information provided"));
4131 * See if the job is owned by the requesting user...
4134 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4136 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4137 cupsdFindDest(job
->dest
));
4142 * Save the authentication information for this job...
4145 save_auth_info(con
, job
, auth_info
);
4148 * Reset the job-hold-until value to "no-hold"...
4151 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4152 IPP_TAG_KEYWORD
)) == NULL
)
4153 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4157 attr
->value_tag
= IPP_TAG_KEYWORD
;
4158 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
4162 * Release the job and return...
4165 cupsdReleaseJob(job
);
4167 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 was not found."));
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-id %d not found."),
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 strcasecmp(job
->dest
, printer
->name
))
4363 if (i
< job_ids
->num_values
)
4365 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
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 was not found."));
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 !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 !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
,
4515 _("Bad job-uri attribute \"%s\""),
4516 uri
->values
[0].string
.text
);
4520 jobid
= atoi(resource
+ 6);
4524 * Look for the "purge-job" attribute...
4527 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4528 IPP_TAG_BOOLEAN
)) != NULL
)
4529 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4531 purge
= CUPSD_JOB_DEFAULT
;
4534 * See if the job exists...
4537 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4540 * Nope - return a "not found" error...
4543 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
4548 * See if the job is owned by the requesting user...
4551 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4553 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4554 cupsdFindDest(job
->dest
));
4559 * See if the job is already completed, canceled, or aborted; if so,
4560 * we can't cancel...
4563 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4565 switch (job
->state_value
)
4567 case IPP_JOB_CANCELED
:
4568 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4569 _("Job #%d is already canceled - can\'t cancel."),
4573 case IPP_JOB_ABORTED
:
4574 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4575 _("Job #%d is already aborted - can\'t cancel."),
4580 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4581 _("Job #%d is already completed - can\'t cancel."),
4590 * Cancel the job and return...
4593 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4594 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4595 "Job canceled by \"%s\"",
4599 if (purge
== CUPSD_JOB_PURGE
)
4600 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4603 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4606 con
->response
->request
.status
.status_code
= IPP_OK
;
4611 * 'cancel_subscription()' - Cancel a subscription.
4615 cancel_subscription(
4616 cupsd_client_t
*con
, /* I - Client connection */
4617 int sub_id
) /* I - Subscription ID */
4619 http_status_t status
; /* Policy status */
4620 cupsd_subscription_t
*sub
; /* Subscription */
4623 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4624 "cancel_subscription(con=%p[%d], sub_id=%d)",
4625 con
, con
->http
.fd
, sub_id
);
4628 * Is the subscription ID valid?
4631 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4634 * Bad subscription ID...
4637 send_ipp_status(con
, IPP_NOT_FOUND
,
4638 _("notify-subscription-id %d no good"), sub_id
);
4646 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4648 con
, sub
->owner
)) != HTTP_OK
)
4650 send_http_error(con
, status
, sub
->dest
);
4655 * Cancel the subscription...
4658 cupsdDeleteSubscription(sub
, 1);
4660 con
->response
->request
.status
.status_code
= IPP_OK
;
4665 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4668 static int /* O - 1 if OK, 0 if not */
4669 check_rss_recipient(
4670 const char *recipient
) /* I - Recipient URI */
4672 cupsd_subscription_t
*sub
; /* Current subscription */
4675 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4677 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4681 * Compare the URIs up to the first ?...
4684 const char *r1
, *r2
;
4686 for (r1
= recipient
, r2
= sub
->recipient
;
4687 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4699 * 'check_quotas()' - Check quotas for a printer and user.
4702 static int /* O - 1 if OK, 0 if forbidden,
4703 -1 if limit reached */
4704 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4705 cupsd_printer_t
*p
) /* I - Printer or class */
4707 char username
[33], /* Username */
4708 *name
; /* Current user name */
4709 cupsd_quota_t
*q
; /* Quota data */
4710 #ifdef HAVE_MBR_UID_TO_UUID
4712 * Use Apple membership APIs which require that all names represent
4713 * valid user account or group records accessible by the server.
4716 uuid_t usr_uuid
; /* UUID for job requesting user */
4717 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4718 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4719 int mbr_err
; /* Error from membership function */
4720 int is_member
; /* Is this user a member? */
4723 * Use standard POSIX APIs for checking users and groups...
4726 struct passwd
*pw
; /* User password data */
4727 #endif /* HAVE_MBR_UID_TO_UUID */
4730 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4731 con
, con
->http
.fd
, p
, p
->name
);
4734 * Figure out who is printing...
4737 strlcpy(username
, get_username(con
), sizeof(username
));
4740 * Check global active job limits for printers and users...
4743 if (MaxJobsPerPrinter
)
4746 * Check if there are too many pending jobs on this printer...
4749 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4751 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4760 * Check if there are too many pending jobs for this user...
4763 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4765 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4772 * Check against users...
4775 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4778 if (cupsArrayCount(p
->users
))
4780 #ifdef HAVE_MBR_UID_TO_UUID
4782 * Get UUID for job requesting user...
4785 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4791 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4792 "check_quotas: UUID lookup failed for user \"%s\"",
4794 cupsdLogMessage(CUPSD_LOG_INFO
,
4795 "Denying user \"%s\" access to printer \"%s\" "
4796 "(unknown user)...",
4802 * Get UID and GID of requesting user...
4805 pw
= getpwnam(username
);
4807 #endif /* HAVE_MBR_UID_TO_UUID */
4809 for (name
= (char *)cupsArrayFirst(p
->users
);
4811 name
= (char *)cupsArrayNext(p
->users
))
4815 * Check group membership...
4818 #ifdef HAVE_MBR_UID_TO_UUID
4821 if (uuid_parse(name
+ 2, grp_uuid
))
4822 uuid_clear(grp_uuid
);
4824 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
4827 * Invalid ACL entries are ignored for matching; just record a
4828 * warning in the log...
4831 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4832 "check_quotas: UUID lookup failed for ACL entry "
4833 "\"%s\" (err=%d)", name
, mbr_err
);
4834 cupsdLogMessage(CUPSD_LOG_WARN
,
4835 "Access control entry \"%s\" not a valid group name; "
4836 "entry ignored", name
);
4839 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4843 * At this point, there should be no errors, but check anyways...
4846 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4847 "check_quotas: group \"%s\" membership check "
4848 "failed (err=%d)", name
+ 1, mbr_err
);
4853 * Stop if we found a match...
4860 if (cupsdCheckGroup(username
, pw
, name
+ 1))
4862 #endif /* HAVE_MBR_UID_TO_UUID */
4864 #ifdef HAVE_MBR_UID_TO_UUID
4869 if (uuid_parse(name
+ 1, usr2_uuid
))
4870 uuid_clear(usr2_uuid
);
4872 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
4875 * Invalid ACL entries are ignored for matching; just record a
4876 * warning in the log...
4879 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4880 "check_quotas: UUID lookup failed for ACL entry "
4881 "\"%s\" (err=%d)", name
, mbr_err
);
4882 cupsdLogMessage(CUPSD_LOG_WARN
,
4883 "Access control entry \"%s\" not a valid user name; "
4884 "entry ignored", name
);
4887 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4891 else if (!strcasecmp(username
, name
))
4893 #endif /* HAVE_MBR_UID_TO_UUID */
4895 if ((name
!= NULL
) == p
->deny_users
)
4897 cupsdLogMessage(CUPSD_LOG_INFO
,
4898 "Denying user \"%s\" access to printer \"%s\"...",
4908 if (p
->k_limit
|| p
->page_limit
)
4910 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4912 cupsdLogMessage(CUPSD_LOG_ERROR
,
4913 "Unable to allocate quota data for user \"%s\"",
4918 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4919 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4921 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4928 * If we have gotten this far, we're done!
4936 * 'close_job()' - Close a multi-file job.
4940 close_job(cupsd_client_t
*con
, /* I - Client connection */
4941 ipp_attribute_t
*uri
) /* I - Printer URI */
4943 cupsd_job_t
*job
; /* Job */
4944 ipp_attribute_t
*attr
; /* Attribute */
4945 char job_uri
[HTTP_MAX_URI
],
4947 username
[256]; /* User name */
4950 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4951 con
->http
.fd
, uri
->values
[0].string
.text
);
4954 * See if we have a job URI or a printer URI...
4957 if (strcmp(uri
->name
, "printer-uri"))
4960 * job-uri is not supported by Close-Job!
4963 send_ipp_status(con
, IPP_BAD_REQUEST
,
4964 _("Close-Job doesn't support the job-uri attribute."));
4969 * Got a printer URI; see if we also have a job-id attribute...
4972 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4973 IPP_TAG_INTEGER
)) == NULL
)
4975 send_ipp_status(con
, IPP_BAD_REQUEST
,
4976 _("Got a printer-uri attribute but no job-id"));
4980 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4983 * Nope - return a "not found" error...
4986 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
4987 attr
->values
[0].integer
);
4992 * See if the job is owned by the requesting user...
4995 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4997 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4998 cupsdFindDest(job
->dest
));
5003 * Add any ending sheet...
5006 if (cupsdTimeoutJob(job
))
5009 if (job
->state_value
== IPP_JOB_STOPPED
)
5011 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5012 job
->state_value
= IPP_JOB_PENDING
;
5014 else if (job
->state_value
== IPP_JOB_HELD
)
5016 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
5017 IPP_TAG_KEYWORD
)) == NULL
)
5018 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
5020 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
5022 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5023 job
->state_value
= IPP_JOB_PENDING
;
5028 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
5031 * Fill in the response info...
5034 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
5035 LocalPort
, job
->id
);
5036 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
5039 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
5041 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
5044 add_job_state_reasons(con
, job
);
5046 con
->response
->request
.status
.status_code
= IPP_OK
;
5049 * Start the job if necessary...
5057 * 'copy_attribute()' - Copy a single attribute.
5060 static ipp_attribute_t
* /* O - New attribute */
5062 ipp_t
*to
, /* O - Destination request/response */
5063 ipp_attribute_t
*attr
, /* I - Attribute to copy */
5064 int quickcopy
) /* I - Do a quick copy? */
5066 int i
; /* Looping var */
5067 ipp_attribute_t
*toattr
; /* Destination attribute */
5070 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5071 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
5072 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
5075 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
5078 toattr
= ippAddSeparator(to
);
5081 case IPP_TAG_INTEGER
:
5083 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5084 attr
->name
, attr
->num_values
, NULL
);
5086 for (i
= 0; i
< attr
->num_values
; i
++)
5087 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
5090 case IPP_TAG_BOOLEAN
:
5091 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
5092 attr
->num_values
, NULL
);
5094 for (i
= 0; i
< attr
->num_values
; i
++)
5095 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
5098 case IPP_TAG_STRING
:
5101 case IPP_TAG_KEYWORD
:
5103 case IPP_TAG_URISCHEME
:
5104 case IPP_TAG_CHARSET
:
5105 case IPP_TAG_LANGUAGE
:
5106 case IPP_TAG_MIMETYPE
:
5107 toattr
= ippAddStrings(to
, attr
->group_tag
,
5108 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5109 attr
->name
, attr
->num_values
, NULL
, NULL
);
5113 for (i
= 0; i
< attr
->num_values
; i
++)
5114 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5116 else if (attr
->value_tag
& IPP_TAG_COPY
)
5118 for (i
= 0; i
< attr
->num_values
; i
++)
5119 toattr
->values
[i
].string
.text
=
5120 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5124 for (i
= 0; i
< attr
->num_values
; i
++)
5125 toattr
->values
[i
].string
.text
=
5126 _cupsStrRetain(attr
->values
[i
].string
.text
);
5131 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
5132 attr
->values
[0].date
);
5135 case IPP_TAG_RESOLUTION
:
5136 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
5137 attr
->num_values
, IPP_RES_PER_INCH
,
5140 for (i
= 0; i
< attr
->num_values
; i
++)
5142 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
5143 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
5144 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
5148 case IPP_TAG_RANGE
:
5149 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
5150 attr
->num_values
, NULL
, NULL
);
5152 for (i
= 0; i
< attr
->num_values
; i
++)
5154 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
5155 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
5159 case IPP_TAG_TEXTLANG
:
5160 case IPP_TAG_NAMELANG
:
5161 toattr
= ippAddStrings(to
, attr
->group_tag
,
5162 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5163 attr
->name
, attr
->num_values
, NULL
, NULL
);
5167 for (i
= 0; i
< attr
->num_values
; i
++)
5169 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
5170 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5173 else if (attr
->value_tag
& IPP_TAG_COPY
)
5175 for (i
= 0; i
< attr
->num_values
; i
++)
5178 toattr
->values
[i
].string
.charset
=
5179 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
5181 toattr
->values
[i
].string
.charset
=
5182 toattr
->values
[0].string
.charset
;
5184 toattr
->values
[i
].string
.text
=
5185 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5190 for (i
= 0; i
< attr
->num_values
; i
++)
5193 toattr
->values
[i
].string
.charset
=
5194 _cupsStrRetain(attr
->values
[i
].string
.charset
);
5196 toattr
->values
[i
].string
.charset
=
5197 toattr
->values
[0].string
.charset
;
5199 toattr
->values
[i
].string
.text
=
5200 _cupsStrRetain(attr
->values
[i
].string
.text
);
5205 case IPP_TAG_BEGIN_COLLECTION
:
5206 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
5207 attr
->num_values
, NULL
);
5209 for (i
= 0; i
< attr
->num_values
; i
++)
5211 toattr
->values
[i
].collection
= attr
->values
[i
].collection
;
5212 attr
->values
[i
].collection
->use
++;
5217 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5218 attr
->name
, attr
->num_values
, NULL
);
5220 for (i
= 0; i
< attr
->num_values
; i
++)
5222 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
5224 if (toattr
->values
[i
].unknown
.length
> 0)
5226 if ((toattr
->values
[i
].unknown
.data
=
5227 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
5228 toattr
->values
[i
].unknown
.length
= 0;
5230 memcpy(toattr
->values
[i
].unknown
.data
,
5231 attr
->values
[i
].unknown
.data
,
5232 toattr
->values
[i
].unknown
.length
);
5235 break; /* anti-compiler-warning-code */
5243 * 'copy_attrs()' - Copy attributes from one request to another.
5247 copy_attrs(ipp_t
*to
, /* I - Destination request */
5248 ipp_t
*from
, /* I - Source request */
5249 cups_array_t
*ra
, /* I - Requested attributes */
5250 ipp_tag_t group
, /* I - Group to copy */
5251 int quickcopy
, /* I - Do a quick copy? */
5252 cups_array_t
*exclude
) /* I - Attributes to exclude? */
5254 ipp_attribute_t
*fromattr
; /* Source attribute */
5257 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5258 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
5259 to
, from
, ra
, group
, quickcopy
);
5264 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
5267 * Filter attributes as needed...
5270 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
5271 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
5275 (cupsArrayFind(exclude
, fromattr
->name
) ||
5276 cupsArrayFind(exclude
, "all")))
5279 * We need to exclude this attribute for security reasons; we require the
5280 * job-id and job-printer-uri attributes regardless of the security
5281 * settings for IPP conformance.
5283 * Subscription attribute security is handled by copy_subscription_attrs().
5286 if (strcmp(fromattr
->name
, "job-id") &&
5287 strcmp(fromattr
->name
, "job-printer-uri"))
5291 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
5294 * Don't send collection attributes by default to IPP/1.x clients
5295 * since many do not support collections. Also don't send
5296 * media-col-database unless specifically requested by the client.
5299 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
5301 (to
->request
.status
.version
[0] == 1 ||
5302 !strcmp(fromattr
->name
, "media-col-database")))
5305 copy_attribute(to
, fromattr
, quickcopy
);
5312 * 'copy_banner()' - Copy a banner file to the requests directory for the
5316 static int /* O - Size of banner file in kbytes */
5317 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
5318 cupsd_job_t
*job
, /* I - Job information */
5319 const char *name
) /* I - Name of banner */
5321 int i
; /* Looping var */
5322 int kbytes
; /* Size of banner file in kbytes */
5323 char filename
[1024]; /* Job filename */
5324 cupsd_banner_t
*banner
; /* Pointer to banner */
5325 cups_file_t
*in
; /* Input file */
5326 cups_file_t
*out
; /* Output file */
5327 int ch
; /* Character from file */
5328 char attrname
[255], /* Name of attribute */
5329 *s
; /* Pointer into name */
5330 ipp_attribute_t
*attr
; /* Attribute */
5333 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5334 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
5335 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
5336 name
? name
: "(null)");
5339 * Find the banner; return if not found or "none"...
5342 if (!name
|| !strcmp(name
, "none") ||
5343 (banner
= cupsdFindBanner(name
)) == NULL
)
5347 * Open the banner and job files...
5350 if (add_file(con
, job
, banner
->filetype
, 0))
5353 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
5355 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
5357 cupsdLogMessage(CUPSD_LOG_ERROR
,
5358 "Unable to create banner job file %s - %s",
5359 filename
, strerror(errno
));
5364 fchmod(cupsFileNumber(out
), 0640);
5365 fchown(cupsFileNumber(out
), RunUser
, Group
);
5368 * Try the localized banner file under the subdirectory...
5371 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5373 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5376 * Convert ll-cc to ll_CC...
5380 attrname
[3] = toupper(attrname
[3] & 255);
5381 attrname
[4] = toupper(attrname
[4] & 255);
5384 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5387 if (access(filename
, 0) && strlen(attrname
) > 2)
5390 * Wasn't able to find "ll_CC" locale file; try the non-national
5391 * localization banner directory.
5396 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5400 if (access(filename
, 0))
5403 * Use the non-localized banner file.
5406 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5409 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5413 cupsdLogMessage(CUPSD_LOG_ERROR
,
5414 "Unable to open banner template file %s - %s",
5415 filename
, strerror(errno
));
5421 * Parse the file to the end...
5424 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5428 * Get an attribute name...
5431 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5432 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5434 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5444 * Ignore { followed by stuff that is not an attribute name...
5447 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5452 * See if it is defined...
5455 if (attrname
[0] == '?')
5460 if (!strcmp(s
, "printer-name"))
5462 cupsFilePuts(out
, job
->dest
);
5465 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5468 * See if we have a leading question mark...
5471 if (attrname
[0] != '?')
5474 * Nope, write to file as-is; probably a PostScript procedure...
5477 cupsFilePrintf(out
, "{%s}", attrname
);
5484 * Output value(s)...
5487 for (i
= 0; i
< attr
->num_values
; i
++)
5490 cupsFilePutChar(out
, ',');
5492 switch (attr
->value_tag
)
5494 case IPP_TAG_INTEGER
:
5496 if (!strncmp(s
, "time-at-", 8))
5498 struct timeval tv
; /* Time value */
5500 tv
.tv_sec
= attr
->values
[i
].integer
;
5503 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5506 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5509 case IPP_TAG_BOOLEAN
:
5510 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5513 case IPP_TAG_NOVALUE
:
5514 cupsFilePuts(out
, "novalue");
5517 case IPP_TAG_RANGE
:
5518 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5519 attr
->values
[i
].range
.upper
);
5522 case IPP_TAG_RESOLUTION
:
5523 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5524 attr
->values
[i
].resolution
.yres
,
5525 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5530 case IPP_TAG_STRING
:
5533 case IPP_TAG_KEYWORD
:
5534 case IPP_TAG_CHARSET
:
5535 case IPP_TAG_LANGUAGE
:
5536 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
5539 * Need to quote strings for PS banners...
5544 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5546 if (*p
== '(' || *p
== ')' || *p
== '\\')
5548 cupsFilePutChar(out
, '\\');
5549 cupsFilePutChar(out
, *p
);
5551 else if (*p
< 32 || *p
> 126)
5552 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5554 cupsFilePutChar(out
, *p
);
5558 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5562 break; /* anti-compiler-warning-code */
5566 else if (ch
== '\\') /* Quoted char */
5568 ch
= cupsFileGetChar(in
);
5570 if (ch
!= '{') /* Only do special handling for \{ */
5571 cupsFilePutChar(out
, '\\');
5573 cupsFilePutChar(out
, ch
);
5576 cupsFilePutChar(out
, ch
);
5580 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5582 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5583 IPP_TAG_INTEGER
)) != NULL
)
5584 attr
->values
[0].integer
+= kbytes
;
5593 * 'copy_file()' - Copy a PPD file or interface script...
5596 static int /* O - 0 = success, -1 = error */
5597 copy_file(const char *from
, /* I - Source file */
5598 const char *to
) /* I - Destination file */
5600 cups_file_t
*src
, /* Source file */
5601 *dst
; /* Destination file */
5602 int bytes
; /* Bytes to read/write */
5603 char buffer
[2048]; /* Copy buffer */
5606 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5609 * Open the source and destination file for a copy...
5612 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5615 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5622 * Copy the source file to the destination...
5625 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5626 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5634 * Close both files and return...
5639 return (cupsFileClose(dst
));
5644 * 'copy_model()' - Copy a PPD model file, substituting default values
5648 static int /* O - 0 = success, -1 = error */
5649 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5650 const char *from
, /* I - Source file */
5651 const char *to
) /* I - Destination file */
5653 fd_set input
; /* select() input set */
5654 struct timeval timeout
; /* select() timeout */
5655 int maxfd
; /* Max file descriptor for select() */
5656 char tempfile
[1024]; /* Temporary PPD file */
5657 int tempfd
; /* Temporary PPD file descriptor */
5658 int temppid
; /* Process ID of cups-driverd */
5659 int temppipe
[2]; /* Temporary pipes */
5660 char *argv
[4], /* Command-line arguments */
5661 *envp
[MAX_ENV
]; /* Environment */
5662 cups_file_t
*src
, /* Source file */
5663 *dst
; /* Destination file */
5664 ppd_file_t
*ppd
; /* PPD file */
5665 int bytes
, /* Bytes from pipe */
5666 total
; /* Total bytes from pipe */
5667 char buffer
[2048]; /* Copy buffer */
5668 int i
; /* Looping var */
5669 char option
[PPD_MAX_NAME
], /* Option name */
5670 choice
[PPD_MAX_NAME
]; /* Choice name */
5671 ppd_size_t
*size
; /* Default size */
5672 int num_defaults
; /* Number of default options */
5673 cups_option_t
*defaults
; /* Default options */
5674 char cups_protocol
[PPD_MAX_LINE
];
5675 /* cupsProtocol attribute */
5678 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5679 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5683 * Run cups-driverd to get the PPD file...
5686 argv
[0] = "cups-driverd";
5688 argv
[2] = (char *)from
;
5691 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5693 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5694 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5695 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5699 cupsdOpenPipe(temppipe
);
5701 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5702 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5704 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5705 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5716 * Wait up to 30 seconds for the PPD file to be copied...
5721 if (temppipe
[0] > CGIPipes
[0])
5722 maxfd
= temppipe
[0] + 1;
5724 maxfd
= CGIPipes
[0] + 1;
5729 * See if we have data ready...
5733 FD_SET(temppipe
[0], &input
);
5734 FD_SET(CGIPipes
[0], &input
);
5736 timeout
.tv_sec
= 30;
5737 timeout
.tv_usec
= 0;
5739 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5749 * We have timed out...
5755 if (FD_ISSET(temppipe
[0], &input
))
5758 * Read the PPD file from the pipe, and write it to the PPD file.
5761 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5763 if (write(tempfd
, buffer
, bytes
) < bytes
)
5772 if (FD_ISSET(CGIPipes
[0], &input
))
5782 * No data from cups-deviced...
5785 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5791 * Read the source file and see what page sizes are supported...
5794 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5801 * Open the destination (if possible) and set the default options...
5806 cups_protocol
[0] = '\0';
5808 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5811 * Read all of the default lines from the old PPD...
5814 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5815 if (!strncmp(buffer
, "*Default", 8))
5818 * Add the default option...
5821 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5822 choice
, sizeof(choice
)))
5824 ppd_option_t
*ppdo
; /* PPD option */
5828 * Only add the default if the default hasn't already been
5829 * set and the choice exists in the new PPD...
5832 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5833 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5834 ppdFindChoice(ppdo
, choice
))
5835 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5839 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5840 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5844 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5847 * Add the default media sizes...
5850 num_defaults
= cupsAddOption("PageSize", size
->name
,
5851 num_defaults
, &defaults
);
5852 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5853 num_defaults
, &defaults
);
5854 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5855 num_defaults
, &defaults
);
5856 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5857 num_defaults
, &defaults
);
5863 * Open the source file for a copy...
5866 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5868 cupsFreeOptions(num_defaults
, defaults
);
5874 * Open the destination file for a copy...
5877 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5879 cupsFreeOptions(num_defaults
, defaults
);
5886 * Copy the source file to the destination...
5889 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5891 if (!strncmp(buffer
, "*Default", 8))
5894 * Check for an previous default option choice...
5897 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5898 choice
, sizeof(choice
)))
5900 const char *val
; /* Default option value */
5903 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5906 * Substitute the previous choice...
5909 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5914 cupsFilePrintf(dst
, "%s\n", buffer
);
5917 if (cups_protocol
[0])
5918 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5920 cupsFreeOptions(num_defaults
, defaults
);
5923 * Close both files and return...
5930 return (cupsFileClose(dst
));
5935 * 'copy_job_attrs()' - Copy job attributes.
5939 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5940 cupsd_job_t
*job
, /* I - Job */
5941 cups_array_t
*ra
, /* I - Requested attributes array */
5942 cups_array_t
*exclude
) /* I - Private attributes array */
5944 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5948 * Send the requested attributes for each job...
5951 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5952 con
->servername
, con
->serverport
, "/jobs/%d",
5955 if (!cupsArrayFind(exclude
, "all"))
5957 if ((!exclude
|| !cupsArrayFind(exclude
, "document-count")) &&
5958 (!ra
|| cupsArrayFind(ra
, "document-count")))
5959 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5960 "document-count", job
->num_files
);
5962 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
5963 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
5964 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5965 "job-media-progress", job
->progress
);
5967 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
5968 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
5969 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5970 "job-more-info", NULL
, job_uri
);
5972 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5973 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
5974 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5975 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5976 job
->num_files
> 0);
5978 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
5979 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
5980 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5981 "job-printer-up-time", time(NULL
));
5984 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5985 add_job_state_reasons(con
, job
);
5987 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5988 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5989 "job-uri", NULL
, job_uri
);
5991 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
5996 * 'copy_printer_attrs()' - Copy printer attributes.
6001 cupsd_client_t
*con
, /* I - Client connection */
6002 cupsd_printer_t
*printer
, /* I - Printer */
6003 cups_array_t
*ra
) /* I - Requested attributes array */
6005 char printer_uri
[HTTP_MAX_URI
];
6007 char printer_icons
[HTTP_MAX_URI
];
6009 time_t curtime
; /* Current time */
6010 int i
; /* Looping var */
6011 ipp_attribute_t
*history
; /* History collection */
6015 * Copy the printer attributes to the response using requested-attributes
6016 * and document-format attributes that may be provided by the client.
6019 curtime
= time(NULL
);
6021 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
6022 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6023 "marker-change-time", printer
->marker_time
);
6025 if (printer
->num_printers
> 0 &&
6026 (!ra
|| cupsArrayFind(ra
, "member-uris")))
6028 ipp_attribute_t
*member_uris
; /* member-uris attribute */
6029 cupsd_printer_t
*p2
; /* Printer in class */
6030 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
6033 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
6034 IPP_TAG_URI
, "member-uris",
6035 printer
->num_printers
, NULL
,
6038 for (i
= 0; i
< printer
->num_printers
; i
++)
6040 p2
= printer
->printers
[i
];
6042 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
6043 IPP_TAG_URI
)) != NULL
)
6044 member_uris
->values
[i
].string
.text
=
6045 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
6048 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
6049 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
6051 (p2
->type
& CUPS_PRINTER_CLASS
) ?
6052 "/classes/%s" : "/printers/%s", p2
->name
);
6053 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
6059 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
6060 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
6061 "printer-alert", NULL
, printer
->alert
);
6063 if (printer
->alert_description
&&
6064 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
6065 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
6066 "printer-alert-description", NULL
,
6067 printer
->alert_description
);
6069 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
6070 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
6071 ippTimeToDate(curtime
));
6074 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
6076 if (printer
->reg_name
)
6077 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6078 "printer-dns-sd-name", NULL
, printer
->reg_name
);
6080 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
6081 "printer-dns-sd-name", 0);
6083 #endif /* HAVE_DNSSD */
6085 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
6086 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6087 "printer-error-policy", NULL
, printer
->error_policy
);
6089 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
6091 static const char * const errors
[] =/* printer-error-policy-supported values */
6094 "retry-current-job",
6099 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
6100 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6101 "printer-error-policy-supported", NULL
, "retry-current-job");
6103 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6104 "printer-error-policy-supported",
6105 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
6108 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
6110 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
6111 "http", NULL
, con
->servername
, con
->serverport
,
6112 "/icons/%s.png", printer
->name
);
6113 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
6114 NULL
, printer_icons
);
6115 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
6118 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
6119 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
6120 printer
->accepting
);
6122 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
6123 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
6126 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
6127 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6129 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6130 "http", NULL
, con
->servername
, con
->serverport
,
6131 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6132 "/classes/%s" : "/printers/%s", printer
->name
);
6133 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6134 "printer-more-info", NULL
, printer_uri
);
6137 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
6138 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6139 "printer-op-policy", NULL
, printer
->op_policy
);
6141 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
6142 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
6145 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
6146 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6147 "printer-state-change-time", printer
->state_time
);
6149 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
6150 cupsArrayFind(ra
, "printer-state-history"))
6153 * Printer history is only sent if specifically requested, so that
6154 * older CUPS/IPP clients won't barf on the collection attributes.
6157 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
6158 "printer-state-history",
6159 printer
->num_history
, NULL
);
6161 for (i
= 0; i
< printer
->num_history
; i
++)
6162 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
6163 NULL
, IPP_TAG_ZERO
, 0, NULL
);
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 */
6179 * Add the CUPS-specific printer-type attribute...
6182 type
= printer
->type
;
6184 if (printer
== DefaultPrinter
)
6185 type
|= CUPS_PRINTER_DEFAULT
;
6187 if (!printer
->accepting
)
6188 type
|= CUPS_PRINTER_REJECTING
;
6190 if (!printer
->shared
)
6191 type
|= CUPS_PRINTER_NOT_SHARED
;
6193 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
6197 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
6198 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6199 "printer-up-time", curtime
);
6201 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
6202 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6204 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6205 "ipp", NULL
, con
->servername
, con
->serverport
,
6206 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6207 "/classes/%s" : "/printers/%s", printer
->name
);
6208 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6209 "printer-uri-supported", NULL
, printer_uri
);
6210 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
6214 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
6215 add_queued_job_count(con
, printer
);
6217 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6218 if (printer
->ppd_attrs
)
6219 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6220 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
6225 * 'copy_subscription_attrs()' - Copy subscription attributes.
6229 copy_subscription_attrs(
6230 cupsd_client_t
*con
, /* I - Client connection */
6231 cupsd_subscription_t
*sub
, /* I - Subscription */
6232 cups_array_t
*ra
, /* I - Requested attributes array */
6233 cups_array_t
*exclude
) /* I - Private attributes array */
6235 ipp_attribute_t
*attr
; /* Current attribute */
6236 char printer_uri
[HTTP_MAX_URI
];
6238 int count
; /* Number of events */
6239 unsigned mask
; /* Current event mask */
6240 const char *name
; /* Current event name */
6243 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6244 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
6245 con
, sub
, ra
, exclude
);
6248 * Copy the subscription attributes to the response using the
6249 * requested-attributes attribute that may be provided by the client.
6252 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
6254 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
6255 (!ra
|| cupsArrayFind(ra
, "notify-events")))
6257 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
6259 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
6262 * Simple event list...
6265 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
6266 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6267 "notify-events", NULL
, name
);
6272 * Complex event list...
6275 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6276 if (sub
->mask
& mask
)
6279 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
6280 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6281 "notify-events", count
, NULL
, NULL
);
6283 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6284 if (sub
->mask
& mask
)
6286 attr
->values
[count
].string
.text
=
6287 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
6294 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
6295 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
6296 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6297 "notify-lease-duration", sub
->lease
);
6299 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
6300 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
6301 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6302 "notify-recipient-uri", NULL
, sub
->recipient
);
6303 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
6304 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
6305 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
6306 "notify-pull-method", NULL
, "ippget");
6308 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
6309 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
6310 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
6311 "notify-subscriber-user-name", NULL
, sub
->owner
);
6313 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
6314 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
6315 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6316 "notify-time-interval", sub
->interval
);
6318 if (sub
->user_data_len
> 0 &&
6319 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
6320 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
6321 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
6322 sub
->user_data
, sub
->user_data_len
);
6325 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
6326 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6327 "notify-job-id", sub
->job
->id
);
6329 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
6331 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6332 "ipp", NULL
, con
->servername
, con
->serverport
,
6333 "/printers/%s", sub
->dest
->name
);
6334 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6335 "notify-printer-uri", NULL
, printer_uri
);
6338 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
6339 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6340 "notify-subscription-id", sub
->id
);
6345 * 'create_job()' - Print a file to a printer or class.
6349 create_job(cupsd_client_t
*con
, /* I - Client connection */
6350 ipp_attribute_t
*uri
) /* I - Printer URI */
6352 cupsd_printer_t
*printer
; /* Printer */
6353 cupsd_job_t
*job
; /* New job */
6356 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
6357 con
->http
.fd
, uri
->values
[0].string
.text
);
6360 * Is the destination valid?
6363 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6369 send_ipp_status(con
, IPP_NOT_FOUND
,
6370 _("The printer or class was not found."));
6375 * Create the job object...
6378 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6381 job
->pending_timeout
= 1;
6384 * Save and log the job...
6387 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6388 job
->dest
, job
->username
);
6393 * 'create_requested_array()' - Create an array for the requested-attributes.
6396 static cups_array_t
* /* O - Array of attributes or NULL */
6397 create_requested_array(ipp_t
*request
) /* I - IPP request */
6399 int i
; /* Looping var */
6400 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6401 cups_array_t
*ra
; /* Requested attributes array */
6402 char *value
; /* Current value */
6406 * Get the requested-attributes attribute, and return NULL if we don't
6410 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6411 IPP_TAG_KEYWORD
)) == NULL
)
6415 * If the attribute contains a single "all" keyword, return NULL...
6418 if (requested
->num_values
== 1 &&
6419 !strcmp(requested
->values
[0].string
.text
, "all"))
6423 * Create an array using "strcmp" as the comparison function...
6426 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6428 for (i
= 0; i
< requested
->num_values
; i
++)
6430 value
= requested
->values
[i
].string
.text
;
6432 if (!strcmp(value
, "job-template"))
6434 cupsArrayAdd(ra
, "copies");
6435 cupsArrayAdd(ra
, "copies-default");
6436 cupsArrayAdd(ra
, "copies-supported");
6437 cupsArrayAdd(ra
, "finishings");
6438 cupsArrayAdd(ra
, "finishings-default");
6439 cupsArrayAdd(ra
, "finishings-supported");
6440 cupsArrayAdd(ra
, "job-hold-until");
6441 cupsArrayAdd(ra
, "job-hold-until-default");
6442 cupsArrayAdd(ra
, "job-hold-until-supported");
6443 cupsArrayAdd(ra
, "job-priority");
6444 cupsArrayAdd(ra
, "job-priority-default");
6445 cupsArrayAdd(ra
, "job-priority-supported");
6446 cupsArrayAdd(ra
, "job-sheets");
6447 cupsArrayAdd(ra
, "job-sheets-default");
6448 cupsArrayAdd(ra
, "job-sheets-supported");
6449 cupsArrayAdd(ra
, "media");
6450 cupsArrayAdd(ra
, "media-default");
6451 cupsArrayAdd(ra
, "media-supported");
6452 cupsArrayAdd(ra
, "multiple-document-handling");
6453 cupsArrayAdd(ra
, "multiple-document-handling-default");
6454 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6455 cupsArrayAdd(ra
, "number-up");
6456 cupsArrayAdd(ra
, "number-up-default");
6457 cupsArrayAdd(ra
, "number-up-supported");
6458 cupsArrayAdd(ra
, "orientation-requested");
6459 cupsArrayAdd(ra
, "orientation-requested-default");
6460 cupsArrayAdd(ra
, "orientation-requested-supported");
6461 cupsArrayAdd(ra
, "page-ranges");
6462 cupsArrayAdd(ra
, "page-ranges-supported");
6463 cupsArrayAdd(ra
, "printer-resolution");
6464 cupsArrayAdd(ra
, "printer-resolution-default");
6465 cupsArrayAdd(ra
, "printer-resolution-supported");
6466 cupsArrayAdd(ra
, "print-quality");
6467 cupsArrayAdd(ra
, "print-quality-default");
6468 cupsArrayAdd(ra
, "print-quality-supported");
6469 cupsArrayAdd(ra
, "sides");
6470 cupsArrayAdd(ra
, "sides-default");
6471 cupsArrayAdd(ra
, "sides-supported");
6473 else if (!strcmp(value
, "job-description"))
6475 cupsArrayAdd(ra
, "date-time-at-completed");
6476 cupsArrayAdd(ra
, "date-time-at-creation");
6477 cupsArrayAdd(ra
, "date-time-at-processing");
6478 cupsArrayAdd(ra
, "job-detailed-status-message");
6479 cupsArrayAdd(ra
, "job-document-access-errors");
6480 cupsArrayAdd(ra
, "job-id");
6481 cupsArrayAdd(ra
, "job-impressions");
6482 cupsArrayAdd(ra
, "job-impressions-completed");
6483 cupsArrayAdd(ra
, "job-k-octets");
6484 cupsArrayAdd(ra
, "job-k-octets-processed");
6485 cupsArrayAdd(ra
, "job-media-progress");
6486 cupsArrayAdd(ra
, "job-media-sheets");
6487 cupsArrayAdd(ra
, "job-media-sheets-completed");
6488 cupsArrayAdd(ra
, "job-message-from-operator");
6489 cupsArrayAdd(ra
, "job-more-info");
6490 cupsArrayAdd(ra
, "job-name");
6491 cupsArrayAdd(ra
, "job-originating-user-name");
6492 cupsArrayAdd(ra
, "job-printer-up-time");
6493 cupsArrayAdd(ra
, "job-printer-uri");
6494 cupsArrayAdd(ra
, "job-state");
6495 cupsArrayAdd(ra
, "job-state-message");
6496 cupsArrayAdd(ra
, "job-state-reasons");
6497 cupsArrayAdd(ra
, "job-uri");
6498 cupsArrayAdd(ra
, "number-of-documents");
6499 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6500 cupsArrayAdd(ra
, "output-device-assigned");
6501 cupsArrayAdd(ra
, "time-at-completed");
6502 cupsArrayAdd(ra
, "time-at-creation");
6503 cupsArrayAdd(ra
, "time-at-processing");
6505 else if (!strcmp(value
, "printer-description"))
6507 cupsArrayAdd(ra
, "charset-configured");
6508 cupsArrayAdd(ra
, "charset-supported");
6509 cupsArrayAdd(ra
, "color-supported");
6510 cupsArrayAdd(ra
, "compression-supported");
6511 cupsArrayAdd(ra
, "document-format-default");
6512 cupsArrayAdd(ra
, "document-format-supported");
6513 cupsArrayAdd(ra
, "generated-natural-language-supported");
6514 cupsArrayAdd(ra
, "ipp-versions-supported");
6515 cupsArrayAdd(ra
, "job-impressions-supported");
6516 cupsArrayAdd(ra
, "job-k-octets-supported");
6517 cupsArrayAdd(ra
, "job-media-sheets-supported");
6518 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6519 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6520 cupsArrayAdd(ra
, "multiple-operation-time-out");
6521 cupsArrayAdd(ra
, "natural-language-configured");
6522 cupsArrayAdd(ra
, "notify-attributes-supported");
6523 cupsArrayAdd(ra
, "notify-lease-duration-default");
6524 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6525 cupsArrayAdd(ra
, "notify-max-events-supported");
6526 cupsArrayAdd(ra
, "notify-events-default");
6527 cupsArrayAdd(ra
, "notify-events-supported");
6528 cupsArrayAdd(ra
, "notify-pull-method-supported");
6529 cupsArrayAdd(ra
, "notify-schemes-supported");
6530 cupsArrayAdd(ra
, "operations-supported");
6531 cupsArrayAdd(ra
, "pages-per-minute");
6532 cupsArrayAdd(ra
, "pages-per-minute-color");
6533 cupsArrayAdd(ra
, "pdl-override-supported");
6534 cupsArrayAdd(ra
, "printer-alert");
6535 cupsArrayAdd(ra
, "printer-alert-description");
6536 cupsArrayAdd(ra
, "printer-commands");
6537 cupsArrayAdd(ra
, "printer-current-time");
6538 cupsArrayAdd(ra
, "printer-driver-installer");
6539 cupsArrayAdd(ra
, "printer-dns-sd-name");
6540 cupsArrayAdd(ra
, "printer-info");
6541 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6542 cupsArrayAdd(ra
, "printer-location");
6543 cupsArrayAdd(ra
, "printer-make-and-model");
6544 cupsArrayAdd(ra
, "printer-message-from-operator");
6545 cupsArrayAdd(ra
, "printer-more-info");
6546 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6547 cupsArrayAdd(ra
, "printer-name");
6548 cupsArrayAdd(ra
, "printer-state");
6549 cupsArrayAdd(ra
, "printer-state-message");
6550 cupsArrayAdd(ra
, "printer-state-reasons");
6551 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6552 cupsArrayAdd(ra
, "printer-type");
6553 cupsArrayAdd(ra
, "printer-up-time");
6554 cupsArrayAdd(ra
, "printer-uri-supported");
6555 cupsArrayAdd(ra
, "queued-job-count");
6556 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6557 cupsArrayAdd(ra
, "uri-authentication-supported");
6558 cupsArrayAdd(ra
, "uri-security-supported");
6560 else if (!strcmp(value
, "printer-defaults"))
6562 char *name
; /* Option name */
6565 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6567 name
= (char *)cupsArrayNext(CommonDefaults
))
6568 cupsArrayAdd(ra
, name
);
6570 else if (!strcmp(value
, "subscription-template"))
6572 cupsArrayAdd(ra
, "notify-attributes");
6573 cupsArrayAdd(ra
, "notify-charset");
6574 cupsArrayAdd(ra
, "notify-events");
6575 cupsArrayAdd(ra
, "notify-lease-duration");
6576 cupsArrayAdd(ra
, "notify-natural-language");
6577 cupsArrayAdd(ra
, "notify-pull-method");
6578 cupsArrayAdd(ra
, "notify-recipient-uri");
6579 cupsArrayAdd(ra
, "notify-time-interval");
6580 cupsArrayAdd(ra
, "notify-user-data");
6583 cupsArrayAdd(ra
, value
);
6591 * 'create_subscription()' - Create a notification subscription.
6595 create_subscription(
6596 cupsd_client_t
*con
, /* I - Client connection */
6597 ipp_attribute_t
*uri
) /* I - Printer URI */
6599 http_status_t status
; /* Policy status */
6600 int i
; /* Looping var */
6601 ipp_attribute_t
*attr
; /* Current attribute */
6602 cups_ptype_t dtype
; /* Destination type (printer/class) */
6603 char scheme
[HTTP_MAX_URI
],
6604 /* Scheme portion of URI */
6605 userpass
[HTTP_MAX_URI
],
6606 /* Username portion of URI */
6608 /* Host portion of URI */
6609 resource
[HTTP_MAX_URI
];
6610 /* Resource portion of URI */
6611 int port
; /* Port portion of URI */
6612 cupsd_printer_t
*printer
; /* Printer/class */
6613 cupsd_job_t
*job
; /* Job */
6614 int jobid
; /* Job ID */
6615 cupsd_subscription_t
*sub
; /* Subscription object */
6616 const char *username
, /* requesting-user-name or
6617 authenticated username */
6618 *recipient
, /* notify-recipient-uri */
6619 *pullmethod
; /* notify-pull-method */
6620 ipp_attribute_t
*user_data
; /* notify-user-data */
6621 int interval
, /* notify-time-interval */
6622 lease
; /* notify-lease-duration */
6623 unsigned mask
; /* notify-events */
6624 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6625 *notify_lease
; /* notify-lease-duration(-default) */
6629 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6631 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6632 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6633 attr
->value_tag
, attr
->name
);
6635 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6640 * Is the destination valid?
6643 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6644 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6645 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6647 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6648 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6649 sizeof(host
), &port
, resource
, sizeof(resource
));
6651 if (!strcmp(resource
, "/"))
6653 dtype
= (cups_ptype_t
)0;
6656 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6658 dtype
= (cups_ptype_t
)0;
6661 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6663 dtype
= CUPS_PRINTER_CLASS
;
6666 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6672 send_ipp_status(con
, IPP_NOT_FOUND
,
6673 _("The printer or class was not found."));
6683 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6686 send_http_error(con
, status
, printer
);
6690 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6692 send_http_error(con
, status
, NULL
);
6697 * Get the user that is requesting the subscription...
6700 username
= get_username(con
);
6703 * Find the first subscription group attribute; return if we have
6707 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6708 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6713 send_ipp_status(con
, IPP_BAD_REQUEST
,
6714 _("No subscription attributes in request"));
6719 * Process the subscription attributes in the request...
6722 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6730 lease
= DefaultLeaseDuration
;
6732 mask
= CUPSD_EVENT_NONE
;
6736 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6738 notify_lease
= ippFindAttribute(printer
->attrs
,
6739 "notify-lease-duration-default",
6743 lease
= notify_lease
->values
[0].integer
;
6747 notify_events
= NULL
;
6748 notify_lease
= NULL
;
6751 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6753 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6754 attr
->value_tag
== IPP_TAG_URI
)
6757 * Validate the recipient scheme against the ServerBin/notifier
6761 char notifier
[1024]; /* Notifier filename */
6764 recipient
= attr
->values
[0].string
.text
;
6766 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6767 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6768 host
, sizeof(host
), &port
,
6769 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6771 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6772 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
6773 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6774 "notify-status-code", IPP_URI_SCHEME
);
6778 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6780 if (access(notifier
, X_OK
))
6782 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6783 _("notify-recipient-uri URI \"%s\" uses unknown "
6784 "scheme"), recipient
);
6785 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6786 "notify-status-code", IPP_URI_SCHEME
);
6790 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6792 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6793 _("notify-recipient-uri URI \"%s\" is already used"),
6795 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6796 "notify-status-code", IPP_ATTRIBUTES
);
6800 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6801 attr
->value_tag
== IPP_TAG_KEYWORD
)
6803 pullmethod
= attr
->values
[0].string
.text
;
6805 if (strcmp(pullmethod
, "ippget"))
6807 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6808 _("Bad notify-pull-method \"%s\""), pullmethod
);
6809 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6810 "notify-status-code", IPP_ATTRIBUTES
);
6814 else if (!strcmp(attr
->name
, "notify-charset") &&
6815 attr
->value_tag
== IPP_TAG_CHARSET
&&
6816 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6817 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6819 send_ipp_status(con
, IPP_CHARSET
,
6820 _("Character set \"%s\" not supported"),
6821 attr
->values
[0].string
.text
);
6824 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6825 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6826 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6828 send_ipp_status(con
, IPP_CHARSET
,
6829 _("Language \"%s\" not supported"),
6830 attr
->values
[0].string
.text
);
6833 else if (!strcmp(attr
->name
, "notify-user-data") &&
6834 attr
->value_tag
== IPP_TAG_STRING
)
6836 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6838 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6839 _("The notify-user-data value is too large "
6840 "(%d > 63 octets)"),
6841 attr
->values
[0].unknown
.length
);
6847 else if (!strcmp(attr
->name
, "notify-events") &&
6848 attr
->value_tag
== IPP_TAG_KEYWORD
)
6849 notify_events
= attr
;
6850 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6851 attr
->value_tag
== IPP_TAG_INTEGER
)
6852 lease
= attr
->values
[0].integer
;
6853 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6854 attr
->value_tag
== IPP_TAG_INTEGER
)
6855 interval
= attr
->values
[0].integer
;
6856 else if (!strcmp(attr
->name
, "notify-job-id") &&
6857 attr
->value_tag
== IPP_TAG_INTEGER
)
6858 jobid
= attr
->values
[0].integer
;
6865 for (i
= 0; i
< notify_events
->num_values
; i
++)
6866 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6870 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6872 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6873 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6874 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6876 if (!recipient
&& !pullmethod
)
6879 if (mask
== CUPSD_EVENT_NONE
)
6882 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6884 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6887 send_ipp_status(con
, IPP_BAD_REQUEST
,
6888 _("notify-events not specified"));
6893 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6895 cupsdLogMessage(CUPSD_LOG_INFO
,
6896 "create_subscription: Limiting notify-lease-duration to "
6899 lease
= MaxLeaseDuration
;
6904 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6906 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found"), jobid
);
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 was not found."));
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.ipp4", CacheDir
, printer
->name
);
7032 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
7035 snprintf(filename
, sizeof(filename
), "%s/%s.pwg3", CacheDir
, printer
->name
);
7040 * Unregister color profiles...
7043 apple_unregister_profiles(printer
);
7044 #endif /* __APPLE__ */
7046 if (dtype
& CUPS_PRINTER_CLASS
)
7048 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
7049 printer
->name
, get_username(con
));
7051 cupsdDeletePrinter(printer
, 0);
7052 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7056 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
7057 printer
->name
, get_username(con
));
7059 if (cupsdDeletePrinter(printer
, 0))
7060 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7062 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
7065 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
7068 * Return with no errors...
7071 con
->response
->request
.status
.status_code
= IPP_OK
;
7076 * 'get_default()' - Get the default destination.
7080 get_default(cupsd_client_t
*con
) /* I - Client connection */
7082 http_status_t status
; /* Policy status */
7083 cups_array_t
*ra
; /* Requested attributes array */
7086 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
7092 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7094 send_http_error(con
, status
, NULL
);
7100 ra
= create_requested_array(con
->request
);
7102 copy_printer_attrs(con
, DefaultPrinter
, ra
);
7104 cupsArrayDelete(ra
);
7106 con
->response
->request
.status
.status_code
= IPP_OK
;
7109 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
7114 * 'get_devices()' - Get the list of available devices on the local system.
7118 get_devices(cupsd_client_t
*con
) /* I - Client connection */
7120 http_status_t status
; /* Policy status */
7121 ipp_attribute_t
*limit
, /* limit attribute */
7122 *timeout
, /* timeout attribute */
7123 *requested
, /* requested-attributes attribute */
7124 *exclude
, /* exclude-schemes attribute */
7125 *include
; /* include-schemes attribute */
7126 char command
[1024], /* cups-deviced command */
7127 options
[2048], /* Options to pass to command */
7129 /* String for requested attributes */
7131 /* String for excluded schemes */
7133 /* String for included schemes */
7136 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
7142 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7144 send_http_error(con
, status
, NULL
);
7149 * Run cups-deviced command with the given options...
7152 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7153 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
7154 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7156 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
7157 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
7160 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7162 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7165 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7167 exclude_str
[0] = '\0';
7170 url_encode_attr(include
, include_str
, sizeof(include_str
));
7172 include_str
[0] = '\0';
7174 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
7175 snprintf(options
, sizeof(options
),
7176 "%d+%d+%d+%d+%s%s%s%s%s",
7177 con
->request
->request
.op
.request_id
,
7178 limit
? limit
->values
[0].integer
: 0,
7179 timeout
? timeout
->values
[0].integer
: 15,
7182 exclude_str
[0] ? "%20" : "", exclude_str
,
7183 include_str
[0] ? "%20" : "", include_str
);
7185 if (cupsdSendCommand(con
, command
, options
, 1))
7188 * Command started successfully, don't send an IPP response here...
7191 ippDelete(con
->response
);
7192 con
->response
= NULL
;
7197 * Command failed, return "internal error" so the user knows something
7201 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7202 _("cups-deviced failed to execute."));
7208 * 'get_document()' - Get a copy of a job file.
7212 get_document(cupsd_client_t
*con
, /* I - Client connection */
7213 ipp_attribute_t
*uri
) /* I - Job URI */
7215 http_status_t status
; /* Policy status */
7216 ipp_attribute_t
*attr
; /* Current attribute */
7217 int jobid
; /* Job ID */
7218 int docnum
; /* Document number */
7219 cupsd_job_t
*job
; /* Current job */
7220 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7221 username
[HTTP_MAX_URI
], /* Username portion of URI */
7222 host
[HTTP_MAX_URI
], /* Host portion of URI */
7223 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7224 int port
; /* Port portion of URI */
7225 char filename
[1024], /* Filename for document */
7226 format
[1024]; /* Format for document */
7229 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
7230 con
->http
.fd
, uri
->values
[0].string
.text
);
7233 * See if we have a job URI or a printer URI...
7236 if (!strcmp(uri
->name
, "printer-uri"))
7239 * Got a printer URI; see if we also have a job-id attribute...
7242 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7243 IPP_TAG_INTEGER
)) == NULL
)
7245 send_ipp_status(con
, IPP_BAD_REQUEST
,
7246 _("Got a printer-uri attribute but no job-id"));
7250 jobid
= attr
->values
[0].integer
;
7255 * Got a job URI; parse it to get the job ID...
7258 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7259 sizeof(scheme
), username
, sizeof(username
), host
,
7260 sizeof(host
), &port
, resource
, sizeof(resource
));
7262 if (strncmp(resource
, "/jobs/", 6))
7268 send_ipp_status(con
, IPP_BAD_REQUEST
,
7269 _("Bad job-uri attribute \"%s\""),
7270 uri
->values
[0].string
.text
);
7274 jobid
= atoi(resource
+ 6);
7278 * See if the job exists...
7281 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7284 * Nope - return a "not found" error...
7287 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
7295 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7297 send_http_error(con
, status
, NULL
);
7302 * Get the document number...
7305 if ((attr
= ippFindAttribute(con
->request
, "document-number",
7306 IPP_TAG_INTEGER
)) == NULL
)
7308 send_ipp_status(con
, IPP_BAD_REQUEST
,
7309 _("Missing document-number attribute"));
7313 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
7314 attr
->num_values
> 1)
7316 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
7321 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
7323 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
7325 cupsdLogMessage(CUPSD_LOG_ERROR
,
7326 "Unable to open document %d in job %d - %s", docnum
, jobid
,
7328 send_ipp_status(con
, IPP_NOT_FOUND
,
7329 _("Unable to open document %d in job %d"), docnum
, jobid
);
7333 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7337 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
7338 job
->filetypes
[docnum
- 1]->type
);
7340 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
7342 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
7344 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
7345 IPP_TAG_NAME
)) != NULL
)
7346 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
7347 NULL
, attr
->values
[0].string
.text
);
7352 * 'get_job_attrs()' - Get job attributes.
7356 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
7357 ipp_attribute_t
*uri
) /* I - Job URI */
7359 http_status_t status
; /* Policy status */
7360 ipp_attribute_t
*attr
; /* Current attribute */
7361 int jobid
; /* Job ID */
7362 cupsd_job_t
*job
; /* Current job */
7363 cupsd_printer_t
*printer
; /* Current printer */
7364 cupsd_policy_t
*policy
; /* Current security policy */
7365 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7366 username
[HTTP_MAX_URI
], /* Username portion of URI */
7367 host
[HTTP_MAX_URI
], /* Host portion of URI */
7368 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7369 int port
; /* Port portion of URI */
7370 cups_array_t
*ra
, /* Requested attributes array */
7371 *exclude
; /* Private attributes array */
7374 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7375 con
->http
.fd
, uri
->values
[0].string
.text
);
7378 * See if we have a job URI or a printer URI...
7381 if (!strcmp(uri
->name
, "printer-uri"))
7384 * Got a printer URI; see if we also have a job-id attribute...
7387 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7388 IPP_TAG_INTEGER
)) == NULL
)
7390 send_ipp_status(con
, IPP_BAD_REQUEST
,
7391 _("Got a printer-uri attribute but no job-id"));
7395 jobid
= attr
->values
[0].integer
;
7400 * Got a job URI; parse it to get the job ID...
7403 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7404 sizeof(scheme
), username
, sizeof(username
), host
,
7405 sizeof(host
), &port
, resource
, sizeof(resource
));
7407 if (strncmp(resource
, "/jobs/", 6))
7413 send_ipp_status(con
, IPP_BAD_REQUEST
,
7414 _("Bad job-uri attribute \"%s\""),
7415 uri
->values
[0].string
.text
);
7419 jobid
= atoi(resource
+ 6);
7423 * See if the job exists...
7426 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7429 * Nope - return a "not found" error...
7432 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
7440 if ((printer
= job
->printer
) == NULL
)
7441 printer
= cupsdFindDest(job
->dest
);
7444 policy
= printer
->op_policy_ptr
;
7446 policy
= DefaultPolicyPtr
;
7448 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
7450 send_http_error(con
, status
, NULL
);
7454 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
7457 * Copy attributes...
7462 ra
= create_requested_array(con
->request
);
7463 copy_job_attrs(con
, job
, ra
, exclude
);
7464 cupsArrayDelete(ra
);
7466 con
->response
->request
.status
.status_code
= IPP_OK
;
7471 * 'get_jobs()' - Get a list of jobs for the specified printer.
7475 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7476 ipp_attribute_t
*uri
) /* I - Printer URI */
7478 http_status_t status
; /* Policy status */
7479 ipp_attribute_t
*attr
; /* Current attribute */
7480 const char *dest
; /* Destination */
7481 cups_ptype_t dtype
; /* Destination type (printer/class) */
7482 cups_ptype_t dmask
; /* Destination type mask */
7483 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7484 username
[HTTP_MAX_URI
], /* Username portion of URI */
7485 host
[HTTP_MAX_URI
], /* Host portion of URI */
7486 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7487 int port
; /* Port portion of URI */
7488 int job_comparison
; /* Job comparison */
7489 ipp_jstate_t job_state
; /* job-state value */
7490 int first_job_id
; /* First job ID */
7491 int limit
; /* Maximum number of jobs to return */
7492 int count
; /* Number of jobs that match */
7493 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7494 cupsd_job_t
*job
; /* Current job pointer */
7495 cupsd_printer_t
*printer
; /* Printer */
7496 cups_array_t
*list
; /* Which job list... */
7497 cups_array_t
*ra
, /* Requested attributes array */
7498 *exclude
; /* Private attributes array */
7499 cupsd_policy_t
*policy
; /* Current policy */
7502 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7503 uri
->values
[0].string
.text
);
7506 * Is the destination valid?
7509 if (strcmp(uri
->name
, "printer-uri"))
7511 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request"));
7515 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7516 sizeof(scheme
), username
, sizeof(username
), host
,
7517 sizeof(host
), &port
, resource
, sizeof(resource
));
7519 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7522 dtype
= (cups_ptype_t
)0;
7523 dmask
= (cups_ptype_t
)0;
7526 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7529 dtype
= (cups_ptype_t
)0;
7530 dmask
= CUPS_PRINTER_CLASS
;
7533 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7536 dtype
= CUPS_PRINTER_CLASS
;
7537 dmask
= CUPS_PRINTER_CLASS
;
7540 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7547 send_ipp_status(con
, IPP_NOT_FOUND
,
7548 _("The printer or class was not found."));
7553 dtype
&= CUPS_PRINTER_CLASS
;
7554 dmask
= CUPS_PRINTER_CLASS
;
7562 policy
= printer
->op_policy_ptr
;
7564 policy
= DefaultPolicyPtr
;
7566 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7568 send_http_error(con
, status
, NULL
);
7572 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7575 * See if the "which-jobs" attribute have been specified...
7578 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7579 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7581 send_ipp_status(con
, IPP_CONFLICT
,
7582 _("The %s attribute cannot be provided with job-ids."),
7586 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7588 job_comparison
= -1;
7589 job_state
= IPP_JOB_STOPPED
;
7592 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7595 job_state
= IPP_JOB_CANCELED
;
7598 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7601 job_state
= IPP_JOB_ABORTED
;
7604 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7607 job_state
= IPP_JOB_PENDING
;
7610 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7613 job_state
= IPP_JOB_CANCELED
;
7616 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7619 job_state
= IPP_JOB_PENDING
;
7622 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7625 job_state
= IPP_JOB_HELD
;
7628 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7631 job_state
= IPP_JOB_PROCESSING
;
7632 list
= PrintingJobs
;
7634 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7637 job_state
= IPP_JOB_STOPPED
;
7642 send_ipp_status(con
, IPP_ATTRIBUTES
,
7643 _("The which-jobs value \"%s\" is not supported."),
7644 attr
->values
[0].string
.text
);
7645 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7646 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7651 * See if they want to limit the number of jobs reported...
7654 if ((attr
= ippFindAttribute(con
->request
, "limit",
7655 IPP_TAG_INTEGER
)) != NULL
)
7659 send_ipp_status(con
, IPP_CONFLICT
,
7660 _("The %s attribute cannot be provided with job-ids."),
7665 limit
= attr
->values
[0].integer
;
7670 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7671 IPP_TAG_INTEGER
)) != NULL
)
7675 send_ipp_status(con
, IPP_CONFLICT
,
7676 _("The %s attribute cannot be provided with job-ids."),
7681 first_job_id
= attr
->values
[0].integer
;
7687 * See if we only want to see jobs for a specific user...
7690 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7691 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7693 send_ipp_status(con
, IPP_CONFLICT
,
7694 _("The %s attribute cannot be provided with job-ids."),
7698 else if (attr
&& attr
->values
[0].boolean
)
7699 strlcpy(username
, get_username(con
), sizeof(username
));
7703 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7704 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7707 * IPP conformance - Get-Jobs has a default requested-attributes value of
7708 * "job-id" and "job-uri".
7711 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7712 cupsArrayAdd(ra
, "job-id");
7713 cupsArrayAdd(ra
, "job-uri");
7717 * OK, build a list of jobs for this printer...
7722 int i
; /* Looping var */
7724 for (i
= 0; i
< job_ids
->num_values
; i
++)
7726 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
7730 if (i
< job_ids
->num_values
)
7732 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
7733 job_ids
->values
[i
].integer
);
7737 for (i
= 0; i
< job_ids
->num_values
; i
++)
7739 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7745 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7751 ippAddSeparator(con
->response
);
7753 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7754 job
->printer
->op_policy_ptr
:
7755 policy
, con
, job
->printer
,
7758 copy_job_attrs(con
, job
, ra
, exclude
);
7763 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7764 (limit
<= 0 || count
< limit
) && job
;
7765 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7768 * Filter out jobs that don't match...
7771 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7772 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7773 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7774 job
->username
, job
->state_value
, job
->attrs
);
7776 if (!job
->dest
|| !job
->username
)
7779 if (!job
->dest
|| !job
->username
)
7782 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7783 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7785 if ((job
->dtype
& dmask
) != dtype
&&
7786 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7789 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7790 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7791 (job_comparison
> 0 && job
->state_value
< job_state
))
7794 if (job
->id
< first_job_id
)
7801 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7806 if (username
[0] && strcasecmp(username
, job
->username
))
7810 ippAddSeparator(con
->response
);
7814 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7815 job
->printer
->op_policy_ptr
:
7816 policy
, con
, job
->printer
,
7819 copy_job_attrs(con
, job
, ra
, exclude
);
7822 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7825 cupsArrayDelete(ra
);
7827 con
->response
->request
.status
.status_code
= IPP_OK
;
7832 * 'get_notifications()' - Get events for a subscription.
7836 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7838 int i
, j
; /* Looping vars */
7839 http_status_t status
; /* Policy status */
7840 cupsd_subscription_t
*sub
; /* Subscription */
7841 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7842 *sequences
; /* notify-sequence-numbers */
7843 int min_seq
; /* Minimum sequence number */
7844 int interval
; /* Poll interval */
7847 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7851 * Get subscription attributes...
7854 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7856 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7861 send_ipp_status(con
, IPP_BAD_REQUEST
,
7862 _("Missing notify-subscription-ids attribute"));
7867 * Are the subscription IDs valid?
7870 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7872 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7875 * Bad subscription ID...
7878 send_ipp_status(con
, IPP_NOT_FOUND
,
7879 _("notify-subscription-id %d no good"),
7880 ids
->values
[i
].integer
);
7888 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7890 con
, sub
->owner
)) != HTTP_OK
)
7892 send_http_error(con
, status
, sub
->dest
);
7897 * Check the subscription type and update the interval accordingly.
7900 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7903 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7905 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7911 * Tell the client to poll again in N seconds...
7915 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7916 "notify-get-interval", interval
);
7918 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7919 "printer-up-time", time(NULL
));
7922 * Copy the subscription event attributes to the response.
7925 con
->response
->request
.status
.status_code
=
7926 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7928 for (i
= 0; i
< ids
->num_values
; i
++)
7931 * Get the subscription and sequence number...
7934 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7936 if (sequences
&& i
< sequences
->num_values
)
7937 min_seq
= sequences
->values
[i
].integer
;
7942 * If we don't have any new events, nothing to do here...
7945 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
7949 * Otherwise copy all of the new events...
7952 if (sub
->first_event_id
> min_seq
)
7955 j
= min_seq
- sub
->first_event_id
;
7957 for (; j
< cupsArrayCount(sub
->events
); j
++)
7959 ippAddSeparator(con
->response
);
7961 copy_attrs(con
->response
,
7962 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7963 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7970 * 'get_ppd()' - Get a named PPD from the local system.
7974 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7975 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7977 http_status_t status
; /* Policy status */
7978 cupsd_printer_t
*dest
; /* Destination */
7979 cups_ptype_t dtype
; /* Destination type */
7982 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7983 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7985 if (!strcmp(uri
->name
, "ppd-name"))
7988 * Return a PPD file from cups-driverd...
7991 char command
[1024], /* cups-driverd command */
7992 options
[1024], /* Options to pass to command */
7993 ppd_name
[1024]; /* ppd-name */
8000 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8002 send_http_error(con
, status
, NULL
);
8007 * Run cups-driverd command with the given options...
8010 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
8011 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
8012 snprintf(options
, sizeof(options
), "get+%d+%s",
8013 con
->request
->request
.op
.request_id
, ppd_name
);
8015 if (cupsdSendCommand(con
, command
, options
, 0))
8018 * Command started successfully, don't send an IPP response here...
8021 ippDelete(con
->response
);
8022 con
->response
= NULL
;
8027 * Command failed, return "internal error" so the user knows something
8031 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8032 _("cups-driverd failed to execute."));
8035 else if (!strcmp(uri
->name
, "printer-uri") &&
8036 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
8038 int i
; /* Looping var */
8039 char filename
[1024]; /* PPD filename */
8046 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8048 send_http_error(con
, status
, dest
);
8053 * See if we need the PPD for a class or remote printer...
8056 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8059 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
8061 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8062 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8063 "printer-uri", NULL
, dest
->uri
);
8066 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
8068 for (i
= 0; i
< dest
->num_printers
; i
++)
8069 if (!(dest
->printers
[i
]->type
&
8070 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
8072 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8073 dest
->printers
[i
]->name
);
8075 if (!access(filename
, 0))
8079 if (i
< dest
->num_printers
)
8080 dest
= dest
->printers
[i
];
8083 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8084 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8085 "printer-uri", NULL
, dest
->printers
[0]->uri
);
8091 * Found the printer with the PPD file, now see if there is one...
8094 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
8096 send_ipp_status(con
, IPP_NOT_FOUND
,
8097 _("The PPD file \"%s\" could not be opened: %s"),
8098 uri
->values
[0].string
.text
, strerror(errno
));
8102 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
8106 con
->response
->request
.status
.status_code
= IPP_OK
;
8109 send_ipp_status(con
, IPP_NOT_FOUND
,
8110 _("The PPD file \"%s\" could not be found."),
8111 uri
->values
[0].string
.text
);
8116 * 'get_ppds()' - Get the list of PPD files on the local system.
8120 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
8122 http_status_t status
; /* Policy status */
8123 ipp_attribute_t
*limit
, /* Limit attribute */
8124 *device
, /* ppd-device-id attribute */
8125 *language
, /* ppd-natural-language attribute */
8126 *make
, /* ppd-make attribute */
8127 *model
, /* ppd-make-and-model attribute */
8128 *model_number
, /* ppd-model-number attribute */
8129 *product
, /* ppd-product attribute */
8130 *psversion
, /* ppd-psverion attribute */
8131 *type
, /* ppd-type attribute */
8132 *requested
, /* requested-attributes attribute */
8133 *exclude
, /* exclude-schemes attribute */
8134 *include
; /* include-schemes attribute */
8135 char command
[1024], /* cups-driverd command */
8136 options
[4096], /* Options to pass to command */
8137 device_str
[256],/* Escaped ppd-device-id string */
8139 /* Escaped ppd-natural-language */
8140 make_str
[256], /* Escaped ppd-make string */
8141 model_str
[256], /* Escaped ppd-make-and-model string */
8142 model_number_str
[256],
8143 /* ppd-model-number string */
8145 /* Escaped ppd-product string */
8147 /* Escaped ppd-psversion string */
8148 type_str
[256], /* Escaped ppd-type string */
8150 /* String for requested attributes */
8152 /* String for excluded schemes */
8154 /* String for included schemes */
8157 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
8163 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8165 send_http_error(con
, status
, NULL
);
8170 * Run cups-driverd command with the given options...
8173 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
8174 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
8175 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
8177 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
8178 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
8180 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
8182 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
8183 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
8184 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
8185 requested
= ippFindAttribute(con
->request
, "requested-attributes",
8187 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
8189 include
= ippFindAttribute(con
->request
, "include-schemes",
8193 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
8195 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
8198 url_encode_attr(device
, device_str
, sizeof(device_str
));
8200 device_str
[0] = '\0';
8203 url_encode_attr(language
, language_str
, sizeof(language_str
));
8205 language_str
[0] = '\0';
8208 url_encode_attr(make
, make_str
, sizeof(make_str
));
8213 url_encode_attr(model
, model_str
, sizeof(model_str
));
8215 model_str
[0] = '\0';
8218 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
8219 model_number
->values
[0].integer
);
8221 model_number_str
[0] = '\0';
8224 url_encode_attr(product
, product_str
, sizeof(product_str
));
8226 product_str
[0] = '\0';
8229 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
8231 psversion_str
[0] = '\0';
8234 url_encode_attr(type
, type_str
, sizeof(type_str
));
8239 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
8241 exclude_str
[0] = '\0';
8244 url_encode_attr(include
, include_str
, sizeof(include_str
));
8246 include_str
[0] = '\0';
8248 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
8249 snprintf(options
, sizeof(options
),
8250 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
8251 con
->request
->request
.op
.request_id
,
8252 limit
? limit
->values
[0].integer
: 0,
8254 device
? "%20" : "", device_str
,
8255 language
? "%20" : "", language_str
,
8256 make
? "%20" : "", make_str
,
8257 model
? "%20" : "", model_str
,
8258 model_number
? "%20" : "", model_number_str
,
8259 product
? "%20" : "", product_str
,
8260 psversion
? "%20" : "", psversion_str
,
8261 type
? "%20" : "", type_str
,
8262 exclude_str
[0] ? "%20" : "", exclude_str
,
8263 include_str
[0] ? "%20" : "", include_str
);
8265 if (cupsdSendCommand(con
, command
, options
, 0))
8268 * Command started successfully, don't send an IPP response here...
8271 ippDelete(con
->response
);
8272 con
->response
= NULL
;
8277 * Command failed, return "internal error" so the user knows something
8281 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8282 _("cups-driverd failed to execute."));
8288 * 'get_printer_attrs()' - Get printer attributes.
8292 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
8293 ipp_attribute_t
*uri
) /* I - Printer URI */
8295 http_status_t status
; /* Policy status */
8296 cups_ptype_t dtype
; /* Destination type (printer/class) */
8297 cupsd_printer_t
*printer
; /* Printer/class */
8298 cups_array_t
*ra
; /* Requested attributes array */
8301 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
8302 con
->http
.fd
, uri
->values
[0].string
.text
);
8305 * Is the destination valid?
8308 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8314 send_ipp_status(con
, IPP_NOT_FOUND
,
8315 _("The printer or class was not found."));
8323 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8325 send_http_error(con
, status
, printer
);
8330 * Send the attributes...
8333 ra
= create_requested_array(con
->request
);
8335 copy_printer_attrs(con
, printer
, ra
);
8337 cupsArrayDelete(ra
);
8339 con
->response
->request
.status
.status_code
= IPP_OK
;
8344 * 'get_printer_supported()' - Get printer supported values.
8348 get_printer_supported(
8349 cupsd_client_t
*con
, /* I - Client connection */
8350 ipp_attribute_t
*uri
) /* I - Printer URI */
8352 http_status_t status
; /* Policy status */
8353 cups_ptype_t dtype
; /* Destination type (printer/class) */
8354 cupsd_printer_t
*printer
; /* Printer/class */
8357 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
8358 con
->http
.fd
, uri
->values
[0].string
.text
);
8361 * Is the destination valid?
8364 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8370 send_ipp_status(con
, IPP_NOT_FOUND
,
8371 _("The printer or class was not found."));
8379 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8381 send_http_error(con
, status
, printer
);
8386 * Return a list of attributes that can be set via Set-Printer-Attributes.
8389 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8391 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8392 "printer-location", 0);
8394 con
->response
->request
.status
.status_code
= IPP_OK
;
8399 * 'get_printers()' - Get a list of printers or classes.
8403 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8404 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8406 http_status_t status
; /* Policy status */
8407 ipp_attribute_t
*attr
; /* Current attribute */
8408 int limit
; /* Max number of printers to return */
8409 int count
; /* Number of printers that match */
8410 cupsd_printer_t
*printer
; /* Current printer pointer */
8411 int printer_type
, /* printer-type attribute */
8412 printer_mask
; /* printer-type-mask attribute */
8413 char *location
; /* Location string */
8414 const char *username
; /* Current user */
8415 char *first_printer_name
; /* first-printer-name attribute */
8416 cups_array_t
*ra
; /* Requested attributes array */
8417 int local
; /* Local connection? */
8420 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8421 con
->http
.fd
, type
);
8427 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8429 send_http_error(con
, status
, NULL
);
8434 * Check for printers...
8437 if (!Printers
|| !cupsArrayCount(Printers
))
8439 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8444 * See if they want to limit the number of printers reported...
8447 if ((attr
= ippFindAttribute(con
->request
, "limit",
8448 IPP_TAG_INTEGER
)) != NULL
)
8449 limit
= attr
->values
[0].integer
;
8453 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8454 IPP_TAG_NAME
)) != NULL
)
8455 first_printer_name
= attr
->values
[0].string
.text
;
8457 first_printer_name
= NULL
;
8460 * Support filtering...
8463 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8464 IPP_TAG_ENUM
)) != NULL
)
8465 printer_type
= attr
->values
[0].integer
;
8469 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8470 IPP_TAG_ENUM
)) != NULL
)
8471 printer_mask
= attr
->values
[0].integer
;
8475 local
= httpAddrLocalhost(&(con
->clientaddr
));
8477 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8478 IPP_TAG_TEXT
)) != NULL
)
8479 location
= attr
->values
[0].string
.text
;
8483 if (con
->username
[0])
8484 username
= con
->username
;
8485 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8486 IPP_TAG_NAME
)) != NULL
)
8487 username
= attr
->values
[0].string
.text
;
8491 ra
= create_requested_array(con
->request
);
8494 * OK, build a list of printers for this printer...
8497 if (first_printer_name
)
8499 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8500 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8503 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8506 count
< limit
&& printer
;
8507 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8509 if (!local
&& !printer
->shared
)
8512 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8513 (printer
->type
& printer_mask
) == printer_type
&&
8515 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
8518 * If HideImplicitMembers is enabled, see if this printer or class
8519 * is a member of an implicit class...
8522 if (ImplicitClasses
&& HideImplicitMembers
&&
8523 printer
->in_implicit_class
)
8527 * If a username is specified, see if it is allowed or denied
8531 if (cupsArrayCount(printer
->users
) && username
&&
8532 !user_allowed(printer
, username
))
8536 * Add the group separator as needed...
8540 ippAddSeparator(con
->response
);
8545 * Send the attributes...
8548 copy_printer_attrs(con
, printer
, ra
);
8552 cupsArrayDelete(ra
);
8554 con
->response
->request
.status
.status_code
= IPP_OK
;
8559 * 'get_subscription_attrs()' - Get subscription attributes.
8563 get_subscription_attrs(
8564 cupsd_client_t
*con
, /* I - Client connection */
8565 int sub_id
) /* I - Subscription ID */
8567 http_status_t status
; /* Policy status */
8568 cupsd_subscription_t
*sub
; /* Subscription */
8569 cupsd_policy_t
*policy
; /* Current security policy */
8570 cups_array_t
*ra
, /* Requested attributes array */
8571 *exclude
; /* Private attributes array */
8574 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8575 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8576 con
, con
->http
.fd
, sub_id
);
8579 * Is the subscription ID valid?
8582 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8585 * Bad subscription ID...
8588 send_ipp_status(con
, IPP_NOT_FOUND
,
8589 _("notify-subscription-id %d no good"), sub_id
);
8598 policy
= sub
->dest
->op_policy_ptr
;
8600 policy
= DefaultPolicyPtr
;
8602 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
8604 send_http_error(con
, status
, sub
->dest
);
8608 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
8611 * Copy the subscription attributes to the response using the
8612 * requested-attributes attribute that may be provided by the client.
8615 ra
= create_requested_array(con
->request
);
8617 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8619 cupsArrayDelete(ra
);
8621 con
->response
->request
.status
.status_code
= IPP_OK
;
8626 * 'get_subscriptions()' - Get subscriptions.
8630 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8631 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8633 http_status_t status
; /* Policy status */
8634 int count
; /* Number of subscriptions */
8635 int limit
; /* Limit */
8636 cupsd_subscription_t
*sub
; /* Subscription */
8637 cups_array_t
*ra
; /* Requested attributes array */
8638 ipp_attribute_t
*attr
; /* Attribute */
8639 cups_ptype_t dtype
; /* Destination type (printer/class) */
8640 char scheme
[HTTP_MAX_URI
],
8641 /* Scheme portion of URI */
8642 username
[HTTP_MAX_URI
],
8643 /* Username portion of URI */
8645 /* Host portion of URI */
8646 resource
[HTTP_MAX_URI
];
8647 /* Resource portion of URI */
8648 int port
; /* Port portion of URI */
8649 cupsd_job_t
*job
; /* Job pointer */
8650 cupsd_printer_t
*printer
; /* Printer */
8651 cupsd_policy_t
*policy
; /* Policy */
8652 cups_array_t
*exclude
; /* Private attributes array */
8655 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8656 "get_subscriptions(con=%p[%d], uri=%s)",
8657 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8660 * Is the destination valid?
8663 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8664 sizeof(scheme
), username
, sizeof(username
), host
,
8665 sizeof(host
), &port
, resource
, sizeof(resource
));
8667 if (!strcmp(resource
, "/") ||
8668 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8669 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8670 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8675 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8678 job
= cupsdFindJob(atoi(resource
+ 6));
8682 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist"),
8687 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8693 send_ipp_status(con
, IPP_NOT_FOUND
,
8694 _("The printer or class was not found."));
8697 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8698 IPP_TAG_INTEGER
)) != NULL
)
8700 job
= cupsdFindJob(attr
->values
[0].integer
);
8704 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
8705 attr
->values
[0].integer
);
8717 policy
= printer
->op_policy_ptr
;
8719 policy
= DefaultPolicyPtr
;
8721 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
8723 send_http_error(con
, status
, printer
);
8728 * Copy the subscription attributes to the response using the
8729 * requested-attributes attribute that may be provided by the client.
8732 ra
= create_requested_array(con
->request
);
8734 if ((attr
= ippFindAttribute(con
->request
, "limit",
8735 IPP_TAG_INTEGER
)) != NULL
)
8736 limit
= attr
->values
[0].integer
;
8741 * See if we only want to see subscriptions for a specific user...
8744 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8745 IPP_TAG_BOOLEAN
)) != NULL
&&
8746 attr
->values
[0].boolean
)
8747 strlcpy(username
, get_username(con
), sizeof(username
));
8751 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8753 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8754 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8755 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
8757 ippAddSeparator(con
->response
);
8759 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
8760 policy
, con
, sub
->dest
,
8763 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8766 if (limit
&& count
>= limit
)
8770 cupsArrayDelete(ra
);
8773 con
->response
->request
.status
.status_code
= IPP_OK
;
8775 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8780 * 'get_username()' - Get the username associated with a request.
8783 static const char * /* O - Username */
8784 get_username(cupsd_client_t
*con
) /* I - Connection */
8786 ipp_attribute_t
*attr
; /* Attribute */
8789 if (con
->username
[0])
8790 return (con
->username
);
8791 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8792 IPP_TAG_NAME
)) != NULL
)
8793 return (attr
->values
[0].string
.text
);
8795 return ("anonymous");
8800 * 'hold_job()' - Hold a print job.
8804 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8805 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8807 ipp_attribute_t
*attr
; /* Current job-hold-until */
8808 const char *when
; /* New value */
8809 int jobid
; /* Job ID */
8810 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8811 username
[HTTP_MAX_URI
], /* Username portion of URI */
8812 host
[HTTP_MAX_URI
], /* Host portion of URI */
8813 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8814 int port
; /* Port portion of URI */
8815 cupsd_job_t
*job
; /* Job information */
8818 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8819 uri
->values
[0].string
.text
);
8822 * See if we have a job URI or a printer URI...
8825 if (!strcmp(uri
->name
, "printer-uri"))
8828 * Got a printer URI; see if we also have a job-id attribute...
8831 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8832 IPP_TAG_INTEGER
)) == NULL
)
8834 send_ipp_status(con
, IPP_BAD_REQUEST
,
8835 _("Got a printer-uri attribute but no job-id"));
8839 jobid
= attr
->values
[0].integer
;
8844 * Got a job URI; parse it to get the job ID...
8847 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8848 sizeof(scheme
), username
, sizeof(username
), host
,
8849 sizeof(host
), &port
, resource
, sizeof(resource
));
8851 if (strncmp(resource
, "/jobs/", 6))
8857 send_ipp_status(con
, IPP_BAD_REQUEST
,
8858 _("Bad job-uri attribute \"%s\""),
8859 uri
->values
[0].string
.text
);
8863 jobid
= atoi(resource
+ 6);
8867 * See if the job exists...
8870 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8873 * Nope - return a "not found" error...
8876 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
8881 * See if the job is owned by the requesting user...
8884 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8886 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8887 cupsdFindDest(job
->dest
));
8892 * Hold the job and return...
8895 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8896 IPP_TAG_KEYWORD
)) == NULL
)
8897 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8901 when
= attr
->values
[0].string
.text
;
8903 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8904 "Job job-hold-until value changed by user.");
8907 when
= "indefinite";
8909 cupsdSetJobHoldUntil(job
, when
, 1);
8910 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8913 con
->response
->request
.status
.status_code
= IPP_OK
;
8918 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8922 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8923 ipp_attribute_t
*uri
) /* I - Printer URI */
8925 http_status_t status
; /* Policy status */
8926 cups_ptype_t dtype
; /* Destination type (printer/class) */
8927 cupsd_printer_t
*printer
; /* Printer data */
8930 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8931 con
->http
.fd
, uri
->values
[0].string
.text
);
8934 * Is the destination valid?
8937 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8943 send_ipp_status(con
, IPP_NOT_FOUND
,
8944 _("The printer or class was not found."));
8952 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8954 send_http_error(con
, status
, printer
);
8959 * Hold pending/new jobs sent to the printer...
8962 printer
->holding_new_jobs
= 1;
8964 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8965 cupsdAddPrinterHistory(printer
);
8967 if (dtype
& CUPS_PRINTER_CLASS
)
8968 cupsdLogMessage(CUPSD_LOG_INFO
,
8969 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8970 printer
->name
, get_username(con
));
8972 cupsdLogMessage(CUPSD_LOG_INFO
,
8973 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8974 printer
->name
, get_username(con
));
8977 * Everything was ok, so return OK status...
8980 con
->response
->request
.status
.status_code
= IPP_OK
;
8985 * 'move_job()' - Move a job to a new destination.
8989 move_job(cupsd_client_t
*con
, /* I - Client connection */
8990 ipp_attribute_t
*uri
) /* I - Job URI */
8992 http_status_t status
; /* Policy status */
8993 ipp_attribute_t
*attr
; /* Current attribute */
8994 int jobid
; /* Job ID */
8995 cupsd_job_t
*job
; /* Current job */
8996 const char *src
; /* Source printer/class */
8997 cups_ptype_t stype
, /* Source type (printer or class) */
8998 dtype
; /* Destination type (printer/class) */
8999 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
9000 username
[HTTP_MAX_URI
], /* Username portion of URI */
9001 host
[HTTP_MAX_URI
], /* Host portion of URI */
9002 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9003 int port
; /* Port portion of URI */
9004 cupsd_printer_t
*sprinter
, /* Source printer */
9005 *dprinter
; /* Destination printer */
9008 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
9009 uri
->values
[0].string
.text
);
9012 * Get the new printer or class...
9015 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
9016 IPP_TAG_URI
)) == NULL
)
9019 * Need job-printer-uri...
9022 send_ipp_status(con
, IPP_BAD_REQUEST
,
9023 _("job-printer-uri attribute missing"));
9027 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
9033 send_ipp_status(con
, IPP_NOT_FOUND
,
9034 _("The printer or class was not found."));
9039 * See if we have a job URI or a printer URI...
9042 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9043 sizeof(scheme
), username
, sizeof(username
), host
,
9044 sizeof(host
), &port
, resource
, sizeof(resource
));
9046 if (!strcmp(uri
->name
, "printer-uri"))
9049 * Got a printer URI; see if we also have a job-id attribute...
9052 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9053 IPP_TAG_INTEGER
)) == NULL
)
9059 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
9060 &sprinter
)) == NULL
)
9066 send_ipp_status(con
, IPP_NOT_FOUND
,
9067 _("The printer or class was not found."));
9076 * Otherwise, just move a single job...
9079 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
9082 * Nope - return a "not found" error...
9085 send_ipp_status(con
, IPP_NOT_FOUND
,
9086 _("Job #%d does not exist"), attr
->values
[0].integer
);
9092 * Job found, initialize source pointers...
9103 * Got a job URI; parse it to get the job ID...
9106 if (strncmp(resource
, "/jobs/", 6))
9112 send_ipp_status(con
, IPP_BAD_REQUEST
,
9113 _("Bad job-uri attribute \"%s\""),
9114 uri
->values
[0].string
.text
);
9119 * See if the job exists...
9122 jobid
= atoi(resource
+ 6);
9124 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9127 * Nope - return a "not found" error...
9130 send_ipp_status(con
, IPP_NOT_FOUND
,
9131 _("Job #%d does not exist"), jobid
);
9137 * Job found, initialize source pointers...
9146 * Check the policy of the destination printer...
9149 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
9150 job
? job
->username
: NULL
)) != HTTP_OK
)
9152 send_http_error(con
, status
, dprinter
);
9157 * Now move the job or jobs...
9163 * See if the job has been completed...
9166 if (job
->state_value
> IPP_JOB_STOPPED
)
9169 * Return a "not-possible" error...
9172 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9173 _("Job #%d is finished and cannot be altered"),
9179 * See if the job is owned by the requesting user...
9182 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9184 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9185 cupsdFindDest(job
->dest
));
9190 * Move the job to a different printer or class...
9193 cupsdMoveJob(job
, dprinter
);
9198 * Got the source printer, now look through the jobs...
9201 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
9203 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
9206 * See if the job is pointing at the source printer or has not been
9210 if (strcasecmp(job
->dest
, src
) ||
9211 job
->state_value
> IPP_JOB_STOPPED
)
9215 * See if the job can be moved by the requesting user...
9218 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9222 * Move the job to a different printer or class...
9225 cupsdMoveJob(job
, dprinter
);
9230 * Start jobs if possible...
9236 * Return with "everything is OK" status...
9239 con
->response
->request
.status
.status_code
= IPP_OK
;
9244 * 'ppd_parse_line()' - Parse a PPD default line.
9247 static int /* O - 0 on success, -1 on failure */
9248 ppd_parse_line(const char *line
, /* I - Line */
9249 char *option
, /* O - Option name */
9250 int olen
, /* I - Size of option name */
9251 char *choice
, /* O - Choice name */
9252 int clen
) /* I - Size of choice name */
9255 * Verify this is a default option line...
9258 if (strncmp(line
, "*Default", 8))
9262 * Read the option name...
9265 for (line
+= 8, olen
--;
9266 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9277 * Skip everything else up to the colon (:)...
9280 while (*line
&& *line
!= ':')
9289 * Now grab the option choice, skipping leading whitespace...
9292 while (isspace(*line
& 255))
9296 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9307 * Return with no errors...
9315 * 'print_job()' - Print a file to a printer or class.
9319 print_job(cupsd_client_t
*con
, /* I - Client connection */
9320 ipp_attribute_t
*uri
) /* I - Printer URI */
9322 ipp_attribute_t
*attr
; /* Current attribute */
9323 ipp_attribute_t
*format
; /* Document-format attribute */
9324 const char *default_format
; /* document-format-default value */
9325 cupsd_job_t
*job
; /* New job */
9326 char filename
[1024]; /* Job filename */
9327 mime_type_t
*filetype
; /* Type of file */
9328 char super
[MIME_MAX_SUPER
], /* Supertype of file */
9329 type
[MIME_MAX_TYPE
], /* Subtype of file */
9330 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9331 /* Textual name of mime type */
9332 cupsd_printer_t
*printer
; /* Printer data */
9333 struct stat fileinfo
; /* File information */
9334 int kbytes
; /* Size of file */
9335 int compression
; /* Document compression */
9338 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
9339 uri
->values
[0].string
.text
);
9342 * Validate print file attributes, for now just document-format and
9343 * compression (CUPS only supports "none" and "gzip")...
9346 compression
= CUPS_FILE_NONE
;
9348 if ((attr
= ippFindAttribute(con
->request
, "compression",
9349 IPP_TAG_KEYWORD
)) != NULL
)
9351 if (strcmp(attr
->values
[0].string
.text
, "none")
9353 && strcmp(attr
->values
[0].string
.text
, "gzip")
9354 #endif /* HAVE_LIBZ */
9357 send_ipp_status(con
, IPP_ATTRIBUTES
,
9358 _("Unsupported compression \"%s\""),
9359 attr
->values
[0].string
.text
);
9360 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9361 "compression", NULL
, attr
->values
[0].string
.text
);
9366 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9367 compression
= CUPS_FILE_GZIP
;
9368 #endif /* HAVE_LIBZ */
9372 * Do we have a file to print?
9377 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
9382 * Is the destination valid?
9385 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
9391 send_ipp_status(con
, IPP_NOT_FOUND
,
9392 _("The printer or class was not found."));
9397 * Is it a format we support?
9400 if ((format
= ippFindAttribute(con
->request
, "document-format",
9401 IPP_TAG_MIMETYPE
)) != NULL
)
9404 * Grab format from client...
9407 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9410 send_ipp_status(con
, IPP_BAD_REQUEST
,
9411 _("Bad document-format \"%s\""),
9412 format
->values
[0].string
.text
);
9416 else if ((default_format
= cupsGetOption("document-format",
9417 printer
->num_options
,
9418 printer
->options
)) != NULL
)
9421 * Use default document format...
9424 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9426 send_ipp_status(con
, IPP_BAD_REQUEST
,
9427 _("Bad document-format \"%s\""),
9438 strcpy(super
, "application");
9439 strcpy(type
, "octet-stream");
9442 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9445 * Auto-type the file...
9448 ipp_attribute_t
*doc_name
; /* document-name attribute */
9451 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9453 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9454 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9455 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9459 filetype
= mimeType(MimeDatabase
, super
, type
);
9461 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9462 filetype
->super
, filetype
->type
);
9465 filetype
= mimeType(MimeDatabase
, super
, type
);
9469 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9472 * Replace the document-format attribute value with the auto-typed or
9476 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9481 _cupsStrFree(format
->values
[0].string
.text
);
9483 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9486 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9487 "document-format", NULL
, mimetype
);
9491 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9492 _("Unsupported document-format \"%s\""),
9493 format
? format
->values
[0].string
.text
:
9494 "application/octet-stream");
9495 cupsdLogMessage(CUPSD_LOG_INFO
,
9496 "Hint: Do you have the raw file printing rules enabled?");
9499 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9500 "document-format", NULL
, format
->values
[0].string
.text
);
9506 * Read any embedded job ticket info from PS files...
9509 if (!strcasecmp(filetype
->super
, "application") &&
9510 (!strcasecmp(filetype
->type
, "postscript") ||
9511 !strcasecmp(filetype
->type
, "pdf")))
9512 read_job_ticket(con
);
9515 * Create the job object...
9518 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9522 * Update quota data...
9525 if (stat(con
->filename
, &fileinfo
))
9528 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9530 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9532 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9533 IPP_TAG_INTEGER
)) != NULL
)
9534 attr
->values
[0].integer
+= kbytes
;
9537 * Add the job file...
9540 if (add_file(con
, job
, filetype
, compression
))
9543 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9545 rename(con
->filename
, filename
);
9546 cupsdClearString(&con
->filename
);
9549 * See if we need to add the ending sheet...
9552 if (cupsdTimeoutJob(job
))
9556 * Log and save the job...
9559 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9560 "File of type %s/%s queued by \"%s\".",
9561 filetype
->super
, filetype
->type
, job
->username
);
9562 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9563 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9564 job
->dest
, job
->username
);
9567 * Start the job if possible...
9575 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9577 * This function only gets called when printing a single PDF or PostScript
9578 * file using the Print-Job operation. It doesn't work for Create-Job +
9579 * Send-File, since the job attributes need to be set at job creation
9580 * time for banners to work. The embedded job ticket stuff is here
9581 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9582 * options and IPP attributes which otherwise would be lost.
9584 * The format of a job ticket is simple:
9586 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9588 * %cupsJobTicket: attr1=value1
9589 * %cupsJobTicket: attr2=value2
9591 * %cupsJobTicket: attrN=valueN
9593 * Job ticket lines must appear immediately after the first line that
9594 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9595 * stops looking for job ticket info when it finds a line that does not begin
9596 * with "%cupsJobTicket:".
9598 * The maximum length of a job ticket line, including the prefix, is
9599 * 255 characters to conform with the Adobe DSC.
9601 * Read-only attributes are rejected with a notice to the error log in
9602 * case a malicious user tries anything. Since the job ticket is read
9603 * prior to attribute validation in print_job(), job ticket attributes
9604 * will go through the same validation as IPP attributes...
9608 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9610 cups_file_t
*fp
; /* File to read from */
9611 char line
[256]; /* Line data */
9612 int num_options
; /* Number of options */
9613 cups_option_t
*options
; /* Options */
9614 ipp_t
*ticket
; /* New attributes */
9615 ipp_attribute_t
*attr
, /* Current attribute */
9616 *attr2
, /* Job attribute */
9617 *prev2
; /* Previous job attribute */
9621 * First open the print file...
9624 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9626 cupsdLogMessage(CUPSD_LOG_ERROR
,
9627 "Unable to open print file for job ticket - %s",
9633 * Skip the first line...
9636 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9638 cupsdLogMessage(CUPSD_LOG_ERROR
,
9639 "Unable to read from print file for job ticket - %s",
9645 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9648 * Not a DSC-compliant file, so no job ticket info will be available...
9656 * Read job ticket info from the file...
9662 while (cupsFileGets(fp
, line
, sizeof(line
)))
9665 * Stop at the first non-ticket line...
9668 if (strncmp(line
, "%cupsJobTicket:", 15))
9672 * Add the options to the option array...
9675 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9679 * Done with the file; see if we have any options...
9684 if (num_options
== 0)
9688 * OK, convert the options to an attribute list, and apply them to
9693 cupsEncodeOptions(ticket
, num_options
, options
);
9696 * See what the user wants to change.
9699 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9701 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9704 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9705 !strcmp(attr
->name
, "job-originating-user-name") ||
9706 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9707 !strcmp(attr
->name
, "job-k-octets") ||
9708 !strcmp(attr
->name
, "job-id") ||
9709 !strncmp(attr
->name
, "job-state", 9) ||
9710 !strncmp(attr
->name
, "time-at-", 8))
9711 continue; /* Read-only attrs */
9713 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9714 IPP_TAG_ZERO
)) != NULL
)
9717 * Some other value; first free the old value...
9720 if (con
->request
->attrs
== attr2
)
9722 con
->request
->attrs
= attr2
->next
;
9727 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9728 if (prev2
->next
== attr2
)
9730 prev2
->next
= attr2
->next
;
9735 if (con
->request
->last
== attr2
)
9736 con
->request
->last
= prev2
;
9738 _ippFreeAttr(attr2
);
9742 * Add new option by copying it...
9745 copy_attribute(con
->request
, attr
, 0);
9749 * Then free the attribute list and option array...
9753 cupsFreeOptions(num_options
, options
);
9758 * 'reject_jobs()' - Reject print jobs to a printer.
9762 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9763 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9765 http_status_t status
; /* Policy status */
9766 cups_ptype_t dtype
; /* Destination type (printer/class) */
9767 cupsd_printer_t
*printer
; /* Printer data */
9768 ipp_attribute_t
*attr
; /* printer-state-message text */
9771 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9772 con
->http
.fd
, uri
->values
[0].string
.text
);
9775 * Is the destination valid?
9778 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9784 send_ipp_status(con
, IPP_NOT_FOUND
,
9785 _("The printer or class was not found."));
9793 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9795 send_http_error(con
, status
, printer
);
9800 * Reject jobs sent to the printer...
9803 printer
->accepting
= 0;
9805 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9806 IPP_TAG_TEXT
)) == NULL
)
9807 strcpy(printer
->state_message
, "Rejecting Jobs");
9809 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9810 sizeof(printer
->state_message
));
9812 cupsdAddPrinterHistory(printer
);
9814 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9815 "No longer accepting jobs.");
9817 if (dtype
& CUPS_PRINTER_CLASS
)
9819 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9821 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9822 printer
->name
, get_username(con
));
9826 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9828 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9829 printer
->name
, get_username(con
));
9833 * Everything was ok, so return OK status...
9836 con
->response
->request
.status
.status_code
= IPP_OK
;
9841 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9845 release_held_new_jobs(
9846 cupsd_client_t
*con
, /* I - Connection */
9847 ipp_attribute_t
*uri
) /* I - Printer URI */
9849 http_status_t status
; /* Policy status */
9850 cups_ptype_t dtype
; /* Destination type (printer/class) */
9851 cupsd_printer_t
*printer
; /* Printer data */
9854 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9855 con
->http
.fd
, uri
->values
[0].string
.text
);
9858 * Is the destination valid?
9861 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9867 send_ipp_status(con
, IPP_NOT_FOUND
,
9868 _("The printer or class was not found."));
9876 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9878 send_http_error(con
, status
, printer
);
9883 * Hold pending/new jobs sent to the printer...
9886 printer
->holding_new_jobs
= 0;
9888 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9889 cupsdAddPrinterHistory(printer
);
9891 if (dtype
& CUPS_PRINTER_CLASS
)
9892 cupsdLogMessage(CUPSD_LOG_INFO
,
9893 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9894 printer
->name
, get_username(con
));
9896 cupsdLogMessage(CUPSD_LOG_INFO
,
9897 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9898 printer
->name
, get_username(con
));
9901 * Everything was ok, so return OK status...
9904 con
->response
->request
.status
.status_code
= IPP_OK
;
9909 * 'release_job()' - Release a held print job.
9913 release_job(cupsd_client_t
*con
, /* I - Client connection */
9914 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9916 ipp_attribute_t
*attr
; /* Current attribute */
9917 int jobid
; /* Job ID */
9918 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9919 username
[HTTP_MAX_URI
], /* Username portion of URI */
9920 host
[HTTP_MAX_URI
], /* Host portion of URI */
9921 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9922 int port
; /* Port portion of URI */
9923 cupsd_job_t
*job
; /* Job information */
9926 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9927 con
->http
.fd
, uri
->values
[0].string
.text
);
9930 * See if we have a job URI or a printer URI...
9933 if (!strcmp(uri
->name
, "printer-uri"))
9936 * Got a printer URI; see if we also have a job-id attribute...
9939 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9940 IPP_TAG_INTEGER
)) == NULL
)
9942 send_ipp_status(con
, IPP_BAD_REQUEST
,
9943 _("Got a printer-uri attribute but no job-id"));
9947 jobid
= attr
->values
[0].integer
;
9952 * Got a job URI; parse it to get the job ID...
9955 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9956 sizeof(scheme
), username
, sizeof(username
), host
,
9957 sizeof(host
), &port
, resource
, sizeof(resource
));
9959 if (strncmp(resource
, "/jobs/", 6))
9965 send_ipp_status(con
, IPP_BAD_REQUEST
,
9966 _("Bad job-uri attribute \"%s\""),
9967 uri
->values
[0].string
.text
);
9971 jobid
= atoi(resource
+ 6);
9975 * See if the job exists...
9978 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9981 * Nope - return a "not found" error...
9984 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9989 * See if job is "held"...
9992 if (job
->state_value
!= IPP_JOB_HELD
)
9995 * Nope - return a "not possible" error...
9998 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held"), jobid
);
10003 * See if the job is owned by the requesting user...
10006 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10008 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10009 cupsdFindDest(job
->dest
));
10014 * Reset the job-hold-until value to "no-hold"...
10017 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10018 IPP_TAG_KEYWORD
)) == NULL
)
10019 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10023 _cupsStrFree(attr
->values
[0].string
.text
);
10025 attr
->value_tag
= IPP_TAG_KEYWORD
;
10026 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
10028 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10029 "Job job-hold-until value changed by user.");
10033 * Release the job and return...
10036 cupsdReleaseJob(job
);
10038 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10039 "Job released by user.");
10041 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
10043 con
->response
->request
.status
.status_code
= IPP_OK
;
10050 * 'renew_subscription()' - Renew an existing subscription...
10054 renew_subscription(
10055 cupsd_client_t
*con
, /* I - Client connection */
10056 int sub_id
) /* I - Subscription ID */
10058 http_status_t status
; /* Policy status */
10059 cupsd_subscription_t
*sub
; /* Subscription */
10060 ipp_attribute_t
*lease
; /* notify-lease-duration */
10063 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
10064 "renew_subscription(con=%p[%d], sub_id=%d)",
10065 con
, con
->http
.fd
, sub_id
);
10068 * Is the subscription ID valid?
10071 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
10074 * Bad subscription ID...
10077 send_ipp_status(con
, IPP_NOT_FOUND
,
10078 _("notify-subscription-id %d no good"), sub_id
);
10085 * Job subscriptions cannot be renewed...
10088 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10089 _("Job subscriptions cannot be renewed"));
10097 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
10099 con
, sub
->owner
)) != HTTP_OK
)
10101 send_http_error(con
, status
, sub
->dest
);
10106 * Renew the subscription...
10109 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
10112 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
10114 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
10116 cupsdLogMessage(CUPSD_LOG_INFO
,
10117 "renew_subscription: Limiting notify-lease-duration to "
10120 sub
->lease
= MaxLeaseDuration
;
10123 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
10125 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
10127 con
->response
->request
.status
.status_code
= IPP_OK
;
10129 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
10130 "notify-lease-duration", sub
->lease
);
10135 * 'restart_job()' - Restart an old print job.
10139 restart_job(cupsd_client_t
*con
, /* I - Client connection */
10140 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
10142 ipp_attribute_t
*attr
; /* Current attribute */
10143 int jobid
; /* Job ID */
10144 cupsd_job_t
*job
; /* Job information */
10145 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
10146 username
[HTTP_MAX_URI
], /* Username portion of URI */
10147 host
[HTTP_MAX_URI
], /* Host portion of URI */
10148 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10149 int port
; /* Port portion of URI */
10152 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
10153 con
->http
.fd
, uri
->values
[0].string
.text
);
10156 * See if we have a job URI or a printer URI...
10159 if (!strcmp(uri
->name
, "printer-uri"))
10162 * Got a printer URI; see if we also have a job-id attribute...
10165 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10166 IPP_TAG_INTEGER
)) == NULL
)
10168 send_ipp_status(con
, IPP_BAD_REQUEST
,
10169 _("Got a printer-uri attribute but no job-id"));
10173 jobid
= attr
->values
[0].integer
;
10178 * Got a job URI; parse it to get the job ID...
10181 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10182 sizeof(scheme
), username
, sizeof(username
), host
,
10183 sizeof(host
), &port
, resource
, sizeof(resource
));
10185 if (strncmp(resource
, "/jobs/", 6))
10191 send_ipp_status(con
, IPP_BAD_REQUEST
,
10192 _("Bad job-uri attribute \"%s\""),
10193 uri
->values
[0].string
.text
);
10197 jobid
= atoi(resource
+ 6);
10201 * See if the job exists...
10204 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10207 * Nope - return a "not found" error...
10210 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10215 * See if job is in any of the "completed" states...
10218 if (job
->state_value
<= IPP_JOB_PROCESSING
)
10221 * Nope - return a "not possible" error...
10224 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete"),
10230 * See if we have retained the job files...
10235 if (!job
->attrs
|| job
->num_files
== 0)
10238 * Nope - return a "not possible" error...
10241 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10242 _("Job #%d cannot be restarted - no files"), jobid
);
10247 * See if the job is owned by the requesting user...
10250 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10252 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10253 cupsdFindDest(job
->dest
));
10258 * See if the job-hold-until attribute is specified...
10261 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
10262 IPP_TAG_KEYWORD
)) == NULL
)
10263 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
10265 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
10268 * Return the job to a held state...
10271 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
10272 "Restarted by \"%s\" with job-hold-until=%s.",
10273 username
, attr
->values
[0].string
.text
);
10274 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10276 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
10277 NULL
, job
, "Job restarted by user with job-hold-until=%s",
10278 attr
->values
[0].string
.text
);
10283 * Restart the job...
10286 cupsdRestartJob(job
);
10290 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
10292 con
->response
->request
.status
.status_code
= IPP_OK
;
10297 * 'save_auth_info()' - Save authentication information for a job.
10302 cupsd_client_t
*con
, /* I - Client connection */
10303 cupsd_job_t
*job
, /* I - Job */
10304 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
10306 int i
; /* Looping var */
10307 char filename
[1024]; /* Job authentication filename */
10308 cups_file_t
*fp
; /* Job authentication file */
10309 char line
[2048]; /* Line for file */
10310 cupsd_printer_t
*dest
; /* Destination printer/class */
10314 * This function saves the in-memory authentication information for
10315 * a job so that it can be used to authenticate with a remote host.
10316 * The information is stored in a file that is readable only by the
10317 * root user. The fields are Base-64 encoded, each on a separate line,
10318 * followed by random number (up to 1024) of newlines to limit the
10319 * amount of information that is exposed.
10321 * Because of the potential for exposing of authentication information,
10322 * this functionality is only enabled when running cupsd as root.
10324 * This caching only works for the Basic and BasicDigest authentication
10325 * types. Digest authentication cannot be cached this way, and in
10326 * the future Kerberos authentication may make all of this obsolete.
10328 * Authentication information is saved whenever an authenticated
10329 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
10332 * This information is deleted after a job is completed or canceled,
10333 * so reprints may require subsequent re-authentication.
10339 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
10343 * Create the authentication file and change permissions...
10346 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
10347 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
10349 cupsdLogMessage(CUPSD_LOG_ERROR
,
10350 "Unable to save authentication info to \"%s\" - %s",
10351 filename
, strerror(errno
));
10355 fchown(cupsFileNumber(fp
), 0, 0);
10356 fchmod(cupsFileNumber(fp
), 0400);
10358 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
10361 * Write 1 to 3 auth values...
10364 cupsdClearString(&job
->auth_username
);
10365 cupsdClearString(&job
->auth_domain
);
10366 cupsdClearString(&job
->auth_password
);
10368 for (i
= 0; i
< auth_info
->num_values
; i
++)
10370 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
10371 strlen(auth_info
->values
[i
].string
.text
));
10372 cupsFilePrintf(fp
, "%s\n", line
);
10374 if (!strcmp(dest
->auth_info_required
[i
], "username"))
10375 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
10376 auth_info
->values
[i
].string
.text
);
10377 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
10378 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
10379 auth_info
->values
[i
].string
.text
);
10380 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
10381 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
10382 auth_info
->values
[i
].string
.text
);
10385 else if (con
->username
[0])
10388 * Write the authenticated username...
10391 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
10392 cupsFilePrintf(fp
, "%s\n", line
);
10394 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
10395 cupsdClearString(&job
->auth_domain
);
10398 * Write the authenticated password...
10401 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10402 cupsFilePrintf(fp
, "%s\n", line
);
10404 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
10408 * Write a random number of newlines to the end of the file...
10411 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10412 cupsFilePutChar(fp
, '\n');
10415 * Close the file and return...
10420 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10421 # ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
10422 if (con
->have_gss
&&
10423 (con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
|| con
->gss_creds
))
10425 if (con
->have_gss
&& con
->gss_creds
)
10426 # endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
10427 save_krb5_creds(con
, job
);
10428 else if (job
->ccname
)
10429 cupsdClearString(&(job
->ccname
));
10430 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10434 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10436 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
10440 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
10441 cupsd_job_t
*job
) /* I - Job */
10444 * Get the credentials...
10447 job
->ccache
= cupsdCopyKrb5Creds(con
);
10450 * Add the KRB5CCNAME environment variable to the job so that the
10451 * backend can use the credentials when printing.
10456 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
10457 krb5_cc_get_name(KerberosContext
, job
->ccache
));
10459 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
10462 cupsdClearString(&(job
->ccname
));
10464 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10468 * 'send_document()' - Send a file to a printer or class.
10472 send_document(cupsd_client_t
*con
, /* I - Client connection */
10473 ipp_attribute_t
*uri
) /* I - Printer URI */
10475 ipp_attribute_t
*attr
; /* Current attribute */
10476 ipp_attribute_t
*format
; /* Request's document-format attribute */
10477 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10478 const char *default_format
;/* document-format-default value */
10479 int jobid
; /* Job ID number */
10480 cupsd_job_t
*job
; /* Current job */
10481 char job_uri
[HTTP_MAX_URI
],
10483 scheme
[HTTP_MAX_URI
],
10484 /* Method portion of URI */
10485 username
[HTTP_MAX_URI
],
10486 /* Username portion of URI */
10487 host
[HTTP_MAX_URI
],
10488 /* Host portion of URI */
10489 resource
[HTTP_MAX_URI
];
10490 /* Resource portion of URI */
10491 int port
; /* Port portion of URI */
10492 mime_type_t
*filetype
; /* Type of file */
10493 char super
[MIME_MAX_SUPER
],
10494 /* Supertype of file */
10495 type
[MIME_MAX_TYPE
],
10496 /* Subtype of file */
10497 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10498 /* Textual name of mime type */
10499 char filename
[1024]; /* Job filename */
10500 cupsd_printer_t
*printer
; /* Current printer */
10501 struct stat fileinfo
; /* File information */
10502 int kbytes
; /* Size of file */
10503 int compression
; /* Type of compression */
10504 int start_job
; /* Start the job? */
10507 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10508 con
->http
.fd
, uri
->values
[0].string
.text
);
10511 * See if we have a job URI or a printer URI...
10514 if (!strcmp(uri
->name
, "printer-uri"))
10517 * Got a printer URI; see if we also have a job-id attribute...
10520 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10521 IPP_TAG_INTEGER
)) == NULL
)
10523 send_ipp_status(con
, IPP_BAD_REQUEST
,
10524 _("Got a printer-uri attribute but no job-id"));
10528 jobid
= attr
->values
[0].integer
;
10533 * Got a job URI; parse it to get the job ID...
10536 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10537 sizeof(scheme
), username
, sizeof(username
), host
,
10538 sizeof(host
), &port
, resource
, sizeof(resource
));
10540 if (strncmp(resource
, "/jobs/", 6))
10546 send_ipp_status(con
, IPP_BAD_REQUEST
,
10547 _("Bad job-uri attribute \"%s\""),
10548 uri
->values
[0].string
.text
);
10552 jobid
= atoi(resource
+ 6);
10556 * See if the job exists...
10559 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10562 * Nope - return a "not found" error...
10565 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10569 printer
= cupsdFindDest(job
->dest
);
10572 * See if the job is owned by the requesting user...
10575 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10577 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10578 cupsdFindDest(job
->dest
));
10583 * OK, see if the client is sending the document compressed - CUPS
10584 * only supports "none" and "gzip".
10587 compression
= CUPS_FILE_NONE
;
10589 if ((attr
= ippFindAttribute(con
->request
, "compression",
10590 IPP_TAG_KEYWORD
)) != NULL
)
10592 if (strcmp(attr
->values
[0].string
.text
, "none")
10594 && strcmp(attr
->values
[0].string
.text
, "gzip")
10595 #endif /* HAVE_LIBZ */
10598 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\""),
10599 attr
->values
[0].string
.text
);
10600 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10601 "compression", NULL
, attr
->values
[0].string
.text
);
10606 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10607 compression
= CUPS_FILE_GZIP
;
10608 #endif /* HAVE_LIBZ */
10612 * Do we have a file to print?
10615 if (!con
->filename
)
10618 * Check for an empty request with "last-document" set to true, which is
10619 * used to close an "open" job by RFC 2911, section 3.3.2.
10622 if (job
->num_files
> 0 &&
10623 (attr
= ippFindAttribute(con
->request
, "last-document",
10624 IPP_TAG_BOOLEAN
)) != NULL
&&
10625 attr
->values
[0].boolean
)
10626 goto last_document
;
10628 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
10633 * Is it a format we support?
10636 if ((format
= ippFindAttribute(con
->request
, "document-format",
10637 IPP_TAG_MIMETYPE
)) != NULL
)
10640 * Grab format from client...
10643 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10646 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
10647 format
->values
[0].string
.text
);
10651 else if ((default_format
= cupsGetOption("document-format",
10652 printer
->num_options
,
10653 printer
->options
)) != NULL
)
10656 * Use default document format...
10659 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10661 send_ipp_status(con
, IPP_BAD_REQUEST
,
10662 _("Could not scan type \"%s\""),
10670 * No document format attribute? Auto-type it!
10673 strcpy(super
, "application");
10674 strcpy(type
, "octet-stream");
10677 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10680 * Auto-type the file...
10683 ipp_attribute_t
*doc_name
; /* document-name attribute */
10686 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10688 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10689 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10690 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10694 filetype
= mimeType(MimeDatabase
, super
, type
);
10697 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10698 filetype
->super
, filetype
->type
);
10701 filetype
= mimeType(MimeDatabase
, super
, type
);
10706 * Replace the document-format attribute value with the auto-typed or
10710 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10713 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10714 IPP_TAG_MIMETYPE
)) != NULL
)
10716 _cupsStrFree(jformat
->values
[0].string
.text
);
10718 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10721 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10722 "document-format", NULL
, mimetype
);
10724 else if (!filetype
)
10726 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10727 _("Unsupported format \'%s/%s\'"), super
, type
);
10728 cupsdLogMessage(CUPSD_LOG_INFO
,
10729 "Hint: Do you have the raw file printing rules enabled?");
10732 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10733 "document-format", NULL
, format
->values
[0].string
.text
);
10738 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10740 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10743 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10744 _("Unsupported format \'%s\'"), mimetype
);
10746 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10747 "document-format", NULL
, mimetype
);
10753 * Add the file to the job...
10758 if (add_file(con
, job
, filetype
, compression
))
10761 if (stat(con
->filename
, &fileinfo
))
10764 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10766 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10768 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10769 IPP_TAG_INTEGER
)) != NULL
)
10770 attr
->values
[0].integer
+= kbytes
;
10772 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10774 rename(con
->filename
, filename
);
10776 cupsdClearString(&con
->filename
);
10778 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10779 filetype
->super
, filetype
->type
, job
->username
);
10782 * Start the job if this is the last document...
10787 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10788 IPP_TAG_BOOLEAN
)) != NULL
&&
10789 attr
->values
[0].boolean
)
10792 * See if we need to add the ending sheet...
10795 if (cupsdTimeoutJob(job
))
10798 if (job
->state_value
== IPP_JOB_STOPPED
)
10800 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10801 job
->state_value
= IPP_JOB_PENDING
;
10803 else if (job
->state_value
== IPP_JOB_HELD
)
10805 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10806 IPP_TAG_KEYWORD
)) == NULL
)
10807 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10809 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10811 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10812 job
->state_value
= IPP_JOB_PENDING
;
10817 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10823 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10824 IPP_TAG_KEYWORD
)) == NULL
)
10825 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10827 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10829 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10830 job
->state_value
= IPP_JOB_HELD
;
10831 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10834 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10841 * Fill in the response info...
10844 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10847 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10850 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10852 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10854 add_job_state_reasons(con
, job
);
10856 con
->response
->request
.status
.status_code
= IPP_OK
;
10859 * Start the job if necessary...
10868 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10873 cupsd_client_t
*con
, /* I - Client connection */
10874 http_status_t status
, /* I - HTTP status code */
10875 cupsd_printer_t
*printer
) /* I - Printer, if any */
10877 ipp_attribute_t
*uri
; /* Request URI, if any */
10880 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10881 IPP_TAG_URI
)) == NULL
)
10882 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10884 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10885 "Returning HTTP %s for %s (%s) from %s",
10886 httpStatus(status
),
10887 ippOpString(con
->request
->request
.op
.operation_id
),
10888 uri
? uri
->values
[0].string
.text
: "no URI",
10889 con
->http
.hostname
);
10893 int auth_type
; /* Type of authentication required */
10896 auth_type
= CUPSD_AUTH_NONE
;
10898 if (status
== HTTP_UNAUTHORIZED
&&
10899 printer
->num_auth_info_required
> 0 &&
10900 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10902 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10903 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10904 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10907 * Creating and authenticating jobs requires Kerberos...
10910 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10915 * Use policy/location-defined authentication requirements...
10918 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10919 cupsd_location_t
*auth
; /* Pointer to authentication element */
10922 if (printer
->type
& CUPS_PRINTER_CLASS
)
10923 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10925 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10927 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10928 auth
->type
== CUPSD_AUTH_NONE
)
10929 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10931 con
->request
->request
.op
.operation_id
:
10936 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10937 auth_type
= DefaultAuthType
;
10939 auth_type
= auth
->type
;
10943 cupsdSendError(con
, status
, auth_type
);
10946 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10948 ippDelete(con
->response
);
10949 con
->response
= NULL
;
10956 * 'send_ipp_status()' - Send a status back to the IPP client.
10960 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10961 ipp_status_t status
, /* I - IPP status code */
10962 const char *message
,/* I - Status message */
10963 ...) /* I - Additional args as needed */
10965 va_list ap
; /* Pointer to additional args */
10966 char formatted
[1024]; /* Formatted errror message */
10969 va_start(ap
, message
);
10970 vsnprintf(formatted
, sizeof(formatted
),
10971 _cupsLangString(con
->language
, message
), ap
);
10974 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10975 ippOpString(con
->request
->request
.op
.operation_id
),
10976 ippErrorString(status
), formatted
);
10978 con
->response
->request
.status
.status_code
= status
;
10980 if (ippFindAttribute(con
->response
, "attributes-charset",
10981 IPP_TAG_ZERO
) == NULL
)
10982 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10983 "attributes-charset", NULL
, "utf-8");
10985 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10986 IPP_TAG_ZERO
) == NULL
)
10987 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10988 "attributes-natural-language", NULL
, DefaultLanguage
);
10990 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10991 "status-message", NULL
, formatted
);
10996 * 'set_default()' - Set the default destination...
11000 set_default(cupsd_client_t
*con
, /* I - Client connection */
11001 ipp_attribute_t
*uri
) /* I - Printer URI */
11003 http_status_t status
; /* Policy status */
11004 cups_ptype_t dtype
; /* Destination type (printer/class) */
11005 cupsd_printer_t
*printer
, /* Printer */
11006 *oldprinter
; /* Old default printer */
11009 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
11010 con
->http
.fd
, uri
->values
[0].string
.text
);
11013 * Is the destination valid?
11016 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11022 send_ipp_status(con
, IPP_NOT_FOUND
,
11023 _("The printer or class was not found."));
11031 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
11033 send_http_error(con
, status
, NULL
);
11038 * Set it as the default...
11041 oldprinter
= DefaultPrinter
;
11042 DefaultPrinter
= printer
;
11045 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
11046 "%s is no longer the default printer.", oldprinter
->name
);
11048 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
11049 "%s is now the default printer.", printer
->name
);
11051 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
11052 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
11054 cupsdLogMessage(CUPSD_LOG_INFO
,
11055 "Default destination set to \"%s\" by \"%s\".",
11056 printer
->name
, get_username(con
));
11059 * Everything was ok, so return OK status...
11062 con
->response
->request
.status
.status_code
= IPP_OK
;
11067 * 'set_job_attrs()' - Set job attributes.
11071 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
11072 ipp_attribute_t
*uri
) /* I - Job URI */
11074 ipp_attribute_t
*attr
, /* Current attribute */
11075 *attr2
; /* Job attribute */
11076 int jobid
; /* Job ID */
11077 cupsd_job_t
*job
; /* Current job */
11078 char scheme
[HTTP_MAX_URI
],
11079 /* Method portion of URI */
11080 username
[HTTP_MAX_URI
],
11081 /* Username portion of URI */
11082 host
[HTTP_MAX_URI
],
11083 /* Host portion of URI */
11084 resource
[HTTP_MAX_URI
];
11085 /* Resource portion of URI */
11086 int port
; /* Port portion of URI */
11087 int event
; /* Events? */
11088 int check_jobs
; /* Check jobs? */
11091 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
11092 con
->http
.fd
, uri
->values
[0].string
.text
);
11095 * Start with "everything is OK" status...
11098 con
->response
->request
.status
.status_code
= IPP_OK
;
11101 * See if we have a job URI or a printer URI...
11104 if (!strcmp(uri
->name
, "printer-uri"))
11107 * Got a printer URI; see if we also have a job-id attribute...
11110 if ((attr
= ippFindAttribute(con
->request
, "job-id",
11111 IPP_TAG_INTEGER
)) == NULL
)
11113 send_ipp_status(con
, IPP_BAD_REQUEST
,
11114 _("Got a printer-uri attribute but no job-id"));
11118 jobid
= attr
->values
[0].integer
;
11123 * Got a job URI; parse it to get the job ID...
11126 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
11127 sizeof(scheme
), username
, sizeof(username
), host
,
11128 sizeof(host
), &port
, resource
, sizeof(resource
));
11130 if (strncmp(resource
, "/jobs/", 6))
11136 send_ipp_status(con
, IPP_BAD_REQUEST
,
11137 _("Bad job-uri attribute \"%s\""),
11138 uri
->values
[0].string
.text
);
11142 jobid
= atoi(resource
+ 6);
11146 * See if the job exists...
11149 if ((job
= cupsdFindJob(jobid
)) == NULL
)
11152 * Nope - return a "not found" error...
11155 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
11160 * See if the job has been completed...
11163 if (job
->state_value
> IPP_JOB_STOPPED
)
11166 * Return a "not-possible" error...
11169 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11170 _("Job #%d is finished and cannot be altered"), jobid
);
11175 * See if the job is owned by the requesting user...
11178 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
11180 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
11181 cupsdFindDest(job
->dest
));
11186 * See what the user wants to change.
11194 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11196 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
11199 if (!strcmp(attr
->name
, "attributes-charset") ||
11200 !strcmp(attr
->name
, "attributes-natural-language") ||
11201 !strcmp(attr
->name
, "document-compression") ||
11202 !strcmp(attr
->name
, "document-format") ||
11203 !strcmp(attr
->name
, "job-detailed-status-messages") ||
11204 !strcmp(attr
->name
, "job-document-access-errors") ||
11205 !strcmp(attr
->name
, "job-id") ||
11206 !strcmp(attr
->name
, "job-impressions-completed") ||
11207 !strcmp(attr
->name
, "job-k-octets") ||
11208 !strcmp(attr
->name
, "job-originating-host-name") ||
11209 !strcmp(attr
->name
, "job-originating-user-name") ||
11210 !strcmp(attr
->name
, "job-printer-up-time") ||
11211 !strcmp(attr
->name
, "job-printer-uri") ||
11212 !strcmp(attr
->name
, "job-sheets") ||
11213 !strcmp(attr
->name
, "job-state-message") ||
11214 !strcmp(attr
->name
, "job-state-reasons") ||
11215 !strcmp(attr
->name
, "job-uri") ||
11216 !strcmp(attr
->name
, "number-of-documents") ||
11217 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
11218 !strcmp(attr
->name
, "output-device-assigned") ||
11219 !strncmp(attr
->name
, "date-time-at-", 13) ||
11220 !strncmp(attr
->name
, "job-k-octets", 12) ||
11221 !strncmp(attr
->name
, "job-media-sheets", 16) ||
11222 !strncmp(attr
->name
, "time-at-", 8))
11228 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
11229 _("%s cannot be changed."), attr
->name
);
11231 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11232 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11237 if (!strcmp(attr
->name
, "job-priority"))
11240 * Change the job priority...
11243 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11245 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value"));
11247 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11248 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11250 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
11252 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11253 _("Job is completed and cannot be changed."));
11256 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11258 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
11259 attr
->values
[0].integer
);
11260 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
11263 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
11264 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
11267 else if (!strcmp(attr
->name
, "job-state"))
11270 * Change the job state...
11273 if (attr
->value_tag
!= IPP_TAG_ENUM
)
11275 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value"));
11277 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11278 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11282 switch (attr
->values
[0].integer
)
11284 case IPP_JOB_PENDING
:
11285 case IPP_JOB_HELD
:
11286 if (job
->state_value
> IPP_JOB_HELD
)
11288 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11289 _("Job state cannot be changed."));
11292 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11294 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11295 attr
->values
[0].integer
);
11296 cupsdSetJobState(job
, attr
->values
[0].integer
,
11298 "Job state changed by \"%s\"", username
);
11303 case IPP_JOB_PROCESSING
:
11304 case IPP_JOB_STOPPED
:
11305 if (job
->state_value
!= attr
->values
[0].integer
)
11307 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11308 _("Job state cannot be changed."));
11313 case IPP_JOB_CANCELED
:
11314 case IPP_JOB_ABORTED
:
11315 case IPP_JOB_COMPLETED
:
11316 if (job
->state_value
> IPP_JOB_PROCESSING
)
11318 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11319 _("Job state cannot be changed."));
11322 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11324 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11325 attr
->values
[0].integer
);
11326 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
11328 "Job state changed by \"%s\"", username
);
11335 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
11337 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11338 IPP_TAG_ZERO
)) != NULL
)
11341 * Some other value; first free the old value...
11344 if (job
->attrs
->prev
)
11345 job
->attrs
->prev
->next
= attr2
->next
;
11347 job
->attrs
->attrs
= attr2
->next
;
11349 if (job
->attrs
->last
== attr2
)
11350 job
->attrs
->last
= job
->attrs
->prev
;
11352 _ippFreeAttr(attr2
);
11355 * Then copy the attribute...
11358 copy_attribute(job
->attrs
, attr
, 0);
11361 * See if the job-name or job-hold-until is being changed.
11364 if (!strcmp(attr
->name
, "job-hold-until"))
11366 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
11367 attr
->values
[0].string
.text
);
11368 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
11370 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
11372 cupsdReleaseJob(job
);
11376 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
11377 "Job held by \"%s\".", username
);
11379 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
11382 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
11385 * Delete the attribute...
11388 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11389 IPP_TAG_ZERO
)) != NULL
)
11391 if (job
->attrs
->prev
)
11392 job
->attrs
->prev
->next
= attr2
->next
;
11394 job
->attrs
->attrs
= attr2
->next
;
11396 if (attr2
== job
->attrs
->last
)
11397 job
->attrs
->last
= job
->attrs
->prev
;
11399 _ippFreeAttr(attr2
);
11401 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11407 * Add new option by copying it...
11410 copy_attribute(job
->attrs
, attr
, 0);
11412 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11421 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11424 * Send events as needed...
11427 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11428 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11429 cupsdFindDest(job
->dest
), job
,
11430 "Job priority changed by user.");
11432 if (event
& CUPSD_EVENT_JOB_STATE
)
11433 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11434 job
->state_value
== IPP_JOB_HELD
?
11435 "Job held by user." : "Job restarted by user.");
11437 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11438 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11439 "Job options changed by user.");
11442 * Start jobs if possible...
11451 * 'set_printer_attrs()' - Set printer attributes.
11455 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11456 ipp_attribute_t
*uri
) /* I - Printer */
11458 http_status_t status
; /* Policy status */
11459 cups_ptype_t dtype
; /* Destination type (printer/class) */
11460 cupsd_printer_t
*printer
; /* Printer/class */
11461 ipp_attribute_t
*attr
; /* Printer attribute */
11462 int changed
= 0; /* Was anything changed? */
11465 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11466 con
->http
.fd
, uri
->values
[0].string
.text
);
11469 * Is the destination valid?
11472 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11478 send_ipp_status(con
, IPP_NOT_FOUND
,
11479 _("The printer or class was not found."));
11487 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11489 send_http_error(con
, status
, printer
);
11494 * Return a list of attributes that can be set via Set-Printer-Attributes.
11497 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11498 IPP_TAG_TEXT
)) != NULL
)
11500 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11504 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11505 IPP_TAG_TEXT
)) != NULL
)
11507 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11512 * Update the printer attributes and return...
11517 cupsdSetPrinterAttrs(printer
);
11518 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11520 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11521 "Printer \"%s\" description or location changed by \"%s\".",
11522 printer
->name
, get_username(con
));
11524 cupsdLogMessage(CUPSD_LOG_INFO
,
11525 "Printer \"%s\" description or location changed by \"%s\".",
11526 printer
->name
, get_username(con
));
11529 con
->response
->request
.status
.status_code
= IPP_OK
;
11534 * 'set_printer_defaults()' - Set printer default options from a request.
11538 set_printer_defaults(
11539 cupsd_client_t
*con
, /* I - Client connection */
11540 cupsd_printer_t
*printer
) /* I - Printer */
11542 int i
; /* Looping var */
11543 ipp_attribute_t
*attr
; /* Current attribute */
11544 int namelen
; /* Length of attribute name */
11545 char name
[256], /* New attribute name */
11546 value
[256]; /* String version of integer attrs */
11549 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11552 * Skip non-printer attributes...
11555 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11558 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11560 if (!strcmp(attr
->name
, "job-sheets-default"))
11563 * Only allow keywords and names...
11566 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11570 * Only allow job-sheets-default to be set when running without a
11571 * system high classification level...
11574 if (Classification
)
11577 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11579 if (attr
->num_values
> 1)
11580 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11582 cupsdSetString(&printer
->job_sheets
[1], "none");
11584 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11586 cupsdFreeStrings(&(printer
->users
));
11588 printer
->deny_users
= 0;
11590 if (attr
->value_tag
== IPP_TAG_NAME
&&
11591 (attr
->num_values
> 1 ||
11592 strcmp(attr
->values
[0].string
.text
, "all")))
11594 for (i
= 0; i
< attr
->num_values
; i
++)
11595 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11598 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11600 cupsdFreeStrings(&(printer
->users
));
11602 printer
->deny_users
= 1;
11604 if (attr
->value_tag
== IPP_TAG_NAME
&&
11605 (attr
->num_values
> 1 ||
11606 strcmp(attr
->values
[0].string
.text
, "none")))
11608 for (i
= 0; i
< attr
->num_values
; i
++)
11609 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11612 else if (!strcmp(attr
->name
, "job-quota-period"))
11614 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11617 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11618 attr
->values
[0].integer
);
11619 cupsdFreeQuotas(printer
);
11621 printer
->quota_period
= attr
->values
[0].integer
;
11623 else if (!strcmp(attr
->name
, "job-k-limit"))
11625 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11628 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11629 attr
->values
[0].integer
);
11630 cupsdFreeQuotas(printer
);
11632 printer
->k_limit
= attr
->values
[0].integer
;
11634 else if (!strcmp(attr
->name
, "job-page-limit"))
11636 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11639 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11640 attr
->values
[0].integer
);
11641 cupsdFreeQuotas(printer
);
11643 printer
->page_limit
= attr
->values
[0].integer
;
11645 else if (!strcmp(attr
->name
, "printer-op-policy"))
11647 cupsd_policy_t
*p
; /* Policy */
11650 if (attr
->value_tag
!= IPP_TAG_NAME
)
11653 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11655 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11656 "Setting printer-op-policy to \"%s\"...",
11657 attr
->values
[0].string
.text
);
11658 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11659 printer
->op_policy_ptr
= p
;
11663 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11664 _("Unknown printer-op-policy \"%s\"."),
11665 attr
->values
[0].string
.text
);
11669 else if (!strcmp(attr
->name
, "printer-error-policy"))
11671 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11674 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11675 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
11676 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11677 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11678 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11680 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11681 _("Unknown printer-error-policy \"%s\"."),
11682 attr
->values
[0].string
.text
);
11686 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11687 "Setting printer-error-policy to \"%s\"...",
11688 attr
->values
[0].string
.text
);
11689 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11693 * Skip any other non-default attributes...
11696 namelen
= strlen(attr
->name
);
11697 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11698 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11702 * OK, anything else must be a user-defined default...
11705 strlcpy(name
, attr
->name
, sizeof(name
));
11706 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11708 switch (attr
->value_tag
)
11710 case IPP_TAG_DELETEATTR
:
11711 printer
->num_options
= cupsRemoveOption(name
,
11712 printer
->num_options
,
11713 &(printer
->options
));
11714 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11715 "Deleting %s", attr
->name
);
11718 case IPP_TAG_NAME
:
11719 case IPP_TAG_KEYWORD
:
11721 printer
->num_options
= cupsAddOption(name
,
11722 attr
->values
[0].string
.text
,
11723 printer
->num_options
,
11724 &(printer
->options
));
11725 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11726 "Setting %s to \"%s\"...", attr
->name
,
11727 attr
->values
[0].string
.text
);
11730 case IPP_TAG_BOOLEAN
:
11731 printer
->num_options
= cupsAddOption(name
,
11732 attr
->values
[0].boolean
?
11734 printer
->num_options
,
11735 &(printer
->options
));
11736 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11737 "Setting %s to %s...", attr
->name
,
11738 attr
->values
[0].boolean
? "true" : "false");
11741 case IPP_TAG_INTEGER
:
11742 case IPP_TAG_ENUM
:
11743 sprintf(value
, "%d", attr
->values
[0].integer
);
11744 printer
->num_options
= cupsAddOption(name
, value
,
11745 printer
->num_options
,
11746 &(printer
->options
));
11747 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11748 "Setting %s to %s...", attr
->name
, value
);
11751 case IPP_TAG_RANGE
:
11752 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11753 attr
->values
[0].range
.upper
);
11754 printer
->num_options
= cupsAddOption(name
, value
,
11755 printer
->num_options
,
11756 &(printer
->options
));
11757 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11758 "Setting %s to %s...", attr
->name
, value
);
11761 case IPP_TAG_RESOLUTION
:
11762 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11763 attr
->values
[0].resolution
.yres
,
11764 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11766 printer
->num_options
= cupsAddOption(name
, value
,
11767 printer
->num_options
,
11768 &(printer
->options
));
11769 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11770 "Setting %s to %s...", attr
->name
, value
);
11774 /* Do nothing for other values */
11782 * 'start_printer()' - Start a printer.
11786 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11787 ipp_attribute_t
*uri
) /* I - Printer URI */
11789 int i
; /* Temporary variable */
11790 http_status_t status
; /* Policy status */
11791 cups_ptype_t dtype
; /* Destination type (printer/class) */
11792 cupsd_printer_t
*printer
; /* Printer data */
11795 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11796 con
->http
.fd
, uri
->values
[0].string
.text
);
11799 * Is the destination valid?
11802 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11808 send_ipp_status(con
, IPP_NOT_FOUND
,
11809 _("The printer or class was not found."));
11817 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11819 send_http_error(con
, status
, printer
);
11824 * Start the printer...
11827 printer
->state_message
[0] = '\0';
11829 cupsdStartPrinter(printer
, 1);
11831 if (dtype
& CUPS_PRINTER_CLASS
)
11832 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11833 printer
->name
, get_username(con
));
11835 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11836 printer
->name
, get_username(con
));
11844 if ((i
= check_quotas(con
, printer
)) < 0)
11846 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
11851 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
11856 * Everything was ok, so return OK status...
11859 con
->response
->request
.status
.status_code
= IPP_OK
;
11864 * 'stop_printer()' - Stop a printer.
11868 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11869 ipp_attribute_t
*uri
) /* I - Printer URI */
11871 http_status_t status
; /* Policy status */
11872 cups_ptype_t dtype
; /* Destination type (printer/class) */
11873 cupsd_printer_t
*printer
; /* Printer data */
11874 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11877 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11878 con
->http
.fd
, uri
->values
[0].string
.text
);
11881 * Is the destination valid?
11884 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11890 send_ipp_status(con
, IPP_NOT_FOUND
,
11891 _("The printer or class was not found."));
11899 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11901 send_http_error(con
, status
, printer
);
11906 * Stop the printer...
11909 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11910 IPP_TAG_TEXT
)) == NULL
)
11911 strcpy(printer
->state_message
, "Paused");
11914 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11915 sizeof(printer
->state_message
));
11918 cupsdStopPrinter(printer
, 1);
11920 if (dtype
& CUPS_PRINTER_CLASS
)
11921 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11922 printer
->name
, get_username(con
));
11924 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11925 printer
->name
, get_username(con
));
11928 * Everything was ok, so return OK status...
11931 con
->response
->request
.status
.status_code
= IPP_OK
;
11936 * 'url_encode_attr()' - URL-encode a string attribute.
11940 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11941 char *buffer
,/* I - String buffer */
11942 int bufsize
)/* I - Size of buffer */
11944 int i
; /* Looping var */
11945 char *bufptr
, /* Pointer into buffer */
11946 *bufend
; /* End of buffer */
11949 strlcpy(buffer
, attr
->name
, bufsize
);
11950 bufptr
= buffer
+ strlen(buffer
);
11951 bufend
= buffer
+ bufsize
- 1;
11953 for (i
= 0; i
< attr
->num_values
; i
++)
11955 if (bufptr
>= bufend
)
11963 if (bufptr
>= bufend
)
11968 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11969 bufptr
, bufend
- bufptr
+ 1);
11971 if (bufptr
>= bufend
)
11982 * 'url_encode_string()' - URL-encode a string.
11985 static char * /* O - End of string */
11986 url_encode_string(const char *s
, /* I - String */
11987 char *buffer
, /* I - String buffer */
11988 int bufsize
) /* I - Size of buffer */
11990 char *bufptr
, /* Pointer into buffer */
11991 *bufend
; /* End of buffer */
11992 static const char *hex
= "0123456789ABCDEF";
11997 bufend
= buffer
+ bufsize
- 1;
11999 while (*s
&& bufptr
< bufend
)
12001 if (*s
== ' ' || *s
== '%' || *s
== '+')
12003 if (bufptr
>= (bufend
- 2))
12007 *bufptr
++ = hex
[(*s
>> 4) & 15];
12008 *bufptr
++ = hex
[*s
& 15];
12012 else if (*s
== '\'' || *s
== '\\')
12014 if (bufptr
>= (bufend
- 1))
12031 * 'user_allowed()' - See if a user is allowed to print to a queue.
12034 static int /* O - 0 if not allowed, 1 if allowed */
12035 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
12036 const char *username
) /* I - Username */
12038 struct passwd
*pw
; /* User password data */
12039 char baseuser
[256], /* Base username */
12040 *baseptr
, /* Pointer to "@" in base username */
12041 *name
; /* Current user name */
12044 if (cupsArrayCount(p
->users
) == 0)
12047 if (!strcmp(username
, "root"))
12050 if (strchr(username
, '@'))
12053 * Strip @REALM for username check...
12056 strlcpy(baseuser
, username
, sizeof(baseuser
));
12058 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
12061 username
= baseuser
;
12064 pw
= getpwnam(username
);
12067 for (name
= (char *)cupsArrayFirst(p
->users
);
12069 name
= (char *)cupsArrayNext(p
->users
))
12071 if (name
[0] == '@')
12074 * Check group membership...
12077 if (cupsdCheckGroup(username
, pw
, name
+ 1))
12080 else if (name
[0] == '#')
12086 if (cupsdCheckGroup(username
, pw
, name
))
12089 else if (!strcasecmp(username
, name
))
12093 return ((name
!= NULL
) != p
->deny_users
);
12098 * 'validate_job()' - Validate printer options and destination.
12102 validate_job(cupsd_client_t
*con
, /* I - Client connection */
12103 ipp_attribute_t
*uri
) /* I - Printer URI */
12105 http_status_t status
; /* Policy status */
12106 ipp_attribute_t
*attr
, /* Current attribute */
12107 *auth_info
; /* auth-info attribute */
12108 ipp_attribute_t
*format
; /* Document-format attribute */
12109 cups_ptype_t dtype
; /* Destination type (printer/class) */
12110 char super
[MIME_MAX_SUPER
],
12111 /* Supertype of file */
12112 type
[MIME_MAX_TYPE
];
12113 /* Subtype of file */
12114 cupsd_printer_t
*printer
; /* Printer */
12117 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
12118 con
->http
.fd
, uri
->values
[0].string
.text
);
12121 * OK, see if the client is sending the document compressed - CUPS
12122 * doesn't support compression yet...
12125 if ((attr
= ippFindAttribute(con
->request
, "compression",
12126 IPP_TAG_KEYWORD
)) != NULL
)
12128 if (strcmp(attr
->values
[0].string
.text
, "none")
12130 && strcmp(attr
->values
[0].string
.text
, "gzip")
12131 #endif /* HAVE_LIBZ */
12134 send_ipp_status(con
, IPP_ATTRIBUTES
,
12135 _("Unsupported compression \"%s\""),
12136 attr
->values
[0].string
.text
);
12137 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
12138 "compression", NULL
, attr
->values
[0].string
.text
);
12144 * Is it a format we support?
12147 if ((format
= ippFindAttribute(con
->request
, "document-format",
12148 IPP_TAG_MIMETYPE
)) != NULL
)
12150 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
12153 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
12154 format
->values
[0].string
.text
);
12158 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
12159 !mimeType(MimeDatabase
, super
, type
))
12161 cupsdLogMessage(CUPSD_LOG_INFO
,
12162 "Hint: Do you have the raw file printing rules enabled?");
12163 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
12164 _("Unsupported document-format \"%s\""),
12165 format
->values
[0].string
.text
);
12166 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
12167 "document-format", NULL
, format
->values
[0].string
.text
);
12173 * Is the destination valid?
12176 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
12182 send_ipp_status(con
, IPP_NOT_FOUND
,
12183 _("The printer or class was not found."));
12191 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
12193 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
12195 send_http_error(con
, status
, printer
);
12198 else if (printer
->num_auth_info_required
== 1 &&
12199 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
12202 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
12206 else if (auth_info
&& !con
->http
.tls
&&
12207 !httpAddrLocalhost(con
->http
.hostaddr
))
12210 * Require encryption of auth-info over non-local connections...
12213 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
12216 #endif /* HAVE_SSL */
12219 * Everything was ok, so return OK status...
12222 con
->response
->request
.status
.status_code
= IPP_OK
;
12227 * 'validate_name()' - Make sure the printer name only contains valid chars.
12230 static int /* O - 0 if name is no good, 1 if good */
12231 validate_name(const char *name
) /* I - Name to check */
12233 const char *ptr
; /* Pointer into name */
12237 * Scan the whole name...
12240 for (ptr
= name
; *ptr
; ptr
++)
12241 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
12245 * All the characters are good; validate the length, too...
12248 return ((ptr
- name
) < 128);
12253 * 'validate_user()' - Validate the user for the request.
12256 static int /* O - 1 if permitted, 0 otherwise */
12257 validate_user(cupsd_job_t
*job
, /* I - Job */
12258 cupsd_client_t
*con
, /* I - Client connection */
12259 const char *owner
, /* I - Owner of job/resource */
12260 char *username
, /* O - Authenticated username */
12261 int userlen
) /* I - Length of username */
12263 cupsd_printer_t
*printer
; /* Printer for job */
12266 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
12267 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
12269 job
->id
, con
? con
->http
.fd
: 0,
12270 owner
? owner
: "(null)", username
, userlen
);
12273 * Validate input...
12276 if (!con
|| !owner
|| !username
|| userlen
<= 0)
12280 * Get the best authenticated username that is available.
12283 strlcpy(username
, get_username(con
), userlen
);
12286 * Check the username against the owner...
12289 printer
= cupsdFindDest(job
->dest
);
12291 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
12292 con
, owner
) == HTTP_OK
);
12297 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".