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 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
930 "Now accepting jobs.");
932 if (dtype
& CUPS_PRINTER_CLASS
)
934 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
936 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
937 printer
->name
, get_username(con
));
941 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
943 cupsdLogMessage(CUPSD_LOG_INFO
,
944 "Printer \"%s\" now accepting jobs (\"%s\").",
945 printer
->name
, get_username(con
));
949 * Everything was ok, so return OK status...
952 con
->response
->request
.status
.status_code
= IPP_OK
;
957 * 'add_class()' - Add a class to the system.
961 add_class(cupsd_client_t
*con
, /* I - Client connection */
962 ipp_attribute_t
*uri
) /* I - URI of class */
964 http_status_t status
; /* Policy status */
965 int i
; /* Looping var */
966 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
967 username
[HTTP_MAX_URI
], /* Username portion of URI */
968 host
[HTTP_MAX_URI
], /* Host portion of URI */
969 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
970 int port
; /* Port portion of URI */
971 cupsd_printer_t
*pclass
, /* Class */
972 *member
; /* Member printer/class */
973 cups_ptype_t dtype
; /* Destination type */
974 ipp_attribute_t
*attr
; /* Printer attribute */
975 int modify
; /* Non-zero if we just modified */
976 char newname
[IPP_MAX_NAME
]; /* New class name */
977 int need_restart_job
; /* Need to restart job? */
980 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
981 con
->http
.fd
, uri
->values
[0].string
.text
);
984 * Do we have a valid URI?
987 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
988 sizeof(scheme
), username
, sizeof(username
), host
,
989 sizeof(host
), &port
, resource
, sizeof(resource
));
992 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
995 * No, return an error...
998 send_ipp_status(con
, IPP_BAD_REQUEST
,
999 _("The printer-uri must be of the form "
1000 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
1005 * Do we have a valid printer name?
1008 if (!validate_name(resource
+ 9))
1011 * No, return an error...
1014 send_ipp_status(con
, IPP_BAD_REQUEST
,
1015 _("The printer-uri \"%s\" contains invalid characters."),
1016 uri
->values
[0].string
.text
);
1021 * See if the class already exists; if not, create a new class...
1024 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1027 * Class doesn't exist; see if we have a printer of the same name...
1030 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
1031 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
1034 * Yes, return an error...
1037 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1038 _("A printer named \"%s\" already exists"),
1044 * No, check the default policy and then add the class...
1047 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1049 send_http_error(con
, status
, NULL
);
1053 pclass
= cupsdAddClass(resource
+ 9);
1056 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1059 * Check the default policy, then rename the implicit class to "AnyClass"
1063 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1065 send_http_error(con
, status
, NULL
);
1069 if (ImplicitAnyClasses
)
1071 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1072 cupsdRenamePrinter(pclass
, newname
);
1075 cupsdDeletePrinter(pclass
, 1);
1078 * Add the class as a new local class...
1081 pclass
= cupsdAddClass(resource
+ 9);
1084 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1087 * Check the default policy, then rename the remote class to "Class"...
1090 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1092 send_http_error(con
, status
, NULL
);
1096 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1097 cupsdRenamePrinter(pclass
, newname
);
1100 * Add the class as a new local class...
1103 pclass
= cupsdAddClass(resource
+ 9);
1106 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1109 send_http_error(con
, status
, pclass
);
1116 * Look for attributes and copy them over as needed...
1119 need_restart_job
= 0;
1121 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1122 IPP_TAG_TEXT
)) != NULL
)
1123 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1125 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1126 IPP_TAG_TEXT
)) != NULL
)
1127 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1129 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1130 IPP_TAG_BOOLEAN
)) != NULL
&&
1131 attr
->values
[0].boolean
!= pclass
->accepting
)
1133 cupsdLogMessage(CUPSD_LOG_INFO
,
1134 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1135 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1137 pclass
->accepting
= attr
->values
[0].boolean
;
1139 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1140 pclass
->accepting
? "Now" : "No longer");
1143 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1144 IPP_TAG_BOOLEAN
)) != NULL
)
1146 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1147 cupsdDeregisterPrinter(pclass
, 1);
1149 cupsdLogMessage(CUPSD_LOG_INFO
,
1150 "Setting %s printer-is-shared to %d (was %d.)",
1151 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1153 pclass
->shared
= attr
->values
[0].boolean
;
1156 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1157 IPP_TAG_ENUM
)) != NULL
)
1159 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1160 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1162 send_ipp_status(con
, IPP_BAD_REQUEST
,
1163 _("Attempt to set %s printer-state to bad value %d"),
1164 pclass
->name
, attr
->values
[0].integer
);
1168 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1169 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1171 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1172 cupsdStopPrinter(pclass
, 0);
1175 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1176 need_restart_job
= 1;
1179 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1180 IPP_TAG_TEXT
)) != NULL
)
1182 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1183 sizeof(pclass
->state_message
));
1185 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1186 pclass
->state_message
);
1188 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1189 IPP_TAG_URI
)) != NULL
)
1192 * Clear the printer array as needed...
1195 need_restart_job
= 1;
1197 if (pclass
->num_printers
> 0)
1199 free(pclass
->printers
);
1200 pclass
->num_printers
= 0;
1204 * Add each printer or class that is listed...
1207 for (i
= 0; i
< attr
->num_values
; i
++)
1210 * Search for the printer or class URI...
1213 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1219 send_ipp_status(con
, IPP_NOT_FOUND
,
1220 _("The printer or class was not found."));
1223 else if (dtype
& CUPS_PRINTER_CLASS
)
1225 send_ipp_status(con
, IPP_BAD_REQUEST
,
1226 _("Nested classes are not allowed"));
1231 * Add it to the class...
1234 cupsdAddPrinterToClass(pclass
, member
);
1238 set_printer_defaults(con
, pclass
);
1240 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1241 IPP_TAG_KEYWORD
)) != NULL
)
1242 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1245 * Update the printer class attributes and return...
1248 cupsdSetPrinterAttrs(pclass
);
1249 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1251 if (need_restart_job
&& pclass
->job
)
1254 * Reset the current job to a "pending" status...
1257 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1258 "Job restarted because the class was modified.");
1261 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1265 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1266 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1267 pclass
->name
, get_username(con
));
1269 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1270 pclass
->name
, get_username(con
));
1274 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1275 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1276 pclass
->name
, get_username(con
));
1278 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1279 pclass
->name
, get_username(con
));
1282 con
->response
->request
.status
.status_code
= IPP_OK
;
1287 * 'add_file()' - Add a file to a job.
1290 static int /* O - 0 on success, -1 on error */
1291 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1292 cupsd_job_t
*job
, /* I - Job to add to */
1293 mime_type_t
*filetype
, /* I - Type of file */
1294 int compression
) /* I - Compression */
1296 mime_type_t
**filetypes
; /* New filetypes array... */
1297 int *compressions
; /* New compressions array... */
1300 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1301 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1302 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1303 filetype
->super
, filetype
->type
, compression
);
1306 * Add the file to the job...
1309 if (job
->num_files
== 0)
1311 compressions
= (int *)malloc(sizeof(int));
1312 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1316 compressions
= (int *)realloc(job
->compressions
,
1317 (job
->num_files
+ 1) * sizeof(int));
1318 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1319 (job
->num_files
+ 1) *
1320 sizeof(mime_type_t
*));
1323 if (!compressions
|| !filetypes
)
1325 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1326 "Job aborted because the scheduler ran out of memory.");
1329 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1330 _("Unable to allocate memory for file types"));
1335 job
->compressions
= compressions
;
1336 job
->compressions
[job
->num_files
] = compression
;
1337 job
->filetypes
= filetypes
;
1338 job
->filetypes
[job
->num_files
] = filetype
;
1343 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1350 * 'add_job()' - Add a job to a print queue.
1353 static cupsd_job_t
* /* O - Job object */
1354 add_job(cupsd_client_t
*con
, /* I - Client connection */
1355 cupsd_printer_t
*printer
, /* I - Destination printer */
1356 mime_type_t
*filetype
) /* I - First print file type, if any */
1358 http_status_t status
; /* Policy status */
1359 ipp_attribute_t
*attr
, /* Current attribute */
1360 *auth_info
; /* auth-info attribute */
1361 const char *val
; /* Default option value */
1362 int priority
; /* Job priority */
1363 cupsd_job_t
*job
; /* Current job */
1364 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1365 int kbytes
; /* Size of print file */
1366 int i
; /* Looping var */
1367 int lowerpagerange
; /* Page range bound */
1368 int exact
; /* Did we have an exact match? */
1369 ipp_attribute_t
*media_col
, /* media-col attribute */
1370 *media_margin
; /* media-*-margin attribute */
1371 ipp_t
*unsup_col
; /* media-col in unsupported response */
1374 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1375 con
, con
->http
.fd
, printer
, printer
->name
,
1376 filetype
, filetype
? filetype
->super
: "none",
1377 filetype
? filetype
->type
: "none");
1380 * Check remote printing to non-shared printer...
1383 if (!printer
->shared
&&
1384 strcasecmp(con
->http
.hostname
, "localhost") &&
1385 strcasecmp(con
->http
.hostname
, ServerName
))
1387 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1388 _("The printer or class is not shared"));
1396 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1398 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1400 send_http_error(con
, status
, printer
);
1403 else if (printer
->num_auth_info_required
== 1 &&
1404 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1407 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1411 else if (auth_info
&& !con
->http
.tls
&&
1412 !httpAddrLocalhost(con
->http
.hostaddr
))
1415 * Require encryption of auth-info over non-local connections...
1418 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1421 #endif /* HAVE_SSL */
1424 * See if the printer is accepting jobs...
1427 if (!printer
->accepting
)
1429 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1430 _("Destination \"%s\" is not accepting jobs."),
1436 * Validate job template attributes; for now just document-format,
1437 * copies, number-up, and page-ranges...
1440 if (filetype
&& printer
->filetypes
&&
1441 !cupsArrayFind(printer
->filetypes
, filetype
))
1443 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1444 /* MIME media type string */
1447 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1450 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1451 _("Unsupported format \'%s\'"), mimetype
);
1453 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1454 "document-format", NULL
, mimetype
);
1459 if ((attr
= ippFindAttribute(con
->request
, "copies",
1460 IPP_TAG_INTEGER
)) != NULL
)
1462 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1464 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1465 attr
->values
[0].integer
);
1466 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1467 "copies", attr
->values
[0].integer
);
1472 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1473 IPP_TAG_ZERO
)) != NULL
)
1475 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1476 attr
->value_tag
!= IPP_TAG_NAME
)
1478 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type"));
1482 if (attr
->num_values
> 2)
1484 send_ipp_status(con
, IPP_BAD_REQUEST
,
1485 _("Too many job-sheets values (%d > 2)"),
1490 for (i
= 0; i
< attr
->num_values
; i
++)
1491 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1492 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1494 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\""),
1495 attr
->values
[i
].string
.text
);
1500 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1501 IPP_TAG_INTEGER
)) != NULL
)
1503 if (attr
->values
[0].integer
!= 1 &&
1504 attr
->values
[0].integer
!= 2 &&
1505 attr
->values
[0].integer
!= 4 &&
1506 attr
->values
[0].integer
!= 6 &&
1507 attr
->values
[0].integer
!= 9 &&
1508 attr
->values
[0].integer
!= 16)
1510 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1511 attr
->values
[0].integer
);
1512 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1513 "number-up", attr
->values
[0].integer
);
1518 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1519 IPP_TAG_RANGE
)) != NULL
)
1521 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1523 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1524 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1526 send_ipp_status(con
, IPP_BAD_REQUEST
,
1527 _("Bad page-ranges values %d-%d."),
1528 attr
->values
[i
].range
.lower
,
1529 attr
->values
[i
].range
.upper
);
1533 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1538 * Do media selection as needed...
1541 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1542 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1543 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1546 (media_col
= ippFindAttribute(con
->request
, "media-col",
1547 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1549 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1551 unsup_col
= ippNew();
1552 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1553 "media-bottom-margin",
1554 IPP_TAG_INTEGER
)) != NULL
)
1555 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1556 "media-bottom-margin", media_margin
->values
[0].integer
);
1558 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1559 "media-left-margin",
1560 IPP_TAG_INTEGER
)) != NULL
)
1561 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1562 "media-left-margin", media_margin
->values
[0].integer
);
1564 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1565 "media-right-margin",
1566 IPP_TAG_INTEGER
)) != NULL
)
1567 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1568 "media-right-margin", media_margin
->values
[0].integer
);
1570 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1572 IPP_TAG_INTEGER
)) != NULL
)
1573 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1574 "media-top-margin", media_margin
->values
[0].integer
);
1576 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1578 ippDelete(unsup_col
);
1583 * Make sure we aren't over our limit...
1586 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1589 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1591 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1592 _("Too many active jobs."));
1596 if ((i
= check_quotas(con
, printer
)) < 0)
1598 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1603 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1608 * Create the job and set things up...
1611 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1612 IPP_TAG_INTEGER
)) != NULL
)
1613 priority
= attr
->values
[0].integer
;
1616 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1617 printer
->options
)) != NULL
)
1618 priority
= atoi(val
);
1622 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1626 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1627 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1630 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1632 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1633 _("Unable to add job for destination \"%s\""),
1638 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1639 CUPS_PRINTER_REMOTE
);
1640 job
->attrs
= con
->request
;
1642 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1644 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1646 add_job_uuid(con
, job
);
1647 apply_printer_defaults(printer
, job
);
1649 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1651 if (con
->username
[0])
1653 cupsdSetString(&job
->username
, con
->username
);
1656 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1660 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1661 "add_job: requesting-user-name=\"%s\"",
1662 attr
->values
[0].string
.text
);
1664 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1667 cupsdSetString(&job
->username
, "anonymous");
1670 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1671 "job-originating-user-name", NULL
, job
->username
);
1674 attr
->group_tag
= IPP_TAG_JOB
;
1675 _cupsStrFree(attr
->name
);
1676 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1679 if (con
->username
[0] || auth_info
)
1681 save_auth_info(con
, job
, auth_info
);
1684 * Remove the auth-info attribute from the attribute data...
1688 ippDeleteAttribute(job
->attrs
, auth_info
);
1691 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1692 IPP_TAG_ZERO
)) != NULL
)
1695 * Request contains a job-originating-host-name attribute; validate it...
1698 if (attr
->value_tag
!= IPP_TAG_NAME
||
1699 attr
->num_values
!= 1 ||
1700 strcmp(con
->http
.hostname
, "localhost"))
1703 * Can't override the value if we aren't connected via localhost.
1704 * Also, we can only have 1 value and it must be a name value.
1707 switch (attr
->value_tag
)
1709 case IPP_TAG_STRING
:
1710 case IPP_TAG_TEXTLANG
:
1711 case IPP_TAG_NAMELANG
:
1714 case IPP_TAG_KEYWORD
:
1716 case IPP_TAG_URISCHEME
:
1717 case IPP_TAG_CHARSET
:
1718 case IPP_TAG_LANGUAGE
:
1719 case IPP_TAG_MIMETYPE
:
1721 * Free old strings...
1724 for (i
= 0; i
< attr
->num_values
; i
++)
1726 _cupsStrFree(attr
->values
[i
].string
.text
);
1727 attr
->values
[i
].string
.text
= NULL
;
1728 if (attr
->values
[i
].string
.charset
)
1730 _cupsStrFree(attr
->values
[i
].string
.charset
);
1731 attr
->values
[i
].string
.charset
= NULL
;
1740 * Use the default connection hostname instead...
1743 attr
->value_tag
= IPP_TAG_NAME
;
1744 attr
->num_values
= 1;
1745 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1748 attr
->group_tag
= IPP_TAG_JOB
;
1753 * No job-originating-host-name attribute, so use the hostname from
1757 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1758 "job-originating-host-name", NULL
, con
->http
.hostname
);
1761 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1763 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1764 "time-at-processing", 0);
1765 attr
->value_tag
= IPP_TAG_NOVALUE
;
1766 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1767 "time-at-completed", 0);
1768 attr
->value_tag
= IPP_TAG_NOVALUE
;
1771 * Add remaining job attributes...
1774 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1775 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1776 "job-state", IPP_JOB_STOPPED
);
1777 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1778 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1779 "job-media-sheets-completed", 0);
1780 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1783 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1784 IPP_TAG_INTEGER
)) != NULL
)
1785 attr
->values
[0].integer
= 0;
1787 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1789 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1790 IPP_TAG_KEYWORD
)) == NULL
)
1791 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1794 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1795 printer
->options
)) == NULL
)
1798 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1799 "job-hold-until", NULL
, val
);
1801 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1804 * Hold job until specified time...
1807 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1809 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1810 job
->state_value
= IPP_JOB_HELD
;
1812 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1814 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1815 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1816 job
->state_value
= IPP_JOB_HELD
;
1820 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1821 job
->state_value
= IPP_JOB_PENDING
;
1824 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1828 * Add job sheets options...
1831 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1832 IPP_TAG_ZERO
)) == NULL
)
1834 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1835 "Adding default job-sheets values \"%s,%s\"...",
1836 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1838 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1840 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1841 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1844 job
->job_sheets
= attr
;
1847 * Enforce classification level if set...
1852 cupsdLogMessage(CUPSD_LOG_INFO
,
1853 "Classification=\"%s\", ClassifyOverride=%d",
1854 Classification
? Classification
: "(null)",
1857 if (ClassifyOverride
)
1859 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1860 (attr
->num_values
== 1 ||
1861 !strcmp(attr
->values
[1].string
.text
, "none")))
1864 * Force the leading banner to have the classification on it...
1867 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1869 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1870 "job-sheets=\"%s,none\", "
1871 "job-originating-user-name=\"%s\"",
1872 Classification
, job
->username
);
1874 else if (attr
->num_values
== 2 &&
1875 strcmp(attr
->values
[0].string
.text
,
1876 attr
->values
[1].string
.text
) &&
1877 strcmp(attr
->values
[0].string
.text
, "none") &&
1878 strcmp(attr
->values
[1].string
.text
, "none"))
1881 * Can't put two different security markings on the same document!
1884 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1886 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1887 "job-sheets=\"%s,%s\", "
1888 "job-originating-user-name=\"%s\"",
1889 attr
->values
[0].string
.text
,
1890 attr
->values
[1].string
.text
, job
->username
);
1892 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1893 strcmp(attr
->values
[0].string
.text
, "none") &&
1894 (attr
->num_values
== 1 ||
1895 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1896 strcmp(attr
->values
[1].string
.text
, "none"))))
1898 if (attr
->num_values
== 1)
1899 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1900 "CLASSIFICATION OVERRIDDEN "
1901 "job-sheets=\"%s\", "
1902 "job-originating-user-name=\"%s\"",
1903 attr
->values
[0].string
.text
, job
->username
);
1905 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1906 "CLASSIFICATION OVERRIDDEN "
1907 "job-sheets=\"%s,%s\",fffff "
1908 "job-originating-user-name=\"%s\"",
1909 attr
->values
[0].string
.text
,
1910 attr
->values
[1].string
.text
, job
->username
);
1913 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1914 (attr
->num_values
== 1 ||
1915 strcmp(attr
->values
[1].string
.text
, Classification
)))
1918 * Force the banner to have the classification on it...
1921 if (attr
->num_values
> 1 &&
1922 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1924 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1925 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1929 if (attr
->num_values
== 1 ||
1930 strcmp(attr
->values
[0].string
.text
, "none"))
1931 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1933 if (attr
->num_values
> 1 &&
1934 strcmp(attr
->values
[1].string
.text
, "none"))
1935 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1938 if (attr
->num_values
> 1)
1939 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1940 "CLASSIFICATION FORCED "
1941 "job-sheets=\"%s,%s\", "
1942 "job-originating-user-name=\"%s\"",
1943 attr
->values
[0].string
.text
,
1944 attr
->values
[1].string
.text
, job
->username
);
1946 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1947 "CLASSIFICATION FORCED "
1948 "job-sheets=\"%s\", "
1949 "job-originating-user-name=\"%s\"",
1950 Classification
, job
->username
);
1955 * See if we need to add the starting sheet...
1958 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1960 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1961 attr
->values
[0].string
.text
);
1963 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1965 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1966 "Aborting job because the start banner could not be "
1971 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1974 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1975 IPP_TAG_ZERO
)) != NULL
)
1976 job
->job_sheets
= attr
;
1979 * Fill in the response info...
1982 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1983 LocalPort
, job
->id
);
1985 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1988 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1990 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1992 add_job_state_reasons(con
, job
);
1994 con
->response
->request
.status
.status_code
= IPP_OK
;
1997 * Add any job subscriptions...
2000 add_job_subscriptions(con
, job
);
2003 * Set all but the first two attributes to the job attributes group...
2006 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
2007 attr
->group_tag
= IPP_TAG_JOB
;
2010 * Fire the "job created" event...
2013 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
2016 * Return the new job...
2024 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
2025 * upon the job and printer state...
2029 add_job_state_reasons(
2030 cupsd_client_t
*con
, /* I - Client connection */
2031 cupsd_job_t
*job
) /* I - Job info */
2033 cupsd_printer_t
*dest
; /* Destination printer */
2036 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
2037 con
, con
->http
.fd
, job
? job
->id
: 0);
2039 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
2041 case IPP_JOB_PENDING
:
2042 dest
= cupsdFindDest(job
->dest
);
2044 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
2045 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2046 "job-state-reasons", NULL
, "printer-stopped");
2048 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2049 "job-state-reasons", NULL
, "none");
2053 if (ippFindAttribute(job
->attrs
, "job-hold-until",
2054 IPP_TAG_KEYWORD
) != NULL
||
2055 ippFindAttribute(job
->attrs
, "job-hold-until",
2056 IPP_TAG_NAME
) != NULL
)
2057 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2058 "job-state-reasons", NULL
, "job-hold-until-specified");
2060 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2061 "job-state-reasons", NULL
, "job-incoming");
2064 case IPP_JOB_PROCESSING
:
2065 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2066 "job-state-reasons", NULL
, "job-printing");
2069 case IPP_JOB_STOPPED
:
2070 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2071 "job-state-reasons", NULL
, "job-stopped");
2074 case IPP_JOB_CANCELED
:
2075 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2076 "job-state-reasons", NULL
, "job-canceled-by-user");
2079 case IPP_JOB_ABORTED
:
2080 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2081 "job-state-reasons", NULL
, "aborted-by-system");
2084 case IPP_JOB_COMPLETED
:
2085 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2086 "job-state-reasons", NULL
, "job-completed-successfully");
2093 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2097 add_job_subscriptions(
2098 cupsd_client_t
*con
, /* I - Client connection */
2099 cupsd_job_t
*job
) /* I - Newly created job */
2101 int i
; /* Looping var */
2102 ipp_attribute_t
*prev
, /* Previous attribute */
2103 *next
, /* Next attribute */
2104 *attr
; /* Current attribute */
2105 cupsd_subscription_t
*sub
; /* Subscription object */
2106 const char *recipient
, /* notify-recipient-uri */
2107 *pullmethod
; /* notify-pull-method */
2108 ipp_attribute_t
*user_data
; /* notify-user-data */
2109 int interval
; /* notify-time-interval */
2110 unsigned mask
; /* notify-events */
2114 * Find the first subscription group attribute; return if we have
2118 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2119 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2126 * Process the subscription attributes in the request...
2135 mask
= CUPSD_EVENT_NONE
;
2137 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2139 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2140 attr
->value_tag
== IPP_TAG_URI
)
2143 * Validate the recipient scheme against the ServerBin/notifier
2147 char notifier
[1024], /* Notifier filename */
2148 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2149 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2150 host
[HTTP_MAX_URI
], /* Host portion of URI */
2151 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2152 int port
; /* Port portion of URI */
2155 recipient
= attr
->values
[0].string
.text
;
2157 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2158 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2159 host
, sizeof(host
), &port
,
2160 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2162 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2163 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
2164 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2165 "notify-status-code", IPP_URI_SCHEME
);
2169 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2171 if (access(notifier
, X_OK
))
2173 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2174 _("notify-recipient-uri URI \"%s\" uses unknown "
2175 "scheme"), recipient
);
2176 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2177 "notify-status-code", IPP_URI_SCHEME
);
2181 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2183 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2184 _("notify-recipient-uri URI \"%s\" is already used"),
2186 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2187 "notify-status-code", IPP_ATTRIBUTES
);
2191 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2192 attr
->value_tag
== IPP_TAG_KEYWORD
)
2194 pullmethod
= attr
->values
[0].string
.text
;
2196 if (strcmp(pullmethod
, "ippget"))
2198 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2199 _("Bad notify-pull-method \"%s\""), pullmethod
);
2200 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2201 "notify-status-code", IPP_ATTRIBUTES
);
2205 else if (!strcmp(attr
->name
, "notify-charset") &&
2206 attr
->value_tag
== IPP_TAG_CHARSET
&&
2207 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2208 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2210 send_ipp_status(con
, IPP_CHARSET
,
2211 _("Character set \"%s\" not supported"),
2212 attr
->values
[0].string
.text
);
2215 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2216 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2217 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2219 send_ipp_status(con
, IPP_CHARSET
,
2220 _("Language \"%s\" not supported"),
2221 attr
->values
[0].string
.text
);
2224 else if (!strcmp(attr
->name
, "notify-user-data") &&
2225 attr
->value_tag
== IPP_TAG_STRING
)
2227 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2229 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2230 _("The notify-user-data value is too large "
2231 "(%d > 63 octets)"),
2232 attr
->values
[0].unknown
.length
);
2238 else if (!strcmp(attr
->name
, "notify-events") &&
2239 attr
->value_tag
== IPP_TAG_KEYWORD
)
2241 for (i
= 0; i
< attr
->num_values
; i
++)
2242 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2244 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2246 send_ipp_status(con
, IPP_BAD_REQUEST
,
2247 _("The notify-lease-duration attribute cannot be "
2248 "used with job subscriptions."));
2251 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2252 attr
->value_tag
== IPP_TAG_INTEGER
)
2253 interval
= attr
->values
[0].integer
;
2258 if (!recipient
&& !pullmethod
)
2261 if (mask
== CUPSD_EVENT_NONE
)
2262 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2264 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2265 recipient
, 0)) != NULL
)
2267 sub
->interval
= interval
;
2269 cupsdSetString(&sub
->owner
, job
->username
);
2273 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2274 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2275 sub
->user_data_len
);
2278 ippAddSeparator(con
->response
);
2279 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2280 "notify-subscription-id", sub
->id
);
2282 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2290 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2293 * Remove all of the subscription attributes from the job request...
2295 * TODO: Optimize this since subscription groups have to come at the
2296 * end of the request...
2299 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2303 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2304 attr
->group_tag
== IPP_TAG_ZERO
)
2307 * Free and remove this attribute...
2315 job
->attrs
->attrs
= next
;
2321 job
->attrs
->last
= prev
;
2322 job
->attrs
->current
= prev
;
2327 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2329 * See RFC 4122 for the definition of UUIDs and the format.
2333 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2334 cupsd_job_t
*job
) /* I - Job */
2336 char uuid
[64]; /* job-uuid string */
2340 * Add a job-uuid attribute if none exists...
2343 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2344 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2345 cupsdMakeUUID(job
->dest
, job
->id
, uuid
, sizeof(uuid
)));
2350 * 'add_printer()' - Add a printer to the system.
2354 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2355 ipp_attribute_t
*uri
) /* I - URI of printer */
2357 http_status_t status
; /* Policy status */
2358 int i
; /* Looping var */
2359 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2360 username
[HTTP_MAX_URI
], /* Username portion of URI */
2361 host
[HTTP_MAX_URI
], /* Host portion of URI */
2362 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2363 int port
; /* Port portion of URI */
2364 cupsd_printer_t
*printer
; /* Printer/class */
2365 ipp_attribute_t
*attr
; /* Printer attribute */
2366 cups_file_t
*fp
; /* Script/PPD file */
2367 char line
[1024]; /* Line from file... */
2368 char srcfile
[1024], /* Source Script/PPD file */
2369 dstfile
[1024]; /* Destination Script/PPD file */
2370 int modify
; /* Non-zero if we are modifying */
2371 char newname
[IPP_MAX_NAME
]; /* New printer name */
2372 int changed_driver
, /* Changed the PPD/interface script? */
2373 need_restart_job
, /* Need to restart job? */
2374 set_device_uri
, /* Did we set the device URI? */
2375 set_port_monitor
; /* Did we set the port monitor? */
2378 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2379 con
->http
.fd
, uri
->values
[0].string
.text
);
2382 * Do we have a valid URI?
2385 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2386 sizeof(scheme
), username
, sizeof(username
), host
,
2387 sizeof(host
), &port
, resource
, sizeof(resource
));
2389 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2392 * No, return an error...
2395 send_ipp_status(con
, IPP_BAD_REQUEST
,
2396 _("The printer-uri must be of the form "
2397 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2402 * Do we have a valid printer name?
2405 if (!validate_name(resource
+ 10))
2408 * No, return an error...
2411 send_ipp_status(con
, IPP_BAD_REQUEST
,
2412 _("The printer-uri \"%s\" contains invalid characters."),
2413 uri
->values
[0].string
.text
);
2418 * See if the printer already exists; if not, create a new printer...
2421 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2424 * Printer doesn't exist; see if we have a class of the same name...
2427 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2428 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2431 * Yes, return an error...
2434 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2435 _("A class named \"%s\" already exists"),
2441 * No, check the default policy then add the printer...
2444 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2446 send_http_error(con
, status
, NULL
);
2450 printer
= cupsdAddPrinter(resource
+ 10);
2453 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2456 * Check the default policy, then rename the implicit printer to
2457 * "AnyPrinter" or delete it...
2460 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2462 send_http_error(con
, status
, NULL
);
2466 if (ImplicitAnyClasses
)
2468 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2469 cupsdRenamePrinter(printer
, newname
);
2472 cupsdDeletePrinter(printer
, 1);
2475 * Add the printer as a new local printer...
2478 printer
= cupsdAddPrinter(resource
+ 10);
2481 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2484 * Check the default policy, then rename the remote printer to
2485 * "Printer@server"...
2488 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2490 send_http_error(con
, status
, NULL
);
2494 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2496 cupsdRenamePrinter(printer
, newname
);
2499 * Add the printer as a new local printer...
2502 printer
= cupsdAddPrinter(resource
+ 10);
2505 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2508 send_http_error(con
, status
, printer
);
2515 * Look for attributes and copy them over as needed...
2519 need_restart_job
= 0;
2521 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2522 IPP_TAG_TEXT
)) != NULL
)
2523 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2525 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2526 IPP_TAG_TEXT
)) != NULL
)
2527 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2531 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2532 IPP_TAG_URI
)) != NULL
)
2535 * Do we have a valid device URI?
2538 http_uri_status_t uri_status
; /* URI separation status */
2539 char old_device_uri
[1024];
2540 /* Old device URI */
2543 need_restart_job
= 1;
2545 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2546 attr
->values
[0].string
.text
,
2547 scheme
, sizeof(scheme
),
2548 username
, sizeof(username
),
2549 host
, sizeof(host
), &port
,
2550 resource
, sizeof(resource
));
2552 if (uri_status
< HTTP_URI_OK
)
2554 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\""),
2555 attr
->values
[0].string
.text
);
2556 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2557 "add_printer: httpSeparateURI returned %d", uri_status
);
2561 if (!strcmp(scheme
, "file"))
2564 * See if the administrator has enabled file devices...
2567 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2570 * File devices are disabled and the URL is not file:/dev/null...
2573 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2574 _("File device URIs have been disabled! "
2575 "To enable, see the FileDevice directive in "
2576 "\"%s/cupsd.conf\"."),
2584 * See if the backend exists and is executable...
2587 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2588 if (access(srcfile
, X_OK
))
2591 * Could not find device in list!
2594 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\""),
2600 if (printer
->sanitized_device_uri
)
2601 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2602 sizeof(old_device_uri
));
2604 old_device_uri
[0] = '\0';
2606 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2608 cupsdLogMessage(CUPSD_LOG_INFO
,
2609 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2610 printer
->name
, printer
->sanitized_device_uri
,
2616 set_port_monitor
= 0;
2618 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2619 IPP_TAG_NAME
)) != NULL
)
2621 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2624 need_restart_job
= 1;
2626 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2630 for (i
= 0; i
< supported
->num_values
; i
++)
2631 if (!strcmp(supported
->values
[i
].string
.text
,
2632 attr
->values
[0].string
.text
))
2636 if (!supported
|| i
>= supported
->num_values
)
2638 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\""),
2639 attr
->values
[0].string
.text
);
2643 cupsdLogMessage(CUPSD_LOG_INFO
,
2644 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2645 printer
->name
, attr
->values
[0].string
.text
,
2646 printer
->port_monitor
? printer
->port_monitor
: "none");
2648 if (strcmp(attr
->values
[0].string
.text
, "none"))
2649 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2651 cupsdClearString(&printer
->port_monitor
);
2653 set_port_monitor
= 1;
2656 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2657 IPP_TAG_BOOLEAN
)) != NULL
&&
2658 attr
->values
[0].boolean
!= printer
->accepting
)
2660 cupsdLogMessage(CUPSD_LOG_INFO
,
2661 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2662 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2664 printer
->accepting
= attr
->values
[0].boolean
;
2666 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2667 "%s accepting jobs.",
2668 printer
->accepting
? "Now" : "No longer");
2671 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2672 IPP_TAG_BOOLEAN
)) != NULL
)
2674 if (printer
->shared
&& !attr
->values
[0].boolean
)
2675 cupsdDeregisterPrinter(printer
, 1);
2677 cupsdLogMessage(CUPSD_LOG_INFO
,
2678 "Setting %s printer-is-shared to %d (was %d.)",
2679 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2681 printer
->shared
= attr
->values
[0].boolean
;
2684 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2685 IPP_TAG_ENUM
)) != NULL
)
2687 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2688 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2690 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d"),
2691 attr
->values
[0].integer
);
2695 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2696 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2698 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2699 cupsdStopPrinter(printer
, 0);
2702 need_restart_job
= 1;
2703 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2707 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2708 IPP_TAG_TEXT
)) != NULL
)
2710 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2711 sizeof(printer
->state_message
));
2713 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2714 printer
->state_message
);
2717 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2718 IPP_TAG_KEYWORD
)) != NULL
)
2720 if (attr
->num_values
>
2721 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2723 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2724 _("Too many printer-state-reasons values (%d > %d)"),
2726 (int)(sizeof(printer
->reasons
) /
2727 sizeof(printer
->reasons
[0])));
2731 for (i
= 0; i
< printer
->num_reasons
; i
++)
2732 _cupsStrFree(printer
->reasons
[i
]);
2734 printer
->num_reasons
= 0;
2735 for (i
= 0; i
< attr
->num_values
; i
++)
2737 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2740 printer
->reasons
[printer
->num_reasons
] =
2741 _cupsStrRetain(attr
->values
[i
].string
.text
);
2742 printer
->num_reasons
++;
2744 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2745 printer
->state
!= IPP_PRINTER_STOPPED
)
2747 cupsdLogMessage(CUPSD_LOG_INFO
,
2748 "Setting %s printer-state to %d (was %d.)",
2749 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2750 cupsdStopPrinter(printer
, 0);
2754 if (PrintcapFormat
== PRINTCAP_PLIST
)
2755 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2757 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2758 "Printer \"%s\" state changed.", printer
->name
);
2761 set_printer_defaults(con
, printer
);
2763 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2764 IPP_TAG_KEYWORD
)) != NULL
)
2765 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2768 * See if we have all required attributes...
2771 if (!printer
->device_uri
)
2772 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2775 * See if we have an interface script or PPD file attached to the request...
2780 need_restart_job
= 1;
2783 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2785 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2788 * Yes; get the first line from it...
2792 cupsFileGets(fp
, line
, sizeof(line
));
2796 * Then see what kind of file it is...
2799 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2802 if (!strncmp(line
, "*PPD-Adobe", 10))
2805 * The new file is a PPD file, so remove any old interface script
2806 * that might be lying around...
2814 * This must be an interface script, so move the file over to the
2815 * interfaces directory and make it executable...
2818 if (copy_file(srcfile
, dstfile
))
2820 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2821 _("Unable to copy interface script - %s"),
2826 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2827 "Copied interface script successfully");
2828 chmod(dstfile
, 0755);
2831 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2834 if (!strncmp(line
, "*PPD-Adobe", 10))
2837 * The new file is a PPD file, so move the file over to the
2838 * ppd directory and make it readable by all...
2841 if (copy_file(srcfile
, dstfile
))
2843 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2844 _("Unable to copy PPD file - %s"),
2849 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2850 "Copied PPD file successfully");
2851 chmod(dstfile
, 0644);
2856 * This must be an interface script, so remove any old PPD file that
2857 * may be lying around...
2864 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2865 IPP_TAG_NAME
)) != NULL
)
2867 need_restart_job
= 1;
2870 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2873 * Raw driver, remove any existing PPD or interface script files.
2876 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2880 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2890 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2894 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2897 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2899 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file"));
2903 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2904 "Copied PPD file successfully");
2905 chmod(dstfile
, 0644);
2912 * If we changed the PPD/interface script, then remove the printer's cache
2913 * file and clear the printer-state-reasons...
2916 char cache_name
[1024]; /* Cache filename for printer attrs */
2918 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2922 cupsdSetPrinterReasons(printer
, "none");
2926 * (Re)register color profiles...
2931 apple_unregister_profiles(printer
);
2932 apple_register_profiles(printer
);
2934 #endif /* __APPLE__ */
2938 * If we set the device URI but not the port monitor, check which port
2939 * monitor to use by default...
2942 if (set_device_uri
&& !set_port_monitor
)
2944 ppd_file_t
*ppd
; /* PPD file */
2945 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2948 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2949 sizeof(scheme
), username
, sizeof(username
), host
,
2950 sizeof(host
), &port
, resource
, sizeof(resource
));
2952 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2954 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2956 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2958 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2959 if (!strcmp(scheme
, ppdattr
->spec
))
2961 cupsdLogMessage(CUPSD_LOG_INFO
,
2962 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2963 printer
->name
, ppdattr
->value
,
2964 printer
->port_monitor
? printer
->port_monitor
2967 if (strcmp(ppdattr
->value
, "none"))
2968 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2970 cupsdClearString(&printer
->port_monitor
);
2980 * Update the printer attributes and return...
2983 cupsdSetPrinterAttrs(printer
);
2984 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2986 if (need_restart_job
&& printer
->job
)
2989 * Restart the current job...
2992 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2993 "Job restarted because the printer was modified.");
2996 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3000 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
3001 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
3002 printer
->name
, get_username(con
));
3004 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
3005 printer
->name
, get_username(con
));
3009 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
3010 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
3011 printer
->name
, get_username(con
));
3013 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
3014 printer
->name
, get_username(con
));
3017 con
->response
->request
.status
.status_code
= IPP_OK
;
3022 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
3023 * based upon the printer state...
3027 add_printer_state_reasons(
3028 cupsd_client_t
*con
, /* I - Client connection */
3029 cupsd_printer_t
*p
) /* I - Printer info */
3031 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3032 "add_printer_state_reasons(%p[%d], %p[%s])",
3033 con
, con
->http
.fd
, p
, p
->name
);
3035 if (p
->num_reasons
== 0)
3036 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3037 "printer-state-reasons", NULL
, "none");
3039 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3040 "printer-state-reasons", p
->num_reasons
, NULL
,
3041 (const char * const *)p
->reasons
);
3046 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
3047 * the specified printer or class.
3051 add_queued_job_count(
3052 cupsd_client_t
*con
, /* I - Client connection */
3053 cupsd_printer_t
*p
) /* I - Printer or class */
3055 int count
; /* Number of jobs on destination */
3058 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3059 con
, con
->http
.fd
, p
, p
->name
);
3061 count
= cupsdGetPrinterJobCount(p
->name
);
3063 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3064 "queued-job-count", count
);
3070 * 'apple_init_profile()' - Initialize a color profile.
3075 ppd_file_t
*ppd
, /* I - PPD file */
3076 cups_array_t
*languages
, /* I - Languages in the PPD file */
3077 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3078 CFMutableDictionaryRef profile
, /* I - Profile dictionary */
3080 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3081 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3082 unsigned id
, /* I - Profile ID */
3083 const char *name
, /* I - Profile name */
3084 const char *text
, /* I - Profile UI text */
3085 const char *iccfile
) /* I - ICC filename */
3087 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3088 CFURLRef url
; /* URL for profile filename */
3089 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3090 CFMutableDictionaryRef dict
; /* Dictionary for name */
3091 char *language
; /* Current language */
3092 ppd_attr_t
*attr
; /* Profile attribute */
3093 CFStringRef cflang
, /* Language string */
3094 cftext
; /* Localized text */
3098 * Build the profile name dictionary...
3101 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3102 &kCFTypeDictionaryKeyCallBacks
,
3103 &kCFTypeDictionaryValueCallBacks
);
3105 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3106 kCFStringEncodingUTF8
);
3110 CFDictionarySetValue(dict
, CFSTR("en_US"), cftext
);
3117 * Find localized names for the color profiles...
3120 cupsArraySave(ppd
->sorted_attrs
);
3122 for (language
= (char *)cupsArrayFirst(languages
);
3124 language
= (char *)cupsArrayNext(languages
))
3128 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3130 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3133 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3135 if (attr
&& attr
->text
[0])
3137 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3138 kCFStringEncodingUTF8
);
3139 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3140 kCFStringEncodingUTF8
);
3142 if (cflang
&& cftext
)
3143 CFDictionarySetValue(dict
, cflang
, cftext
);
3153 cupsArrayRestore(ppd
->sorted_attrs
);
3157 * Fill in the profile data...
3160 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3163 url
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
3164 (const UInt8
*)iccfile
,
3165 strlen(iccfile
), false);
3169 CFDictionarySetValue(profile
, kColorSyncDeviceProfileURL
, url
);
3174 CFDictionarySetValue(profile
, kColorSyncDeviceModeDescriptions
, dict
);
3178 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3179 profile
->profileID
= id
;
3180 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3181 profile
->profileName
= dict
;
3184 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3185 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3186 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3191 * 'apple_register_profiles()' - Register color profiles for a printer.
3195 apple_register_profiles(
3196 cupsd_printer_t
*p
) /* I - Printer */
3198 int i
; /* Looping var */
3199 char ppdfile
[1024], /* PPD filename */
3200 iccfile
[1024], /* ICC filename */
3201 selector
[PPD_MAX_NAME
];
3202 /* Profile selection string */
3203 ppd_file_t
*ppd
; /* PPD file */
3204 ppd_attr_t
*attr
, /* Profile attributes */
3205 *profileid_attr
,/* cupsProfileID attribute */
3206 *q1_attr
, /* ColorModel (or other) qualifier */
3207 *q2_attr
, /* MediaType (or other) qualifier */
3208 *q3_attr
; /* Resolution (or other) qualifier */
3209 char q_keyword
[PPD_MAX_NAME
];
3210 /* Qualifier keyword */
3211 const char *q1_choice
, /* ColorModel (or other) choice */
3212 *q2_choice
, /* MediaType (or other) choice */
3213 *q3_choice
; /* Resolution (or other) choice */
3214 const char *profile_key
; /* Profile keyword */
3215 ppd_option_t
*cm_option
; /* Color model option */
3216 ppd_choice_t
*cm_choice
; /* Color model choice */
3217 int num_profiles
; /* Number of profiles */
3218 OSStatus error
= 0; /* Last error */
3219 unsigned device_id
, /* Printer device ID */
3220 profile_id
, /* Profile ID */
3221 default_profile_id
= 0;
3222 /* Default profile ID */
3223 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3224 CFStringRef printer_name
; /* Printer name string */
3225 cups_array_t
*languages
; /* Languages array */
3226 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3227 CFMutableDictionaryRef profiles
, /* Dictionary of profiles */
3228 profile
; /* Current profile info dictionary */
3229 CFStringRef dict_key
; /* Key in factory profile dictionary */
3231 CMDeviceScope scope
= /* Scope of the registration */
3233 kCFPreferencesAnyUser
,
3234 kCFPreferencesCurrentHost
3236 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3237 CMDeviceProfileInfo
*profile
; /* Current profile */
3238 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3242 * Make sure ColorSync is available...
3245 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3246 if (ColorSyncRegisterDevice
== NULL
)
3250 if (CMRegisterColorDevice
== NULL
)
3252 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3255 * Try opening the PPD file for this printer...
3258 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3259 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3263 * See if we have any profiles...
3266 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3267 profile_key
= "APTiogaProfile";
3270 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3271 profile_key
= "cupsICCProfile";
3274 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3275 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3277 if (attr
->value
[0] != '/')
3278 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3281 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3283 if (access(iccfile
, 0))
3289 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3291 * Create a dictionary for the factory profiles...
3294 profiles
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3295 &kCFTypeDictionaryKeyCallBacks
,
3296 &kCFTypeDictionaryValueCallBacks
);
3299 cupsdLogMessage(CUPSD_LOG_ERROR
,
3300 "Unable to allocate memory for factory profiles.");
3304 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3307 * If we have profiles, add them...
3310 if (num_profiles
> 0)
3312 if (profile_key
[0] == 'A')
3315 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3319 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3321 default_profile_id
= atoi(attr
->value
);
3323 q1_choice
= q2_choice
= q3_choice
= NULL
;
3328 * For CUPS PPDs, figure out the default profile selector values...
3331 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3332 attr
->value
&& attr
->value
[0])
3334 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3335 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3337 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3338 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3340 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3341 q1_choice
= q1_attr
->value
;
3345 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3346 attr
->value
&& attr
->value
[0])
3348 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3349 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3352 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3354 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3355 q2_choice
= q2_attr
->value
;
3359 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3360 attr
->value
&& attr
->value
[0])
3362 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3363 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3366 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3368 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3369 q3_choice
= q3_attr
->value
;
3374 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3376 * Build the array of profiles...
3378 * Note: This calloc actually requests slightly more memory than needed.
3381 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3383 cupsdLogMessage(CUPSD_LOG_ERROR
,
3384 "Unable to allocate memory for factory profiles.");
3389 profiles
->profileCount
= num_profiles
;
3390 profile
= profiles
->profiles
;
3391 # endif /* !HAVE_COLORSYNCREGISTERDEVICE */
3394 * Loop through the profiles listed in the PPD...
3397 languages
= _ppdGetLanguages(ppd
);
3399 for (attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3401 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3402 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3405 * Add this profile...
3408 if (attr
->value
[0] != '/')
3409 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3412 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3414 if (access(iccfile
, 0))
3417 if (profile_key
[0] == 'c')
3419 cupsArraySave(ppd
->sorted_attrs
);
3421 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3422 attr
->spec
)) != NULL
&&
3423 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3424 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3426 profile_id
= _ppdHashName(attr
->spec
);
3428 cupsArrayRestore(ppd
->sorted_attrs
);
3431 profile_id
= atoi(attr
->spec
);
3433 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3434 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3435 &kCFTypeDictionaryKeyCallBacks
,
3436 &kCFTypeDictionaryValueCallBacks
);
3439 cupsdLogMessage(CUPSD_LOG_ERROR
,
3440 "Unable to allocate memory for color profile.");
3441 CFRelease(profiles
);
3446 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3447 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3449 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3450 CFSTR("%u"), profile_id
);
3453 CFDictionarySetValue(profiles
, dict_key
, profile
);
3454 CFRelease(dict_key
);
3460 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3461 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3464 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3467 * See if this is the default profile...
3470 if (!default_profile_id
&& q1_choice
&& q2_choice
&& q3_choice
)
3472 snprintf(selector
, sizeof(selector
), "%s.%s.%s", q1_choice
, q2_choice
,
3474 if (!strcmp(selector
, attr
->spec
))
3475 default_profile_id
= profile_id
;
3478 if (!default_profile_id
&& q1_choice
&& q2_choice
)
3480 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
, q2_choice
);
3481 if (!strcmp(selector
, attr
->spec
))
3482 default_profile_id
= profile_id
;
3485 if (!default_profile_id
&& q1_choice
&& q3_choice
)
3487 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
, q3_choice
);
3488 if (!strcmp(selector
, attr
->spec
))
3489 default_profile_id
= profile_id
;
3492 if (!default_profile_id
&& q1_choice
)
3494 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3495 if (!strcmp(selector
, attr
->spec
))
3496 default_profile_id
= profile_id
;
3499 if (!default_profile_id
&& q2_choice
&& q3_choice
)
3501 snprintf(selector
, sizeof(selector
), ".%s.%s", q2_choice
, q3_choice
);
3502 if (!strcmp(selector
, attr
->spec
))
3503 default_profile_id
= profile_id
;
3506 if (!default_profile_id
&& q2_choice
)
3508 snprintf(selector
, sizeof(selector
), ".%s.", q2_choice
);
3509 if (!strcmp(selector
, attr
->spec
))
3510 default_profile_id
= profile_id
;
3513 if (!default_profile_id
&& q3_choice
)
3515 snprintf(selector
, sizeof(selector
), "..%s", q3_choice
);
3516 if (!strcmp(selector
, attr
->spec
))
3517 default_profile_id
= profile_id
;
3521 _ppdFreeLanguages(languages
);
3523 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3526 * Extract profiles from ColorModel option...
3529 const char *profile_name
; /* Name of generic profile */
3532 num_profiles
= cm_option
->num_choices
;
3534 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3536 * Create an array for the factory profiles...
3539 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3541 cupsdLogMessage(CUPSD_LOG_ERROR
,
3542 "Unable to allocate memory for factory profiles.");
3547 profiles
->profileCount
= num_profiles
;
3548 profile
= profiles
->profiles
;
3549 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3551 for (i
= cm_option
->num_choices
, cm_choice
= cm_option
->choices
;
3555 if (!strcmp(cm_choice
->choice
, "Gray") ||
3556 !strcmp(cm_choice
->choice
, "Black"))
3557 profile_name
= "Gray";
3558 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3559 !strcmp(cm_choice
->choice
, "CMY"))
3560 profile_name
= "RGB";
3561 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3562 !strcmp(cm_choice
->choice
, "KCMY"))
3563 profile_name
= "CMYK";
3565 profile_name
= "DeviceN";
3567 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3568 profile_id
= _ppdHashName(selector
);
3570 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3571 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3572 &kCFTypeDictionaryKeyCallBacks
,
3573 &kCFTypeDictionaryValueCallBacks
);
3576 cupsdLogMessage(CUPSD_LOG_ERROR
,
3577 "Unable to allocate memory for color profile.");
3578 CFRelease(profiles
);
3583 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3584 cm_choice
->text
, NULL
);
3586 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3587 CFSTR("%u"), profile_id
);
3590 CFDictionarySetValue(profiles
, dict_key
, profile
);
3591 CFRelease(dict_key
);
3597 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3598 cm_choice
->text
, NULL
);
3600 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3602 if (cm_choice
->marked
)
3603 default_profile_id
= profile_id
;
3609 * Use the default colorspace...
3612 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3614 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3616 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3618 * Add the grayscale profile first. We always have a grayscale profile.
3621 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3622 &kCFTypeDictionaryKeyCallBacks
,
3623 &kCFTypeDictionaryValueCallBacks
);
3627 cupsdLogMessage(CUPSD_LOG_ERROR
,
3628 "Unable to allocate memory for color profile.");
3629 CFRelease(profiles
);
3634 profile_id
= _ppdHashName("Gray..");
3635 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "Gray", "Gray", NULL
);
3637 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3641 CFDictionarySetValue(profiles
, dict_key
, profile
);
3642 CFRelease(dict_key
);
3648 * Then add the RGB/CMYK/DeviceN color 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 switch (ppd
->colorspace
)
3668 profile_id
= _ppdHashName("RGB..");
3669 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "RGB", "RGB",
3674 profile_id
= _ppdHashName("CMYK..");
3675 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "CMYK", "CMYK",
3684 profile_id
= _ppdHashName("DeviceN..");
3685 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "DeviceN",
3690 if (CFDictionaryGetCount(profile
) > 0)
3692 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3693 CFSTR("%u"), profile_id
);
3696 CFDictionarySetValue(profiles
, dict_key
, profile
);
3697 CFRelease(dict_key
);
3705 * Create an array for the factory profiles...
3708 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3710 cupsdLogMessage(CUPSD_LOG_ERROR
,
3711 "Unable to allocate memory for factory profiles.");
3716 profiles
->profileCount
= num_profiles
;
3719 * Add the grayscale profile first. We always have a grayscale profile.
3722 profile_id
= _ppdHashName("Gray..");
3723 apple_init_profile(ppd
, NULL
, profiles
->profiles
, profile_id
, "Gray",
3727 * Then add the RGB/CMYK/DeviceN color profile...
3730 switch (ppd
->colorspace
)
3734 profile_id
= _ppdHashName("RGB..");
3735 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3736 "RGB", "RGB", NULL
);
3740 profile_id
= _ppdHashName("CMYK..");
3741 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3742 "CMYK", "CMYK", NULL
);
3750 profile_id
= _ppdHashName("DeviceN..");
3751 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3752 "DeviceN", "DeviceN", NULL
);
3755 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3758 if (num_profiles
> 0)
3761 * Make sure we have a default profile ID...
3764 if (!default_profile_id
)
3765 default_profile_id
= profile_id
; /* Last profile */
3767 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3768 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3769 default_profile_id
);
3772 CFDictionarySetValue(profiles
, kColorSyncDeviceDefaultProfileID
,
3774 CFRelease(dict_key
);
3776 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3779 * Get the device ID hash and pathelogical name dictionary.
3782 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3785 device_id
= _ppdHashName(p
->name
);
3786 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3787 &kCFTypeDictionaryKeyCallBacks
,
3788 &kCFTypeDictionaryValueCallBacks
);
3789 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3790 p
->name
, kCFStringEncodingUTF8
);
3792 if (device_name
&& printer_name
)
3794 CFDictionarySetValue(device_name
, CFSTR("en_US"), printer_name
);
3797 * Register the device with ColorSync...
3800 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3801 CFTypeRef deviceDictKeys
[] =
3803 kColorSyncDeviceDescriptions
,
3804 kColorSyncFactoryProfiles
,
3805 kColorSyncDeviceUserScope
,
3806 kColorSyncDeviceHostScope
3808 CFTypeRef deviceDictVals
[] =
3809 { /* Device values */
3812 kCFPreferencesAnyUser
,
3813 kCFPreferencesCurrentHost
3815 CFDictionaryRef deviceDict
; /* Device dictionary */
3816 CFStringRef printerUUID
; /* Printer UUID */
3817 CFUUIDRef deviceUUID
; /* Device UUID */
3819 deviceDict
= CFDictionaryCreate(kCFAllocatorDefault
,
3820 (const void **)deviceDictKeys
,
3821 (const void **)deviceDictVals
,
3822 sizeof(deviceDictKeys
) /
3823 sizeof(deviceDictKeys
[0]),
3824 &kCFTypeDictionaryKeyCallBacks
,
3825 &kCFTypeDictionaryValueCallBacks
);
3826 printerUUID
= CFStringCreateWithCString(kCFAllocatorDefault
,
3827 p
->uuid
+ 9, /* Skip urn:uuid: */
3828 kCFStringEncodingUTF8
);
3831 deviceUUID
= CFUUIDCreateFromString(kCFAllocatorDefault
, printerUUID
);
3832 CFRelease(printerUUID
);
3834 if (!deviceDict
|| !deviceUUID
||
3835 !ColorSyncRegisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
,
3843 CFRelease(deviceUUID
);
3846 CFRelease(deviceDict
);
3849 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3850 device_name
, &scope
);
3853 * Register the profiles...
3857 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3858 default_profile_id
, profiles
);
3859 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3869 cupsdLogMessage(CUPSD_LOG_ERROR
,
3870 "Unable to register ICC color profiles for \"%s\": %d",
3871 p
->name
, (int)error
);
3874 CFRelease(printer_name
);
3877 CFRelease(device_name
);
3881 * Free any memory we used...
3884 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3885 CFRelease(profiles
);
3888 if (num_profiles
> 0)
3890 for (profile
= profiles
->profiles
;
3892 profile
++, num_profiles
--)
3893 CFRelease(profile
->profileName
);
3897 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3904 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3909 apple_unregister_profiles(
3910 cupsd_printer_t
*p
) /* I - Printer */
3913 * Make sure ColorSync is available...
3916 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3917 if (ColorSyncUnregisterDevice
!= NULL
)
3920 * Because we may have registered the printer profiles using a prior device
3921 * ID-based UUID, remove both the old style UUID and current UUID for the
3925 CFStringRef printerUUID
; /* Printer UUID */
3926 CFUUIDRef deviceUUID
; /* Device UUID */
3928 deviceUUID
= ColorSyncCreateUUIDFromUInt32(_ppdHashName(p
->name
));
3931 ColorSyncUnregisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
);
3932 CFRelease(deviceUUID
);
3935 printerUUID
= CFStringCreateWithCString(kCFAllocatorDefault
, p
->uuid
+ 9,
3936 kCFStringEncodingUTF8
);
3939 deviceUUID
= CFUUIDCreateFromString(kCFAllocatorDefault
, printerUUID
);
3942 ColorSyncUnregisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
);
3943 CFRelease(deviceUUID
);
3946 CFRelease(printerUUID
);
3951 if (CMUnregisterColorDevice
!= NULL
)
3952 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3953 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3955 #endif /* __APPLE__ */
3959 * 'apply_printer_defaults()' - Apply printer default options to a job.
3963 apply_printer_defaults(
3964 cupsd_printer_t
*printer
, /* I - Printer */
3965 cupsd_job_t
*job
) /* I - Job */
3967 int i
, /* Looping var */
3968 num_options
; /* Number of default options */
3969 cups_option_t
*options
, /* Default options */
3970 *option
; /* Current option */
3974 * Collect all of the default options and add the missing ones to the
3978 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3979 option
= printer
->options
;
3982 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3984 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3989 * Encode these options as attributes in the job object...
3992 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3993 cupsFreeOptions(num_options
, options
);
3998 * 'authenticate_job()' - Set job authentication info.
4002 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
4003 ipp_attribute_t
*uri
) /* I - Job URI */
4005 ipp_attribute_t
*attr
, /* job-id attribute */
4006 *auth_info
; /* auth-info attribute */
4007 int jobid
; /* Job ID */
4008 cupsd_job_t
*job
; /* Current job */
4009 char scheme
[HTTP_MAX_URI
],
4010 /* Method portion of URI */
4011 username
[HTTP_MAX_URI
],
4012 /* Username portion of URI */
4014 /* Host portion of URI */
4015 resource
[HTTP_MAX_URI
];
4016 /* Resource portion of URI */
4017 int port
; /* Port portion of URI */
4020 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
4021 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
4024 * Start with "everything is OK" status...
4027 con
->response
->request
.status
.status_code
= IPP_OK
;
4030 * See if we have a job URI or a printer URI...
4033 if (!strcmp(uri
->name
, "printer-uri"))
4036 * Got a printer URI; see if we also have a job-id attribute...
4039 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4040 IPP_TAG_INTEGER
)) == NULL
)
4042 send_ipp_status(con
, IPP_BAD_REQUEST
,
4043 _("Got a printer-uri attribute but no job-id"));
4047 jobid
= attr
->values
[0].integer
;
4052 * Got a job URI; parse it to get the job ID...
4055 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4056 sizeof(scheme
), username
, sizeof(username
), host
,
4057 sizeof(host
), &port
, resource
, sizeof(resource
));
4059 if (strncmp(resource
, "/jobs/", 6))
4065 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\""),
4066 uri
->values
[0].string
.text
);
4070 jobid
= atoi(resource
+ 6);
4074 * See if the job exists...
4077 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4080 * Nope - return a "not found" error...
4083 send_ipp_status(con
, IPP_NOT_FOUND
,
4084 _("Job #%d does not exist"), jobid
);
4089 * See if the job has been completed...
4092 if (job
->state_value
!= IPP_JOB_HELD
)
4095 * Return a "not-possible" error...
4098 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4099 _("Job #%d is not held for authentication"),
4105 * See if we have already authenticated...
4108 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
4110 if (!con
->username
[0] && !auth_info
)
4112 cupsd_printer_t
*printer
; /* Job destination */
4116 * No auth data. If we need to authenticate via Kerberos, send a
4117 * HTTP auth challenge, otherwise just return an IPP error...
4120 printer
= cupsdFindDest(job
->dest
);
4122 if (printer
&& printer
->num_auth_info_required
> 0 &&
4123 !strcmp(printer
->auth_info_required
[0], "negotiate"))
4124 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
4126 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
4127 _("No authentication information provided"));
4132 * See if the job is owned by the requesting user...
4135 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4137 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4138 cupsdFindDest(job
->dest
));
4143 * Save the authentication information for this job...
4146 save_auth_info(con
, job
, auth_info
);
4149 * Reset the job-hold-until value to "no-hold"...
4152 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4153 IPP_TAG_KEYWORD
)) == NULL
)
4154 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4158 attr
->value_tag
= IPP_TAG_KEYWORD
;
4159 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
4163 * Release the job and return...
4166 cupsdReleaseJob(job
);
4168 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
4170 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
4177 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
4181 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
4182 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4184 int i
; /* Looping var */
4185 http_status_t status
; /* Policy status */
4186 cups_ptype_t dtype
; /* Destination type */
4187 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4188 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
4189 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
4190 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4191 int port
; /* Port portion of URI */
4192 ipp_attribute_t
*attr
; /* Attribute in request */
4193 const char *username
= NULL
; /* Username */
4194 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
4196 cupsd_printer_t
*printer
; /* Printer */
4197 ipp_attribute_t
*job_ids
; /* job-ids attribute */
4198 cupsd_job_t
*job
; /* Job */
4201 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
4202 con
->http
.fd
, uri
->values
[0].string
.text
);
4205 * Get the jobs to cancel/purge...
4208 switch (con
->request
->request
.op
.operation_id
)
4210 case IPP_PURGE_JOBS
:
4212 * Get the username (if any) for the jobs we want to cancel (only if
4213 * "my-jobs" is specified...
4216 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
4217 IPP_TAG_BOOLEAN
)) != NULL
&&
4218 attr
->values
[0].boolean
)
4220 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4221 IPP_TAG_NAME
)) != NULL
)
4222 username
= attr
->values
[0].string
.text
;
4225 send_ipp_status(con
, IPP_BAD_REQUEST
,
4226 _("Missing requesting-user-name attribute"));
4232 * Look for the "purge-jobs" attribute...
4235 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
4236 IPP_TAG_BOOLEAN
)) != NULL
)
4237 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4239 purge
= CUPSD_JOB_PURGE
;
4242 case IPP_CANCEL_MY_JOBS
:
4243 if (con
->username
[0])
4244 username
= con
->username
;
4245 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4246 IPP_TAG_NAME
)) != NULL
)
4247 username
= attr
->values
[0].string
.text
;
4250 send_ipp_status(con
, IPP_BAD_REQUEST
,
4251 _("Missing requesting-user-name attribute"));
4259 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
4262 * See if we have a printer URI...
4265 if (strcmp(uri
->name
, "printer-uri"))
4267 send_ipp_status(con
, IPP_BAD_REQUEST
,
4268 _("The printer-uri attribute is required"));
4273 * And if the destination is valid...
4276 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4282 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
4283 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
4284 hostname
, sizeof(hostname
), &port
,
4285 resource
, sizeof(resource
));
4287 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
4288 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
4290 send_ipp_status(con
, IPP_NOT_FOUND
,
4291 _("The printer or class was not found."));
4299 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
4301 send_http_error(con
, status
, NULL
);
4307 for (i
= 0; i
< job_ids
->num_values
; i
++)
4309 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
4313 if (i
< job_ids
->num_values
)
4315 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
4316 job_ids
->values
[i
].integer
);
4320 for (i
= 0; i
< job_ids
->num_values
; i
++)
4322 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4324 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4325 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4326 "Job canceled by user.");
4329 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4330 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4336 * Cancel all jobs on all printers...
4339 cupsdCancelJobs(NULL
, username
, purge
);
4341 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
4342 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4352 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4355 send_http_error(con
, status
, printer
);
4361 for (i
= 0; i
< job_ids
->num_values
; i
++)
4363 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
4364 strcasecmp(job
->dest
, printer
->name
))
4368 if (i
< job_ids
->num_values
)
4370 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
4371 job_ids
->values
[i
].integer
);
4375 for (i
= 0; i
< job_ids
->num_values
; i
++)
4377 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4379 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4380 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4381 "Job canceled by user.");
4384 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4385 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4391 * Cancel all of the jobs on the named printer...
4394 cupsdCancelJobs(printer
->name
, username
, purge
);
4396 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
4398 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4403 con
->response
->request
.status
.status_code
= IPP_OK
;
4408 * 'cancel_job()' - Cancel a print job.
4412 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
4413 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4415 ipp_attribute_t
*attr
; /* Current attribute */
4416 int jobid
; /* Job ID */
4417 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4418 username
[HTTP_MAX_URI
], /* Username portion of URI */
4419 host
[HTTP_MAX_URI
], /* Host portion of URI */
4420 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4421 int port
; /* Port portion of URI */
4422 cupsd_job_t
*job
; /* Job information */
4423 cups_ptype_t dtype
; /* Destination type (printer/class) */
4424 cupsd_printer_t
*printer
; /* Printer data */
4425 cupsd_jobaction_t purge
; /* Purge the job? */
4428 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
4429 con
->http
.fd
, uri
->values
[0].string
.text
);
4432 * See if we have a job URI or a printer URI...
4435 if (!strcmp(uri
->name
, "printer-uri"))
4438 * Got a printer URI; see if we also have a job-id attribute...
4441 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4442 IPP_TAG_INTEGER
)) == NULL
)
4444 send_ipp_status(con
, IPP_BAD_REQUEST
,
4445 _("Got a printer-uri attribute but no job-id"));
4449 if ((jobid
= attr
->values
[0].integer
) == 0)
4452 * Find the current job on the specified printer...
4455 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4461 send_ipp_status(con
, IPP_NOT_FOUND
,
4462 _("The printer or class was not found."));
4467 * See if there are any pending jobs...
4470 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4472 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4473 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
4474 !strcasecmp(job
->dest
, printer
->name
))
4482 * No, try stopped jobs...
4485 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4487 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4488 if (job
->state_value
== IPP_JOB_STOPPED
&&
4489 !strcasecmp(job
->dest
, printer
->name
))
4496 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s"),
4506 * Got a job URI; parse it to get the job ID...
4509 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4510 sizeof(scheme
), username
, sizeof(username
), host
,
4511 sizeof(host
), &port
, resource
, sizeof(resource
));
4513 if (strncmp(resource
, "/jobs/", 6))
4519 send_ipp_status(con
, IPP_BAD_REQUEST
,
4520 _("Bad job-uri attribute \"%s\""),
4521 uri
->values
[0].string
.text
);
4525 jobid
= atoi(resource
+ 6);
4529 * Look for the "purge-job" attribute...
4532 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4533 IPP_TAG_BOOLEAN
)) != NULL
)
4534 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4536 purge
= CUPSD_JOB_DEFAULT
;
4539 * See if the job exists...
4542 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4545 * Nope - return a "not found" error...
4548 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
4553 * See if the job is owned by the requesting user...
4556 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4558 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4559 cupsdFindDest(job
->dest
));
4564 * See if the job is already completed, canceled, or aborted; if so,
4565 * we can't cancel...
4568 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4570 switch (job
->state_value
)
4572 case IPP_JOB_CANCELED
:
4573 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4574 _("Job #%d is already canceled - can\'t cancel."),
4578 case IPP_JOB_ABORTED
:
4579 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4580 _("Job #%d is already aborted - can\'t cancel."),
4585 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4586 _("Job #%d is already completed - can\'t cancel."),
4595 * Cancel the job and return...
4598 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4599 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4600 "Job canceled by \"%s\"",
4604 if (purge
== CUPSD_JOB_PURGE
)
4605 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4608 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4611 con
->response
->request
.status
.status_code
= IPP_OK
;
4616 * 'cancel_subscription()' - Cancel a subscription.
4620 cancel_subscription(
4621 cupsd_client_t
*con
, /* I - Client connection */
4622 int sub_id
) /* I - Subscription ID */
4624 http_status_t status
; /* Policy status */
4625 cupsd_subscription_t
*sub
; /* Subscription */
4628 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4629 "cancel_subscription(con=%p[%d], sub_id=%d)",
4630 con
, con
->http
.fd
, sub_id
);
4633 * Is the subscription ID valid?
4636 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4639 * Bad subscription ID...
4642 send_ipp_status(con
, IPP_NOT_FOUND
,
4643 _("notify-subscription-id %d no good"), sub_id
);
4651 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4653 con
, sub
->owner
)) != HTTP_OK
)
4655 send_http_error(con
, status
, sub
->dest
);
4660 * Cancel the subscription...
4663 cupsdDeleteSubscription(sub
, 1);
4665 con
->response
->request
.status
.status_code
= IPP_OK
;
4670 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4673 static int /* O - 1 if OK, 0 if not */
4674 check_rss_recipient(
4675 const char *recipient
) /* I - Recipient URI */
4677 cupsd_subscription_t
*sub
; /* Current subscription */
4680 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4682 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4686 * Compare the URIs up to the first ?...
4689 const char *r1
, *r2
;
4691 for (r1
= recipient
, r2
= sub
->recipient
;
4692 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4704 * 'check_quotas()' - Check quotas for a printer and user.
4707 static int /* O - 1 if OK, 0 if forbidden,
4708 -1 if limit reached */
4709 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4710 cupsd_printer_t
*p
) /* I - Printer or class */
4712 char username
[33], /* Username */
4713 *name
; /* Current user name */
4714 cupsd_quota_t
*q
; /* Quota data */
4715 #ifdef HAVE_MBR_UID_TO_UUID
4717 * Use Apple membership APIs which require that all names represent
4718 * valid user account or group records accessible by the server.
4721 uuid_t usr_uuid
; /* UUID for job requesting user */
4722 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4723 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4724 int mbr_err
; /* Error from membership function */
4725 int is_member
; /* Is this user a member? */
4728 * Use standard POSIX APIs for checking users and groups...
4731 struct passwd
*pw
; /* User password data */
4732 #endif /* HAVE_MBR_UID_TO_UUID */
4735 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4736 con
, con
->http
.fd
, p
, p
->name
);
4739 * Figure out who is printing...
4742 strlcpy(username
, get_username(con
), sizeof(username
));
4745 * Check global active job limits for printers and users...
4748 if (MaxJobsPerPrinter
)
4751 * Check if there are too many pending jobs on this printer...
4754 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4756 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4765 * Check if there are too many pending jobs for this user...
4768 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4770 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4777 * Check against users...
4780 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4783 if (cupsArrayCount(p
->users
))
4785 #ifdef HAVE_MBR_UID_TO_UUID
4787 * Get UUID for job requesting user...
4790 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4796 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4797 "check_quotas: UUID lookup failed for user \"%s\"",
4799 cupsdLogMessage(CUPSD_LOG_INFO
,
4800 "Denying user \"%s\" access to printer \"%s\" "
4801 "(unknown user)...",
4807 * Get UID and GID of requesting user...
4810 pw
= getpwnam(username
);
4812 #endif /* HAVE_MBR_UID_TO_UUID */
4814 for (name
= (char *)cupsArrayFirst(p
->users
);
4816 name
= (char *)cupsArrayNext(p
->users
))
4820 * Check group membership...
4823 #ifdef HAVE_MBR_UID_TO_UUID
4826 if (uuid_parse(name
+ 2, grp_uuid
))
4827 uuid_clear(grp_uuid
);
4829 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
4832 * Invalid ACL entries are ignored for matching; just record a
4833 * warning in the log...
4836 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4837 "check_quotas: UUID lookup failed for ACL entry "
4838 "\"%s\" (err=%d)", name
, mbr_err
);
4839 cupsdLogMessage(CUPSD_LOG_WARN
,
4840 "Access control entry \"%s\" not a valid group name; "
4841 "entry ignored", name
);
4844 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4848 * At this point, there should be no errors, but check anyways...
4851 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4852 "check_quotas: group \"%s\" membership check "
4853 "failed (err=%d)", name
+ 1, mbr_err
);
4858 * Stop if we found a match...
4865 if (cupsdCheckGroup(username
, pw
, name
+ 1))
4867 #endif /* HAVE_MBR_UID_TO_UUID */
4869 #ifdef HAVE_MBR_UID_TO_UUID
4874 if (uuid_parse(name
+ 1, usr2_uuid
))
4875 uuid_clear(usr2_uuid
);
4877 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
4880 * Invalid ACL entries are ignored for matching; just record a
4881 * warning in the log...
4884 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4885 "check_quotas: UUID lookup failed for ACL entry "
4886 "\"%s\" (err=%d)", name
, mbr_err
);
4887 cupsdLogMessage(CUPSD_LOG_WARN
,
4888 "Access control entry \"%s\" not a valid user name; "
4889 "entry ignored", name
);
4892 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4896 else if (!strcasecmp(username
, name
))
4898 #endif /* HAVE_MBR_UID_TO_UUID */
4900 if ((name
!= NULL
) == p
->deny_users
)
4902 cupsdLogMessage(CUPSD_LOG_INFO
,
4903 "Denying user \"%s\" access to printer \"%s\"...",
4913 if (p
->k_limit
|| p
->page_limit
)
4915 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4917 cupsdLogMessage(CUPSD_LOG_ERROR
,
4918 "Unable to allocate quota data for user \"%s\"",
4923 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4924 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4926 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4933 * If we have gotten this far, we're done!
4941 * 'close_job()' - Close a multi-file job.
4945 close_job(cupsd_client_t
*con
, /* I - Client connection */
4946 ipp_attribute_t
*uri
) /* I - Printer URI */
4948 cupsd_job_t
*job
; /* Job */
4949 ipp_attribute_t
*attr
; /* Attribute */
4950 char job_uri
[HTTP_MAX_URI
],
4952 username
[256]; /* User name */
4955 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4956 con
->http
.fd
, uri
->values
[0].string
.text
);
4959 * See if we have a job URI or a printer URI...
4962 if (strcmp(uri
->name
, "printer-uri"))
4965 * job-uri is not supported by Close-Job!
4968 send_ipp_status(con
, IPP_BAD_REQUEST
,
4969 _("Close-Job doesn't support the job-uri attribute."));
4974 * Got a printer URI; see if we also have a job-id attribute...
4977 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4978 IPP_TAG_INTEGER
)) == NULL
)
4980 send_ipp_status(con
, IPP_BAD_REQUEST
,
4981 _("Got a printer-uri attribute but no job-id"));
4985 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4988 * Nope - return a "not found" error...
4991 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
4992 attr
->values
[0].integer
);
4997 * See if the job is owned by the requesting user...
5000 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
5002 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
5003 cupsdFindDest(job
->dest
));
5008 * Add any ending sheet...
5011 if (cupsdTimeoutJob(job
))
5014 if (job
->state_value
== IPP_JOB_STOPPED
)
5016 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5017 job
->state_value
= IPP_JOB_PENDING
;
5019 else if (job
->state_value
== IPP_JOB_HELD
)
5021 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
5022 IPP_TAG_KEYWORD
)) == NULL
)
5023 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
5025 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
5027 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5028 job
->state_value
= IPP_JOB_PENDING
;
5033 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
5036 * Fill in the response info...
5039 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
5040 LocalPort
, job
->id
);
5041 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
5044 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
5046 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
5049 add_job_state_reasons(con
, job
);
5051 con
->response
->request
.status
.status_code
= IPP_OK
;
5054 * Start the job if necessary...
5062 * 'copy_attribute()' - Copy a single attribute.
5065 static ipp_attribute_t
* /* O - New attribute */
5067 ipp_t
*to
, /* O - Destination request/response */
5068 ipp_attribute_t
*attr
, /* I - Attribute to copy */
5069 int quickcopy
) /* I - Do a quick copy? */
5071 int i
; /* Looping var */
5072 ipp_attribute_t
*toattr
; /* Destination attribute */
5075 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5076 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
5077 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
5080 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
5083 toattr
= ippAddSeparator(to
);
5086 case IPP_TAG_INTEGER
:
5088 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5089 attr
->name
, attr
->num_values
, NULL
);
5091 for (i
= 0; i
< attr
->num_values
; i
++)
5092 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
5095 case IPP_TAG_BOOLEAN
:
5096 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
5097 attr
->num_values
, NULL
);
5099 for (i
= 0; i
< attr
->num_values
; i
++)
5100 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
5103 case IPP_TAG_STRING
:
5106 case IPP_TAG_KEYWORD
:
5108 case IPP_TAG_URISCHEME
:
5109 case IPP_TAG_CHARSET
:
5110 case IPP_TAG_LANGUAGE
:
5111 case IPP_TAG_MIMETYPE
:
5112 toattr
= ippAddStrings(to
, attr
->group_tag
,
5113 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5114 attr
->name
, attr
->num_values
, NULL
, NULL
);
5118 for (i
= 0; i
< attr
->num_values
; i
++)
5119 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5121 else if (attr
->value_tag
& IPP_TAG_COPY
)
5123 for (i
= 0; i
< attr
->num_values
; i
++)
5124 toattr
->values
[i
].string
.text
=
5125 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5129 for (i
= 0; i
< attr
->num_values
; i
++)
5130 toattr
->values
[i
].string
.text
=
5131 _cupsStrRetain(attr
->values
[i
].string
.text
);
5136 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
5137 attr
->values
[0].date
);
5140 case IPP_TAG_RESOLUTION
:
5141 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
5142 attr
->num_values
, IPP_RES_PER_INCH
,
5145 for (i
= 0; i
< attr
->num_values
; i
++)
5147 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
5148 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
5149 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
5153 case IPP_TAG_RANGE
:
5154 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
5155 attr
->num_values
, NULL
, NULL
);
5157 for (i
= 0; i
< attr
->num_values
; i
++)
5159 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
5160 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
5164 case IPP_TAG_TEXTLANG
:
5165 case IPP_TAG_NAMELANG
:
5166 toattr
= ippAddStrings(to
, attr
->group_tag
,
5167 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5168 attr
->name
, attr
->num_values
, NULL
, NULL
);
5172 for (i
= 0; i
< attr
->num_values
; i
++)
5174 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
5175 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5178 else if (attr
->value_tag
& IPP_TAG_COPY
)
5180 for (i
= 0; i
< attr
->num_values
; i
++)
5183 toattr
->values
[i
].string
.charset
=
5184 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
5186 toattr
->values
[i
].string
.charset
=
5187 toattr
->values
[0].string
.charset
;
5189 toattr
->values
[i
].string
.text
=
5190 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5195 for (i
= 0; i
< attr
->num_values
; i
++)
5198 toattr
->values
[i
].string
.charset
=
5199 _cupsStrRetain(attr
->values
[i
].string
.charset
);
5201 toattr
->values
[i
].string
.charset
=
5202 toattr
->values
[0].string
.charset
;
5204 toattr
->values
[i
].string
.text
=
5205 _cupsStrRetain(attr
->values
[i
].string
.text
);
5210 case IPP_TAG_BEGIN_COLLECTION
:
5211 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
5212 attr
->num_values
, NULL
);
5214 for (i
= 0; i
< attr
->num_values
; i
++)
5216 toattr
->values
[i
].collection
= attr
->values
[i
].collection
;
5217 attr
->values
[i
].collection
->use
++;
5222 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5223 attr
->name
, attr
->num_values
, NULL
);
5225 for (i
= 0; i
< attr
->num_values
; i
++)
5227 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
5229 if (toattr
->values
[i
].unknown
.length
> 0)
5231 if ((toattr
->values
[i
].unknown
.data
=
5232 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
5233 toattr
->values
[i
].unknown
.length
= 0;
5235 memcpy(toattr
->values
[i
].unknown
.data
,
5236 attr
->values
[i
].unknown
.data
,
5237 toattr
->values
[i
].unknown
.length
);
5240 break; /* anti-compiler-warning-code */
5248 * 'copy_attrs()' - Copy attributes from one request to another.
5252 copy_attrs(ipp_t
*to
, /* I - Destination request */
5253 ipp_t
*from
, /* I - Source request */
5254 cups_array_t
*ra
, /* I - Requested attributes */
5255 ipp_tag_t group
, /* I - Group to copy */
5256 int quickcopy
, /* I - Do a quick copy? */
5257 cups_array_t
*exclude
) /* I - Attributes to exclude? */
5259 ipp_attribute_t
*fromattr
; /* Source attribute */
5262 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5263 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
5264 to
, from
, ra
, group
, quickcopy
);
5269 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
5272 * Filter attributes as needed...
5275 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
5276 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
5280 (cupsArrayFind(exclude
, fromattr
->name
) ||
5281 cupsArrayFind(exclude
, "all")))
5284 * We need to exclude this attribute for security reasons; we require the
5285 * job-id and job-printer-uri attributes regardless of the security
5286 * settings for IPP conformance.
5288 * Subscription attribute security is handled by copy_subscription_attrs().
5291 if (strcmp(fromattr
->name
, "job-id") &&
5292 strcmp(fromattr
->name
, "job-printer-uri"))
5296 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
5299 * Don't send collection attributes by default to IPP/1.x clients
5300 * since many do not support collections. Also don't send
5301 * media-col-database unless specifically requested by the client.
5304 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
5306 (to
->request
.status
.version
[0] == 1 ||
5307 !strcmp(fromattr
->name
, "media-col-database")))
5310 copy_attribute(to
, fromattr
, quickcopy
);
5317 * 'copy_banner()' - Copy a banner file to the requests directory for the
5321 static int /* O - Size of banner file in kbytes */
5322 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
5323 cupsd_job_t
*job
, /* I - Job information */
5324 const char *name
) /* I - Name of banner */
5326 int i
; /* Looping var */
5327 int kbytes
; /* Size of banner file in kbytes */
5328 char filename
[1024]; /* Job filename */
5329 cupsd_banner_t
*banner
; /* Pointer to banner */
5330 cups_file_t
*in
; /* Input file */
5331 cups_file_t
*out
; /* Output file */
5332 int ch
; /* Character from file */
5333 char attrname
[255], /* Name of attribute */
5334 *s
; /* Pointer into name */
5335 ipp_attribute_t
*attr
; /* Attribute */
5338 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5339 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
5340 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
5341 name
? name
: "(null)");
5344 * Find the banner; return if not found or "none"...
5347 if (!name
|| !strcmp(name
, "none") ||
5348 (banner
= cupsdFindBanner(name
)) == NULL
)
5352 * Open the banner and job files...
5355 if (add_file(con
, job
, banner
->filetype
, 0))
5358 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
5360 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
5362 cupsdLogMessage(CUPSD_LOG_ERROR
,
5363 "Unable to create banner job file %s - %s",
5364 filename
, strerror(errno
));
5369 fchmod(cupsFileNumber(out
), 0640);
5370 fchown(cupsFileNumber(out
), RunUser
, Group
);
5373 * Try the localized banner file under the subdirectory...
5376 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5378 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5381 * Convert ll-cc to ll_CC...
5385 attrname
[3] = toupper(attrname
[3] & 255);
5386 attrname
[4] = toupper(attrname
[4] & 255);
5389 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5392 if (access(filename
, 0) && strlen(attrname
) > 2)
5395 * Wasn't able to find "ll_CC" locale file; try the non-national
5396 * localization banner directory.
5401 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5405 if (access(filename
, 0))
5408 * Use the non-localized banner file.
5411 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5414 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5418 cupsdLogMessage(CUPSD_LOG_ERROR
,
5419 "Unable to open banner template file %s - %s",
5420 filename
, strerror(errno
));
5426 * Parse the file to the end...
5429 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5433 * Get an attribute name...
5436 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5437 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5439 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5449 * Ignore { followed by stuff that is not an attribute name...
5452 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5457 * See if it is defined...
5460 if (attrname
[0] == '?')
5465 if (!strcmp(s
, "printer-name"))
5467 cupsFilePuts(out
, job
->dest
);
5470 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5473 * See if we have a leading question mark...
5476 if (attrname
[0] != '?')
5479 * Nope, write to file as-is; probably a PostScript procedure...
5482 cupsFilePrintf(out
, "{%s}", attrname
);
5489 * Output value(s)...
5492 for (i
= 0; i
< attr
->num_values
; i
++)
5495 cupsFilePutChar(out
, ',');
5497 switch (attr
->value_tag
)
5499 case IPP_TAG_INTEGER
:
5501 if (!strncmp(s
, "time-at-", 8))
5503 struct timeval tv
; /* Time value */
5505 tv
.tv_sec
= attr
->values
[i
].integer
;
5508 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5511 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5514 case IPP_TAG_BOOLEAN
:
5515 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5518 case IPP_TAG_NOVALUE
:
5519 cupsFilePuts(out
, "novalue");
5522 case IPP_TAG_RANGE
:
5523 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5524 attr
->values
[i
].range
.upper
);
5527 case IPP_TAG_RESOLUTION
:
5528 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5529 attr
->values
[i
].resolution
.yres
,
5530 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5535 case IPP_TAG_STRING
:
5538 case IPP_TAG_KEYWORD
:
5539 case IPP_TAG_CHARSET
:
5540 case IPP_TAG_LANGUAGE
:
5541 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
5544 * Need to quote strings for PS banners...
5549 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5551 if (*p
== '(' || *p
== ')' || *p
== '\\')
5553 cupsFilePutChar(out
, '\\');
5554 cupsFilePutChar(out
, *p
);
5556 else if (*p
< 32 || *p
> 126)
5557 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5559 cupsFilePutChar(out
, *p
);
5563 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5567 break; /* anti-compiler-warning-code */
5571 else if (ch
== '\\') /* Quoted char */
5573 ch
= cupsFileGetChar(in
);
5575 if (ch
!= '{') /* Only do special handling for \{ */
5576 cupsFilePutChar(out
, '\\');
5578 cupsFilePutChar(out
, ch
);
5581 cupsFilePutChar(out
, ch
);
5585 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5587 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5588 IPP_TAG_INTEGER
)) != NULL
)
5589 attr
->values
[0].integer
+= kbytes
;
5598 * 'copy_file()' - Copy a PPD file or interface script...
5601 static int /* O - 0 = success, -1 = error */
5602 copy_file(const char *from
, /* I - Source file */
5603 const char *to
) /* I - Destination file */
5605 cups_file_t
*src
, /* Source file */
5606 *dst
; /* Destination file */
5607 int bytes
; /* Bytes to read/write */
5608 char buffer
[2048]; /* Copy buffer */
5611 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5614 * Open the source and destination file for a copy...
5617 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5620 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5627 * Copy the source file to the destination...
5630 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5631 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5639 * Close both files and return...
5644 return (cupsFileClose(dst
));
5649 * 'copy_model()' - Copy a PPD model file, substituting default values
5653 static int /* O - 0 = success, -1 = error */
5654 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5655 const char *from
, /* I - Source file */
5656 const char *to
) /* I - Destination file */
5658 fd_set input
; /* select() input set */
5659 struct timeval timeout
; /* select() timeout */
5660 int maxfd
; /* Max file descriptor for select() */
5661 char tempfile
[1024]; /* Temporary PPD file */
5662 int tempfd
; /* Temporary PPD file descriptor */
5663 int temppid
; /* Process ID of cups-driverd */
5664 int temppipe
[2]; /* Temporary pipes */
5665 char *argv
[4], /* Command-line arguments */
5666 *envp
[MAX_ENV
]; /* Environment */
5667 cups_file_t
*src
, /* Source file */
5668 *dst
; /* Destination file */
5669 ppd_file_t
*ppd
; /* PPD file */
5670 int bytes
, /* Bytes from pipe */
5671 total
; /* Total bytes from pipe */
5672 char buffer
[2048]; /* Copy buffer */
5673 int i
; /* Looping var */
5674 char option
[PPD_MAX_NAME
], /* Option name */
5675 choice
[PPD_MAX_NAME
]; /* Choice name */
5676 ppd_size_t
*size
; /* Default size */
5677 int num_defaults
; /* Number of default options */
5678 cups_option_t
*defaults
; /* Default options */
5679 char cups_protocol
[PPD_MAX_LINE
];
5680 /* cupsProtocol attribute */
5683 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5684 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5688 * Run cups-driverd to get the PPD file...
5691 argv
[0] = "cups-driverd";
5693 argv
[2] = (char *)from
;
5696 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5698 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5699 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5700 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5704 cupsdOpenPipe(temppipe
);
5706 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5707 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5709 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5710 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5721 * Wait up to 30 seconds for the PPD file to be copied...
5726 if (temppipe
[0] > CGIPipes
[0])
5727 maxfd
= temppipe
[0] + 1;
5729 maxfd
= CGIPipes
[0] + 1;
5734 * See if we have data ready...
5738 FD_SET(temppipe
[0], &input
);
5739 FD_SET(CGIPipes
[0], &input
);
5741 timeout
.tv_sec
= 30;
5742 timeout
.tv_usec
= 0;
5744 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5754 * We have timed out...
5760 if (FD_ISSET(temppipe
[0], &input
))
5763 * Read the PPD file from the pipe, and write it to the PPD file.
5766 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5768 if (write(tempfd
, buffer
, bytes
) < bytes
)
5777 if (FD_ISSET(CGIPipes
[0], &input
))
5787 * No data from cups-deviced...
5790 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5796 * Read the source file and see what page sizes are supported...
5799 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5806 * Open the destination (if possible) and set the default options...
5811 cups_protocol
[0] = '\0';
5813 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5816 * Read all of the default lines from the old PPD...
5819 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5820 if (!strncmp(buffer
, "*Default", 8))
5823 * Add the default option...
5826 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5827 choice
, sizeof(choice
)))
5829 ppd_option_t
*ppdo
; /* PPD option */
5833 * Only add the default if the default hasn't already been
5834 * set and the choice exists in the new PPD...
5837 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5838 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5839 ppdFindChoice(ppdo
, choice
))
5840 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5844 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5845 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5849 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5852 * Add the default media sizes...
5855 num_defaults
= cupsAddOption("PageSize", size
->name
,
5856 num_defaults
, &defaults
);
5857 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5858 num_defaults
, &defaults
);
5859 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5860 num_defaults
, &defaults
);
5861 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5862 num_defaults
, &defaults
);
5868 * Open the source file for a copy...
5871 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5873 cupsFreeOptions(num_defaults
, defaults
);
5879 * Open the destination file for a copy...
5882 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5884 cupsFreeOptions(num_defaults
, defaults
);
5891 * Copy the source file to the destination...
5894 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5896 if (!strncmp(buffer
, "*Default", 8))
5899 * Check for an previous default option choice...
5902 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5903 choice
, sizeof(choice
)))
5905 const char *val
; /* Default option value */
5908 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5911 * Substitute the previous choice...
5914 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5919 cupsFilePrintf(dst
, "%s\n", buffer
);
5922 if (cups_protocol
[0])
5923 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5925 cupsFreeOptions(num_defaults
, defaults
);
5928 * Close both files and return...
5935 return (cupsFileClose(dst
));
5940 * 'copy_job_attrs()' - Copy job attributes.
5944 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5945 cupsd_job_t
*job
, /* I - Job */
5946 cups_array_t
*ra
, /* I - Requested attributes array */
5947 cups_array_t
*exclude
) /* I - Private attributes array */
5949 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5953 * Send the requested attributes for each job...
5956 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5957 con
->servername
, con
->serverport
, "/jobs/%d",
5960 if (!cupsArrayFind(exclude
, "all"))
5962 if ((!exclude
|| !cupsArrayFind(exclude
, "document-count")) &&
5963 (!ra
|| cupsArrayFind(ra
, "document-count")))
5964 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5965 "document-count", job
->num_files
);
5967 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
5968 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
5969 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5970 "job-media-progress", job
->progress
);
5972 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
5973 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
5974 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5975 "job-more-info", NULL
, job_uri
);
5977 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5978 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
5979 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5980 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5981 job
->num_files
> 0);
5983 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
5984 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
5985 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5986 "job-printer-up-time", time(NULL
));
5989 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5990 add_job_state_reasons(con
, job
);
5992 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5993 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5994 "job-uri", NULL
, job_uri
);
5996 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
6001 * 'copy_printer_attrs()' - Copy printer attributes.
6006 cupsd_client_t
*con
, /* I - Client connection */
6007 cupsd_printer_t
*printer
, /* I - Printer */
6008 cups_array_t
*ra
) /* I - Requested attributes array */
6010 char printer_uri
[HTTP_MAX_URI
];
6012 char printer_icons
[HTTP_MAX_URI
];
6014 time_t curtime
; /* Current time */
6015 int i
; /* Looping var */
6019 * Copy the printer attributes to the response using requested-attributes
6020 * and document-format attributes that may be provided by the client.
6023 curtime
= time(NULL
);
6025 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
6026 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6027 "marker-change-time", printer
->marker_time
);
6029 if (printer
->num_printers
> 0 &&
6030 (!ra
|| cupsArrayFind(ra
, "member-uris")))
6032 ipp_attribute_t
*member_uris
; /* member-uris attribute */
6033 cupsd_printer_t
*p2
; /* Printer in class */
6034 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
6037 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
6038 IPP_TAG_URI
, "member-uris",
6039 printer
->num_printers
, NULL
,
6042 for (i
= 0; i
< printer
->num_printers
; i
++)
6044 p2
= printer
->printers
[i
];
6046 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
6047 IPP_TAG_URI
)) != NULL
)
6048 member_uris
->values
[i
].string
.text
=
6049 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
6052 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
6053 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
6055 (p2
->type
& CUPS_PRINTER_CLASS
) ?
6056 "/classes/%s" : "/printers/%s", p2
->name
);
6057 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
6063 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
6064 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
6065 "printer-alert", NULL
, printer
->alert
);
6067 if (printer
->alert_description
&&
6068 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
6069 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
6070 "printer-alert-description", NULL
,
6071 printer
->alert_description
);
6073 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
6074 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
6075 ippTimeToDate(curtime
));
6078 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
6080 if (printer
->reg_name
)
6081 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6082 "printer-dns-sd-name", NULL
, printer
->reg_name
);
6084 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
6085 "printer-dns-sd-name", 0);
6087 #endif /* HAVE_DNSSD */
6089 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
6090 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6091 "printer-error-policy", NULL
, printer
->error_policy
);
6093 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
6095 static const char * const errors
[] =/* printer-error-policy-supported values */
6098 "retry-current-job",
6103 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
6104 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6105 "printer-error-policy-supported", NULL
, "retry-current-job");
6107 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6108 "printer-error-policy-supported",
6109 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
6112 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
6114 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
6115 "http", NULL
, con
->servername
, con
->serverport
,
6116 "/icons/%s.png", printer
->name
);
6117 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
6118 NULL
, printer_icons
);
6119 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
6122 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
6123 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
6124 printer
->accepting
);
6126 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
6127 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
6130 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
6131 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6133 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6134 "http", NULL
, con
->servername
, con
->serverport
,
6135 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6136 "/classes/%s" : "/printers/%s", printer
->name
);
6137 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6138 "printer-more-info", NULL
, printer_uri
);
6141 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
6142 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6143 "printer-op-policy", NULL
, printer
->op_policy
);
6145 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
6146 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
6149 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
6150 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6151 "printer-state-change-time", printer
->state_time
);
6153 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
6154 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
6155 "printer-state-message", NULL
, printer
->state_message
);
6157 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
6158 add_printer_state_reasons(con
, printer
);
6160 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
6162 int type
; /* printer-type value */
6165 * Add the CUPS-specific printer-type attribute...
6168 type
= printer
->type
;
6170 if (printer
== DefaultPrinter
)
6171 type
|= CUPS_PRINTER_DEFAULT
;
6173 if (!printer
->accepting
)
6174 type
|= CUPS_PRINTER_REJECTING
;
6176 if (!printer
->shared
)
6177 type
|= CUPS_PRINTER_NOT_SHARED
;
6179 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
6183 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
6184 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6185 "printer-up-time", curtime
);
6187 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
6188 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6190 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6191 "ipp", NULL
, con
->servername
, con
->serverport
,
6192 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6193 "/classes/%s" : "/printers/%s", printer
->name
);
6194 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6195 "printer-uri-supported", NULL
, printer_uri
);
6196 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
6200 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
6201 add_queued_job_count(con
, printer
);
6203 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6204 if (printer
->ppd_attrs
)
6205 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6206 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
6211 * 'copy_subscription_attrs()' - Copy subscription attributes.
6215 copy_subscription_attrs(
6216 cupsd_client_t
*con
, /* I - Client connection */
6217 cupsd_subscription_t
*sub
, /* I - Subscription */
6218 cups_array_t
*ra
, /* I - Requested attributes array */
6219 cups_array_t
*exclude
) /* I - Private attributes array */
6221 ipp_attribute_t
*attr
; /* Current attribute */
6222 char printer_uri
[HTTP_MAX_URI
];
6224 int count
; /* Number of events */
6225 unsigned mask
; /* Current event mask */
6226 const char *name
; /* Current event name */
6229 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6230 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
6231 con
, sub
, ra
, exclude
);
6234 * Copy the subscription attributes to the response using the
6235 * requested-attributes attribute that may be provided by the client.
6238 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
6240 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
6241 (!ra
|| cupsArrayFind(ra
, "notify-events")))
6243 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
6245 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
6248 * Simple event list...
6251 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
6252 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6253 "notify-events", NULL
, name
);
6258 * Complex event list...
6261 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6262 if (sub
->mask
& mask
)
6265 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
6266 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6267 "notify-events", count
, NULL
, NULL
);
6269 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6270 if (sub
->mask
& mask
)
6272 attr
->values
[count
].string
.text
=
6273 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
6280 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
6281 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
6282 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6283 "notify-lease-duration", sub
->lease
);
6285 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
6286 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
6287 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6288 "notify-recipient-uri", NULL
, sub
->recipient
);
6289 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
6290 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
6291 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
6292 "notify-pull-method", NULL
, "ippget");
6294 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
6295 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
6296 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
6297 "notify-subscriber-user-name", NULL
, sub
->owner
);
6299 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
6300 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
6301 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6302 "notify-time-interval", sub
->interval
);
6304 if (sub
->user_data_len
> 0 &&
6305 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
6306 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
6307 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
6308 sub
->user_data
, sub
->user_data_len
);
6311 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
6312 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6313 "notify-job-id", sub
->job
->id
);
6315 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
6317 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6318 "ipp", NULL
, con
->servername
, con
->serverport
,
6319 "/printers/%s", sub
->dest
->name
);
6320 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6321 "notify-printer-uri", NULL
, printer_uri
);
6324 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
6325 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6326 "notify-subscription-id", sub
->id
);
6331 * 'create_job()' - Print a file to a printer or class.
6335 create_job(cupsd_client_t
*con
, /* I - Client connection */
6336 ipp_attribute_t
*uri
) /* I - Printer URI */
6338 cupsd_printer_t
*printer
; /* Printer */
6339 cupsd_job_t
*job
; /* New job */
6342 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
6343 con
->http
.fd
, uri
->values
[0].string
.text
);
6346 * Is the destination valid?
6349 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6355 send_ipp_status(con
, IPP_NOT_FOUND
,
6356 _("The printer or class was not found."));
6361 * Create the job object...
6364 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6367 job
->pending_timeout
= 1;
6370 * Save and log the job...
6373 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6374 job
->dest
, job
->username
);
6379 * 'create_requested_array()' - Create an array for the requested-attributes.
6382 static cups_array_t
* /* O - Array of attributes or NULL */
6383 create_requested_array(ipp_t
*request
) /* I - IPP request */
6385 int i
; /* Looping var */
6386 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6387 cups_array_t
*ra
; /* Requested attributes array */
6388 char *value
; /* Current value */
6392 * Get the requested-attributes attribute, and return NULL if we don't
6396 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6397 IPP_TAG_KEYWORD
)) == NULL
)
6401 * If the attribute contains a single "all" keyword, return NULL...
6404 if (requested
->num_values
== 1 &&
6405 !strcmp(requested
->values
[0].string
.text
, "all"))
6409 * Create an array using "strcmp" as the comparison function...
6412 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6414 for (i
= 0; i
< requested
->num_values
; i
++)
6416 value
= requested
->values
[i
].string
.text
;
6418 if (!strcmp(value
, "job-template"))
6420 cupsArrayAdd(ra
, "copies");
6421 cupsArrayAdd(ra
, "copies-default");
6422 cupsArrayAdd(ra
, "copies-supported");
6423 cupsArrayAdd(ra
, "finishings");
6424 cupsArrayAdd(ra
, "finishings-default");
6425 cupsArrayAdd(ra
, "finishings-supported");
6426 cupsArrayAdd(ra
, "job-hold-until");
6427 cupsArrayAdd(ra
, "job-hold-until-default");
6428 cupsArrayAdd(ra
, "job-hold-until-supported");
6429 cupsArrayAdd(ra
, "job-priority");
6430 cupsArrayAdd(ra
, "job-priority-default");
6431 cupsArrayAdd(ra
, "job-priority-supported");
6432 cupsArrayAdd(ra
, "job-sheets");
6433 cupsArrayAdd(ra
, "job-sheets-default");
6434 cupsArrayAdd(ra
, "job-sheets-supported");
6435 cupsArrayAdd(ra
, "media");
6436 cupsArrayAdd(ra
, "media-default");
6437 cupsArrayAdd(ra
, "media-supported");
6438 cupsArrayAdd(ra
, "multiple-document-handling");
6439 cupsArrayAdd(ra
, "multiple-document-handling-default");
6440 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6441 cupsArrayAdd(ra
, "number-up");
6442 cupsArrayAdd(ra
, "number-up-default");
6443 cupsArrayAdd(ra
, "number-up-supported");
6444 cupsArrayAdd(ra
, "orientation-requested");
6445 cupsArrayAdd(ra
, "orientation-requested-default");
6446 cupsArrayAdd(ra
, "orientation-requested-supported");
6447 cupsArrayAdd(ra
, "page-ranges");
6448 cupsArrayAdd(ra
, "page-ranges-supported");
6449 cupsArrayAdd(ra
, "printer-resolution");
6450 cupsArrayAdd(ra
, "printer-resolution-default");
6451 cupsArrayAdd(ra
, "printer-resolution-supported");
6452 cupsArrayAdd(ra
, "print-quality");
6453 cupsArrayAdd(ra
, "print-quality-default");
6454 cupsArrayAdd(ra
, "print-quality-supported");
6455 cupsArrayAdd(ra
, "sides");
6456 cupsArrayAdd(ra
, "sides-default");
6457 cupsArrayAdd(ra
, "sides-supported");
6459 else if (!strcmp(value
, "job-description"))
6461 cupsArrayAdd(ra
, "date-time-at-completed");
6462 cupsArrayAdd(ra
, "date-time-at-creation");
6463 cupsArrayAdd(ra
, "date-time-at-processing");
6464 cupsArrayAdd(ra
, "job-detailed-status-message");
6465 cupsArrayAdd(ra
, "job-document-access-errors");
6466 cupsArrayAdd(ra
, "job-id");
6467 cupsArrayAdd(ra
, "job-impressions");
6468 cupsArrayAdd(ra
, "job-impressions-completed");
6469 cupsArrayAdd(ra
, "job-k-octets");
6470 cupsArrayAdd(ra
, "job-k-octets-processed");
6471 cupsArrayAdd(ra
, "job-media-progress");
6472 cupsArrayAdd(ra
, "job-media-sheets");
6473 cupsArrayAdd(ra
, "job-media-sheets-completed");
6474 cupsArrayAdd(ra
, "job-message-from-operator");
6475 cupsArrayAdd(ra
, "job-more-info");
6476 cupsArrayAdd(ra
, "job-name");
6477 cupsArrayAdd(ra
, "job-originating-user-name");
6478 cupsArrayAdd(ra
, "job-printer-up-time");
6479 cupsArrayAdd(ra
, "job-printer-uri");
6480 cupsArrayAdd(ra
, "job-state");
6481 cupsArrayAdd(ra
, "job-state-message");
6482 cupsArrayAdd(ra
, "job-state-reasons");
6483 cupsArrayAdd(ra
, "job-uri");
6484 cupsArrayAdd(ra
, "number-of-documents");
6485 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6486 cupsArrayAdd(ra
, "output-device-assigned");
6487 cupsArrayAdd(ra
, "time-at-completed");
6488 cupsArrayAdd(ra
, "time-at-creation");
6489 cupsArrayAdd(ra
, "time-at-processing");
6491 else if (!strcmp(value
, "printer-description"))
6493 cupsArrayAdd(ra
, "charset-configured");
6494 cupsArrayAdd(ra
, "charset-supported");
6495 cupsArrayAdd(ra
, "color-supported");
6496 cupsArrayAdd(ra
, "compression-supported");
6497 cupsArrayAdd(ra
, "document-format-default");
6498 cupsArrayAdd(ra
, "document-format-supported");
6499 cupsArrayAdd(ra
, "generated-natural-language-supported");
6500 cupsArrayAdd(ra
, "ipp-versions-supported");
6501 cupsArrayAdd(ra
, "job-impressions-supported");
6502 cupsArrayAdd(ra
, "job-k-octets-supported");
6503 cupsArrayAdd(ra
, "job-media-sheets-supported");
6504 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6505 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6506 cupsArrayAdd(ra
, "multiple-operation-time-out");
6507 cupsArrayAdd(ra
, "natural-language-configured");
6508 cupsArrayAdd(ra
, "notify-attributes-supported");
6509 cupsArrayAdd(ra
, "notify-lease-duration-default");
6510 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6511 cupsArrayAdd(ra
, "notify-max-events-supported");
6512 cupsArrayAdd(ra
, "notify-events-default");
6513 cupsArrayAdd(ra
, "notify-events-supported");
6514 cupsArrayAdd(ra
, "notify-pull-method-supported");
6515 cupsArrayAdd(ra
, "notify-schemes-supported");
6516 cupsArrayAdd(ra
, "operations-supported");
6517 cupsArrayAdd(ra
, "pages-per-minute");
6518 cupsArrayAdd(ra
, "pages-per-minute-color");
6519 cupsArrayAdd(ra
, "pdl-override-supported");
6520 cupsArrayAdd(ra
, "printer-alert");
6521 cupsArrayAdd(ra
, "printer-alert-description");
6522 cupsArrayAdd(ra
, "printer-commands");
6523 cupsArrayAdd(ra
, "printer-current-time");
6524 cupsArrayAdd(ra
, "printer-driver-installer");
6525 cupsArrayAdd(ra
, "printer-dns-sd-name");
6526 cupsArrayAdd(ra
, "printer-info");
6527 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6528 cupsArrayAdd(ra
, "printer-location");
6529 cupsArrayAdd(ra
, "printer-make-and-model");
6530 cupsArrayAdd(ra
, "printer-message-from-operator");
6531 cupsArrayAdd(ra
, "printer-more-info");
6532 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6533 cupsArrayAdd(ra
, "printer-name");
6534 cupsArrayAdd(ra
, "printer-state");
6535 cupsArrayAdd(ra
, "printer-state-message");
6536 cupsArrayAdd(ra
, "printer-state-reasons");
6537 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6538 cupsArrayAdd(ra
, "printer-type");
6539 cupsArrayAdd(ra
, "printer-up-time");
6540 cupsArrayAdd(ra
, "printer-uri-supported");
6541 cupsArrayAdd(ra
, "queued-job-count");
6542 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6543 cupsArrayAdd(ra
, "uri-authentication-supported");
6544 cupsArrayAdd(ra
, "uri-security-supported");
6546 else if (!strcmp(value
, "printer-defaults"))
6548 char *name
; /* Option name */
6551 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6553 name
= (char *)cupsArrayNext(CommonDefaults
))
6554 cupsArrayAdd(ra
, name
);
6556 else if (!strcmp(value
, "subscription-template"))
6558 cupsArrayAdd(ra
, "notify-attributes");
6559 cupsArrayAdd(ra
, "notify-charset");
6560 cupsArrayAdd(ra
, "notify-events");
6561 cupsArrayAdd(ra
, "notify-lease-duration");
6562 cupsArrayAdd(ra
, "notify-natural-language");
6563 cupsArrayAdd(ra
, "notify-pull-method");
6564 cupsArrayAdd(ra
, "notify-recipient-uri");
6565 cupsArrayAdd(ra
, "notify-time-interval");
6566 cupsArrayAdd(ra
, "notify-user-data");
6569 cupsArrayAdd(ra
, value
);
6577 * 'create_subscription()' - Create a notification subscription.
6581 create_subscription(
6582 cupsd_client_t
*con
, /* I - Client connection */
6583 ipp_attribute_t
*uri
) /* I - Printer URI */
6585 http_status_t status
; /* Policy status */
6586 int i
; /* Looping var */
6587 ipp_attribute_t
*attr
; /* Current attribute */
6588 cups_ptype_t dtype
; /* Destination type (printer/class) */
6589 char scheme
[HTTP_MAX_URI
],
6590 /* Scheme portion of URI */
6591 userpass
[HTTP_MAX_URI
],
6592 /* Username portion of URI */
6594 /* Host portion of URI */
6595 resource
[HTTP_MAX_URI
];
6596 /* Resource portion of URI */
6597 int port
; /* Port portion of URI */
6598 cupsd_printer_t
*printer
; /* Printer/class */
6599 cupsd_job_t
*job
; /* Job */
6600 int jobid
; /* Job ID */
6601 cupsd_subscription_t
*sub
; /* Subscription object */
6602 const char *username
, /* requesting-user-name or
6603 authenticated username */
6604 *recipient
, /* notify-recipient-uri */
6605 *pullmethod
; /* notify-pull-method */
6606 ipp_attribute_t
*user_data
; /* notify-user-data */
6607 int interval
, /* notify-time-interval */
6608 lease
; /* notify-lease-duration */
6609 unsigned mask
; /* notify-events */
6610 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6611 *notify_lease
; /* notify-lease-duration(-default) */
6615 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6617 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6618 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6619 attr
->value_tag
, attr
->name
);
6621 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6626 * Is the destination valid?
6629 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6630 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6631 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6633 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6634 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6635 sizeof(host
), &port
, resource
, sizeof(resource
));
6637 if (!strcmp(resource
, "/"))
6639 dtype
= (cups_ptype_t
)0;
6642 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6644 dtype
= (cups_ptype_t
)0;
6647 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6649 dtype
= CUPS_PRINTER_CLASS
;
6652 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6658 send_ipp_status(con
, IPP_NOT_FOUND
,
6659 _("The printer or class was not found."));
6669 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6672 send_http_error(con
, status
, printer
);
6676 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6678 send_http_error(con
, status
, NULL
);
6683 * Get the user that is requesting the subscription...
6686 username
= get_username(con
);
6689 * Find the first subscription group attribute; return if we have
6693 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6694 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6699 send_ipp_status(con
, IPP_BAD_REQUEST
,
6700 _("No subscription attributes in request"));
6705 * Process the subscription attributes in the request...
6708 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6716 lease
= DefaultLeaseDuration
;
6718 mask
= CUPSD_EVENT_NONE
;
6722 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6724 notify_lease
= ippFindAttribute(printer
->attrs
,
6725 "notify-lease-duration-default",
6729 lease
= notify_lease
->values
[0].integer
;
6733 notify_events
= NULL
;
6734 notify_lease
= NULL
;
6737 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6739 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6740 attr
->value_tag
== IPP_TAG_URI
)
6743 * Validate the recipient scheme against the ServerBin/notifier
6747 char notifier
[1024]; /* Notifier filename */
6750 recipient
= attr
->values
[0].string
.text
;
6752 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6753 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6754 host
, sizeof(host
), &port
,
6755 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6757 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6758 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
6759 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6760 "notify-status-code", IPP_URI_SCHEME
);
6764 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6766 if (access(notifier
, X_OK
))
6768 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6769 _("notify-recipient-uri URI \"%s\" uses unknown "
6770 "scheme"), recipient
);
6771 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6772 "notify-status-code", IPP_URI_SCHEME
);
6776 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6778 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6779 _("notify-recipient-uri URI \"%s\" is already used"),
6781 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6782 "notify-status-code", IPP_ATTRIBUTES
);
6786 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6787 attr
->value_tag
== IPP_TAG_KEYWORD
)
6789 pullmethod
= attr
->values
[0].string
.text
;
6791 if (strcmp(pullmethod
, "ippget"))
6793 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6794 _("Bad notify-pull-method \"%s\""), pullmethod
);
6795 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6796 "notify-status-code", IPP_ATTRIBUTES
);
6800 else if (!strcmp(attr
->name
, "notify-charset") &&
6801 attr
->value_tag
== IPP_TAG_CHARSET
&&
6802 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6803 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6805 send_ipp_status(con
, IPP_CHARSET
,
6806 _("Character set \"%s\" not supported"),
6807 attr
->values
[0].string
.text
);
6810 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6811 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6812 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6814 send_ipp_status(con
, IPP_CHARSET
,
6815 _("Language \"%s\" not supported"),
6816 attr
->values
[0].string
.text
);
6819 else if (!strcmp(attr
->name
, "notify-user-data") &&
6820 attr
->value_tag
== IPP_TAG_STRING
)
6822 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6824 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6825 _("The notify-user-data value is too large "
6826 "(%d > 63 octets)"),
6827 attr
->values
[0].unknown
.length
);
6833 else if (!strcmp(attr
->name
, "notify-events") &&
6834 attr
->value_tag
== IPP_TAG_KEYWORD
)
6835 notify_events
= attr
;
6836 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6837 attr
->value_tag
== IPP_TAG_INTEGER
)
6838 lease
= attr
->values
[0].integer
;
6839 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6840 attr
->value_tag
== IPP_TAG_INTEGER
)
6841 interval
= attr
->values
[0].integer
;
6842 else if (!strcmp(attr
->name
, "notify-job-id") &&
6843 attr
->value_tag
== IPP_TAG_INTEGER
)
6844 jobid
= attr
->values
[0].integer
;
6851 for (i
= 0; i
< notify_events
->num_values
; i
++)
6852 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6856 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6858 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6859 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6860 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6862 if (!recipient
&& !pullmethod
)
6865 if (mask
== CUPSD_EVENT_NONE
)
6868 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6870 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6873 send_ipp_status(con
, IPP_BAD_REQUEST
,
6874 _("notify-events not specified"));
6879 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6881 cupsdLogMessage(CUPSD_LOG_INFO
,
6882 "create_subscription: Limiting notify-lease-duration to "
6885 lease
= MaxLeaseDuration
;
6890 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6892 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found"), jobid
);
6899 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6901 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6902 _("There are too many subscriptions."));
6907 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6910 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6911 "Added subscription %d for printer \"%s\"",
6912 sub
->id
, printer
->name
);
6914 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6917 sub
->interval
= interval
;
6919 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6921 cupsdSetString(&sub
->owner
, username
);
6925 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6926 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6927 sub
->user_data_len
);
6930 ippAddSeparator(con
->response
);
6931 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6932 "notify-subscription-id", sub
->id
);
6934 con
->response
->request
.status
.status_code
= IPP_OK
;
6940 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6945 * 'delete_printer()' - Remove a printer or class from the system.
6949 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6950 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6952 http_status_t status
; /* Policy status */
6953 cups_ptype_t dtype
; /* Destination type (printer/class) */
6954 cupsd_printer_t
*printer
; /* Printer/class */
6955 char filename
[1024]; /* Script/PPD filename */
6958 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6959 con
->http
.fd
, uri
->values
[0].string
.text
);
6962 * Do we have a valid URI?
6965 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6971 send_ipp_status(con
, IPP_NOT_FOUND
,
6972 _("The printer or class was not found."));
6980 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6982 send_http_error(con
, status
, NULL
);
6987 * Remove old jobs...
6990 cupsdCancelJobs(printer
->name
, NULL
, 1);
6993 * Remove old subscriptions and send a "deleted printer" event...
6996 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6997 "%s \"%s\" deleted by \"%s\".",
6998 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6999 printer
->name
, get_username(con
));
7001 cupsdExpireSubscriptions(printer
, NULL
);
7004 * Remove any old PPD or script files...
7007 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
7011 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7015 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
7018 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
7023 * Unregister color profiles...
7026 apple_unregister_profiles(printer
);
7027 #endif /* __APPLE__ */
7029 if (dtype
& CUPS_PRINTER_CLASS
)
7031 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
7032 printer
->name
, get_username(con
));
7034 cupsdDeletePrinter(printer
, 0);
7035 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7039 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
7040 printer
->name
, get_username(con
));
7042 if (cupsdDeletePrinter(printer
, 0))
7043 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7045 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
7048 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
7051 * Return with no errors...
7054 con
->response
->request
.status
.status_code
= IPP_OK
;
7059 * 'get_default()' - Get the default destination.
7063 get_default(cupsd_client_t
*con
) /* I - Client connection */
7065 http_status_t status
; /* Policy status */
7066 cups_array_t
*ra
; /* Requested attributes array */
7069 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
7075 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7077 send_http_error(con
, status
, NULL
);
7083 ra
= create_requested_array(con
->request
);
7085 copy_printer_attrs(con
, DefaultPrinter
, ra
);
7087 cupsArrayDelete(ra
);
7089 con
->response
->request
.status
.status_code
= IPP_OK
;
7092 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
7097 * 'get_devices()' - Get the list of available devices on the local system.
7101 get_devices(cupsd_client_t
*con
) /* I - Client connection */
7103 http_status_t status
; /* Policy status */
7104 ipp_attribute_t
*limit
, /* limit attribute */
7105 *timeout
, /* timeout attribute */
7106 *requested
, /* requested-attributes attribute */
7107 *exclude
, /* exclude-schemes attribute */
7108 *include
; /* include-schemes attribute */
7109 char command
[1024], /* cups-deviced command */
7110 options
[2048], /* Options to pass to command */
7112 /* String for requested attributes */
7114 /* String for excluded schemes */
7116 /* String for included schemes */
7119 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
7125 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7127 send_http_error(con
, status
, NULL
);
7132 * Run cups-deviced command with the given options...
7135 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7136 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
7137 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7139 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
7140 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
7143 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7145 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7148 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7150 exclude_str
[0] = '\0';
7153 url_encode_attr(include
, include_str
, sizeof(include_str
));
7155 include_str
[0] = '\0';
7157 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
7158 snprintf(options
, sizeof(options
),
7159 "%d+%d+%d+%d+%s%s%s%s%s",
7160 con
->request
->request
.op
.request_id
,
7161 limit
? limit
->values
[0].integer
: 0,
7162 timeout
? timeout
->values
[0].integer
: 15,
7165 exclude_str
[0] ? "%20" : "", exclude_str
,
7166 include_str
[0] ? "%20" : "", include_str
);
7168 if (cupsdSendCommand(con
, command
, options
, 1))
7171 * Command started successfully, don't send an IPP response here...
7174 ippDelete(con
->response
);
7175 con
->response
= NULL
;
7180 * Command failed, return "internal error" so the user knows something
7184 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7185 _("cups-deviced failed to execute."));
7191 * 'get_document()' - Get a copy of a job file.
7195 get_document(cupsd_client_t
*con
, /* I - Client connection */
7196 ipp_attribute_t
*uri
) /* I - Job URI */
7198 http_status_t status
; /* Policy status */
7199 ipp_attribute_t
*attr
; /* Current attribute */
7200 int jobid
; /* Job ID */
7201 int docnum
; /* Document number */
7202 cupsd_job_t
*job
; /* Current job */
7203 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7204 username
[HTTP_MAX_URI
], /* Username portion of URI */
7205 host
[HTTP_MAX_URI
], /* Host portion of URI */
7206 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7207 int port
; /* Port portion of URI */
7208 char filename
[1024], /* Filename for document */
7209 format
[1024]; /* Format for document */
7212 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
7213 con
->http
.fd
, uri
->values
[0].string
.text
);
7216 * See if we have a job URI or a printer URI...
7219 if (!strcmp(uri
->name
, "printer-uri"))
7222 * Got a printer URI; see if we also have a job-id attribute...
7225 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7226 IPP_TAG_INTEGER
)) == NULL
)
7228 send_ipp_status(con
, IPP_BAD_REQUEST
,
7229 _("Got a printer-uri attribute but no job-id"));
7233 jobid
= attr
->values
[0].integer
;
7238 * Got a job URI; parse it to get the job ID...
7241 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7242 sizeof(scheme
), username
, sizeof(username
), host
,
7243 sizeof(host
), &port
, resource
, sizeof(resource
));
7245 if (strncmp(resource
, "/jobs/", 6))
7251 send_ipp_status(con
, IPP_BAD_REQUEST
,
7252 _("Bad job-uri attribute \"%s\""),
7253 uri
->values
[0].string
.text
);
7257 jobid
= atoi(resource
+ 6);
7261 * See if the job exists...
7264 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7267 * Nope - return a "not found" error...
7270 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
7278 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
7279 job
->username
)) != HTTP_OK
)
7281 send_http_error(con
, status
, NULL
);
7286 * Get the document number...
7289 if ((attr
= ippFindAttribute(con
->request
, "document-number",
7290 IPP_TAG_INTEGER
)) == NULL
)
7292 send_ipp_status(con
, IPP_BAD_REQUEST
,
7293 _("Missing document-number attribute"));
7297 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
7298 attr
->num_values
> 1)
7300 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
7305 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
7307 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
7309 cupsdLogMessage(CUPSD_LOG_ERROR
,
7310 "Unable to open document %d in job %d - %s", docnum
, jobid
,
7312 send_ipp_status(con
, IPP_NOT_FOUND
,
7313 _("Unable to open document %d in job %d"), docnum
, jobid
);
7317 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7321 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
7322 job
->filetypes
[docnum
- 1]->type
);
7324 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
7326 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
7328 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
7329 IPP_TAG_NAME
)) != NULL
)
7330 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
7331 NULL
, attr
->values
[0].string
.text
);
7336 * 'get_job_attrs()' - Get job attributes.
7340 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
7341 ipp_attribute_t
*uri
) /* I - Job URI */
7343 http_status_t status
; /* Policy status */
7344 ipp_attribute_t
*attr
; /* Current attribute */
7345 int jobid
; /* Job ID */
7346 cupsd_job_t
*job
; /* Current job */
7347 cupsd_printer_t
*printer
; /* Current printer */
7348 cupsd_policy_t
*policy
; /* Current security policy */
7349 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7350 username
[HTTP_MAX_URI
], /* Username portion of URI */
7351 host
[HTTP_MAX_URI
], /* Host portion of URI */
7352 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7353 int port
; /* Port portion of URI */
7354 cups_array_t
*ra
, /* Requested attributes array */
7355 *exclude
; /* Private attributes array */
7358 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7359 con
->http
.fd
, uri
->values
[0].string
.text
);
7362 * See if we have a job URI or a printer URI...
7365 if (!strcmp(uri
->name
, "printer-uri"))
7368 * Got a printer URI; see if we also have a job-id attribute...
7371 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7372 IPP_TAG_INTEGER
)) == NULL
)
7374 send_ipp_status(con
, IPP_BAD_REQUEST
,
7375 _("Got a printer-uri attribute but no job-id"));
7379 jobid
= attr
->values
[0].integer
;
7384 * Got a job URI; parse it to get the job ID...
7387 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7388 sizeof(scheme
), username
, sizeof(username
), host
,
7389 sizeof(host
), &port
, resource
, sizeof(resource
));
7391 if (strncmp(resource
, "/jobs/", 6))
7397 send_ipp_status(con
, IPP_BAD_REQUEST
,
7398 _("Bad job-uri attribute \"%s\""),
7399 uri
->values
[0].string
.text
);
7403 jobid
= atoi(resource
+ 6);
7407 * See if the job exists...
7410 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7413 * Nope - return a "not found" error...
7416 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
7424 if ((printer
= job
->printer
) == NULL
)
7425 printer
= cupsdFindDest(job
->dest
);
7428 policy
= printer
->op_policy_ptr
;
7430 policy
= DefaultPolicyPtr
;
7432 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
7434 send_http_error(con
, status
, NULL
);
7438 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
7441 * Copy attributes...
7446 ra
= create_requested_array(con
->request
);
7447 copy_job_attrs(con
, job
, ra
, exclude
);
7448 cupsArrayDelete(ra
);
7450 con
->response
->request
.status
.status_code
= IPP_OK
;
7455 * 'get_jobs()' - Get a list of jobs for the specified printer.
7459 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7460 ipp_attribute_t
*uri
) /* I - Printer URI */
7462 http_status_t status
; /* Policy status */
7463 ipp_attribute_t
*attr
; /* Current attribute */
7464 const char *dest
; /* Destination */
7465 cups_ptype_t dtype
; /* Destination type (printer/class) */
7466 cups_ptype_t dmask
; /* Destination type mask */
7467 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7468 username
[HTTP_MAX_URI
], /* Username portion of URI */
7469 host
[HTTP_MAX_URI
], /* Host portion of URI */
7470 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7471 int port
; /* Port portion of URI */
7472 int job_comparison
; /* Job comparison */
7473 ipp_jstate_t job_state
; /* job-state value */
7474 int first_job_id
; /* First job ID */
7475 int limit
; /* Maximum number of jobs to return */
7476 int count
; /* Number of jobs that match */
7477 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7478 cupsd_job_t
*job
; /* Current job pointer */
7479 cupsd_printer_t
*printer
; /* Printer */
7480 cups_array_t
*list
; /* Which job list... */
7481 cups_array_t
*ra
, /* Requested attributes array */
7482 *exclude
; /* Private attributes array */
7483 cupsd_policy_t
*policy
; /* Current policy */
7486 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7487 uri
->values
[0].string
.text
);
7490 * Is the destination valid?
7493 if (strcmp(uri
->name
, "printer-uri"))
7495 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request"));
7499 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7500 sizeof(scheme
), username
, sizeof(username
), host
,
7501 sizeof(host
), &port
, resource
, sizeof(resource
));
7503 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7506 dtype
= (cups_ptype_t
)0;
7507 dmask
= (cups_ptype_t
)0;
7510 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7513 dtype
= (cups_ptype_t
)0;
7514 dmask
= CUPS_PRINTER_CLASS
;
7517 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7520 dtype
= CUPS_PRINTER_CLASS
;
7521 dmask
= CUPS_PRINTER_CLASS
;
7524 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7531 send_ipp_status(con
, IPP_NOT_FOUND
,
7532 _("The printer or class was not found."));
7537 dtype
&= CUPS_PRINTER_CLASS
;
7538 dmask
= CUPS_PRINTER_CLASS
;
7546 policy
= printer
->op_policy_ptr
;
7548 policy
= DefaultPolicyPtr
;
7550 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7552 send_http_error(con
, status
, NULL
);
7556 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7559 * See if the "which-jobs" attribute have been specified...
7562 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7563 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7565 send_ipp_status(con
, IPP_CONFLICT
,
7566 _("The %s attribute cannot be provided with job-ids."),
7570 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7572 job_comparison
= -1;
7573 job_state
= IPP_JOB_STOPPED
;
7576 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7579 job_state
= IPP_JOB_CANCELED
;
7582 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7585 job_state
= IPP_JOB_ABORTED
;
7588 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7591 job_state
= IPP_JOB_PENDING
;
7594 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7597 job_state
= IPP_JOB_CANCELED
;
7600 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7603 job_state
= IPP_JOB_PENDING
;
7606 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7609 job_state
= IPP_JOB_HELD
;
7612 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7615 job_state
= IPP_JOB_PROCESSING
;
7616 list
= PrintingJobs
;
7618 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7621 job_state
= IPP_JOB_STOPPED
;
7626 send_ipp_status(con
, IPP_ATTRIBUTES
,
7627 _("The which-jobs value \"%s\" is not supported."),
7628 attr
->values
[0].string
.text
);
7629 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7630 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7635 * See if they want to limit the number of jobs reported...
7638 if ((attr
= ippFindAttribute(con
->request
, "limit",
7639 IPP_TAG_INTEGER
)) != NULL
)
7643 send_ipp_status(con
, IPP_CONFLICT
,
7644 _("The %s attribute cannot be provided with job-ids."),
7649 limit
= attr
->values
[0].integer
;
7654 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7655 IPP_TAG_INTEGER
)) != NULL
)
7659 send_ipp_status(con
, IPP_CONFLICT
,
7660 _("The %s attribute cannot be provided with job-ids."),
7665 first_job_id
= attr
->values
[0].integer
;
7671 * See if we only want to see jobs for a specific user...
7674 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7675 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7677 send_ipp_status(con
, IPP_CONFLICT
,
7678 _("The %s attribute cannot be provided with job-ids."),
7682 else if (attr
&& attr
->values
[0].boolean
)
7683 strlcpy(username
, get_username(con
), sizeof(username
));
7687 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7688 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7691 * IPP conformance - Get-Jobs has a default requested-attributes value of
7692 * "job-id" and "job-uri".
7695 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7696 cupsArrayAdd(ra
, "job-id");
7697 cupsArrayAdd(ra
, "job-uri");
7701 * OK, build a list of jobs for this printer...
7706 int i
; /* Looping var */
7708 for (i
= 0; i
< job_ids
->num_values
; i
++)
7710 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
7714 if (i
< job_ids
->num_values
)
7716 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
7717 job_ids
->values
[i
].integer
);
7721 for (i
= 0; i
< job_ids
->num_values
; i
++)
7723 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7729 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7735 ippAddSeparator(con
->response
);
7737 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7738 job
->printer
->op_policy_ptr
:
7739 policy
, con
, job
->printer
,
7742 copy_job_attrs(con
, job
, ra
, exclude
);
7747 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7748 (limit
<= 0 || count
< limit
) && job
;
7749 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7752 * Filter out jobs that don't match...
7755 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7756 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7757 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7758 job
->username
, job
->state_value
, job
->attrs
);
7760 if (!job
->dest
|| !job
->username
)
7763 if (!job
->dest
|| !job
->username
)
7766 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7767 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7769 if ((job
->dtype
& dmask
) != dtype
&&
7770 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7773 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7774 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7775 (job_comparison
> 0 && job
->state_value
< job_state
))
7778 if (job
->id
< first_job_id
)
7785 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7790 if (username
[0] && strcasecmp(username
, job
->username
))
7794 ippAddSeparator(con
->response
);
7798 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7799 job
->printer
->op_policy_ptr
:
7800 policy
, con
, job
->printer
,
7803 copy_job_attrs(con
, job
, ra
, exclude
);
7806 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7809 cupsArrayDelete(ra
);
7811 con
->response
->request
.status
.status_code
= IPP_OK
;
7816 * 'get_notifications()' - Get events for a subscription.
7820 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7822 int i
, j
; /* Looping vars */
7823 http_status_t status
; /* Policy status */
7824 cupsd_subscription_t
*sub
; /* Subscription */
7825 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7826 *sequences
; /* notify-sequence-numbers */
7827 int min_seq
; /* Minimum sequence number */
7828 int interval
; /* Poll interval */
7831 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7835 * Get subscription attributes...
7838 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7840 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7845 send_ipp_status(con
, IPP_BAD_REQUEST
,
7846 _("Missing notify-subscription-ids attribute"));
7851 * Are the subscription IDs valid?
7854 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7856 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7859 * Bad subscription ID...
7862 send_ipp_status(con
, IPP_NOT_FOUND
,
7863 _("notify-subscription-id %d no good"),
7864 ids
->values
[i
].integer
);
7872 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7874 con
, sub
->owner
)) != HTTP_OK
)
7876 send_http_error(con
, status
, sub
->dest
);
7881 * Check the subscription type and update the interval accordingly.
7884 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7887 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7889 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7895 * Tell the client to poll again in N seconds...
7899 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7900 "notify-get-interval", interval
);
7902 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7903 "printer-up-time", time(NULL
));
7906 * Copy the subscription event attributes to the response.
7909 con
->response
->request
.status
.status_code
=
7910 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7912 for (i
= 0; i
< ids
->num_values
; i
++)
7915 * Get the subscription and sequence number...
7918 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7920 if (sequences
&& i
< sequences
->num_values
)
7921 min_seq
= sequences
->values
[i
].integer
;
7926 * If we don't have any new events, nothing to do here...
7929 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
7933 * Otherwise copy all of the new events...
7936 if (sub
->first_event_id
> min_seq
)
7939 j
= min_seq
- sub
->first_event_id
;
7941 for (; j
< cupsArrayCount(sub
->events
); j
++)
7943 ippAddSeparator(con
->response
);
7945 copy_attrs(con
->response
,
7946 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7947 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7954 * 'get_ppd()' - Get a named PPD from the local system.
7958 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7959 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7961 http_status_t status
; /* Policy status */
7962 cupsd_printer_t
*dest
; /* Destination */
7963 cups_ptype_t dtype
; /* Destination type */
7966 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7967 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7969 if (!strcmp(uri
->name
, "ppd-name"))
7972 * Return a PPD file from cups-driverd...
7975 char command
[1024], /* cups-driverd command */
7976 options
[1024], /* Options to pass to command */
7977 ppd_name
[1024]; /* ppd-name */
7984 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7986 send_http_error(con
, status
, NULL
);
7991 * Run cups-driverd command with the given options...
7994 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7995 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7996 snprintf(options
, sizeof(options
), "get+%d+%s",
7997 con
->request
->request
.op
.request_id
, ppd_name
);
7999 if (cupsdSendCommand(con
, command
, options
, 0))
8002 * Command started successfully, don't send an IPP response here...
8005 ippDelete(con
->response
);
8006 con
->response
= NULL
;
8011 * Command failed, return "internal error" so the user knows something
8015 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8016 _("cups-driverd failed to execute."));
8019 else if (!strcmp(uri
->name
, "printer-uri") &&
8020 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
8022 int i
; /* Looping var */
8023 char filename
[1024]; /* PPD filename */
8030 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8032 send_http_error(con
, status
, dest
);
8037 * See if we need the PPD for a class or remote printer...
8040 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8043 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
8045 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8046 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8047 "printer-uri", NULL
, dest
->uri
);
8050 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
8052 for (i
= 0; i
< dest
->num_printers
; i
++)
8053 if (!(dest
->printers
[i
]->type
&
8054 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
8056 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8057 dest
->printers
[i
]->name
);
8059 if (!access(filename
, 0))
8063 if (i
< dest
->num_printers
)
8064 dest
= dest
->printers
[i
];
8067 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8068 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8069 "printer-uri", NULL
, dest
->printers
[0]->uri
);
8075 * Found the printer with the PPD file, now see if there is one...
8078 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
8080 send_ipp_status(con
, IPP_NOT_FOUND
,
8081 _("The PPD file \"%s\" could not be opened: %s"),
8082 uri
->values
[0].string
.text
, strerror(errno
));
8086 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
8090 con
->response
->request
.status
.status_code
= IPP_OK
;
8093 send_ipp_status(con
, IPP_NOT_FOUND
,
8094 _("The PPD file \"%s\" could not be found."),
8095 uri
->values
[0].string
.text
);
8100 * 'get_ppds()' - Get the list of PPD files on the local system.
8104 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
8106 http_status_t status
; /* Policy status */
8107 ipp_attribute_t
*limit
, /* Limit attribute */
8108 *device
, /* ppd-device-id attribute */
8109 *language
, /* ppd-natural-language attribute */
8110 *make
, /* ppd-make attribute */
8111 *model
, /* ppd-make-and-model attribute */
8112 *model_number
, /* ppd-model-number attribute */
8113 *product
, /* ppd-product attribute */
8114 *psversion
, /* ppd-psverion attribute */
8115 *type
, /* ppd-type attribute */
8116 *requested
, /* requested-attributes attribute */
8117 *exclude
, /* exclude-schemes attribute */
8118 *include
; /* include-schemes attribute */
8119 char command
[1024], /* cups-driverd command */
8120 options
[4096], /* Options to pass to command */
8121 device_str
[256],/* Escaped ppd-device-id string */
8123 /* Escaped ppd-natural-language */
8124 make_str
[256], /* Escaped ppd-make string */
8125 model_str
[256], /* Escaped ppd-make-and-model string */
8126 model_number_str
[256],
8127 /* ppd-model-number string */
8129 /* Escaped ppd-product string */
8131 /* Escaped ppd-psversion string */
8132 type_str
[256], /* Escaped ppd-type string */
8134 /* String for requested attributes */
8136 /* String for excluded schemes */
8138 /* String for included schemes */
8141 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
8147 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8149 send_http_error(con
, status
, NULL
);
8154 * Run cups-driverd command with the given options...
8157 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
8158 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
8159 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
8161 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
8162 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
8164 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
8166 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
8167 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
8168 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
8169 requested
= ippFindAttribute(con
->request
, "requested-attributes",
8171 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
8173 include
= ippFindAttribute(con
->request
, "include-schemes",
8177 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
8179 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
8182 url_encode_attr(device
, device_str
, sizeof(device_str
));
8184 device_str
[0] = '\0';
8187 url_encode_attr(language
, language_str
, sizeof(language_str
));
8189 language_str
[0] = '\0';
8192 url_encode_attr(make
, make_str
, sizeof(make_str
));
8197 url_encode_attr(model
, model_str
, sizeof(model_str
));
8199 model_str
[0] = '\0';
8202 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
8203 model_number
->values
[0].integer
);
8205 model_number_str
[0] = '\0';
8208 url_encode_attr(product
, product_str
, sizeof(product_str
));
8210 product_str
[0] = '\0';
8213 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
8215 psversion_str
[0] = '\0';
8218 url_encode_attr(type
, type_str
, sizeof(type_str
));
8223 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
8225 exclude_str
[0] = '\0';
8228 url_encode_attr(include
, include_str
, sizeof(include_str
));
8230 include_str
[0] = '\0';
8232 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
8233 snprintf(options
, sizeof(options
),
8234 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
8235 con
->request
->request
.op
.request_id
,
8236 limit
? limit
->values
[0].integer
: 0,
8238 device
? "%20" : "", device_str
,
8239 language
? "%20" : "", language_str
,
8240 make
? "%20" : "", make_str
,
8241 model
? "%20" : "", model_str
,
8242 model_number
? "%20" : "", model_number_str
,
8243 product
? "%20" : "", product_str
,
8244 psversion
? "%20" : "", psversion_str
,
8245 type
? "%20" : "", type_str
,
8246 exclude_str
[0] ? "%20" : "", exclude_str
,
8247 include_str
[0] ? "%20" : "", include_str
);
8249 if (cupsdSendCommand(con
, command
, options
, 0))
8252 * Command started successfully, don't send an IPP response here...
8255 ippDelete(con
->response
);
8256 con
->response
= NULL
;
8261 * Command failed, return "internal error" so the user knows something
8265 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8266 _("cups-driverd failed to execute."));
8272 * 'get_printer_attrs()' - Get printer attributes.
8276 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
8277 ipp_attribute_t
*uri
) /* I - Printer URI */
8279 http_status_t status
; /* Policy status */
8280 cups_ptype_t dtype
; /* Destination type (printer/class) */
8281 cupsd_printer_t
*printer
; /* Printer/class */
8282 cups_array_t
*ra
; /* Requested attributes array */
8285 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
8286 con
->http
.fd
, uri
->values
[0].string
.text
);
8289 * Is the destination valid?
8292 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8298 send_ipp_status(con
, IPP_NOT_FOUND
,
8299 _("The printer or class was not found."));
8307 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8309 send_http_error(con
, status
, printer
);
8314 * Send the attributes...
8317 ra
= create_requested_array(con
->request
);
8319 copy_printer_attrs(con
, printer
, ra
);
8321 cupsArrayDelete(ra
);
8323 con
->response
->request
.status
.status_code
= IPP_OK
;
8328 * 'get_printer_supported()' - Get printer supported values.
8332 get_printer_supported(
8333 cupsd_client_t
*con
, /* I - Client connection */
8334 ipp_attribute_t
*uri
) /* I - Printer URI */
8336 http_status_t status
; /* Policy status */
8337 cups_ptype_t dtype
; /* Destination type (printer/class) */
8338 cupsd_printer_t
*printer
; /* Printer/class */
8341 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
8342 con
->http
.fd
, uri
->values
[0].string
.text
);
8345 * Is the destination valid?
8348 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8354 send_ipp_status(con
, IPP_NOT_FOUND
,
8355 _("The printer or class was not found."));
8363 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8365 send_http_error(con
, status
, printer
);
8370 * Return a list of attributes that can be set via Set-Printer-Attributes.
8373 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8375 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8376 "printer-location", 0);
8378 con
->response
->request
.status
.status_code
= IPP_OK
;
8383 * 'get_printers()' - Get a list of printers or classes.
8387 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8388 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8390 http_status_t status
; /* Policy status */
8391 ipp_attribute_t
*attr
; /* Current attribute */
8392 int limit
; /* Max number of printers to return */
8393 int count
; /* Number of printers that match */
8394 cupsd_printer_t
*printer
; /* Current printer pointer */
8395 int printer_type
, /* printer-type attribute */
8396 printer_mask
; /* printer-type-mask attribute */
8397 char *location
; /* Location string */
8398 const char *username
; /* Current user */
8399 char *first_printer_name
; /* first-printer-name attribute */
8400 cups_array_t
*ra
; /* Requested attributes array */
8401 int local
; /* Local connection? */
8404 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8405 con
->http
.fd
, type
);
8411 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8413 send_http_error(con
, status
, NULL
);
8418 * Check for printers...
8421 if (!Printers
|| !cupsArrayCount(Printers
))
8423 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8428 * See if they want to limit the number of printers reported...
8431 if ((attr
= ippFindAttribute(con
->request
, "limit",
8432 IPP_TAG_INTEGER
)) != NULL
)
8433 limit
= attr
->values
[0].integer
;
8437 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8438 IPP_TAG_NAME
)) != NULL
)
8439 first_printer_name
= attr
->values
[0].string
.text
;
8441 first_printer_name
= NULL
;
8444 * Support filtering...
8447 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8448 IPP_TAG_ENUM
)) != NULL
)
8449 printer_type
= attr
->values
[0].integer
;
8453 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8454 IPP_TAG_ENUM
)) != NULL
)
8455 printer_mask
= attr
->values
[0].integer
;
8459 local
= httpAddrLocalhost(&(con
->clientaddr
));
8461 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8462 IPP_TAG_TEXT
)) != NULL
)
8463 location
= attr
->values
[0].string
.text
;
8467 if (con
->username
[0])
8468 username
= con
->username
;
8469 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8470 IPP_TAG_NAME
)) != NULL
)
8471 username
= attr
->values
[0].string
.text
;
8475 ra
= create_requested_array(con
->request
);
8478 * OK, build a list of printers for this printer...
8481 if (first_printer_name
)
8483 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8484 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8487 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8490 count
< limit
&& printer
;
8491 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8493 if (!local
&& !printer
->shared
)
8496 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8497 (printer
->type
& printer_mask
) == printer_type
&&
8499 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
8502 * If HideImplicitMembers is enabled, see if this printer or class
8503 * is a member of an implicit class...
8506 if (ImplicitClasses
&& HideImplicitMembers
&&
8507 printer
->in_implicit_class
)
8511 * If a username is specified, see if it is allowed or denied
8515 if (cupsArrayCount(printer
->users
) && username
&&
8516 !user_allowed(printer
, username
))
8520 * Add the group separator as needed...
8524 ippAddSeparator(con
->response
);
8529 * Send the attributes...
8532 copy_printer_attrs(con
, printer
, ra
);
8536 cupsArrayDelete(ra
);
8538 con
->response
->request
.status
.status_code
= IPP_OK
;
8543 * 'get_subscription_attrs()' - Get subscription attributes.
8547 get_subscription_attrs(
8548 cupsd_client_t
*con
, /* I - Client connection */
8549 int sub_id
) /* I - Subscription ID */
8551 http_status_t status
; /* Policy status */
8552 cupsd_subscription_t
*sub
; /* Subscription */
8553 cupsd_policy_t
*policy
; /* Current security policy */
8554 cups_array_t
*ra
, /* Requested attributes array */
8555 *exclude
; /* Private attributes array */
8558 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8559 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8560 con
, con
->http
.fd
, sub_id
);
8563 * Is the subscription ID valid?
8566 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8569 * Bad subscription ID...
8572 send_ipp_status(con
, IPP_NOT_FOUND
,
8573 _("notify-subscription-id %d no good"), sub_id
);
8582 policy
= sub
->dest
->op_policy_ptr
;
8584 policy
= DefaultPolicyPtr
;
8586 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
8588 send_http_error(con
, status
, sub
->dest
);
8592 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
8595 * Copy the subscription attributes to the response using the
8596 * requested-attributes attribute that may be provided by the client.
8599 ra
= create_requested_array(con
->request
);
8601 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8603 cupsArrayDelete(ra
);
8605 con
->response
->request
.status
.status_code
= IPP_OK
;
8610 * 'get_subscriptions()' - Get subscriptions.
8614 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8615 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8617 http_status_t status
; /* Policy status */
8618 int count
; /* Number of subscriptions */
8619 int limit
; /* Limit */
8620 cupsd_subscription_t
*sub
; /* Subscription */
8621 cups_array_t
*ra
; /* Requested attributes array */
8622 ipp_attribute_t
*attr
; /* Attribute */
8623 cups_ptype_t dtype
; /* Destination type (printer/class) */
8624 char scheme
[HTTP_MAX_URI
],
8625 /* Scheme portion of URI */
8626 username
[HTTP_MAX_URI
],
8627 /* Username portion of URI */
8629 /* Host portion of URI */
8630 resource
[HTTP_MAX_URI
];
8631 /* Resource portion of URI */
8632 int port
; /* Port portion of URI */
8633 cupsd_job_t
*job
; /* Job pointer */
8634 cupsd_printer_t
*printer
; /* Printer */
8635 cupsd_policy_t
*policy
; /* Policy */
8636 cups_array_t
*exclude
; /* Private attributes array */
8639 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8640 "get_subscriptions(con=%p[%d], uri=%s)",
8641 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8644 * Is the destination valid?
8647 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8648 sizeof(scheme
), username
, sizeof(username
), host
,
8649 sizeof(host
), &port
, resource
, sizeof(resource
));
8651 if (!strcmp(resource
, "/") ||
8652 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8653 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8654 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8659 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8662 job
= cupsdFindJob(atoi(resource
+ 6));
8666 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist"),
8671 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8677 send_ipp_status(con
, IPP_NOT_FOUND
,
8678 _("The printer or class was not found."));
8681 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8682 IPP_TAG_INTEGER
)) != NULL
)
8684 job
= cupsdFindJob(attr
->values
[0].integer
);
8688 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
8689 attr
->values
[0].integer
);
8701 policy
= printer
->op_policy_ptr
;
8703 policy
= DefaultPolicyPtr
;
8705 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
8707 send_http_error(con
, status
, printer
);
8712 * Copy the subscription attributes to the response using the
8713 * requested-attributes attribute that may be provided by the client.
8716 ra
= create_requested_array(con
->request
);
8718 if ((attr
= ippFindAttribute(con
->request
, "limit",
8719 IPP_TAG_INTEGER
)) != NULL
)
8720 limit
= attr
->values
[0].integer
;
8725 * See if we only want to see subscriptions for a specific user...
8728 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8729 IPP_TAG_BOOLEAN
)) != NULL
&&
8730 attr
->values
[0].boolean
)
8731 strlcpy(username
, get_username(con
), sizeof(username
));
8735 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8737 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8738 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8739 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
8741 ippAddSeparator(con
->response
);
8743 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
8744 policy
, con
, sub
->dest
,
8747 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8750 if (limit
&& count
>= limit
)
8754 cupsArrayDelete(ra
);
8757 con
->response
->request
.status
.status_code
= IPP_OK
;
8759 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8764 * 'get_username()' - Get the username associated with a request.
8767 static const char * /* O - Username */
8768 get_username(cupsd_client_t
*con
) /* I - Connection */
8770 ipp_attribute_t
*attr
; /* Attribute */
8773 if (con
->username
[0])
8774 return (con
->username
);
8775 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8776 IPP_TAG_NAME
)) != NULL
)
8777 return (attr
->values
[0].string
.text
);
8779 return ("anonymous");
8784 * 'hold_job()' - Hold a print job.
8788 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8789 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8791 ipp_attribute_t
*attr
; /* Current job-hold-until */
8792 const char *when
; /* New value */
8793 int jobid
; /* Job ID */
8794 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8795 username
[HTTP_MAX_URI
], /* Username portion of URI */
8796 host
[HTTP_MAX_URI
], /* Host portion of URI */
8797 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8798 int port
; /* Port portion of URI */
8799 cupsd_job_t
*job
; /* Job information */
8802 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8803 uri
->values
[0].string
.text
);
8806 * See if we have a job URI or a printer URI...
8809 if (!strcmp(uri
->name
, "printer-uri"))
8812 * Got a printer URI; see if we also have a job-id attribute...
8815 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8816 IPP_TAG_INTEGER
)) == NULL
)
8818 send_ipp_status(con
, IPP_BAD_REQUEST
,
8819 _("Got a printer-uri attribute but no job-id"));
8823 jobid
= attr
->values
[0].integer
;
8828 * Got a job URI; parse it to get the job ID...
8831 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8832 sizeof(scheme
), username
, sizeof(username
), host
,
8833 sizeof(host
), &port
, resource
, sizeof(resource
));
8835 if (strncmp(resource
, "/jobs/", 6))
8841 send_ipp_status(con
, IPP_BAD_REQUEST
,
8842 _("Bad job-uri attribute \"%s\""),
8843 uri
->values
[0].string
.text
);
8847 jobid
= atoi(resource
+ 6);
8851 * See if the job exists...
8854 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8857 * Nope - return a "not found" error...
8860 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
8865 * See if the job is owned by the requesting user...
8868 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8870 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8871 cupsdFindDest(job
->dest
));
8876 * Hold the job and return...
8879 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8880 IPP_TAG_KEYWORD
)) == NULL
)
8881 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8885 when
= attr
->values
[0].string
.text
;
8887 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8888 "Job job-hold-until value changed by user.");
8891 when
= "indefinite";
8893 cupsdSetJobHoldUntil(job
, when
, 1);
8894 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8897 con
->response
->request
.status
.status_code
= IPP_OK
;
8902 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8906 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8907 ipp_attribute_t
*uri
) /* I - Printer URI */
8909 http_status_t status
; /* Policy status */
8910 cups_ptype_t dtype
; /* Destination type (printer/class) */
8911 cupsd_printer_t
*printer
; /* Printer data */
8914 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8915 con
->http
.fd
, uri
->values
[0].string
.text
);
8918 * Is the destination valid?
8921 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8927 send_ipp_status(con
, IPP_NOT_FOUND
,
8928 _("The printer or class was not found."));
8936 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8938 send_http_error(con
, status
, printer
);
8943 * Hold pending/new jobs sent to the printer...
8946 printer
->holding_new_jobs
= 1;
8948 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8950 if (dtype
& CUPS_PRINTER_CLASS
)
8951 cupsdLogMessage(CUPSD_LOG_INFO
,
8952 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8953 printer
->name
, get_username(con
));
8955 cupsdLogMessage(CUPSD_LOG_INFO
,
8956 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8957 printer
->name
, get_username(con
));
8960 * Everything was ok, so return OK status...
8963 con
->response
->request
.status
.status_code
= IPP_OK
;
8968 * 'move_job()' - Move a job to a new destination.
8972 move_job(cupsd_client_t
*con
, /* I - Client connection */
8973 ipp_attribute_t
*uri
) /* I - Job URI */
8975 http_status_t status
; /* Policy status */
8976 ipp_attribute_t
*attr
; /* Current attribute */
8977 int jobid
; /* Job ID */
8978 cupsd_job_t
*job
; /* Current job */
8979 const char *src
; /* Source printer/class */
8980 cups_ptype_t stype
, /* Source type (printer or class) */
8981 dtype
; /* Destination type (printer/class) */
8982 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8983 username
[HTTP_MAX_URI
], /* Username portion of URI */
8984 host
[HTTP_MAX_URI
], /* Host portion of URI */
8985 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8986 int port
; /* Port portion of URI */
8987 cupsd_printer_t
*sprinter
, /* Source printer */
8988 *dprinter
; /* Destination printer */
8991 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8992 uri
->values
[0].string
.text
);
8995 * Get the new printer or class...
8998 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8999 IPP_TAG_URI
)) == NULL
)
9002 * Need job-printer-uri...
9005 send_ipp_status(con
, IPP_BAD_REQUEST
,
9006 _("job-printer-uri attribute missing"));
9010 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
9016 send_ipp_status(con
, IPP_NOT_FOUND
,
9017 _("The printer or class was not found."));
9022 * See if we have a job URI or a printer URI...
9025 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9026 sizeof(scheme
), username
, sizeof(username
), host
,
9027 sizeof(host
), &port
, resource
, sizeof(resource
));
9029 if (!strcmp(uri
->name
, "printer-uri"))
9032 * Got a printer URI; see if we also have a job-id attribute...
9035 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9036 IPP_TAG_INTEGER
)) == NULL
)
9042 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
9043 &sprinter
)) == NULL
)
9049 send_ipp_status(con
, IPP_NOT_FOUND
,
9050 _("The printer or class was not found."));
9059 * Otherwise, just move a single job...
9062 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
9065 * Nope - return a "not found" error...
9068 send_ipp_status(con
, IPP_NOT_FOUND
,
9069 _("Job #%d does not exist"), attr
->values
[0].integer
);
9075 * Job found, initialize source pointers...
9086 * Got a job URI; parse it to get the job ID...
9089 if (strncmp(resource
, "/jobs/", 6))
9095 send_ipp_status(con
, IPP_BAD_REQUEST
,
9096 _("Bad job-uri attribute \"%s\""),
9097 uri
->values
[0].string
.text
);
9102 * See if the job exists...
9105 jobid
= atoi(resource
+ 6);
9107 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9110 * Nope - return a "not found" error...
9113 send_ipp_status(con
, IPP_NOT_FOUND
,
9114 _("Job #%d does not exist"), jobid
);
9120 * Job found, initialize source pointers...
9129 * Check the policy of the destination printer...
9132 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
9133 job
? job
->username
: NULL
)) != HTTP_OK
)
9135 send_http_error(con
, status
, dprinter
);
9140 * Now move the job or jobs...
9146 * See if the job has been completed...
9149 if (job
->state_value
> IPP_JOB_STOPPED
)
9152 * Return a "not-possible" error...
9155 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9156 _("Job #%d is finished and cannot be altered"),
9162 * See if the job is owned by the requesting user...
9165 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9167 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9168 cupsdFindDest(job
->dest
));
9173 * Move the job to a different printer or class...
9176 cupsdMoveJob(job
, dprinter
);
9181 * Got the source printer, now look through the jobs...
9184 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
9186 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
9189 * See if the job is pointing at the source printer or has not been
9193 if (strcasecmp(job
->dest
, src
) ||
9194 job
->state_value
> IPP_JOB_STOPPED
)
9198 * See if the job can be moved by the requesting user...
9201 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9205 * Move the job to a different printer or class...
9208 cupsdMoveJob(job
, dprinter
);
9213 * Start jobs if possible...
9219 * Return with "everything is OK" status...
9222 con
->response
->request
.status
.status_code
= IPP_OK
;
9227 * 'ppd_parse_line()' - Parse a PPD default line.
9230 static int /* O - 0 on success, -1 on failure */
9231 ppd_parse_line(const char *line
, /* I - Line */
9232 char *option
, /* O - Option name */
9233 int olen
, /* I - Size of option name */
9234 char *choice
, /* O - Choice name */
9235 int clen
) /* I - Size of choice name */
9238 * Verify this is a default option line...
9241 if (strncmp(line
, "*Default", 8))
9245 * Read the option name...
9248 for (line
+= 8, olen
--;
9249 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9260 * Skip everything else up to the colon (:)...
9263 while (*line
&& *line
!= ':')
9272 * Now grab the option choice, skipping leading whitespace...
9275 while (isspace(*line
& 255))
9279 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9290 * Return with no errors...
9298 * 'print_job()' - Print a file to a printer or class.
9302 print_job(cupsd_client_t
*con
, /* I - Client connection */
9303 ipp_attribute_t
*uri
) /* I - Printer URI */
9305 ipp_attribute_t
*attr
; /* Current attribute */
9306 ipp_attribute_t
*format
; /* Document-format attribute */
9307 const char *default_format
; /* document-format-default value */
9308 cupsd_job_t
*job
; /* New job */
9309 char filename
[1024]; /* Job filename */
9310 mime_type_t
*filetype
; /* Type of file */
9311 char super
[MIME_MAX_SUPER
], /* Supertype of file */
9312 type
[MIME_MAX_TYPE
], /* Subtype of file */
9313 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9314 /* Textual name of mime type */
9315 cupsd_printer_t
*printer
; /* Printer data */
9316 struct stat fileinfo
; /* File information */
9317 int kbytes
; /* Size of file */
9318 int compression
; /* Document compression */
9321 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
9322 uri
->values
[0].string
.text
);
9325 * Validate print file attributes, for now just document-format and
9326 * compression (CUPS only supports "none" and "gzip")...
9329 compression
= CUPS_FILE_NONE
;
9331 if ((attr
= ippFindAttribute(con
->request
, "compression",
9332 IPP_TAG_KEYWORD
)) != NULL
)
9334 if (strcmp(attr
->values
[0].string
.text
, "none")
9336 && strcmp(attr
->values
[0].string
.text
, "gzip")
9337 #endif /* HAVE_LIBZ */
9340 send_ipp_status(con
, IPP_ATTRIBUTES
,
9341 _("Unsupported compression \"%s\""),
9342 attr
->values
[0].string
.text
);
9343 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9344 "compression", NULL
, attr
->values
[0].string
.text
);
9349 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9350 compression
= CUPS_FILE_GZIP
;
9351 #endif /* HAVE_LIBZ */
9355 * Do we have a file to print?
9360 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
9365 * Is the destination valid?
9368 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
9374 send_ipp_status(con
, IPP_NOT_FOUND
,
9375 _("The printer or class was not found."));
9380 * Is it a format we support?
9383 if ((format
= ippFindAttribute(con
->request
, "document-format",
9384 IPP_TAG_MIMETYPE
)) != NULL
)
9387 * Grab format from client...
9390 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9393 send_ipp_status(con
, IPP_BAD_REQUEST
,
9394 _("Bad document-format \"%s\""),
9395 format
->values
[0].string
.text
);
9399 else if ((default_format
= cupsGetOption("document-format",
9400 printer
->num_options
,
9401 printer
->options
)) != NULL
)
9404 * Use default document format...
9407 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9409 send_ipp_status(con
, IPP_BAD_REQUEST
,
9410 _("Bad document-format \"%s\""),
9421 strcpy(super
, "application");
9422 strcpy(type
, "octet-stream");
9425 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9428 * Auto-type the file...
9431 ipp_attribute_t
*doc_name
; /* document-name attribute */
9434 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9436 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9437 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9438 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9442 filetype
= mimeType(MimeDatabase
, super
, type
);
9444 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9445 filetype
->super
, filetype
->type
);
9448 filetype
= mimeType(MimeDatabase
, super
, type
);
9452 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9455 * Replace the document-format attribute value with the auto-typed or
9459 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9464 _cupsStrFree(format
->values
[0].string
.text
);
9466 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9469 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9470 "document-format", NULL
, mimetype
);
9474 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9475 _("Unsupported document-format \"%s\""),
9476 format
? format
->values
[0].string
.text
:
9477 "application/octet-stream");
9478 cupsdLogMessage(CUPSD_LOG_INFO
,
9479 "Hint: Do you have the raw file printing rules enabled?");
9482 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9483 "document-format", NULL
, format
->values
[0].string
.text
);
9489 * Read any embedded job ticket info from PS files...
9492 if (!strcasecmp(filetype
->super
, "application") &&
9493 (!strcasecmp(filetype
->type
, "postscript") ||
9494 !strcasecmp(filetype
->type
, "pdf")))
9495 read_job_ticket(con
);
9498 * Create the job object...
9501 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9505 * Update quota data...
9508 if (stat(con
->filename
, &fileinfo
))
9511 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9513 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9515 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9516 IPP_TAG_INTEGER
)) != NULL
)
9517 attr
->values
[0].integer
+= kbytes
;
9520 * Add the job file...
9523 if (add_file(con
, job
, filetype
, compression
))
9526 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9528 rename(con
->filename
, filename
);
9529 cupsdClearString(&con
->filename
);
9532 * See if we need to add the ending sheet...
9535 if (cupsdTimeoutJob(job
))
9539 * Log and save the job...
9542 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9543 "File of type %s/%s queued by \"%s\".",
9544 filetype
->super
, filetype
->type
, job
->username
);
9545 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9546 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9547 job
->dest
, job
->username
);
9550 * Start the job if possible...
9558 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9560 * This function only gets called when printing a single PDF or PostScript
9561 * file using the Print-Job operation. It doesn't work for Create-Job +
9562 * Send-File, since the job attributes need to be set at job creation
9563 * time for banners to work. The embedded job ticket stuff is here
9564 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9565 * options and IPP attributes which otherwise would be lost.
9567 * The format of a job ticket is simple:
9569 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9571 * %cupsJobTicket: attr1=value1
9572 * %cupsJobTicket: attr2=value2
9574 * %cupsJobTicket: attrN=valueN
9576 * Job ticket lines must appear immediately after the first line that
9577 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9578 * stops looking for job ticket info when it finds a line that does not begin
9579 * with "%cupsJobTicket:".
9581 * The maximum length of a job ticket line, including the prefix, is
9582 * 255 characters to conform with the Adobe DSC.
9584 * Read-only attributes are rejected with a notice to the error log in
9585 * case a malicious user tries anything. Since the job ticket is read
9586 * prior to attribute validation in print_job(), job ticket attributes
9587 * will go through the same validation as IPP attributes...
9591 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9593 cups_file_t
*fp
; /* File to read from */
9594 char line
[256]; /* Line data */
9595 int num_options
; /* Number of options */
9596 cups_option_t
*options
; /* Options */
9597 ipp_t
*ticket
; /* New attributes */
9598 ipp_attribute_t
*attr
, /* Current attribute */
9599 *attr2
, /* Job attribute */
9600 *prev2
; /* Previous job attribute */
9604 * First open the print file...
9607 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9609 cupsdLogMessage(CUPSD_LOG_ERROR
,
9610 "Unable to open print file for job ticket - %s",
9616 * Skip the first line...
9619 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9621 cupsdLogMessage(CUPSD_LOG_ERROR
,
9622 "Unable to read from print file for job ticket - %s",
9628 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9631 * Not a DSC-compliant file, so no job ticket info will be available...
9639 * Read job ticket info from the file...
9645 while (cupsFileGets(fp
, line
, sizeof(line
)))
9648 * Stop at the first non-ticket line...
9651 if (strncmp(line
, "%cupsJobTicket:", 15))
9655 * Add the options to the option array...
9658 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9662 * Done with the file; see if we have any options...
9667 if (num_options
== 0)
9671 * OK, convert the options to an attribute list, and apply them to
9676 cupsEncodeOptions(ticket
, num_options
, options
);
9679 * See what the user wants to change.
9682 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9684 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9687 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9688 !strcmp(attr
->name
, "job-originating-user-name") ||
9689 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9690 !strcmp(attr
->name
, "job-k-octets") ||
9691 !strcmp(attr
->name
, "job-id") ||
9692 !strncmp(attr
->name
, "job-state", 9) ||
9693 !strncmp(attr
->name
, "time-at-", 8))
9694 continue; /* Read-only attrs */
9696 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9697 IPP_TAG_ZERO
)) != NULL
)
9700 * Some other value; first free the old value...
9703 if (con
->request
->attrs
== attr2
)
9705 con
->request
->attrs
= attr2
->next
;
9710 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9711 if (prev2
->next
== attr2
)
9713 prev2
->next
= attr2
->next
;
9718 if (con
->request
->last
== attr2
)
9719 con
->request
->last
= prev2
;
9721 _ippFreeAttr(attr2
);
9725 * Add new option by copying it...
9728 copy_attribute(con
->request
, attr
, 0);
9732 * Then free the attribute list and option array...
9736 cupsFreeOptions(num_options
, options
);
9741 * 'reject_jobs()' - Reject print jobs to a printer.
9745 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9746 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9748 http_status_t status
; /* Policy status */
9749 cups_ptype_t dtype
; /* Destination type (printer/class) */
9750 cupsd_printer_t
*printer
; /* Printer data */
9751 ipp_attribute_t
*attr
; /* printer-state-message text */
9754 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9755 con
->http
.fd
, uri
->values
[0].string
.text
);
9758 * Is the destination valid?
9761 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9767 send_ipp_status(con
, IPP_NOT_FOUND
,
9768 _("The printer or class was not found."));
9776 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9778 send_http_error(con
, status
, printer
);
9783 * Reject jobs sent to the printer...
9786 printer
->accepting
= 0;
9788 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9789 IPP_TAG_TEXT
)) == NULL
)
9790 strcpy(printer
->state_message
, "Rejecting Jobs");
9792 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9793 sizeof(printer
->state_message
));
9795 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9796 "No longer accepting jobs.");
9798 if (dtype
& CUPS_PRINTER_CLASS
)
9800 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9802 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9803 printer
->name
, get_username(con
));
9807 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9809 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9810 printer
->name
, get_username(con
));
9814 * Everything was ok, so return OK status...
9817 con
->response
->request
.status
.status_code
= IPP_OK
;
9822 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9826 release_held_new_jobs(
9827 cupsd_client_t
*con
, /* I - Connection */
9828 ipp_attribute_t
*uri
) /* I - Printer URI */
9830 http_status_t status
; /* Policy status */
9831 cups_ptype_t dtype
; /* Destination type (printer/class) */
9832 cupsd_printer_t
*printer
; /* Printer data */
9835 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9836 con
->http
.fd
, uri
->values
[0].string
.text
);
9839 * Is the destination valid?
9842 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9848 send_ipp_status(con
, IPP_NOT_FOUND
,
9849 _("The printer or class was not found."));
9857 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9859 send_http_error(con
, status
, printer
);
9864 * Hold pending/new jobs sent to the printer...
9867 printer
->holding_new_jobs
= 0;
9869 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9871 if (dtype
& CUPS_PRINTER_CLASS
)
9872 cupsdLogMessage(CUPSD_LOG_INFO
,
9873 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9874 printer
->name
, get_username(con
));
9876 cupsdLogMessage(CUPSD_LOG_INFO
,
9877 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9878 printer
->name
, get_username(con
));
9881 * Everything was ok, so return OK status...
9884 con
->response
->request
.status
.status_code
= IPP_OK
;
9889 * 'release_job()' - Release a held print job.
9893 release_job(cupsd_client_t
*con
, /* I - Client connection */
9894 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9896 ipp_attribute_t
*attr
; /* Current attribute */
9897 int jobid
; /* Job ID */
9898 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9899 username
[HTTP_MAX_URI
], /* Username portion of URI */
9900 host
[HTTP_MAX_URI
], /* Host portion of URI */
9901 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9902 int port
; /* Port portion of URI */
9903 cupsd_job_t
*job
; /* Job information */
9906 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9907 con
->http
.fd
, uri
->values
[0].string
.text
);
9910 * See if we have a job URI or a printer URI...
9913 if (!strcmp(uri
->name
, "printer-uri"))
9916 * Got a printer URI; see if we also have a job-id attribute...
9919 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9920 IPP_TAG_INTEGER
)) == NULL
)
9922 send_ipp_status(con
, IPP_BAD_REQUEST
,
9923 _("Got a printer-uri attribute but no job-id"));
9927 jobid
= attr
->values
[0].integer
;
9932 * Got a job URI; parse it to get the job ID...
9935 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9936 sizeof(scheme
), username
, sizeof(username
), host
,
9937 sizeof(host
), &port
, resource
, sizeof(resource
));
9939 if (strncmp(resource
, "/jobs/", 6))
9945 send_ipp_status(con
, IPP_BAD_REQUEST
,
9946 _("Bad job-uri attribute \"%s\""),
9947 uri
->values
[0].string
.text
);
9951 jobid
= atoi(resource
+ 6);
9955 * See if the job exists...
9958 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9961 * Nope - return a "not found" error...
9964 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9969 * See if job is "held"...
9972 if (job
->state_value
!= IPP_JOB_HELD
)
9975 * Nope - return a "not possible" error...
9978 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held"), jobid
);
9983 * See if the job is owned by the requesting user...
9986 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9988 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9989 cupsdFindDest(job
->dest
));
9994 * Reset the job-hold-until value to "no-hold"...
9997 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9998 IPP_TAG_KEYWORD
)) == NULL
)
9999 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10003 _cupsStrFree(attr
->values
[0].string
.text
);
10005 attr
->value_tag
= IPP_TAG_KEYWORD
;
10006 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
10008 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10009 "Job job-hold-until value changed by user.");
10013 * Release the job and return...
10016 cupsdReleaseJob(job
);
10018 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10019 "Job released by user.");
10021 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
10023 con
->response
->request
.status
.status_code
= IPP_OK
;
10030 * 'renew_subscription()' - Renew an existing subscription...
10034 renew_subscription(
10035 cupsd_client_t
*con
, /* I - Client connection */
10036 int sub_id
) /* I - Subscription ID */
10038 http_status_t status
; /* Policy status */
10039 cupsd_subscription_t
*sub
; /* Subscription */
10040 ipp_attribute_t
*lease
; /* notify-lease-duration */
10043 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
10044 "renew_subscription(con=%p[%d], sub_id=%d)",
10045 con
, con
->http
.fd
, sub_id
);
10048 * Is the subscription ID valid?
10051 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
10054 * Bad subscription ID...
10057 send_ipp_status(con
, IPP_NOT_FOUND
,
10058 _("notify-subscription-id %d no good"), sub_id
);
10065 * Job subscriptions cannot be renewed...
10068 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10069 _("Job subscriptions cannot be renewed"));
10077 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
10079 con
, sub
->owner
)) != HTTP_OK
)
10081 send_http_error(con
, status
, sub
->dest
);
10086 * Renew the subscription...
10089 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
10092 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
10094 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
10096 cupsdLogMessage(CUPSD_LOG_INFO
,
10097 "renew_subscription: Limiting notify-lease-duration to "
10100 sub
->lease
= MaxLeaseDuration
;
10103 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
10105 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
10107 con
->response
->request
.status
.status_code
= IPP_OK
;
10109 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
10110 "notify-lease-duration", sub
->lease
);
10115 * 'restart_job()' - Restart an old print job.
10119 restart_job(cupsd_client_t
*con
, /* I - Client connection */
10120 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
10122 ipp_attribute_t
*attr
; /* Current attribute */
10123 int jobid
; /* Job ID */
10124 cupsd_job_t
*job
; /* Job information */
10125 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
10126 username
[HTTP_MAX_URI
], /* Username portion of URI */
10127 host
[HTTP_MAX_URI
], /* Host portion of URI */
10128 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10129 int port
; /* Port portion of URI */
10132 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
10133 con
->http
.fd
, uri
->values
[0].string
.text
);
10136 * See if we have a job URI or a printer URI...
10139 if (!strcmp(uri
->name
, "printer-uri"))
10142 * Got a printer URI; see if we also have a job-id attribute...
10145 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10146 IPP_TAG_INTEGER
)) == NULL
)
10148 send_ipp_status(con
, IPP_BAD_REQUEST
,
10149 _("Got a printer-uri attribute but no job-id"));
10153 jobid
= attr
->values
[0].integer
;
10158 * Got a job URI; parse it to get the job ID...
10161 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10162 sizeof(scheme
), username
, sizeof(username
), host
,
10163 sizeof(host
), &port
, resource
, sizeof(resource
));
10165 if (strncmp(resource
, "/jobs/", 6))
10171 send_ipp_status(con
, IPP_BAD_REQUEST
,
10172 _("Bad job-uri attribute \"%s\""),
10173 uri
->values
[0].string
.text
);
10177 jobid
= atoi(resource
+ 6);
10181 * See if the job exists...
10184 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10187 * Nope - return a "not found" error...
10190 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10195 * See if job is in any of the "completed" states...
10198 if (job
->state_value
<= IPP_JOB_PROCESSING
)
10201 * Nope - return a "not possible" error...
10204 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete"),
10210 * See if we have retained the job files...
10215 if (!job
->attrs
|| job
->num_files
== 0)
10218 * Nope - return a "not possible" error...
10221 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10222 _("Job #%d cannot be restarted - no files"), jobid
);
10227 * See if the job is owned by the requesting user...
10230 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10232 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10233 cupsdFindDest(job
->dest
));
10238 * See if the job-hold-until attribute is specified...
10241 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
10242 IPP_TAG_KEYWORD
)) == NULL
)
10243 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
10245 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
10248 * Return the job to a held state...
10251 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
10252 "Restarted by \"%s\" with job-hold-until=%s.",
10253 username
, attr
->values
[0].string
.text
);
10254 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10256 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
10257 NULL
, job
, "Job restarted by user with job-hold-until=%s",
10258 attr
->values
[0].string
.text
);
10263 * Restart the job...
10266 cupsdRestartJob(job
);
10270 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
10272 con
->response
->request
.status
.status_code
= IPP_OK
;
10277 * 'save_auth_info()' - Save authentication information for a job.
10282 cupsd_client_t
*con
, /* I - Client connection */
10283 cupsd_job_t
*job
, /* I - Job */
10284 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
10286 int i
; /* Looping var */
10287 char filename
[1024]; /* Job authentication filename */
10288 cups_file_t
*fp
; /* Job authentication file */
10289 char line
[2048]; /* Line for file */
10290 cupsd_printer_t
*dest
; /* Destination printer/class */
10294 * This function saves the in-memory authentication information for
10295 * a job so that it can be used to authenticate with a remote host.
10296 * The information is stored in a file that is readable only by the
10297 * root user. The fields are Base-64 encoded, each on a separate line,
10298 * followed by random number (up to 1024) of newlines to limit the
10299 * amount of information that is exposed.
10301 * Because of the potential for exposing of authentication information,
10302 * this functionality is only enabled when running cupsd as root.
10304 * This caching only works for the Basic and BasicDigest authentication
10305 * types. Digest authentication cannot be cached this way, and in
10306 * the future Kerberos authentication may make all of this obsolete.
10308 * Authentication information is saved whenever an authenticated
10309 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
10312 * This information is deleted after a job is completed or canceled,
10313 * so reprints may require subsequent re-authentication.
10319 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
10323 * Create the authentication file and change permissions...
10326 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
10327 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
10329 cupsdLogMessage(CUPSD_LOG_ERROR
,
10330 "Unable to save authentication info to \"%s\" - %s",
10331 filename
, strerror(errno
));
10335 fchown(cupsFileNumber(fp
), 0, 0);
10336 fchmod(cupsFileNumber(fp
), 0400);
10338 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
10341 * Write 1 to 3 auth values...
10344 cupsdClearString(&job
->auth_username
);
10345 cupsdClearString(&job
->auth_domain
);
10346 cupsdClearString(&job
->auth_password
);
10348 for (i
= 0; i
< auth_info
->num_values
; i
++)
10350 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
10351 strlen(auth_info
->values
[i
].string
.text
));
10352 cupsFilePrintf(fp
, "%s\n", line
);
10354 if (!strcmp(dest
->auth_info_required
[i
], "username"))
10355 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
10356 auth_info
->values
[i
].string
.text
);
10357 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
10358 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
10359 auth_info
->values
[i
].string
.text
);
10360 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
10361 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
10362 auth_info
->values
[i
].string
.text
);
10365 else if (con
->username
[0])
10368 * Write the authenticated username...
10371 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
10372 cupsFilePrintf(fp
, "%s\n", line
);
10374 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
10375 cupsdClearString(&job
->auth_domain
);
10378 * Write the authenticated password...
10381 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10382 cupsFilePrintf(fp
, "%s\n", line
);
10384 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
10388 * Write a random number of newlines to the end of the file...
10391 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10392 cupsFilePutChar(fp
, '\n');
10395 * Close the file and return...
10400 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10401 # ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
10402 if (con
->have_gss
&&
10403 (con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
|| con
->gss_creds
))
10405 if (con
->have_gss
&& con
->gss_creds
)
10406 # endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
10407 save_krb5_creds(con
, job
);
10408 else if (job
->ccname
)
10409 cupsdClearString(&(job
->ccname
));
10410 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10414 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10416 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
10420 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
10421 cupsd_job_t
*job
) /* I - Job */
10424 * Get the credentials...
10427 job
->ccache
= cupsdCopyKrb5Creds(con
);
10430 * Add the KRB5CCNAME environment variable to the job so that the
10431 * backend can use the credentials when printing.
10436 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
10437 krb5_cc_get_name(KerberosContext
, job
->ccache
));
10439 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
10442 cupsdClearString(&(job
->ccname
));
10444 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10448 * 'send_document()' - Send a file to a printer or class.
10452 send_document(cupsd_client_t
*con
, /* I - Client connection */
10453 ipp_attribute_t
*uri
) /* I - Printer URI */
10455 ipp_attribute_t
*attr
; /* Current attribute */
10456 ipp_attribute_t
*format
; /* Request's document-format attribute */
10457 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10458 const char *default_format
;/* document-format-default value */
10459 int jobid
; /* Job ID number */
10460 cupsd_job_t
*job
; /* Current job */
10461 char job_uri
[HTTP_MAX_URI
],
10463 scheme
[HTTP_MAX_URI
],
10464 /* Method portion of URI */
10465 username
[HTTP_MAX_URI
],
10466 /* Username portion of URI */
10467 host
[HTTP_MAX_URI
],
10468 /* Host portion of URI */
10469 resource
[HTTP_MAX_URI
];
10470 /* Resource portion of URI */
10471 int port
; /* Port portion of URI */
10472 mime_type_t
*filetype
; /* Type of file */
10473 char super
[MIME_MAX_SUPER
],
10474 /* Supertype of file */
10475 type
[MIME_MAX_TYPE
],
10476 /* Subtype of file */
10477 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10478 /* Textual name of mime type */
10479 char filename
[1024]; /* Job filename */
10480 cupsd_printer_t
*printer
; /* Current printer */
10481 struct stat fileinfo
; /* File information */
10482 int kbytes
; /* Size of file */
10483 int compression
; /* Type of compression */
10484 int start_job
; /* Start the job? */
10487 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10488 con
->http
.fd
, uri
->values
[0].string
.text
);
10491 * See if we have a job URI or a printer URI...
10494 if (!strcmp(uri
->name
, "printer-uri"))
10497 * Got a printer URI; see if we also have a job-id attribute...
10500 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10501 IPP_TAG_INTEGER
)) == NULL
)
10503 send_ipp_status(con
, IPP_BAD_REQUEST
,
10504 _("Got a printer-uri attribute but no job-id"));
10508 jobid
= attr
->values
[0].integer
;
10513 * Got a job URI; parse it to get the job ID...
10516 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10517 sizeof(scheme
), username
, sizeof(username
), host
,
10518 sizeof(host
), &port
, resource
, sizeof(resource
));
10520 if (strncmp(resource
, "/jobs/", 6))
10526 send_ipp_status(con
, IPP_BAD_REQUEST
,
10527 _("Bad job-uri attribute \"%s\""),
10528 uri
->values
[0].string
.text
);
10532 jobid
= atoi(resource
+ 6);
10536 * See if the job exists...
10539 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10542 * Nope - return a "not found" error...
10545 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10549 printer
= cupsdFindDest(job
->dest
);
10552 * See if the job is owned by the requesting user...
10555 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10557 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10558 cupsdFindDest(job
->dest
));
10563 * OK, see if the client is sending the document compressed - CUPS
10564 * only supports "none" and "gzip".
10567 compression
= CUPS_FILE_NONE
;
10569 if ((attr
= ippFindAttribute(con
->request
, "compression",
10570 IPP_TAG_KEYWORD
)) != NULL
)
10572 if (strcmp(attr
->values
[0].string
.text
, "none")
10574 && strcmp(attr
->values
[0].string
.text
, "gzip")
10575 #endif /* HAVE_LIBZ */
10578 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\""),
10579 attr
->values
[0].string
.text
);
10580 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10581 "compression", NULL
, attr
->values
[0].string
.text
);
10586 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10587 compression
= CUPS_FILE_GZIP
;
10588 #endif /* HAVE_LIBZ */
10592 * Do we have a file to print?
10595 if (!con
->filename
)
10598 * Check for an empty request with "last-document" set to true, which is
10599 * used to close an "open" job by RFC 2911, section 3.3.2.
10602 if (job
->num_files
> 0 &&
10603 (attr
= ippFindAttribute(con
->request
, "last-document",
10604 IPP_TAG_BOOLEAN
)) != NULL
&&
10605 attr
->values
[0].boolean
)
10606 goto last_document
;
10608 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
10613 * Is it a format we support?
10616 if ((format
= ippFindAttribute(con
->request
, "document-format",
10617 IPP_TAG_MIMETYPE
)) != NULL
)
10620 * Grab format from client...
10623 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10626 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
10627 format
->values
[0].string
.text
);
10631 else if ((default_format
= cupsGetOption("document-format",
10632 printer
->num_options
,
10633 printer
->options
)) != NULL
)
10636 * Use default document format...
10639 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10641 send_ipp_status(con
, IPP_BAD_REQUEST
,
10642 _("Could not scan type \"%s\""),
10650 * No document format attribute? Auto-type it!
10653 strcpy(super
, "application");
10654 strcpy(type
, "octet-stream");
10657 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10660 * Auto-type the file...
10663 ipp_attribute_t
*doc_name
; /* document-name attribute */
10666 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10668 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10669 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10670 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10674 filetype
= mimeType(MimeDatabase
, super
, type
);
10677 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10678 filetype
->super
, filetype
->type
);
10681 filetype
= mimeType(MimeDatabase
, super
, type
);
10686 * Replace the document-format attribute value with the auto-typed or
10690 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10693 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10694 IPP_TAG_MIMETYPE
)) != NULL
)
10696 _cupsStrFree(jformat
->values
[0].string
.text
);
10698 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10701 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10702 "document-format", NULL
, mimetype
);
10704 else if (!filetype
)
10706 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10707 _("Unsupported format \'%s/%s\'"), super
, type
);
10708 cupsdLogMessage(CUPSD_LOG_INFO
,
10709 "Hint: Do you have the raw file printing rules enabled?");
10712 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10713 "document-format", NULL
, format
->values
[0].string
.text
);
10718 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10720 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10723 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10724 _("Unsupported format \'%s\'"), mimetype
);
10726 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10727 "document-format", NULL
, mimetype
);
10733 * Add the file to the job...
10738 if (add_file(con
, job
, filetype
, compression
))
10741 if (stat(con
->filename
, &fileinfo
))
10744 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10746 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10748 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10749 IPP_TAG_INTEGER
)) != NULL
)
10750 attr
->values
[0].integer
+= kbytes
;
10752 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10754 rename(con
->filename
, filename
);
10756 cupsdClearString(&con
->filename
);
10758 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10759 filetype
->super
, filetype
->type
, job
->username
);
10762 * Start the job if this is the last document...
10767 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10768 IPP_TAG_BOOLEAN
)) != NULL
&&
10769 attr
->values
[0].boolean
)
10772 * See if we need to add the ending sheet...
10775 if (cupsdTimeoutJob(job
))
10778 if (job
->state_value
== IPP_JOB_STOPPED
)
10780 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10781 job
->state_value
= IPP_JOB_PENDING
;
10783 else if (job
->state_value
== IPP_JOB_HELD
)
10785 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10786 IPP_TAG_KEYWORD
)) == NULL
)
10787 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10789 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10791 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10792 job
->state_value
= IPP_JOB_PENDING
;
10797 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10803 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10804 IPP_TAG_KEYWORD
)) == NULL
)
10805 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10807 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10809 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10810 job
->state_value
= IPP_JOB_HELD
;
10811 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10814 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10821 * Fill in the response info...
10824 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10827 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10830 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10832 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10834 add_job_state_reasons(con
, job
);
10836 con
->response
->request
.status
.status_code
= IPP_OK
;
10839 * Start the job if necessary...
10848 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10853 cupsd_client_t
*con
, /* I - Client connection */
10854 http_status_t status
, /* I - HTTP status code */
10855 cupsd_printer_t
*printer
) /* I - Printer, if any */
10857 ipp_attribute_t
*uri
; /* Request URI, if any */
10860 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10861 IPP_TAG_URI
)) == NULL
)
10862 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10864 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10865 "Returning HTTP %s for %s (%s) from %s",
10866 httpStatus(status
),
10867 ippOpString(con
->request
->request
.op
.operation_id
),
10868 uri
? uri
->values
[0].string
.text
: "no URI",
10869 con
->http
.hostname
);
10873 int auth_type
; /* Type of authentication required */
10876 auth_type
= CUPSD_AUTH_NONE
;
10878 if (status
== HTTP_UNAUTHORIZED
&&
10879 printer
->num_auth_info_required
> 0 &&
10880 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10882 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10883 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10884 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10887 * Creating and authenticating jobs requires Kerberos...
10890 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10895 * Use policy/location-defined authentication requirements...
10898 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10899 cupsd_location_t
*auth
; /* Pointer to authentication element */
10902 if (printer
->type
& CUPS_PRINTER_CLASS
)
10903 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10905 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10907 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10908 auth
->type
== CUPSD_AUTH_NONE
)
10909 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10911 con
->request
->request
.op
.operation_id
:
10916 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10917 auth_type
= DefaultAuthType
;
10919 auth_type
= auth
->type
;
10923 cupsdSendError(con
, status
, auth_type
);
10926 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10928 ippDelete(con
->response
);
10929 con
->response
= NULL
;
10936 * 'send_ipp_status()' - Send a status back to the IPP client.
10940 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10941 ipp_status_t status
, /* I - IPP status code */
10942 const char *message
,/* I - Status message */
10943 ...) /* I - Additional args as needed */
10945 va_list ap
; /* Pointer to additional args */
10946 char formatted
[1024]; /* Formatted errror message */
10949 va_start(ap
, message
);
10950 vsnprintf(formatted
, sizeof(formatted
),
10951 _cupsLangString(con
->language
, message
), ap
);
10954 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10955 ippOpString(con
->request
->request
.op
.operation_id
),
10956 ippErrorString(status
), formatted
);
10958 con
->response
->request
.status
.status_code
= status
;
10960 if (ippFindAttribute(con
->response
, "attributes-charset",
10961 IPP_TAG_ZERO
) == NULL
)
10962 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10963 "attributes-charset", NULL
, "utf-8");
10965 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10966 IPP_TAG_ZERO
) == NULL
)
10967 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10968 "attributes-natural-language", NULL
, DefaultLanguage
);
10970 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10971 "status-message", NULL
, formatted
);
10976 * 'set_default()' - Set the default destination...
10980 set_default(cupsd_client_t
*con
, /* I - Client connection */
10981 ipp_attribute_t
*uri
) /* I - Printer URI */
10983 http_status_t status
; /* Policy status */
10984 cups_ptype_t dtype
; /* Destination type (printer/class) */
10985 cupsd_printer_t
*printer
, /* Printer */
10986 *oldprinter
; /* Old default printer */
10989 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10990 con
->http
.fd
, uri
->values
[0].string
.text
);
10993 * Is the destination valid?
10996 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11002 send_ipp_status(con
, IPP_NOT_FOUND
,
11003 _("The printer or class was not found."));
11011 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
11013 send_http_error(con
, status
, NULL
);
11018 * Set it as the default...
11021 oldprinter
= DefaultPrinter
;
11022 DefaultPrinter
= printer
;
11025 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
11026 "%s is no longer the default printer.", oldprinter
->name
);
11028 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
11029 "%s is now the default printer.", printer
->name
);
11031 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
11032 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
11034 cupsdLogMessage(CUPSD_LOG_INFO
,
11035 "Default destination set to \"%s\" by \"%s\".",
11036 printer
->name
, get_username(con
));
11039 * Everything was ok, so return OK status...
11042 con
->response
->request
.status
.status_code
= IPP_OK
;
11047 * 'set_job_attrs()' - Set job attributes.
11051 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
11052 ipp_attribute_t
*uri
) /* I - Job URI */
11054 ipp_attribute_t
*attr
, /* Current attribute */
11055 *attr2
; /* Job attribute */
11056 int jobid
; /* Job ID */
11057 cupsd_job_t
*job
; /* Current job */
11058 char scheme
[HTTP_MAX_URI
],
11059 /* Method portion of URI */
11060 username
[HTTP_MAX_URI
],
11061 /* Username portion of URI */
11062 host
[HTTP_MAX_URI
],
11063 /* Host portion of URI */
11064 resource
[HTTP_MAX_URI
];
11065 /* Resource portion of URI */
11066 int port
; /* Port portion of URI */
11067 int event
; /* Events? */
11068 int check_jobs
; /* Check jobs? */
11071 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
11072 con
->http
.fd
, uri
->values
[0].string
.text
);
11075 * Start with "everything is OK" status...
11078 con
->response
->request
.status
.status_code
= IPP_OK
;
11081 * See if we have a job URI or a printer URI...
11084 if (!strcmp(uri
->name
, "printer-uri"))
11087 * Got a printer URI; see if we also have a job-id attribute...
11090 if ((attr
= ippFindAttribute(con
->request
, "job-id",
11091 IPP_TAG_INTEGER
)) == NULL
)
11093 send_ipp_status(con
, IPP_BAD_REQUEST
,
11094 _("Got a printer-uri attribute but no job-id"));
11098 jobid
= attr
->values
[0].integer
;
11103 * Got a job URI; parse it to get the job ID...
11106 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
11107 sizeof(scheme
), username
, sizeof(username
), host
,
11108 sizeof(host
), &port
, resource
, sizeof(resource
));
11110 if (strncmp(resource
, "/jobs/", 6))
11116 send_ipp_status(con
, IPP_BAD_REQUEST
,
11117 _("Bad job-uri attribute \"%s\""),
11118 uri
->values
[0].string
.text
);
11122 jobid
= atoi(resource
+ 6);
11126 * See if the job exists...
11129 if ((job
= cupsdFindJob(jobid
)) == NULL
)
11132 * Nope - return a "not found" error...
11135 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
11140 * See if the job has been completed...
11143 if (job
->state_value
> IPP_JOB_STOPPED
)
11146 * Return a "not-possible" error...
11149 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11150 _("Job #%d is finished and cannot be altered"), jobid
);
11155 * See if the job is owned by the requesting user...
11158 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
11160 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
11161 cupsdFindDest(job
->dest
));
11166 * See what the user wants to change.
11174 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11176 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
11179 if (!strcmp(attr
->name
, "attributes-charset") ||
11180 !strcmp(attr
->name
, "attributes-natural-language") ||
11181 !strcmp(attr
->name
, "document-compression") ||
11182 !strcmp(attr
->name
, "document-format") ||
11183 !strcmp(attr
->name
, "job-detailed-status-messages") ||
11184 !strcmp(attr
->name
, "job-document-access-errors") ||
11185 !strcmp(attr
->name
, "job-id") ||
11186 !strcmp(attr
->name
, "job-impressions-completed") ||
11187 !strcmp(attr
->name
, "job-k-octets") ||
11188 !strcmp(attr
->name
, "job-originating-host-name") ||
11189 !strcmp(attr
->name
, "job-originating-user-name") ||
11190 !strcmp(attr
->name
, "job-printer-up-time") ||
11191 !strcmp(attr
->name
, "job-printer-uri") ||
11192 !strcmp(attr
->name
, "job-sheets") ||
11193 !strcmp(attr
->name
, "job-state-message") ||
11194 !strcmp(attr
->name
, "job-state-reasons") ||
11195 !strcmp(attr
->name
, "job-uri") ||
11196 !strcmp(attr
->name
, "number-of-documents") ||
11197 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
11198 !strcmp(attr
->name
, "output-device-assigned") ||
11199 !strncmp(attr
->name
, "date-time-at-", 13) ||
11200 !strncmp(attr
->name
, "job-k-octets", 12) ||
11201 !strncmp(attr
->name
, "job-media-sheets", 16) ||
11202 !strncmp(attr
->name
, "time-at-", 8))
11208 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
11209 _("%s cannot be changed."), attr
->name
);
11211 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11212 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11217 if (!strcmp(attr
->name
, "job-priority"))
11220 * Change the job priority...
11223 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11225 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value"));
11227 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11228 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11230 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
11232 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11233 _("Job is completed and cannot be changed."));
11236 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11238 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
11239 attr
->values
[0].integer
);
11240 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
11243 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
11244 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
11247 else if (!strcmp(attr
->name
, "job-state"))
11250 * Change the job state...
11253 if (attr
->value_tag
!= IPP_TAG_ENUM
)
11255 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value"));
11257 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11258 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11262 switch (attr
->values
[0].integer
)
11264 case IPP_JOB_PENDING
:
11265 case IPP_JOB_HELD
:
11266 if (job
->state_value
> IPP_JOB_HELD
)
11268 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11269 _("Job state cannot be changed."));
11272 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11274 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11275 attr
->values
[0].integer
);
11276 cupsdSetJobState(job
, attr
->values
[0].integer
,
11278 "Job state changed by \"%s\"", username
);
11283 case IPP_JOB_PROCESSING
:
11284 case IPP_JOB_STOPPED
:
11285 if (job
->state_value
!= attr
->values
[0].integer
)
11287 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11288 _("Job state cannot be changed."));
11293 case IPP_JOB_CANCELED
:
11294 case IPP_JOB_ABORTED
:
11295 case IPP_JOB_COMPLETED
:
11296 if (job
->state_value
> IPP_JOB_PROCESSING
)
11298 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11299 _("Job state cannot be changed."));
11302 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11304 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11305 attr
->values
[0].integer
);
11306 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
11308 "Job state changed by \"%s\"", username
);
11315 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
11317 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11318 IPP_TAG_ZERO
)) != NULL
)
11321 * Some other value; first free the old value...
11324 if (job
->attrs
->prev
)
11325 job
->attrs
->prev
->next
= attr2
->next
;
11327 job
->attrs
->attrs
= attr2
->next
;
11329 if (job
->attrs
->last
== attr2
)
11330 job
->attrs
->last
= job
->attrs
->prev
;
11332 _ippFreeAttr(attr2
);
11335 * Then copy the attribute...
11338 copy_attribute(job
->attrs
, attr
, 0);
11341 * See if the job-name or job-hold-until is being changed.
11344 if (!strcmp(attr
->name
, "job-hold-until"))
11346 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
11347 attr
->values
[0].string
.text
);
11348 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
11350 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
11352 cupsdReleaseJob(job
);
11356 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
11357 "Job held by \"%s\".", username
);
11359 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
11362 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
11365 * Delete the attribute...
11368 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11369 IPP_TAG_ZERO
)) != NULL
)
11371 if (job
->attrs
->prev
)
11372 job
->attrs
->prev
->next
= attr2
->next
;
11374 job
->attrs
->attrs
= attr2
->next
;
11376 if (attr2
== job
->attrs
->last
)
11377 job
->attrs
->last
= job
->attrs
->prev
;
11379 _ippFreeAttr(attr2
);
11381 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11387 * Add new option by copying it...
11390 copy_attribute(job
->attrs
, attr
, 0);
11392 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11401 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11404 * Send events as needed...
11407 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11408 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11409 cupsdFindDest(job
->dest
), job
,
11410 "Job priority changed by user.");
11412 if (event
& CUPSD_EVENT_JOB_STATE
)
11413 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11414 job
->state_value
== IPP_JOB_HELD
?
11415 "Job held by user." : "Job restarted by user.");
11417 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11418 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11419 "Job options changed by user.");
11422 * Start jobs if possible...
11431 * 'set_printer_attrs()' - Set printer attributes.
11435 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11436 ipp_attribute_t
*uri
) /* I - Printer */
11438 http_status_t status
; /* Policy status */
11439 cups_ptype_t dtype
; /* Destination type (printer/class) */
11440 cupsd_printer_t
*printer
; /* Printer/class */
11441 ipp_attribute_t
*attr
; /* Printer attribute */
11442 int changed
= 0; /* Was anything changed? */
11445 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11446 con
->http
.fd
, uri
->values
[0].string
.text
);
11449 * Is the destination valid?
11452 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11458 send_ipp_status(con
, IPP_NOT_FOUND
,
11459 _("The printer or class was not found."));
11467 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11469 send_http_error(con
, status
, printer
);
11474 * Return a list of attributes that can be set via Set-Printer-Attributes.
11477 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11478 IPP_TAG_TEXT
)) != NULL
)
11480 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11484 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11485 IPP_TAG_TEXT
)) != NULL
)
11487 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11492 * Update the printer attributes and return...
11497 cupsdSetPrinterAttrs(printer
);
11498 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11500 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11501 "Printer \"%s\" description or location changed by \"%s\".",
11502 printer
->name
, get_username(con
));
11504 cupsdLogMessage(CUPSD_LOG_INFO
,
11505 "Printer \"%s\" description or location changed by \"%s\".",
11506 printer
->name
, get_username(con
));
11509 con
->response
->request
.status
.status_code
= IPP_OK
;
11514 * 'set_printer_defaults()' - Set printer default options from a request.
11518 set_printer_defaults(
11519 cupsd_client_t
*con
, /* I - Client connection */
11520 cupsd_printer_t
*printer
) /* I - Printer */
11522 int i
; /* Looping var */
11523 ipp_attribute_t
*attr
; /* Current attribute */
11524 int namelen
; /* Length of attribute name */
11525 char name
[256], /* New attribute name */
11526 value
[256]; /* String version of integer attrs */
11529 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11532 * Skip non-printer attributes...
11535 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11538 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11540 if (!strcmp(attr
->name
, "job-sheets-default"))
11543 * Only allow keywords and names...
11546 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11550 * Only allow job-sheets-default to be set when running without a
11551 * system high classification level...
11554 if (Classification
)
11557 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11559 if (attr
->num_values
> 1)
11560 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11562 cupsdSetString(&printer
->job_sheets
[1], "none");
11564 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11566 cupsdFreeStrings(&(printer
->users
));
11568 printer
->deny_users
= 0;
11570 if (attr
->value_tag
== IPP_TAG_NAME
&&
11571 (attr
->num_values
> 1 ||
11572 strcmp(attr
->values
[0].string
.text
, "all")))
11574 for (i
= 0; i
< attr
->num_values
; i
++)
11575 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11578 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11580 cupsdFreeStrings(&(printer
->users
));
11582 printer
->deny_users
= 1;
11584 if (attr
->value_tag
== IPP_TAG_NAME
&&
11585 (attr
->num_values
> 1 ||
11586 strcmp(attr
->values
[0].string
.text
, "none")))
11588 for (i
= 0; i
< attr
->num_values
; i
++)
11589 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11592 else if (!strcmp(attr
->name
, "job-quota-period"))
11594 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11597 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11598 attr
->values
[0].integer
);
11599 cupsdFreeQuotas(printer
);
11601 printer
->quota_period
= attr
->values
[0].integer
;
11603 else if (!strcmp(attr
->name
, "job-k-limit"))
11605 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11608 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11609 attr
->values
[0].integer
);
11610 cupsdFreeQuotas(printer
);
11612 printer
->k_limit
= attr
->values
[0].integer
;
11614 else if (!strcmp(attr
->name
, "job-page-limit"))
11616 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11619 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11620 attr
->values
[0].integer
);
11621 cupsdFreeQuotas(printer
);
11623 printer
->page_limit
= attr
->values
[0].integer
;
11625 else if (!strcmp(attr
->name
, "printer-op-policy"))
11627 cupsd_policy_t
*p
; /* Policy */
11630 if (attr
->value_tag
!= IPP_TAG_NAME
)
11633 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11635 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11636 "Setting printer-op-policy to \"%s\"...",
11637 attr
->values
[0].string
.text
);
11638 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11639 printer
->op_policy_ptr
= p
;
11643 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11644 _("Unknown printer-op-policy \"%s\"."),
11645 attr
->values
[0].string
.text
);
11649 else if (!strcmp(attr
->name
, "printer-error-policy"))
11651 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11654 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11655 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
11656 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11657 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11658 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11660 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11661 _("Unknown printer-error-policy \"%s\"."),
11662 attr
->values
[0].string
.text
);
11666 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11667 "Setting printer-error-policy to \"%s\"...",
11668 attr
->values
[0].string
.text
);
11669 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11673 * Skip any other non-default attributes...
11676 namelen
= strlen(attr
->name
);
11677 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11678 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11682 * OK, anything else must be a user-defined default...
11685 strlcpy(name
, attr
->name
, sizeof(name
));
11686 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11688 switch (attr
->value_tag
)
11690 case IPP_TAG_DELETEATTR
:
11691 printer
->num_options
= cupsRemoveOption(name
,
11692 printer
->num_options
,
11693 &(printer
->options
));
11694 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11695 "Deleting %s", attr
->name
);
11698 case IPP_TAG_NAME
:
11699 case IPP_TAG_KEYWORD
:
11701 printer
->num_options
= cupsAddOption(name
,
11702 attr
->values
[0].string
.text
,
11703 printer
->num_options
,
11704 &(printer
->options
));
11705 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11706 "Setting %s to \"%s\"...", attr
->name
,
11707 attr
->values
[0].string
.text
);
11710 case IPP_TAG_BOOLEAN
:
11711 printer
->num_options
= cupsAddOption(name
,
11712 attr
->values
[0].boolean
?
11714 printer
->num_options
,
11715 &(printer
->options
));
11716 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11717 "Setting %s to %s...", attr
->name
,
11718 attr
->values
[0].boolean
? "true" : "false");
11721 case IPP_TAG_INTEGER
:
11722 case IPP_TAG_ENUM
:
11723 sprintf(value
, "%d", attr
->values
[0].integer
);
11724 printer
->num_options
= cupsAddOption(name
, value
,
11725 printer
->num_options
,
11726 &(printer
->options
));
11727 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11728 "Setting %s to %s...", attr
->name
, value
);
11731 case IPP_TAG_RANGE
:
11732 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11733 attr
->values
[0].range
.upper
);
11734 printer
->num_options
= cupsAddOption(name
, value
,
11735 printer
->num_options
,
11736 &(printer
->options
));
11737 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11738 "Setting %s to %s...", attr
->name
, value
);
11741 case IPP_TAG_RESOLUTION
:
11742 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11743 attr
->values
[0].resolution
.yres
,
11744 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11746 printer
->num_options
= cupsAddOption(name
, value
,
11747 printer
->num_options
,
11748 &(printer
->options
));
11749 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11750 "Setting %s to %s...", attr
->name
, value
);
11754 /* Do nothing for other values */
11762 * 'start_printer()' - Start a printer.
11766 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11767 ipp_attribute_t
*uri
) /* I - Printer URI */
11769 int i
; /* Temporary variable */
11770 http_status_t status
; /* Policy status */
11771 cups_ptype_t dtype
; /* Destination type (printer/class) */
11772 cupsd_printer_t
*printer
; /* Printer data */
11775 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11776 con
->http
.fd
, uri
->values
[0].string
.text
);
11779 * Is the destination valid?
11782 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11788 send_ipp_status(con
, IPP_NOT_FOUND
,
11789 _("The printer or class was not found."));
11797 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11799 send_http_error(con
, status
, printer
);
11804 * Start the printer...
11807 printer
->state_message
[0] = '\0';
11809 cupsdStartPrinter(printer
, 1);
11811 if (dtype
& CUPS_PRINTER_CLASS
)
11812 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11813 printer
->name
, get_username(con
));
11815 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11816 printer
->name
, get_username(con
));
11824 if ((i
= check_quotas(con
, printer
)) < 0)
11826 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
11831 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
11836 * Everything was ok, so return OK status...
11839 con
->response
->request
.status
.status_code
= IPP_OK
;
11844 * 'stop_printer()' - Stop a printer.
11848 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11849 ipp_attribute_t
*uri
) /* I - Printer URI */
11851 http_status_t status
; /* Policy status */
11852 cups_ptype_t dtype
; /* Destination type (printer/class) */
11853 cupsd_printer_t
*printer
; /* Printer data */
11854 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11857 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11858 con
->http
.fd
, uri
->values
[0].string
.text
);
11861 * Is the destination valid?
11864 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11870 send_ipp_status(con
, IPP_NOT_FOUND
,
11871 _("The printer or class was not found."));
11879 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11881 send_http_error(con
, status
, printer
);
11886 * Stop the printer...
11889 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11890 IPP_TAG_TEXT
)) == NULL
)
11891 strcpy(printer
->state_message
, "Paused");
11894 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11895 sizeof(printer
->state_message
));
11898 cupsdStopPrinter(printer
, 1);
11900 if (dtype
& CUPS_PRINTER_CLASS
)
11901 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11902 printer
->name
, get_username(con
));
11904 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11905 printer
->name
, get_username(con
));
11908 * Everything was ok, so return OK status...
11911 con
->response
->request
.status
.status_code
= IPP_OK
;
11916 * 'url_encode_attr()' - URL-encode a string attribute.
11920 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11921 char *buffer
,/* I - String buffer */
11922 int bufsize
)/* I - Size of buffer */
11924 int i
; /* Looping var */
11925 char *bufptr
, /* Pointer into buffer */
11926 *bufend
; /* End of buffer */
11929 strlcpy(buffer
, attr
->name
, bufsize
);
11930 bufptr
= buffer
+ strlen(buffer
);
11931 bufend
= buffer
+ bufsize
- 1;
11933 for (i
= 0; i
< attr
->num_values
; i
++)
11935 if (bufptr
>= bufend
)
11943 if (bufptr
>= bufend
)
11948 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11949 bufptr
, bufend
- bufptr
+ 1);
11951 if (bufptr
>= bufend
)
11962 * 'url_encode_string()' - URL-encode a string.
11965 static char * /* O - End of string */
11966 url_encode_string(const char *s
, /* I - String */
11967 char *buffer
, /* I - String buffer */
11968 int bufsize
) /* I - Size of buffer */
11970 char *bufptr
, /* Pointer into buffer */
11971 *bufend
; /* End of buffer */
11972 static const char *hex
= "0123456789ABCDEF";
11977 bufend
= buffer
+ bufsize
- 1;
11979 while (*s
&& bufptr
< bufend
)
11981 if (*s
== ' ' || *s
== '%' || *s
== '+')
11983 if (bufptr
>= (bufend
- 2))
11987 *bufptr
++ = hex
[(*s
>> 4) & 15];
11988 *bufptr
++ = hex
[*s
& 15];
11992 else if (*s
== '\'' || *s
== '\\')
11994 if (bufptr
>= (bufend
- 1))
12011 * 'user_allowed()' - See if a user is allowed to print to a queue.
12014 static int /* O - 0 if not allowed, 1 if allowed */
12015 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
12016 const char *username
) /* I - Username */
12018 struct passwd
*pw
; /* User password data */
12019 char baseuser
[256], /* Base username */
12020 *baseptr
, /* Pointer to "@" in base username */
12021 *name
; /* Current user name */
12024 if (cupsArrayCount(p
->users
) == 0)
12027 if (!strcmp(username
, "root"))
12030 if (strchr(username
, '@'))
12033 * Strip @REALM for username check...
12036 strlcpy(baseuser
, username
, sizeof(baseuser
));
12038 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
12041 username
= baseuser
;
12044 pw
= getpwnam(username
);
12047 for (name
= (char *)cupsArrayFirst(p
->users
);
12049 name
= (char *)cupsArrayNext(p
->users
))
12051 if (name
[0] == '@')
12054 * Check group membership...
12057 if (cupsdCheckGroup(username
, pw
, name
+ 1))
12060 else if (name
[0] == '#')
12066 if (cupsdCheckGroup(username
, pw
, name
))
12069 else if (!strcasecmp(username
, name
))
12073 return ((name
!= NULL
) != p
->deny_users
);
12078 * 'validate_job()' - Validate printer options and destination.
12082 validate_job(cupsd_client_t
*con
, /* I - Client connection */
12083 ipp_attribute_t
*uri
) /* I - Printer URI */
12085 http_status_t status
; /* Policy status */
12086 ipp_attribute_t
*attr
, /* Current attribute */
12087 *auth_info
; /* auth-info attribute */
12088 ipp_attribute_t
*format
; /* Document-format attribute */
12089 cups_ptype_t dtype
; /* Destination type (printer/class) */
12090 char super
[MIME_MAX_SUPER
],
12091 /* Supertype of file */
12092 type
[MIME_MAX_TYPE
];
12093 /* Subtype of file */
12094 cupsd_printer_t
*printer
; /* Printer */
12097 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
12098 con
->http
.fd
, uri
->values
[0].string
.text
);
12101 * OK, see if the client is sending the document compressed - CUPS
12102 * doesn't support compression yet...
12105 if ((attr
= ippFindAttribute(con
->request
, "compression",
12106 IPP_TAG_KEYWORD
)) != NULL
)
12108 if (strcmp(attr
->values
[0].string
.text
, "none")
12110 && strcmp(attr
->values
[0].string
.text
, "gzip")
12111 #endif /* HAVE_LIBZ */
12114 send_ipp_status(con
, IPP_ATTRIBUTES
,
12115 _("Unsupported compression \"%s\""),
12116 attr
->values
[0].string
.text
);
12117 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
12118 "compression", NULL
, attr
->values
[0].string
.text
);
12124 * Is it a format we support?
12127 if ((format
= ippFindAttribute(con
->request
, "document-format",
12128 IPP_TAG_MIMETYPE
)) != NULL
)
12130 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
12133 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
12134 format
->values
[0].string
.text
);
12138 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
12139 !mimeType(MimeDatabase
, super
, type
))
12141 cupsdLogMessage(CUPSD_LOG_INFO
,
12142 "Hint: Do you have the raw file printing rules enabled?");
12143 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
12144 _("Unsupported document-format \"%s\""),
12145 format
->values
[0].string
.text
);
12146 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
12147 "document-format", NULL
, format
->values
[0].string
.text
);
12153 * Is the destination valid?
12156 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
12162 send_ipp_status(con
, IPP_NOT_FOUND
,
12163 _("The printer or class was not found."));
12171 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
12173 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
12175 send_http_error(con
, status
, printer
);
12178 else if (printer
->num_auth_info_required
== 1 &&
12179 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
12182 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
12186 else if (auth_info
&& !con
->http
.tls
&&
12187 !httpAddrLocalhost(con
->http
.hostaddr
))
12190 * Require encryption of auth-info over non-local connections...
12193 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
12196 #endif /* HAVE_SSL */
12199 * Everything was ok, so return OK status...
12202 con
->response
->request
.status
.status_code
= IPP_OK
;
12207 * 'validate_name()' - Make sure the printer name only contains valid chars.
12210 static int /* O - 0 if name is no good, 1 if good */
12211 validate_name(const char *name
) /* I - Name to check */
12213 const char *ptr
; /* Pointer into name */
12217 * Scan the whole name...
12220 for (ptr
= name
; *ptr
; ptr
++)
12221 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
12225 * All the characters are good; validate the length, too...
12228 return ((ptr
- name
) < 128);
12233 * 'validate_user()' - Validate the user for the request.
12236 static int /* O - 1 if permitted, 0 otherwise */
12237 validate_user(cupsd_job_t
*job
, /* I - Job */
12238 cupsd_client_t
*con
, /* I - Client connection */
12239 const char *owner
, /* I - Owner of job/resource */
12240 char *username
, /* O - Authenticated username */
12241 int userlen
) /* I - Length of username */
12243 cupsd_printer_t
*printer
; /* Printer for job */
12246 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
12247 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
12249 job
->id
, con
? con
->http
.fd
: 0,
12250 owner
? owner
: "(null)", username
, userlen
);
12253 * Validate input...
12256 if (!con
|| !owner
|| !username
|| userlen
<= 0)
12260 * Get the best authenticated username that is available.
12263 strlcpy(username
, get_username(con
), userlen
);
12266 * Check the username against the owner...
12269 printer
= cupsdFindDest(job
->dest
);
12271 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
12272 con
, owner
) == HTTP_OK
);
12277 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".