2 * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * This file contains Kerberos support code, copyright 2006 by
12 * These coded instructions, statements, and computer programs are the
13 * property of Apple Inc. and are protected by Federal copyright
14 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 * which should have been included with this file. If this file is
16 * file is missing or damaged, see the license at "http://www.cups.org/".
20 * cupsdProcessIPPRequest() - Process an incoming IPP request.
21 * cupsdTimeoutJob() - Timeout a job waiting on job files.
22 * accept_jobs() - Accept print jobs to a printer.
23 * add_class() - Add a class to the system.
24 * add_file() - Add a file to a job.
25 * add_job() - Add a job to a print queue.
26 * add_job_state_reasons() - Add the "job-state-reasons" attribute based
27 * upon the job and printer state...
28 * add_job_subscriptions() - Add any subscriptions for a job.
29 * add_job_uuid() - Add job-uuid attribute to a job.
30 * add_printer() - Add a printer to the system.
31 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
32 * based upon the printer state...
33 * add_queued_job_count() - Add the "queued-job-count" attribute for the
34 * specified printer or class.
35 * apple_init_profile() - Initialize a color profile.
36 * apple_register_profiles() - Register color profiles for a printer.
37 * apple_unregister_profiles() - Remove color profiles for the specified
39 * apply_printer_defaults() - Apply printer default options to a job.
40 * authenticate_job() - Set job authentication info.
41 * cancel_all_jobs() - Cancel all or selected print jobs.
42 * cancel_job() - Cancel a print job.
43 * cancel_subscription() - Cancel a subscription.
44 * check_rss_recipient() - Check that we do not have a duplicate RSS
46 * check_quotas() - Check quotas for a printer and user.
47 * close_job() - Close a multi-file job.
48 * copy_attribute() - Copy a single attribute.
49 * copy_attrs() - Copy attributes from one request to another.
50 * copy_banner() - Copy a banner file to the requests directory
51 * for the specified job.
52 * copy_file() - Copy a PPD file or interface script...
53 * copy_model() - Copy a PPD model file, substituting default
55 * copy_job_attrs() - Copy job attributes.
56 * copy_printer_attrs() - Copy printer attributes.
57 * copy_subscription_attrs() - Copy subscription attributes.
58 * create_job() - Print a file to a printer or class.
59 * create_requested_array() - Create an array for the requested-attributes.
60 * create_subscription() - Create a notification subscription.
61 * delete_printer() - Remove a printer or class from the system.
62 * get_default() - Get the default destination.
63 * get_devices() - Get the list of available devices on the
65 * get_document() - Get a copy of a job file.
66 * get_job_attrs() - Get job attributes.
67 * get_jobs() - Get a list of jobs for the specified printer.
68 * get_notifications() - Get events for a subscription.
69 * get_ppd() - Get a named PPD from the local system.
70 * get_ppds() - Get the list of PPD files on the local
72 * get_printer_attrs() - Get printer attributes.
73 * get_printer_supported() - Get printer supported values.
74 * get_printers() - Get a list of printers or classes.
75 * get_subscription_attrs() - Get subscription attributes.
76 * get_subscriptions() - Get subscriptions.
77 * get_username() - Get the username associated with a request.
78 * hold_job() - Hold a print job.
79 * hold_new_jobs() - Hold pending/new jobs on a printer or class.
80 * move_job() - Move a job to a new destination.
81 * ppd_parse_line() - Parse a PPD default line.
82 * print_job() - Print a file to a printer or class.
83 * read_job_ticket() - Read a job ticket embedded in a print file.
84 * reject_jobs() - Reject print jobs to a printer.
85 * release_held_new_jobs() - Release pending/new jobs on a printer or
87 * release_job() - Release a held print job.
88 * renew_subscription() - Renew an existing subscription...
89 * restart_job() - Restart an old print job.
90 * save_auth_info() - Save authentication information for a job.
91 * save_krb5_creds() - Save Kerberos credentials for the job.
92 * send_document() - Send a file to a printer or class.
93 * send_http_error() - Send a HTTP error back to the IPP client.
94 * send_ipp_status() - Send a status back to the IPP client.
95 * set_default() - Set the default destination...
96 * set_job_attrs() - Set job attributes.
97 * set_printer_attrs() - Set printer attributes.
98 * set_printer_defaults() - Set printer default options from a request.
99 * start_printer() - Start a printer.
100 * stop_printer() - Stop a printer.
101 * url_encode_attr() - URL-encode a string attribute.
102 * url_encode_string() - URL-encode a string.
103 * user_allowed() - See if a user is allowed to print to a queue.
104 * validate_job() - Validate printer options and destination.
105 * validate_name() - Make sure the printer name only contains
107 * validate_user() - Validate the user for the request.
111 * Include necessary headers...
115 #include <cups/ppd-private.h>
118 # include <ApplicationServices/ApplicationServices.h>
119 # ifdef HAVE_COLORSYNCREGISTERDEVICE
120 extern CFUUIDRef
ColorSyncCreateUUIDFromUInt32(unsigned id
);
121 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
122 # include <CoreFoundation/CoreFoundation.h>
123 # ifdef HAVE_MEMBERSHIP_H
124 # include <membership.h>
125 # endif /* HAVE_MEMBERSHIP_H */
126 # ifdef HAVE_MEMBERSHIPPRIV_H
127 # include <membershipPriv.h>
129 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
130 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
131 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
132 # endif /* HAVE_MEMBERSHIPPRIV_H */
133 #endif /* __APPLE__ */
140 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
141 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
142 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
143 mime_type_t
*filetype
, int compression
);
144 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
145 mime_type_t
*filetype
);
146 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
147 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
148 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
149 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
150 static void add_printer_state_reasons(cupsd_client_t
*con
,
152 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
154 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
155 # ifdef HAVE_COLORSYNCREGISTERDEVICE
156 CFMutableDictionaryRef profile
,
158 CMDeviceProfileInfo
*profile
,
159 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
160 unsigned id
, const char *name
,
161 const char *text
, const char *iccfile
);
162 static void apple_register_profiles(cupsd_printer_t
*p
);
163 static void apple_unregister_profiles(cupsd_printer_t
*p
);
164 #endif /* __APPLE__ */
165 static void apply_printer_defaults(cupsd_printer_t
*printer
,
167 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
168 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
169 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
170 static void cancel_subscription(cupsd_client_t
*con
, int id
);
171 static int check_rss_recipient(const char *recipient
);
172 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
173 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
175 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
176 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
177 ipp_tag_t group
, int quickcopy
,
178 cups_array_t
*exclude
);
179 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
181 static int copy_file(const char *from
, const char *to
);
182 static int copy_model(cupsd_client_t
*con
, const char *from
,
184 static void copy_job_attrs(cupsd_client_t
*con
,
186 cups_array_t
*ra
, cups_array_t
*exclude
);
187 static void copy_printer_attrs(cupsd_client_t
*con
,
188 cupsd_printer_t
*printer
,
190 static void copy_subscription_attrs(cupsd_client_t
*con
,
191 cupsd_subscription_t
*sub
,
193 cups_array_t
*exclude
);
194 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
195 static cups_array_t
*create_requested_array(ipp_t
*request
);
196 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
197 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static void get_default(cupsd_client_t
*con
);
199 static void get_devices(cupsd_client_t
*con
);
200 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
201 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
202 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
203 static void get_notifications(cupsd_client_t
*con
);
204 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
205 static void get_ppds(cupsd_client_t
*con
);
206 static void get_printers(cupsd_client_t
*con
, int type
);
207 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
208 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
209 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
210 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
211 static const char *get_username(cupsd_client_t
*con
);
212 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
213 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
214 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
215 static int ppd_parse_line(const char *line
, char *option
, int olen
,
216 char *choice
, int clen
);
217 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
218 static void read_job_ticket(cupsd_client_t
*con
);
219 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
220 static void release_held_new_jobs(cupsd_client_t
*con
,
221 ipp_attribute_t
*uri
);
222 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
223 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
224 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
225 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
226 ipp_attribute_t
*auth_info
);
227 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
228 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
229 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
230 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
231 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
232 cupsd_printer_t
*printer
);
233 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
234 const char *message
, ...)
236 __attribute__ ((__format__ (__printf__
, 3, 4)))
237 # endif /* __GNUC__ */
239 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
240 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
241 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
242 static void set_printer_defaults(cupsd_client_t
*con
,
243 cupsd_printer_t
*printer
);
244 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
245 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
246 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
248 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
249 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
250 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
251 static int validate_name(const char *name
);
252 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
253 const char *owner
, char *username
,
258 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
261 int /* O - 1 on success, 0 on failure */
262 cupsdProcessIPPRequest(
263 cupsd_client_t
*con
) /* I - Client connection */
265 ipp_tag_t group
; /* Current group tag */
266 ipp_attribute_t
*attr
; /* Current attribute */
267 ipp_attribute_t
*charset
; /* Character set attribute */
268 ipp_attribute_t
*language
; /* Language attribute */
269 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
270 ipp_attribute_t
*username
; /* requesting-user-name attr */
271 int sub_id
; /* Subscription ID */
274 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
275 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
276 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
279 * First build an empty response message for this request...
282 con
->response
= ippNew();
284 con
->response
->request
.status
.version
[0] =
285 con
->request
->request
.op
.version
[0];
286 con
->response
->request
.status
.version
[1] =
287 con
->request
->request
.op
.version
[1];
288 con
->response
->request
.status
.request_id
=
289 con
->request
->request
.op
.request_id
;
292 * Then validate the request header and required attributes...
295 if (con
->request
->request
.any
.version
[0] != 1 &&
296 con
->request
->request
.any
.version
[0] != 2)
299 * Return an error, since we only support IPP 1.x and 2.x.
302 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
303 "%04X %s Bad request version number %d.%d",
304 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
305 con
->request
->request
.any
.version
[0],
306 con
->request
->request
.any
.version
[1]);
308 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
309 _("Bad request version number %d.%d"),
310 con
->request
->request
.any
.version
[0],
311 con
->request
->request
.any
.version
[1]);
313 else if (con
->request
->request
.any
.request_id
< 1)
316 * Return an error, since request IDs must be between 1 and 2^31-1
319 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
320 "%04X %s Bad request ID %d",
321 IPP_BAD_REQUEST
, con
->http
.hostname
,
322 con
->request
->request
.any
.request_id
);
324 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d"),
325 con
->request
->request
.any
.request_id
);
327 else if (!con
->request
->attrs
)
329 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
330 "%04X %s No attributes in request",
331 IPP_BAD_REQUEST
, con
->http
.hostname
);
333 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request"));
338 * Make sure that the attributes are provided in the correct order and
339 * don't repeat groups...
342 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
345 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
348 * Out of order; return an error...
351 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
352 "%04X %s Attribute groups are out of order",
353 IPP_BAD_REQUEST
, con
->http
.hostname
);
355 send_ipp_status(con
, IPP_BAD_REQUEST
,
356 _("Attribute groups are out of order (%x < %x)"),
357 attr
->group_tag
, group
);
361 group
= attr
->group_tag
;
366 * Then make sure that the first three attributes are:
369 * attributes-natural-language
370 * printer-uri/job-uri
373 attr
= con
->request
->attrs
;
374 if (attr
&& attr
->name
&&
375 !strcmp(attr
->name
, "attributes-charset") &&
376 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
384 if (attr
&& attr
->name
&&
385 !strcmp(attr
->name
, "attributes-natural-language") &&
386 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
391 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
392 IPP_TAG_URI
)) != NULL
)
394 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
395 IPP_TAG_URI
)) != NULL
)
397 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
398 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
403 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
404 "attributes-charset", NULL
,
405 charset
->values
[0].string
.text
);
407 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
408 "attributes-charset", NULL
, "utf-8");
411 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
412 "attributes-natural-language", NULL
,
413 language
->values
[0].string
.text
);
415 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
416 "attributes-natural-language", NULL
, DefaultLanguage
);
419 strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
420 strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
423 * Bad character set...
426 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
427 charset
->values
[0].string
.text
);
428 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
429 "%04X %s Unsupported attributes-charset value \"%s\"",
430 IPP_CHARSET
, con
->http
.hostname
,
431 charset
->values
[0].string
.text
);
432 send_ipp_status(con
, IPP_BAD_REQUEST
,
433 _("Unsupported character set \"%s\""),
434 charset
->values
[0].string
.text
);
436 else if (!charset
|| !language
||
438 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
439 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
440 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
441 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
442 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
445 * Return an error, since attributes-charset,
446 * attributes-natural-language, and printer-uri/job-uri are required
447 * for all operations.
452 cupsdLogMessage(CUPSD_LOG_ERROR
,
453 "Missing attributes-charset attribute");
455 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
456 "%04X %s Missing attributes-charset attribute",
457 IPP_BAD_REQUEST
, con
->http
.hostname
);
462 cupsdLogMessage(CUPSD_LOG_ERROR
,
463 "Missing attributes-natural-language attribute");
465 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
466 "%04X %s Missing attributes-natural-language attribute",
467 IPP_BAD_REQUEST
, con
->http
.hostname
);
472 cupsdLogMessage(CUPSD_LOG_ERROR
,
473 "Missing printer-uri, job-uri, or ppd-name "
476 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
477 "%04X %s Missing printer-uri, job-uri, or ppd-name "
478 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
481 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
483 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
484 cupsdLogMessage(CUPSD_LOG_DEBUG
,
485 "attr \"%s\": group_tag = %x, value_tag = %x",
486 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
489 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
491 send_ipp_status(con
, IPP_BAD_REQUEST
,
492 _("Missing required attributes"));
497 * OK, all the checks pass so far; make sure requesting-user-name is
498 * not "root" from a remote host...
501 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
502 IPP_TAG_NAME
)) != NULL
)
505 * Check for root user...
508 if (!strcmp(username
->values
[0].string
.text
, "root") &&
509 strcasecmp(con
->http
.hostname
, "localhost") &&
510 strcmp(con
->username
, "root"))
513 * Remote unauthenticated user masquerading as local root...
516 _cupsStrFree(username
->values
[0].string
.text
);
517 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
521 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
522 IPP_TAG_INTEGER
)) != NULL
)
523 sub_id
= attr
->values
[0].integer
;
528 * Then try processing the operation...
532 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
533 ippOpString(con
->request
->request
.op
.operation_id
),
534 uri
->values
[0].string
.text
);
536 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
537 ippOpString(con
->request
->request
.op
.operation_id
));
539 switch (con
->request
->request
.op
.operation_id
)
545 case IPP_VALIDATE_JOB
:
546 validate_job(con
, uri
);
549 case IPP_CREATE_JOB
:
550 create_job(con
, uri
);
553 case IPP_SEND_DOCUMENT
:
554 send_document(con
, uri
);
557 case IPP_CANCEL_JOB
:
558 cancel_job(con
, uri
);
561 case IPP_GET_JOB_ATTRIBUTES
:
562 get_job_attrs(con
, uri
);
569 case IPP_GET_PRINTER_ATTRIBUTES
:
570 get_printer_attrs(con
, uri
);
573 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
574 get_printer_supported(con
, uri
);
581 case IPP_RELEASE_JOB
:
582 release_job(con
, uri
);
585 case IPP_RESTART_JOB
:
586 restart_job(con
, uri
);
589 case IPP_PAUSE_PRINTER
:
590 stop_printer(con
, uri
);
593 case IPP_RESUME_PRINTER
:
594 start_printer(con
, uri
);
597 case IPP_PURGE_JOBS
:
598 case IPP_CANCEL_JOBS
:
599 case IPP_CANCEL_MY_JOBS
:
600 cancel_all_jobs(con
, uri
);
603 case IPP_SET_JOB_ATTRIBUTES
:
604 set_job_attrs(con
, uri
);
607 case IPP_SET_PRINTER_ATTRIBUTES
:
608 set_printer_attrs(con
, uri
);
611 case IPP_HOLD_NEW_JOBS
:
612 hold_new_jobs(con
, uri
);
615 case IPP_RELEASE_HELD_NEW_JOBS
:
616 release_held_new_jobs(con
, uri
);
623 case CUPS_GET_DEFAULT
:
627 case CUPS_GET_PRINTERS
:
628 get_printers(con
, 0);
631 case CUPS_GET_CLASSES
:
632 get_printers(con
, CUPS_PRINTER_CLASS
);
635 case CUPS_ADD_PRINTER
:
636 add_printer(con
, uri
);
639 case CUPS_DELETE_PRINTER
:
640 delete_printer(con
, uri
);
643 case CUPS_ADD_CLASS
:
647 case CUPS_DELETE_CLASS
:
648 delete_printer(con
, uri
);
651 case CUPS_ACCEPT_JOBS
:
652 case IPP_ENABLE_PRINTER
:
653 accept_jobs(con
, uri
);
656 case CUPS_REJECT_JOBS
:
657 case IPP_DISABLE_PRINTER
:
658 reject_jobs(con
, uri
);
661 case CUPS_SET_DEFAULT
:
662 set_default(con
, uri
);
665 case CUPS_GET_DEVICES
:
669 case CUPS_GET_DOCUMENT
:
670 get_document(con
, uri
);
685 case CUPS_AUTHENTICATE_JOB
:
686 authenticate_job(con
, uri
);
689 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
690 case IPP_CREATE_JOB_SUBSCRIPTION
:
691 create_subscription(con
, uri
);
694 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
695 get_subscription_attrs(con
, sub_id
);
698 case IPP_GET_SUBSCRIPTIONS
:
699 get_subscriptions(con
, uri
);
702 case IPP_RENEW_SUBSCRIPTION
:
703 renew_subscription(con
, sub_id
);
706 case IPP_CANCEL_SUBSCRIPTION
:
707 cancel_subscription(con
, sub_id
);
710 case IPP_GET_NOTIFICATIONS
:
711 get_notifications(con
);
715 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
716 "%04X %s Operation %04X (%s) not supported",
717 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
718 con
->request
->request
.op
.operation_id
,
719 ippOpString(con
->request
->request
.op
.operation_id
));
721 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
722 _("%s not supported"),
724 con
->request
->request
.op
.operation_id
));
734 * Sending data from the scheduler...
737 cupsdLogMessage(con
->response
->request
.status
.status_code
738 >= IPP_BAD_REQUEST
&&
739 con
->response
->request
.status
.status_code
740 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
741 "Returning IPP %s for %s (%s) from %s",
742 ippErrorString(con
->response
->request
.status
.status_code
),
743 ippOpString(con
->request
->request
.op
.operation_id
),
744 uri
? uri
->values
[0].string
.text
: "no URI",
747 if (LogLevel
== CUPSD_LOG_DEBUG2
)
748 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
749 "cupsdProcessIPPRequest: ippLength(response)=%ld",
750 (long)ippLength(con
->response
));
752 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
754 #ifdef CUPSD_USE_CHUNKING
756 * Because older versions of CUPS (1.1.17 and older) and some IPP
757 * clients do not implement chunking properly, we cannot use
758 * chunking by default. This may become the default in future
759 * CUPS releases, or we might add a configuration directive for
763 if (con
->http
.version
== HTTP_1_1
)
765 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
768 if (cupsdFlushHeader(con
) < 0)
771 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
774 #endif /* CUPSD_USE_CHUNKING */
776 size_t length
; /* Length of response */
779 length
= ippLength(con
->response
);
781 if (con
->file
>= 0 && !con
->pipe_pid
)
783 struct stat fileinfo
; /* File information */
786 if (!fstat(con
->file
, &fileinfo
))
787 length
+= fileinfo
.st_size
;
790 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
791 CUPS_LLCAST length
) < 0)
794 if (cupsdFlushHeader(con
) < 0)
797 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
798 con
->http
.data_remaining
= length
;
800 if (con
->http
.data_remaining
<= INT_MAX
)
801 con
->http
._data_remaining
= con
->http
.data_remaining
;
803 con
->http
._data_remaining
= INT_MAX
;
806 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
807 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
810 * Tell the caller the response header was sent successfully...
818 * Tell the caller the response header could not be sent...
827 * Sending data from a subprocess like cups-deviced; tell the caller
828 * everything is A-OK so far...
837 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
840 int /* O - 0 on success, -1 on error */
841 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
843 cupsd_printer_t
*printer
; /* Destination printer or class */
844 ipp_attribute_t
*attr
; /* job-sheets attribute */
845 int kbytes
; /* Kilobytes in banner */
848 job
->pending_timeout
= 0;
851 * See if we need to add the ending sheet...
854 if (!cupsdLoadJob(job
))
857 printer
= cupsdFindDest(job
->dest
);
858 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
861 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
862 attr
&& attr
->num_values
> 1)
868 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
869 attr
->values
[1].string
.text
);
871 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
874 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
882 * 'accept_jobs()' - Accept print jobs to a printer.
886 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
887 ipp_attribute_t
*uri
) /* I - Printer or class URI */
889 http_status_t status
; /* Policy status */
890 cups_ptype_t dtype
; /* Destination type (printer/class) */
891 cupsd_printer_t
*printer
; /* Printer data */
894 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
895 con
->http
.fd
, uri
->values
[0].string
.text
);
898 * Is the destination valid?
901 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
907 send_ipp_status(con
, IPP_NOT_FOUND
,
908 _("The printer or class was not found."));
916 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
918 send_http_error(con
, status
, printer
);
923 * Accept jobs sent to the printer...
926 printer
->accepting
= 1;
927 printer
->state_message
[0] = '\0';
929 cupsdAddPrinterHistory(printer
);
931 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
932 "Now accepting jobs.");
934 if (dtype
& CUPS_PRINTER_CLASS
)
936 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
938 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
939 printer
->name
, get_username(con
));
943 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
945 cupsdLogMessage(CUPSD_LOG_INFO
,
946 "Printer \"%s\" now accepting jobs (\"%s\").",
947 printer
->name
, get_username(con
));
951 * Everything was ok, so return OK status...
954 con
->response
->request
.status
.status_code
= IPP_OK
;
959 * 'add_class()' - Add a class to the system.
963 add_class(cupsd_client_t
*con
, /* I - Client connection */
964 ipp_attribute_t
*uri
) /* I - URI of class */
966 http_status_t status
; /* Policy status */
967 int i
; /* Looping var */
968 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
969 username
[HTTP_MAX_URI
], /* Username portion of URI */
970 host
[HTTP_MAX_URI
], /* Host portion of URI */
971 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
972 int port
; /* Port portion of URI */
973 cupsd_printer_t
*pclass
, /* Class */
974 *member
; /* Member printer/class */
975 cups_ptype_t dtype
; /* Destination type */
976 ipp_attribute_t
*attr
; /* Printer attribute */
977 int modify
; /* Non-zero if we just modified */
978 char newname
[IPP_MAX_NAME
]; /* New class name */
979 int need_restart_job
; /* Need to restart job? */
982 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
983 con
->http
.fd
, uri
->values
[0].string
.text
);
986 * Do we have a valid URI?
989 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
990 sizeof(scheme
), username
, sizeof(username
), host
,
991 sizeof(host
), &port
, resource
, sizeof(resource
));
994 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
997 * No, return an error...
1000 send_ipp_status(con
, IPP_BAD_REQUEST
,
1001 _("The printer-uri must be of the form "
1002 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
1007 * Do we have a valid printer name?
1010 if (!validate_name(resource
+ 9))
1013 * No, return an error...
1016 send_ipp_status(con
, IPP_BAD_REQUEST
,
1017 _("The printer-uri \"%s\" contains invalid characters."),
1018 uri
->values
[0].string
.text
);
1023 * See if the class already exists; if not, create a new class...
1026 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1029 * Class doesn't exist; see if we have a printer of the same name...
1032 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
1033 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
1036 * Yes, return an error...
1039 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1040 _("A printer named \"%s\" already exists"),
1046 * No, check the default policy and then add the class...
1049 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1051 send_http_error(con
, status
, NULL
);
1055 pclass
= cupsdAddClass(resource
+ 9);
1058 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1061 * Check the default policy, then rename the implicit class to "AnyClass"
1065 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1067 send_http_error(con
, status
, NULL
);
1071 if (ImplicitAnyClasses
)
1073 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1074 cupsdRenamePrinter(pclass
, newname
);
1077 cupsdDeletePrinter(pclass
, 1);
1080 * Add the class as a new local class...
1083 pclass
= cupsdAddClass(resource
+ 9);
1086 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1089 * Check the default policy, then rename the remote class to "Class"...
1092 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1094 send_http_error(con
, status
, NULL
);
1098 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1099 cupsdRenamePrinter(pclass
, newname
);
1102 * Add the class as a new local class...
1105 pclass
= cupsdAddClass(resource
+ 9);
1108 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1111 send_http_error(con
, status
, pclass
);
1118 * Look for attributes and copy them over as needed...
1121 need_restart_job
= 0;
1123 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1124 IPP_TAG_TEXT
)) != NULL
)
1125 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1127 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1128 IPP_TAG_TEXT
)) != NULL
)
1129 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1131 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1132 IPP_TAG_BOOLEAN
)) != NULL
&&
1133 attr
->values
[0].boolean
!= pclass
->accepting
)
1135 cupsdLogMessage(CUPSD_LOG_INFO
,
1136 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1137 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1139 pclass
->accepting
= attr
->values
[0].boolean
;
1140 cupsdAddPrinterHistory(pclass
);
1142 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1143 pclass
->accepting
? "Now" : "No longer");
1146 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1147 IPP_TAG_BOOLEAN
)) != NULL
)
1149 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1150 cupsdDeregisterPrinter(pclass
, 1);
1152 cupsdLogMessage(CUPSD_LOG_INFO
,
1153 "Setting %s printer-is-shared to %d (was %d.)",
1154 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1156 pclass
->shared
= attr
->values
[0].boolean
;
1159 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1160 IPP_TAG_ENUM
)) != NULL
)
1162 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1163 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1165 send_ipp_status(con
, IPP_BAD_REQUEST
,
1166 _("Attempt to set %s printer-state to bad value %d"),
1167 pclass
->name
, attr
->values
[0].integer
);
1171 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1172 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1174 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1175 cupsdStopPrinter(pclass
, 0);
1178 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1179 need_restart_job
= 1;
1182 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1183 IPP_TAG_TEXT
)) != NULL
)
1185 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1186 sizeof(pclass
->state_message
));
1187 cupsdAddPrinterHistory(pclass
);
1189 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1190 pclass
->state_message
);
1192 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1193 IPP_TAG_URI
)) != NULL
)
1196 * Clear the printer array as needed...
1199 need_restart_job
= 1;
1201 if (pclass
->num_printers
> 0)
1203 free(pclass
->printers
);
1204 pclass
->num_printers
= 0;
1208 * Add each printer or class that is listed...
1211 for (i
= 0; i
< attr
->num_values
; i
++)
1214 * Search for the printer or class URI...
1217 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1223 send_ipp_status(con
, IPP_NOT_FOUND
,
1224 _("The printer or class was not found."));
1227 else if (dtype
& CUPS_PRINTER_CLASS
)
1229 send_ipp_status(con
, IPP_BAD_REQUEST
,
1230 _("Nested classes are not allowed"));
1235 * Add it to the class...
1238 cupsdAddPrinterToClass(pclass
, member
);
1242 set_printer_defaults(con
, pclass
);
1244 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1245 IPP_TAG_KEYWORD
)) != NULL
)
1246 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1249 * Update the printer class attributes and return...
1252 cupsdSetPrinterAttrs(pclass
);
1253 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1255 if (need_restart_job
&& pclass
->job
)
1258 * Reset the current job to a "pending" status...
1261 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1262 "Job restarted because the class was modified.");
1265 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1269 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1270 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1271 pclass
->name
, get_username(con
));
1273 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1274 pclass
->name
, get_username(con
));
1278 cupsdAddPrinterHistory(pclass
);
1280 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1281 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1282 pclass
->name
, get_username(con
));
1284 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1285 pclass
->name
, get_username(con
));
1288 con
->response
->request
.status
.status_code
= IPP_OK
;
1293 * 'add_file()' - Add a file to a job.
1296 static int /* O - 0 on success, -1 on error */
1297 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1298 cupsd_job_t
*job
, /* I - Job to add to */
1299 mime_type_t
*filetype
, /* I - Type of file */
1300 int compression
) /* I - Compression */
1302 mime_type_t
**filetypes
; /* New filetypes array... */
1303 int *compressions
; /* New compressions array... */
1306 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1307 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1308 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1309 filetype
->super
, filetype
->type
, compression
);
1312 * Add the file to the job...
1315 if (job
->num_files
== 0)
1317 compressions
= (int *)malloc(sizeof(int));
1318 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1322 compressions
= (int *)realloc(job
->compressions
,
1323 (job
->num_files
+ 1) * sizeof(int));
1324 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1325 (job
->num_files
+ 1) *
1326 sizeof(mime_type_t
*));
1329 if (!compressions
|| !filetypes
)
1331 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1332 "Job aborted because the scheduler ran out of memory.");
1335 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1336 _("Unable to allocate memory for file types"));
1341 job
->compressions
= compressions
;
1342 job
->compressions
[job
->num_files
] = compression
;
1343 job
->filetypes
= filetypes
;
1344 job
->filetypes
[job
->num_files
] = filetype
;
1349 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1356 * 'add_job()' - Add a job to a print queue.
1359 static cupsd_job_t
* /* O - Job object */
1360 add_job(cupsd_client_t
*con
, /* I - Client connection */
1361 cupsd_printer_t
*printer
, /* I - Destination printer */
1362 mime_type_t
*filetype
) /* I - First print file type, if any */
1364 http_status_t status
; /* Policy status */
1365 ipp_attribute_t
*attr
, /* Current attribute */
1366 *auth_info
; /* auth-info attribute */
1367 const char *val
; /* Default option value */
1368 int priority
; /* Job priority */
1369 cupsd_job_t
*job
; /* Current job */
1370 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1371 int kbytes
; /* Size of print file */
1372 int i
; /* Looping var */
1373 int lowerpagerange
; /* Page range bound */
1374 int exact
; /* Did we have an exact match? */
1375 ipp_attribute_t
*media_col
, /* media-col attribute */
1376 *media_margin
; /* media-*-margin attribute */
1377 ipp_t
*unsup_col
; /* media-col in unsupported response */
1380 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1381 con
, con
->http
.fd
, printer
, printer
->name
,
1382 filetype
, filetype
? filetype
->super
: "none",
1383 filetype
? filetype
->type
: "none");
1386 * Check remote printing to non-shared printer...
1389 if (!printer
->shared
&&
1390 strcasecmp(con
->http
.hostname
, "localhost") &&
1391 strcasecmp(con
->http
.hostname
, ServerName
))
1393 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1394 _("The printer or class is not shared"));
1402 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1404 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1406 send_http_error(con
, status
, printer
);
1409 else if (printer
->num_auth_info_required
== 1 &&
1410 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1413 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1417 else if (auth_info
&& !con
->http
.tls
&&
1418 !httpAddrLocalhost(con
->http
.hostaddr
))
1421 * Require encryption of auth-info over non-local connections...
1424 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1427 #endif /* HAVE_SSL */
1430 * See if the printer is accepting jobs...
1433 if (!printer
->accepting
)
1435 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1436 _("Destination \"%s\" is not accepting jobs."),
1442 * Validate job template attributes; for now just document-format,
1443 * copies, number-up, and page-ranges...
1446 if (filetype
&& printer
->filetypes
&&
1447 !cupsArrayFind(printer
->filetypes
, filetype
))
1449 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1450 /* MIME media type string */
1453 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1456 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1457 _("Unsupported format \'%s\'"), mimetype
);
1459 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1460 "document-format", NULL
, mimetype
);
1465 if ((attr
= ippFindAttribute(con
->request
, "copies",
1466 IPP_TAG_INTEGER
)) != NULL
)
1468 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1470 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1471 attr
->values
[0].integer
);
1472 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1473 "copies", attr
->values
[0].integer
);
1478 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1479 IPP_TAG_ZERO
)) != NULL
)
1481 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1482 attr
->value_tag
!= IPP_TAG_NAME
)
1484 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type"));
1488 if (attr
->num_values
> 2)
1490 send_ipp_status(con
, IPP_BAD_REQUEST
,
1491 _("Too many job-sheets values (%d > 2)"),
1496 for (i
= 0; i
< attr
->num_values
; i
++)
1497 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1498 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1500 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\""),
1501 attr
->values
[i
].string
.text
);
1506 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1507 IPP_TAG_INTEGER
)) != NULL
)
1509 if (attr
->values
[0].integer
!= 1 &&
1510 attr
->values
[0].integer
!= 2 &&
1511 attr
->values
[0].integer
!= 4 &&
1512 attr
->values
[0].integer
!= 6 &&
1513 attr
->values
[0].integer
!= 9 &&
1514 attr
->values
[0].integer
!= 16)
1516 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1517 attr
->values
[0].integer
);
1518 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1519 "number-up", attr
->values
[0].integer
);
1524 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1525 IPP_TAG_RANGE
)) != NULL
)
1527 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1529 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1530 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1532 send_ipp_status(con
, IPP_BAD_REQUEST
,
1533 _("Bad page-ranges values %d-%d."),
1534 attr
->values
[i
].range
.lower
,
1535 attr
->values
[i
].range
.upper
);
1539 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1544 * Do media selection as needed...
1547 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1548 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1549 _pwgGetPageSize(printer
->pwg
, con
->request
, NULL
, &exact
))
1552 (media_col
= ippFindAttribute(con
->request
, "media-col",
1553 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1555 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1557 unsup_col
= ippNew();
1558 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1559 "media-bottom-margin",
1560 IPP_TAG_INTEGER
)) != NULL
)
1561 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1562 "media-bottom-margin", media_margin
->values
[0].integer
);
1564 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1565 "media-left-margin",
1566 IPP_TAG_INTEGER
)) != NULL
)
1567 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1568 "media-left-margin", media_margin
->values
[0].integer
);
1570 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1571 "media-right-margin",
1572 IPP_TAG_INTEGER
)) != NULL
)
1573 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1574 "media-right-margin", media_margin
->values
[0].integer
);
1576 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1578 IPP_TAG_INTEGER
)) != NULL
)
1579 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1580 "media-top-margin", media_margin
->values
[0].integer
);
1582 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1584 ippDelete(unsup_col
);
1589 * Make sure we aren't over our limit...
1592 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1595 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1597 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1598 _("Too many active jobs."));
1602 if ((i
= check_quotas(con
, printer
)) < 0)
1604 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1609 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1614 * Create the job and set things up...
1617 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1618 IPP_TAG_INTEGER
)) != NULL
)
1619 priority
= attr
->values
[0].integer
;
1622 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1623 printer
->options
)) != NULL
)
1624 priority
= atoi(val
);
1628 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1632 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1633 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1636 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1638 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1639 _("Unable to add job for destination \"%s\""),
1644 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1645 CUPS_PRINTER_REMOTE
);
1646 job
->attrs
= con
->request
;
1648 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1650 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1652 add_job_uuid(con
, job
);
1653 apply_printer_defaults(printer
, job
);
1655 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1657 if (con
->username
[0])
1659 cupsdSetString(&job
->username
, con
->username
);
1662 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1666 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1667 "add_job: requesting-user-name=\"%s\"",
1668 attr
->values
[0].string
.text
);
1670 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1673 cupsdSetString(&job
->username
, "anonymous");
1676 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1677 "job-originating-user-name", NULL
, job
->username
);
1680 attr
->group_tag
= IPP_TAG_JOB
;
1681 _cupsStrFree(attr
->name
);
1682 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1685 if (con
->username
[0] || auth_info
)
1687 save_auth_info(con
, job
, auth_info
);
1690 * Remove the auth-info attribute from the attribute data...
1694 ippDeleteAttribute(job
->attrs
, auth_info
);
1697 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1698 IPP_TAG_ZERO
)) != NULL
)
1701 * Request contains a job-originating-host-name attribute; validate it...
1704 if (attr
->value_tag
!= IPP_TAG_NAME
||
1705 attr
->num_values
!= 1 ||
1706 strcmp(con
->http
.hostname
, "localhost"))
1709 * Can't override the value if we aren't connected via localhost.
1710 * Also, we can only have 1 value and it must be a name value.
1713 switch (attr
->value_tag
)
1715 case IPP_TAG_STRING
:
1716 case IPP_TAG_TEXTLANG
:
1717 case IPP_TAG_NAMELANG
:
1720 case IPP_TAG_KEYWORD
:
1722 case IPP_TAG_URISCHEME
:
1723 case IPP_TAG_CHARSET
:
1724 case IPP_TAG_LANGUAGE
:
1725 case IPP_TAG_MIMETYPE
:
1727 * Free old strings...
1730 for (i
= 0; i
< attr
->num_values
; i
++)
1732 _cupsStrFree(attr
->values
[i
].string
.text
);
1733 attr
->values
[i
].string
.text
= NULL
;
1734 if (attr
->values
[i
].string
.charset
)
1736 _cupsStrFree(attr
->values
[i
].string
.charset
);
1737 attr
->values
[i
].string
.charset
= NULL
;
1746 * Use the default connection hostname instead...
1749 attr
->value_tag
= IPP_TAG_NAME
;
1750 attr
->num_values
= 1;
1751 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1754 attr
->group_tag
= IPP_TAG_JOB
;
1759 * No job-originating-host-name attribute, so use the hostname from
1763 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1764 "job-originating-host-name", NULL
, con
->http
.hostname
);
1767 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1769 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1770 "time-at-processing", 0);
1771 attr
->value_tag
= IPP_TAG_NOVALUE
;
1772 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1773 "time-at-completed", 0);
1774 attr
->value_tag
= IPP_TAG_NOVALUE
;
1777 * Add remaining job attributes...
1780 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1781 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1782 "job-state", IPP_JOB_STOPPED
);
1783 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1784 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1785 "job-media-sheets-completed", 0);
1786 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1789 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1790 IPP_TAG_INTEGER
)) != NULL
)
1791 attr
->values
[0].integer
= 0;
1793 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1795 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1796 IPP_TAG_KEYWORD
)) == NULL
)
1797 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1800 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1801 printer
->options
)) == NULL
)
1804 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1805 "job-hold-until", NULL
, val
);
1807 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1810 * Hold job until specified time...
1813 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1815 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1816 job
->state_value
= IPP_JOB_HELD
;
1818 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1820 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1821 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1822 job
->state_value
= IPP_JOB_HELD
;
1826 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1827 job
->state_value
= IPP_JOB_PENDING
;
1830 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1834 * Add job sheets options...
1837 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1838 IPP_TAG_ZERO
)) == NULL
)
1840 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1841 "Adding default job-sheets values \"%s,%s\"...",
1842 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1844 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1846 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1847 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1850 job
->job_sheets
= attr
;
1853 * Enforce classification level if set...
1858 cupsdLogMessage(CUPSD_LOG_INFO
,
1859 "Classification=\"%s\", ClassifyOverride=%d",
1860 Classification
? Classification
: "(null)",
1863 if (ClassifyOverride
)
1865 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1866 (attr
->num_values
== 1 ||
1867 !strcmp(attr
->values
[1].string
.text
, "none")))
1870 * Force the leading banner to have the classification on it...
1873 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1875 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1876 "job-sheets=\"%s,none\", "
1877 "job-originating-user-name=\"%s\"",
1878 Classification
, job
->username
);
1880 else if (attr
->num_values
== 2 &&
1881 strcmp(attr
->values
[0].string
.text
,
1882 attr
->values
[1].string
.text
) &&
1883 strcmp(attr
->values
[0].string
.text
, "none") &&
1884 strcmp(attr
->values
[1].string
.text
, "none"))
1887 * Can't put two different security markings on the same document!
1890 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1892 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1893 "job-sheets=\"%s,%s\", "
1894 "job-originating-user-name=\"%s\"",
1895 attr
->values
[0].string
.text
,
1896 attr
->values
[1].string
.text
, job
->username
);
1898 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1899 strcmp(attr
->values
[0].string
.text
, "none") &&
1900 (attr
->num_values
== 1 ||
1901 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1902 strcmp(attr
->values
[1].string
.text
, "none"))))
1904 if (attr
->num_values
== 1)
1905 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1906 "CLASSIFICATION OVERRIDDEN "
1907 "job-sheets=\"%s\", "
1908 "job-originating-user-name=\"%s\"",
1909 attr
->values
[0].string
.text
, job
->username
);
1911 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1912 "CLASSIFICATION OVERRIDDEN "
1913 "job-sheets=\"%s,%s\",fffff "
1914 "job-originating-user-name=\"%s\"",
1915 attr
->values
[0].string
.text
,
1916 attr
->values
[1].string
.text
, job
->username
);
1919 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1920 (attr
->num_values
== 1 ||
1921 strcmp(attr
->values
[1].string
.text
, Classification
)))
1924 * Force the banner to have the classification on it...
1927 if (attr
->num_values
> 1 &&
1928 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1930 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1931 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1935 if (attr
->num_values
== 1 ||
1936 strcmp(attr
->values
[0].string
.text
, "none"))
1937 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1939 if (attr
->num_values
> 1 &&
1940 strcmp(attr
->values
[1].string
.text
, "none"))
1941 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1944 if (attr
->num_values
> 1)
1945 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1946 "CLASSIFICATION FORCED "
1947 "job-sheets=\"%s,%s\", "
1948 "job-originating-user-name=\"%s\"",
1949 attr
->values
[0].string
.text
,
1950 attr
->values
[1].string
.text
, job
->username
);
1952 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1953 "CLASSIFICATION FORCED "
1954 "job-sheets=\"%s\", "
1955 "job-originating-user-name=\"%s\"",
1956 Classification
, job
->username
);
1961 * See if we need to add the starting sheet...
1964 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1966 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1967 attr
->values
[0].string
.text
);
1969 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1971 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1972 "Aborting job because the start banner could not be "
1977 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1980 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1981 IPP_TAG_ZERO
)) != NULL
)
1982 job
->job_sheets
= attr
;
1985 * Fill in the response info...
1988 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1989 LocalPort
, job
->id
);
1991 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1994 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1996 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1998 add_job_state_reasons(con
, job
);
2000 con
->response
->request
.status
.status_code
= IPP_OK
;
2003 * Add any job subscriptions...
2006 add_job_subscriptions(con
, job
);
2009 * Set all but the first two attributes to the job attributes group...
2012 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
2013 attr
->group_tag
= IPP_TAG_JOB
;
2016 * Fire the "job created" event...
2019 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
2022 * Return the new job...
2030 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
2031 * upon the job and printer state...
2035 add_job_state_reasons(
2036 cupsd_client_t
*con
, /* I - Client connection */
2037 cupsd_job_t
*job
) /* I - Job info */
2039 cupsd_printer_t
*dest
; /* Destination printer */
2042 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
2043 con
, con
->http
.fd
, job
? job
->id
: 0);
2045 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
2047 case IPP_JOB_PENDING
:
2048 dest
= cupsdFindDest(job
->dest
);
2050 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
2051 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2052 "job-state-reasons", NULL
, "printer-stopped");
2054 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2055 "job-state-reasons", NULL
, "none");
2059 if (ippFindAttribute(job
->attrs
, "job-hold-until",
2060 IPP_TAG_KEYWORD
) != NULL
||
2061 ippFindAttribute(job
->attrs
, "job-hold-until",
2062 IPP_TAG_NAME
) != NULL
)
2063 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2064 "job-state-reasons", NULL
, "job-hold-until-specified");
2066 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2067 "job-state-reasons", NULL
, "job-incoming");
2070 case IPP_JOB_PROCESSING
:
2071 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2072 "job-state-reasons", NULL
, "job-printing");
2075 case IPP_JOB_STOPPED
:
2076 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2077 "job-state-reasons", NULL
, "job-stopped");
2080 case IPP_JOB_CANCELED
:
2081 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2082 "job-state-reasons", NULL
, "job-canceled-by-user");
2085 case IPP_JOB_ABORTED
:
2086 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2087 "job-state-reasons", NULL
, "aborted-by-system");
2090 case IPP_JOB_COMPLETED
:
2091 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2092 "job-state-reasons", NULL
, "job-completed-successfully");
2099 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2103 add_job_subscriptions(
2104 cupsd_client_t
*con
, /* I - Client connection */
2105 cupsd_job_t
*job
) /* I - Newly created job */
2107 int i
; /* Looping var */
2108 ipp_attribute_t
*prev
, /* Previous attribute */
2109 *next
, /* Next attribute */
2110 *attr
; /* Current attribute */
2111 cupsd_subscription_t
*sub
; /* Subscription object */
2112 const char *recipient
, /* notify-recipient-uri */
2113 *pullmethod
; /* notify-pull-method */
2114 ipp_attribute_t
*user_data
; /* notify-user-data */
2115 int interval
; /* notify-time-interval */
2116 unsigned mask
; /* notify-events */
2120 * Find the first subscription group attribute; return if we have
2124 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2125 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2132 * Process the subscription attributes in the request...
2141 mask
= CUPSD_EVENT_NONE
;
2143 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2145 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2146 attr
->value_tag
== IPP_TAG_URI
)
2149 * Validate the recipient scheme against the ServerBin/notifier
2153 char notifier
[1024], /* Notifier filename */
2154 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2155 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2156 host
[HTTP_MAX_URI
], /* Host portion of URI */
2157 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2158 int port
; /* Port portion of URI */
2161 recipient
= attr
->values
[0].string
.text
;
2163 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2164 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2165 host
, sizeof(host
), &port
,
2166 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2168 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2169 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
2170 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2171 "notify-status-code", IPP_URI_SCHEME
);
2175 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2177 if (access(notifier
, X_OK
))
2179 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2180 _("notify-recipient-uri URI \"%s\" uses unknown "
2181 "scheme"), recipient
);
2182 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2183 "notify-status-code", IPP_URI_SCHEME
);
2187 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2189 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2190 _("notify-recipient-uri URI \"%s\" is already used"),
2192 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2193 "notify-status-code", IPP_ATTRIBUTES
);
2197 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2198 attr
->value_tag
== IPP_TAG_KEYWORD
)
2200 pullmethod
= attr
->values
[0].string
.text
;
2202 if (strcmp(pullmethod
, "ippget"))
2204 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2205 _("Bad notify-pull-method \"%s\""), pullmethod
);
2206 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2207 "notify-status-code", IPP_ATTRIBUTES
);
2211 else if (!strcmp(attr
->name
, "notify-charset") &&
2212 attr
->value_tag
== IPP_TAG_CHARSET
&&
2213 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2214 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2216 send_ipp_status(con
, IPP_CHARSET
,
2217 _("Character set \"%s\" not supported"),
2218 attr
->values
[0].string
.text
);
2221 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2222 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2223 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2225 send_ipp_status(con
, IPP_CHARSET
,
2226 _("Language \"%s\" not supported"),
2227 attr
->values
[0].string
.text
);
2230 else if (!strcmp(attr
->name
, "notify-user-data") &&
2231 attr
->value_tag
== IPP_TAG_STRING
)
2233 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2235 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2236 _("The notify-user-data value is too large "
2237 "(%d > 63 octets)"),
2238 attr
->values
[0].unknown
.length
);
2244 else if (!strcmp(attr
->name
, "notify-events") &&
2245 attr
->value_tag
== IPP_TAG_KEYWORD
)
2247 for (i
= 0; i
< attr
->num_values
; i
++)
2248 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2250 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2252 send_ipp_status(con
, IPP_BAD_REQUEST
,
2253 _("The notify-lease-duration attribute cannot be "
2254 "used with job subscriptions."));
2257 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2258 attr
->value_tag
== IPP_TAG_INTEGER
)
2259 interval
= attr
->values
[0].integer
;
2264 if (!recipient
&& !pullmethod
)
2267 if (mask
== CUPSD_EVENT_NONE
)
2268 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2270 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2271 recipient
, 0)) != NULL
)
2273 sub
->interval
= interval
;
2275 cupsdSetString(&sub
->owner
, job
->username
);
2279 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2280 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2281 sub
->user_data_len
);
2284 ippAddSeparator(con
->response
);
2285 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2286 "notify-subscription-id", sub
->id
);
2288 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2296 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2299 * Remove all of the subscription attributes from the job request...
2301 * TODO: Optimize this since subscription groups have to come at the
2302 * end of the request...
2305 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2309 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2310 attr
->group_tag
== IPP_TAG_ZERO
)
2313 * Free and remove this attribute...
2321 job
->attrs
->attrs
= next
;
2327 job
->attrs
->last
= prev
;
2328 job
->attrs
->current
= prev
;
2333 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2335 * See RFC 4122 for the definition of UUIDs and the format.
2339 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2340 cupsd_job_t
*job
) /* I - Job */
2342 char uuid
[1024]; /* job-uuid string */
2343 _cups_md5_state_t md5state
; /* MD5 state */
2344 unsigned char md5sum
[16]; /* MD5 digest/sum */
2348 * First see if the job already has a job-uuid attribute; if so, return...
2351 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2355 * No job-uuid attribute, so build a version 3 UUID with the local job
2356 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2357 * the ServerName, server name and port that the client connected to,
2358 * and local job ID...
2361 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2362 con
->serverport
, job
->id
);
2364 _cupsMD5Init(&md5state
);
2365 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2366 _cupsMD5Finish(&md5state
, md5sum
);
2369 * Format the UUID URI using the MD5 sum and job ID.
2372 snprintf(uuid
, sizeof(uuid
),
2373 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2374 "%02x%02x%02x%02x%02x%02x",
2375 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2376 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2377 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2378 md5sum
[14], md5sum
[15]);
2380 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2385 * 'add_printer()' - Add a printer to the system.
2389 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2390 ipp_attribute_t
*uri
) /* I - URI of printer */
2392 http_status_t status
; /* Policy status */
2393 int i
; /* Looping var */
2394 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2395 username
[HTTP_MAX_URI
], /* Username portion of URI */
2396 host
[HTTP_MAX_URI
], /* Host portion of URI */
2397 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2398 int port
; /* Port portion of URI */
2399 cupsd_printer_t
*printer
; /* Printer/class */
2400 ipp_attribute_t
*attr
; /* Printer attribute */
2401 cups_file_t
*fp
; /* Script/PPD file */
2402 char line
[1024]; /* Line from file... */
2403 char srcfile
[1024], /* Source Script/PPD file */
2404 dstfile
[1024]; /* Destination Script/PPD file */
2405 int modify
; /* Non-zero if we are modifying */
2406 char newname
[IPP_MAX_NAME
]; /* New printer name */
2407 int changed_driver
, /* Changed the PPD/interface script? */
2408 need_restart_job
, /* Need to restart job? */
2409 set_device_uri
, /* Did we set the device URI? */
2410 set_port_monitor
; /* Did we set the port monitor? */
2413 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2414 con
->http
.fd
, uri
->values
[0].string
.text
);
2417 * Do we have a valid URI?
2420 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2421 sizeof(scheme
), username
, sizeof(username
), host
,
2422 sizeof(host
), &port
, resource
, sizeof(resource
));
2424 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2427 * No, return an error...
2430 send_ipp_status(con
, IPP_BAD_REQUEST
,
2431 _("The printer-uri must be of the form "
2432 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2437 * Do we have a valid printer name?
2440 if (!validate_name(resource
+ 10))
2443 * No, return an error...
2446 send_ipp_status(con
, IPP_BAD_REQUEST
,
2447 _("The printer-uri \"%s\" contains invalid characters."),
2448 uri
->values
[0].string
.text
);
2453 * See if the printer already exists; if not, create a new printer...
2456 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2459 * Printer doesn't exist; see if we have a class of the same name...
2462 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2463 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2466 * Yes, return an error...
2469 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2470 _("A class named \"%s\" already exists"),
2476 * No, check the default policy then add the printer...
2479 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2481 send_http_error(con
, status
, NULL
);
2485 printer
= cupsdAddPrinter(resource
+ 10);
2488 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2491 * Check the default policy, then rename the implicit printer to
2492 * "AnyPrinter" or delete it...
2495 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2497 send_http_error(con
, status
, NULL
);
2501 if (ImplicitAnyClasses
)
2503 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2504 cupsdRenamePrinter(printer
, newname
);
2507 cupsdDeletePrinter(printer
, 1);
2510 * Add the printer as a new local printer...
2513 printer
= cupsdAddPrinter(resource
+ 10);
2516 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2519 * Check the default policy, then rename the remote printer to
2520 * "Printer@server"...
2523 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2525 send_http_error(con
, status
, NULL
);
2529 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2531 cupsdRenamePrinter(printer
, newname
);
2534 * Add the printer as a new local printer...
2537 printer
= cupsdAddPrinter(resource
+ 10);
2540 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2543 send_http_error(con
, status
, printer
);
2550 * Look for attributes and copy them over as needed...
2554 need_restart_job
= 0;
2556 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2557 IPP_TAG_TEXT
)) != NULL
)
2558 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2560 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2561 IPP_TAG_TEXT
)) != NULL
)
2562 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2566 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2567 IPP_TAG_URI
)) != NULL
)
2570 * Do we have a valid device URI?
2573 http_uri_status_t uri_status
; /* URI separation status */
2574 char old_device_uri
[1024];
2575 /* Old device URI */
2578 need_restart_job
= 1;
2580 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2581 attr
->values
[0].string
.text
,
2582 scheme
, sizeof(scheme
),
2583 username
, sizeof(username
),
2584 host
, sizeof(host
), &port
,
2585 resource
, sizeof(resource
));
2587 if (uri_status
< HTTP_URI_OK
)
2589 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\""),
2590 attr
->values
[0].string
.text
);
2591 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2592 "add_printer: httpSeparateURI returned %d", uri_status
);
2596 if (!strcmp(scheme
, "file"))
2599 * See if the administrator has enabled file devices...
2602 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2605 * File devices are disabled and the URL is not file:/dev/null...
2608 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2609 _("File device URIs have been disabled! "
2610 "To enable, see the FileDevice directive in "
2611 "\"%s/cupsd.conf\"."),
2619 * See if the backend exists and is executable...
2622 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2623 if (access(srcfile
, X_OK
))
2626 * Could not find device in list!
2629 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\""),
2635 if (printer
->sanitized_device_uri
)
2636 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2637 sizeof(old_device_uri
));
2639 old_device_uri
[0] = '\0';
2641 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2643 cupsdLogMessage(CUPSD_LOG_INFO
,
2644 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2645 printer
->name
, printer
->sanitized_device_uri
,
2651 set_port_monitor
= 0;
2653 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2654 IPP_TAG_NAME
)) != NULL
)
2656 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2659 need_restart_job
= 1;
2661 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2665 for (i
= 0; i
< supported
->num_values
; i
++)
2666 if (!strcmp(supported
->values
[i
].string
.text
,
2667 attr
->values
[0].string
.text
))
2671 if (!supported
|| i
>= supported
->num_values
)
2673 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\""),
2674 attr
->values
[0].string
.text
);
2678 cupsdLogMessage(CUPSD_LOG_INFO
,
2679 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2680 printer
->name
, attr
->values
[0].string
.text
,
2681 printer
->port_monitor
? printer
->port_monitor
: "none");
2683 if (strcmp(attr
->values
[0].string
.text
, "none"))
2684 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2686 cupsdClearString(&printer
->port_monitor
);
2688 set_port_monitor
= 1;
2691 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2692 IPP_TAG_BOOLEAN
)) != NULL
&&
2693 attr
->values
[0].boolean
!= printer
->accepting
)
2695 cupsdLogMessage(CUPSD_LOG_INFO
,
2696 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2697 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2699 printer
->accepting
= attr
->values
[0].boolean
;
2700 cupsdAddPrinterHistory(printer
);
2702 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2703 "%s accepting jobs.",
2704 printer
->accepting
? "Now" : "No longer");
2707 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2708 IPP_TAG_BOOLEAN
)) != NULL
)
2710 if (printer
->shared
&& !attr
->values
[0].boolean
)
2711 cupsdDeregisterPrinter(printer
, 1);
2713 cupsdLogMessage(CUPSD_LOG_INFO
,
2714 "Setting %s printer-is-shared to %d (was %d.)",
2715 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2717 printer
->shared
= attr
->values
[0].boolean
;
2720 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2721 IPP_TAG_ENUM
)) != NULL
)
2723 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2724 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2726 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d"),
2727 attr
->values
[0].integer
);
2731 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2732 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2734 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2735 cupsdStopPrinter(printer
, 0);
2738 need_restart_job
= 1;
2739 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2743 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2744 IPP_TAG_TEXT
)) != NULL
)
2746 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2747 sizeof(printer
->state_message
));
2748 cupsdAddPrinterHistory(printer
);
2750 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2751 printer
->state_message
);
2754 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2755 IPP_TAG_KEYWORD
)) != NULL
)
2757 if (attr
->num_values
>
2758 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2760 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2761 _("Too many printer-state-reasons values (%d > %d)"),
2763 (int)(sizeof(printer
->reasons
) /
2764 sizeof(printer
->reasons
[0])));
2768 for (i
= 0; i
< printer
->num_reasons
; i
++)
2769 _cupsStrFree(printer
->reasons
[i
]);
2771 printer
->num_reasons
= 0;
2772 for (i
= 0; i
< attr
->num_values
; i
++)
2774 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2777 printer
->reasons
[printer
->num_reasons
] =
2778 _cupsStrRetain(attr
->values
[i
].string
.text
);
2779 printer
->num_reasons
++;
2781 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2782 printer
->state
!= IPP_PRINTER_STOPPED
)
2784 cupsdLogMessage(CUPSD_LOG_INFO
,
2785 "Setting %s printer-state to %d (was %d.)",
2786 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2787 cupsdStopPrinter(printer
, 0);
2791 if (PrintcapFormat
== PRINTCAP_PLIST
)
2792 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2794 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2795 "Printer \"%s\" state changed.", printer
->name
);
2798 set_printer_defaults(con
, printer
);
2800 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2801 IPP_TAG_KEYWORD
)) != NULL
)
2802 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2805 * See if we have all required attributes...
2808 if (!printer
->device_uri
)
2809 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2812 * See if we have an interface script or PPD file attached to the request...
2817 need_restart_job
= 1;
2820 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2822 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2825 * Yes; get the first line from it...
2829 cupsFileGets(fp
, line
, sizeof(line
));
2833 * Then see what kind of file it is...
2836 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2839 if (!strncmp(line
, "*PPD-Adobe", 10))
2842 * The new file is a PPD file, so remove any old interface script
2843 * that might be lying around...
2851 * This must be an interface script, so move the file over to the
2852 * interfaces directory and make it executable...
2855 if (copy_file(srcfile
, dstfile
))
2857 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2858 _("Unable to copy interface script - %s"),
2863 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2864 "Copied interface script successfully");
2865 chmod(dstfile
, 0755);
2868 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2871 if (!strncmp(line
, "*PPD-Adobe", 10))
2874 * The new file is a PPD file, so move the file over to the
2875 * ppd directory and make it readable by all...
2878 if (copy_file(srcfile
, dstfile
))
2880 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2881 _("Unable to copy PPD file - %s"),
2886 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2887 "Copied PPD file successfully");
2888 chmod(dstfile
, 0644);
2893 * This must be an interface script, so remove any old PPD file that
2894 * may be lying around...
2901 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2902 IPP_TAG_NAME
)) != NULL
)
2904 need_restart_job
= 1;
2907 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2910 * Raw driver, remove any existing PPD or interface script files.
2913 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2917 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2927 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2931 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2934 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2936 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file"));
2940 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2941 "Copied PPD file successfully");
2942 chmod(dstfile
, 0644);
2949 * If we changed the PPD/interface script, then remove the printer's cache
2950 * file and clear the printer-state-reasons...
2953 char cache_name
[1024]; /* Cache filename for printer attrs */
2955 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp4", CacheDir
,
2959 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.pwg3", CacheDir
,
2963 cupsdSetPrinterReasons(printer
, "none");
2967 * (Re)register color profiles...
2972 apple_unregister_profiles(printer
);
2973 apple_register_profiles(printer
);
2975 #endif /* __APPLE__ */
2979 * If we set the device URI but not the port monitor, check which port
2980 * monitor to use by default...
2983 if (set_device_uri
&& !set_port_monitor
)
2985 ppd_file_t
*ppd
; /* PPD file */
2986 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2989 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2990 sizeof(scheme
), username
, sizeof(username
), host
,
2991 sizeof(host
), &port
, resource
, sizeof(resource
));
2993 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2995 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2997 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2999 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
3000 if (!strcmp(scheme
, ppdattr
->spec
))
3002 cupsdLogMessage(CUPSD_LOG_INFO
,
3003 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
3004 printer
->name
, ppdattr
->value
,
3005 printer
->port_monitor
? printer
->port_monitor
3008 if (strcmp(ppdattr
->value
, "none"))
3009 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
3011 cupsdClearString(&printer
->port_monitor
);
3021 * Update the printer attributes and return...
3024 cupsdSetPrinterAttrs(printer
);
3025 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3027 if (need_restart_job
&& printer
->job
)
3030 * Restart the current job...
3033 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
3034 "Job restarted because the printer was modified.");
3037 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3041 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
3042 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
3043 printer
->name
, get_username(con
));
3045 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
3046 printer
->name
, get_username(con
));
3050 cupsdAddPrinterHistory(printer
);
3052 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
3053 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
3054 printer
->name
, get_username(con
));
3056 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
3057 printer
->name
, get_username(con
));
3060 con
->response
->request
.status
.status_code
= IPP_OK
;
3065 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
3066 * based upon the printer state...
3070 add_printer_state_reasons(
3071 cupsd_client_t
*con
, /* I - Client connection */
3072 cupsd_printer_t
*p
) /* I - Printer info */
3074 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3075 "add_printer_state_reasons(%p[%d], %p[%s])",
3076 con
, con
->http
.fd
, p
, p
->name
);
3078 if (p
->num_reasons
== 0)
3079 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3080 "printer-state-reasons", NULL
, "none");
3082 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3083 "printer-state-reasons", p
->num_reasons
, NULL
,
3084 (const char * const *)p
->reasons
);
3089 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
3090 * the specified printer or class.
3094 add_queued_job_count(
3095 cupsd_client_t
*con
, /* I - Client connection */
3096 cupsd_printer_t
*p
) /* I - Printer or class */
3098 int count
; /* Number of jobs on destination */
3101 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3102 con
, con
->http
.fd
, p
, p
->name
);
3104 count
= cupsdGetPrinterJobCount(p
->name
);
3106 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3107 "queued-job-count", count
);
3113 * 'apple_init_profile()' - Initialize a color profile.
3118 ppd_file_t
*ppd
, /* I - PPD file */
3119 cups_array_t
*languages
, /* I - Languages in the PPD file */
3120 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3121 CFMutableDictionaryRef profile
, /* I - Profile dictionary */
3123 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3124 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3125 unsigned id
, /* I - Profile ID */
3126 const char *name
, /* I - Profile name */
3127 const char *text
, /* I - Profile UI text */
3128 const char *iccfile
) /* I - ICC filename */
3130 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3131 CFURLRef url
; /* URL for profile filename */
3132 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3133 CFMutableDictionaryRef dict
; /* Dictionary for name */
3134 char *language
; /* Current language */
3135 ppd_attr_t
*attr
; /* Profile attribute */
3136 CFStringRef cflang
, /* Language string */
3137 cftext
; /* Localized text */
3141 * Build the profile name dictionary...
3144 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3145 &kCFTypeDictionaryKeyCallBacks
,
3146 &kCFTypeDictionaryValueCallBacks
);
3148 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3149 kCFStringEncodingUTF8
);
3153 CFDictionarySetValue(dict
, CFSTR("en_US"), cftext
);
3160 * Find localized names for the color profiles...
3163 cupsArraySave(ppd
->sorted_attrs
);
3165 for (language
= (char *)cupsArrayFirst(languages
);
3167 language
= (char *)cupsArrayNext(languages
))
3171 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3173 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3176 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3178 if (attr
&& attr
->text
[0])
3180 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3181 kCFStringEncodingUTF8
);
3182 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3183 kCFStringEncodingUTF8
);
3185 if (cflang
&& cftext
)
3186 CFDictionarySetValue(dict
, cflang
, cftext
);
3196 cupsArrayRestore(ppd
->sorted_attrs
);
3200 * Fill in the profile data...
3203 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3206 url
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
3207 (const UInt8
*)iccfile
,
3208 strlen(iccfile
), false);
3212 CFDictionarySetValue(profile
, kColorSyncDeviceProfileURL
, url
);
3217 CFDictionarySetValue(profile
, kColorSyncDeviceModeDescriptions
, dict
);
3221 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3222 profile
->profileID
= id
;
3223 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3224 profile
->profileName
= dict
;
3227 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3228 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3229 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3234 * 'apple_register_profiles()' - Register color profiles for a printer.
3238 apple_register_profiles(
3239 cupsd_printer_t
*p
) /* I - Printer */
3241 int i
; /* Looping var */
3242 char ppdfile
[1024], /* PPD filename */
3243 iccfile
[1024], /* ICC filename */
3244 selector
[PPD_MAX_NAME
];
3245 /* Profile selection string */
3246 ppd_file_t
*ppd
; /* PPD file */
3247 ppd_attr_t
*attr
, /* Profile attributes */
3248 *profileid_attr
,/* cupsProfileID attribute */
3249 *q1_attr
, /* ColorModel (or other) qualifier */
3250 *q2_attr
, /* MediaType (or other) qualifier */
3251 *q3_attr
; /* Resolution (or other) qualifier */
3252 char q_keyword
[PPD_MAX_NAME
];
3253 /* Qualifier keyword */
3254 const char *q1_choice
, /* ColorModel (or other) choice */
3255 *q2_choice
, /* MediaType (or other) choice */
3256 *q3_choice
; /* Resolution (or other) choice */
3257 const char *profile_key
; /* Profile keyword */
3258 ppd_option_t
*cm_option
; /* Color model option */
3259 ppd_choice_t
*cm_choice
; /* Color model choice */
3260 int num_profiles
; /* Number of profiles */
3261 OSStatus error
= 0; /* Last error */
3262 unsigned device_id
, /* Printer device ID */
3263 profile_id
, /* Profile ID */
3264 default_profile_id
= 0;
3265 /* Default profile ID */
3266 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3267 CFStringRef printer_name
; /* Printer name string */
3268 cups_array_t
*languages
; /* Languages array */
3269 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3270 CFMutableDictionaryRef profiles
, /* Dictionary of profiles */
3271 profile
; /* Current profile info dictionary */
3272 CFStringRef dict_key
; /* Key in factory profile dictionary */
3274 CMDeviceScope scope
= /* Scope of the registration */
3276 kCFPreferencesAnyUser
,
3277 kCFPreferencesCurrentHost
3279 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3280 CMDeviceProfileInfo
*profile
; /* Current profile */
3281 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3285 * Make sure ColorSync is available...
3288 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3289 if (ColorSyncRegisterDevice
== NULL
)
3293 if (CMRegisterColorDevice
== NULL
)
3295 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3298 * Try opening the PPD file for this printer...
3301 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3302 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3306 * See if we have any profiles...
3309 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3310 profile_key
= "APTiogaProfile";
3313 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3314 profile_key
= "cupsICCProfile";
3317 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3318 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3320 if (attr
->value
[0] != '/')
3321 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3324 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3326 if (access(iccfile
, 0))
3332 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3334 * Create a dictionary for the factory profiles...
3337 profiles
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3338 &kCFTypeDictionaryKeyCallBacks
,
3339 &kCFTypeDictionaryValueCallBacks
);
3342 cupsdLogMessage(CUPSD_LOG_ERROR
,
3343 "Unable to allocate memory for factory profiles.");
3347 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3350 * If we have profiles, add them...
3353 if (num_profiles
> 0)
3355 if (profile_key
[0] == 'A')
3358 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3362 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3364 default_profile_id
= atoi(attr
->value
);
3366 q1_choice
= q2_choice
= q3_choice
= NULL
;
3371 * For CUPS PPDs, figure out the default profile selector values...
3374 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3375 attr
->value
&& attr
->value
[0])
3377 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3378 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3380 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3381 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3383 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3384 q1_choice
= q1_attr
->value
;
3388 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3389 attr
->value
&& attr
->value
[0])
3391 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3392 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3395 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3397 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3398 q2_choice
= q2_attr
->value
;
3402 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3403 attr
->value
&& attr
->value
[0])
3405 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3406 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3409 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3411 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3412 q3_choice
= q3_attr
->value
;
3417 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3419 * Build the array of profiles...
3421 * Note: This calloc actually requests slightly more memory than needed.
3424 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3426 cupsdLogMessage(CUPSD_LOG_ERROR
,
3427 "Unable to allocate memory for factory profiles.");
3432 profiles
->profileCount
= num_profiles
;
3433 profile
= profiles
->profiles
;
3434 # endif /* !HAVE_COLORSYNCREGISTERDEVICE */
3437 * Loop through the profiles listed in the PPD...
3440 languages
= _ppdGetLanguages(ppd
);
3442 for (attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3444 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3445 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3448 * Add this profile...
3451 if (attr
->value
[0] != '/')
3452 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3455 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3457 if (access(iccfile
, 0))
3460 if (profile_key
[0] == 'c')
3462 cupsArraySave(ppd
->sorted_attrs
);
3464 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3465 attr
->spec
)) != NULL
&&
3466 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3467 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3469 profile_id
= _ppdHashName(attr
->spec
);
3471 cupsArrayRestore(ppd
->sorted_attrs
);
3474 profile_id
= atoi(attr
->spec
);
3476 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3477 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3478 &kCFTypeDictionaryKeyCallBacks
,
3479 &kCFTypeDictionaryValueCallBacks
);
3482 cupsdLogMessage(CUPSD_LOG_ERROR
,
3483 "Unable to allocate memory for color profile.");
3484 CFRelease(profiles
);
3489 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3490 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3492 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3493 CFSTR("%u"), profile_id
);
3496 CFDictionarySetValue(profiles
, dict_key
, profile
);
3497 CFRelease(dict_key
);
3503 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3504 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3507 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3510 * See if this is the default profile...
3513 if (!default_profile_id
&& q1_choice
&& q2_choice
&& q3_choice
)
3515 snprintf(selector
, sizeof(selector
), "%s.%s.%s", q1_choice
, q2_choice
,
3517 if (!strcmp(selector
, attr
->spec
))
3518 default_profile_id
= profile_id
;
3521 if (!default_profile_id
&& q1_choice
&& q2_choice
)
3523 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
, q2_choice
);
3524 if (!strcmp(selector
, attr
->spec
))
3525 default_profile_id
= profile_id
;
3528 if (!default_profile_id
&& q1_choice
&& q3_choice
)
3530 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
, q3_choice
);
3531 if (!strcmp(selector
, attr
->spec
))
3532 default_profile_id
= profile_id
;
3535 if (!default_profile_id
&& q1_choice
)
3537 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3538 if (!strcmp(selector
, attr
->spec
))
3539 default_profile_id
= profile_id
;
3542 if (!default_profile_id
&& q2_choice
&& q3_choice
)
3544 snprintf(selector
, sizeof(selector
), ".%s.%s", q2_choice
, q3_choice
);
3545 if (!strcmp(selector
, attr
->spec
))
3546 default_profile_id
= profile_id
;
3549 if (!default_profile_id
&& q2_choice
)
3551 snprintf(selector
, sizeof(selector
), ".%s.", q2_choice
);
3552 if (!strcmp(selector
, attr
->spec
))
3553 default_profile_id
= profile_id
;
3556 if (!default_profile_id
&& q3_choice
)
3558 snprintf(selector
, sizeof(selector
), "..%s", q3_choice
);
3559 if (!strcmp(selector
, attr
->spec
))
3560 default_profile_id
= profile_id
;
3564 _ppdFreeLanguages(languages
);
3566 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3569 * Extract profiles from ColorModel option...
3572 const char *profile_name
; /* Name of generic profile */
3575 num_profiles
= cm_option
->num_choices
;
3577 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3579 * Create an array for the factory profiles...
3582 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3584 cupsdLogMessage(CUPSD_LOG_ERROR
,
3585 "Unable to allocate memory for factory profiles.");
3590 profiles
->profileCount
= num_profiles
;
3591 profile
= profiles
->profiles
;
3592 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3594 for (i
= cm_option
->num_choices
, cm_choice
= cm_option
->choices
;
3598 if (!strcmp(cm_choice
->choice
, "Gray") ||
3599 !strcmp(cm_choice
->choice
, "Black"))
3600 profile_name
= "Gray";
3601 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3602 !strcmp(cm_choice
->choice
, "CMY"))
3603 profile_name
= "RGB";
3604 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3605 !strcmp(cm_choice
->choice
, "KCMY"))
3606 profile_name
= "CMYK";
3608 profile_name
= "DeviceN";
3610 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3611 profile_id
= _ppdHashName(selector
);
3613 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3614 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3615 &kCFTypeDictionaryKeyCallBacks
,
3616 &kCFTypeDictionaryValueCallBacks
);
3619 cupsdLogMessage(CUPSD_LOG_ERROR
,
3620 "Unable to allocate memory for color profile.");
3621 CFRelease(profiles
);
3626 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3627 cm_choice
->text
, NULL
);
3629 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3630 CFSTR("%u"), profile_id
);
3633 CFDictionarySetValue(profiles
, dict_key
, profile
);
3634 CFRelease(dict_key
);
3640 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3641 cm_choice
->text
, NULL
);
3643 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3645 if (cm_choice
->marked
)
3646 default_profile_id
= profile_id
;
3652 * Use the default colorspace...
3655 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3657 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3659 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3661 * Add the grayscale profile first. We always have a grayscale profile.
3664 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3665 &kCFTypeDictionaryKeyCallBacks
,
3666 &kCFTypeDictionaryValueCallBacks
);
3670 cupsdLogMessage(CUPSD_LOG_ERROR
,
3671 "Unable to allocate memory for color profile.");
3672 CFRelease(profiles
);
3677 profile_id
= _ppdHashName("Gray..");
3678 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "Gray", "Gray", NULL
);
3680 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3684 CFDictionarySetValue(profiles
, dict_key
, profile
);
3685 CFRelease(dict_key
);
3691 * Then add the RGB/CMYK/DeviceN color profile...
3694 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3695 &kCFTypeDictionaryKeyCallBacks
,
3696 &kCFTypeDictionaryValueCallBacks
);
3700 cupsdLogMessage(CUPSD_LOG_ERROR
,
3701 "Unable to allocate memory for color profile.");
3702 CFRelease(profiles
);
3707 switch (ppd
->colorspace
)
3711 profile_id
= _ppdHashName("RGB..");
3712 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "RGB", "RGB",
3717 profile_id
= _ppdHashName("CMYK..");
3718 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "CMYK", "CMYK",
3727 profile_id
= _ppdHashName("DeviceN..");
3728 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "DeviceN",
3733 if (CFDictionaryGetCount(profile
) > 0)
3735 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3736 CFSTR("%u"), profile_id
);
3739 CFDictionarySetValue(profiles
, dict_key
, profile
);
3740 CFRelease(dict_key
);
3748 * Create an array for the factory profiles...
3751 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3753 cupsdLogMessage(CUPSD_LOG_ERROR
,
3754 "Unable to allocate memory for factory profiles.");
3759 profiles
->profileCount
= num_profiles
;
3762 * Add the grayscale profile first. We always have a grayscale profile.
3765 profile_id
= _ppdHashName("Gray..");
3766 apple_init_profile(ppd
, NULL
, profiles
->profiles
, profile_id
, "Gray",
3770 * Then add the RGB/CMYK/DeviceN color profile...
3773 switch (ppd
->colorspace
)
3777 profile_id
= _ppdHashName("RGB..");
3778 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3779 "RGB", "RGB", NULL
);
3783 profile_id
= _ppdHashName("CMYK..");
3784 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3785 "CMYK", "CMYK", NULL
);
3793 profile_id
= _ppdHashName("DeviceN..");
3794 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3795 "DeviceN", "DeviceN", NULL
);
3798 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3801 if (num_profiles
> 0)
3804 * Make sure we have a default profile ID...
3807 if (!default_profile_id
)
3808 default_profile_id
= profile_id
; /* Last profile */
3810 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3811 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3812 default_profile_id
);
3815 CFDictionarySetValue(profiles
, kColorSyncDeviceDefaultProfileID
,
3817 CFRelease(dict_key
);
3819 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3822 * Get the device ID hash and pathelogical name dictionary.
3825 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3828 device_id
= _ppdHashName(p
->name
);
3829 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3830 &kCFTypeDictionaryKeyCallBacks
,
3831 &kCFTypeDictionaryValueCallBacks
);
3832 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3833 p
->name
, kCFStringEncodingUTF8
);
3835 if (device_name
&& printer_name
)
3837 CFDictionarySetValue(device_name
, CFSTR("en_US"), printer_name
);
3840 * Register the device with ColorSync...
3843 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3844 CFTypeRef deviceDictKeys
[] =
3846 kColorSyncDeviceDescriptions
,
3847 kColorSyncFactoryProfiles
,
3848 kColorSyncDeviceUserScope
,
3849 kColorSyncDeviceHostScope
3851 CFTypeRef deviceDictVals
[] =
3852 { /* Device values */
3855 kCFPreferencesAnyUser
,
3856 kCFPreferencesCurrentHost
3858 CFDictionaryRef deviceDict
; /* Device dictionary */
3859 CFUUIDRef deviceUUID
; /* Device UUID (TODO: use printer-uuid value) */
3861 deviceDict
= CFDictionaryCreate(kCFAllocatorDefault
,
3862 (const void **)deviceDictKeys
,
3863 (const void **)deviceDictVals
,
3864 sizeof(deviceDictKeys
) /
3865 sizeof(deviceDictKeys
[0]),
3866 &kCFTypeDictionaryKeyCallBacks
,
3867 &kCFTypeDictionaryValueCallBacks
);
3868 deviceUUID
= ColorSyncCreateUUIDFromUInt32(device_id
);
3869 if (deviceDict
&& deviceUUID
&&
3870 !ColorSyncRegisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
,
3875 CFRelease(deviceUUID
);
3878 CFRelease(deviceDict
);
3881 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3882 device_name
, &scope
);
3885 * Register the profiles...
3889 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3890 default_profile_id
, profiles
);
3891 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3901 cupsdLogMessage(CUPSD_LOG_ERROR
,
3902 "Unable to register ICC color profiles for \"%s\": %d",
3903 p
->name
, (int)error
);
3906 CFRelease(printer_name
);
3909 CFRelease(device_name
);
3913 * Free any memory we used...
3916 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3917 CFRelease(profiles
);
3920 if (num_profiles
> 0)
3922 for (profile
= profiles
->profiles
;
3924 profile
++, num_profiles
--)
3925 CFRelease(profile
->profileName
);
3929 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3936 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3941 apple_unregister_profiles(
3942 cupsd_printer_t
*p
) /* I - Printer */
3945 * Make sure ColorSync is available...
3948 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3949 if (ColorSyncUnregisterDevice
!= NULL
)
3951 CFUUIDRef deviceUUID
; /* Printer UUID */
3953 deviceUUID
= ColorSyncCreateUUIDFromUInt32(_ppdHashName(p
->name
));
3954 /* TODO: Use printer-uuid value */
3958 ColorSyncUnregisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
);
3959 CFRelease(deviceUUID
);
3964 if (CMUnregisterColorDevice
!= NULL
)
3965 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3966 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3968 #endif /* __APPLE__ */
3971 * 'apply_printer_defaults()' - Apply printer default options to a job.
3975 apply_printer_defaults(
3976 cupsd_printer_t
*printer
, /* I - Printer */
3977 cupsd_job_t
*job
) /* I - Job */
3979 int i
, /* Looping var */
3980 num_options
; /* Number of default options */
3981 cups_option_t
*options
, /* Default options */
3982 *option
; /* Current option */
3986 * Collect all of the default options and add the missing ones to the
3990 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3991 option
= printer
->options
;
3994 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3996 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
4001 * Encode these options as attributes in the job object...
4004 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
4005 cupsFreeOptions(num_options
, options
);
4010 * 'authenticate_job()' - Set job authentication info.
4014 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
4015 ipp_attribute_t
*uri
) /* I - Job URI */
4017 ipp_attribute_t
*attr
, /* job-id attribute */
4018 *auth_info
; /* auth-info attribute */
4019 int jobid
; /* Job ID */
4020 cupsd_job_t
*job
; /* Current job */
4021 char scheme
[HTTP_MAX_URI
],
4022 /* Method portion of URI */
4023 username
[HTTP_MAX_URI
],
4024 /* Username portion of URI */
4026 /* Host portion of URI */
4027 resource
[HTTP_MAX_URI
];
4028 /* Resource portion of URI */
4029 int port
; /* Port portion of URI */
4032 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
4033 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
4036 * Start with "everything is OK" status...
4039 con
->response
->request
.status
.status_code
= IPP_OK
;
4042 * See if we have a job URI or a printer URI...
4045 if (!strcmp(uri
->name
, "printer-uri"))
4048 * Got a printer URI; see if we also have a job-id attribute...
4051 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4052 IPP_TAG_INTEGER
)) == NULL
)
4054 send_ipp_status(con
, IPP_BAD_REQUEST
,
4055 _("Got a printer-uri attribute but no job-id"));
4059 jobid
= attr
->values
[0].integer
;
4064 * Got a job URI; parse it to get the job ID...
4067 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4068 sizeof(scheme
), username
, sizeof(username
), host
,
4069 sizeof(host
), &port
, resource
, sizeof(resource
));
4071 if (strncmp(resource
, "/jobs/", 6))
4077 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\""),
4078 uri
->values
[0].string
.text
);
4082 jobid
= atoi(resource
+ 6);
4086 * See if the job exists...
4089 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4092 * Nope - return a "not found" error...
4095 send_ipp_status(con
, IPP_NOT_FOUND
,
4096 _("Job #%d does not exist"), jobid
);
4101 * See if the job has been completed...
4104 if (job
->state_value
!= IPP_JOB_HELD
)
4107 * Return a "not-possible" error...
4110 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4111 _("Job #%d is not held for authentication"),
4117 * See if we have already authenticated...
4120 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
4122 if (!con
->username
[0] && !auth_info
)
4124 cupsd_printer_t
*printer
; /* Job destination */
4128 * No auth data. If we need to authenticate via Kerberos, send a
4129 * HTTP auth challenge, otherwise just return an IPP error...
4132 printer
= cupsdFindDest(job
->dest
);
4134 if (printer
&& printer
->num_auth_info_required
> 0 &&
4135 !strcmp(printer
->auth_info_required
[0], "negotiate"))
4136 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
4138 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
4139 _("No authentication information provided"));
4144 * See if the job is owned by the requesting user...
4147 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4149 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4150 cupsdFindDest(job
->dest
));
4155 * Save the authentication information for this job...
4158 save_auth_info(con
, job
, auth_info
);
4161 * Reset the job-hold-until value to "no-hold"...
4164 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4165 IPP_TAG_KEYWORD
)) == NULL
)
4166 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4170 attr
->value_tag
= IPP_TAG_KEYWORD
;
4171 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
4175 * Release the job and return...
4178 cupsdReleaseJob(job
);
4180 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
4182 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
4189 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
4193 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
4194 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4196 int i
; /* Looping var */
4197 http_status_t status
; /* Policy status */
4198 cups_ptype_t dtype
; /* Destination type */
4199 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4200 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
4201 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
4202 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4203 int port
; /* Port portion of URI */
4204 ipp_attribute_t
*attr
; /* Attribute in request */
4205 const char *username
= NULL
; /* Username */
4206 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
4208 cupsd_printer_t
*printer
; /* Printer */
4209 ipp_attribute_t
*job_ids
; /* job-ids attribute */
4210 cupsd_job_t
*job
; /* Job */
4213 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
4214 con
->http
.fd
, uri
->values
[0].string
.text
);
4217 * Get the jobs to cancel/purge...
4220 switch (con
->request
->request
.op
.operation_id
)
4222 case IPP_PURGE_JOBS
:
4224 * Get the username (if any) for the jobs we want to cancel (only if
4225 * "my-jobs" is specified...
4228 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
4229 IPP_TAG_BOOLEAN
)) != NULL
&&
4230 attr
->values
[0].boolean
)
4232 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4233 IPP_TAG_NAME
)) != NULL
)
4234 username
= attr
->values
[0].string
.text
;
4237 send_ipp_status(con
, IPP_BAD_REQUEST
,
4238 _("Missing requesting-user-name attribute"));
4244 * Look for the "purge-jobs" attribute...
4247 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
4248 IPP_TAG_BOOLEAN
)) != NULL
)
4249 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4251 purge
= CUPSD_JOB_PURGE
;
4254 case IPP_CANCEL_MY_JOBS
:
4255 if (con
->username
[0])
4256 username
= con
->username
;
4257 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4258 IPP_TAG_NAME
)) != NULL
)
4259 username
= attr
->values
[0].string
.text
;
4262 send_ipp_status(con
, IPP_BAD_REQUEST
,
4263 _("Missing requesting-user-name attribute"));
4271 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
4274 * See if we have a printer URI...
4277 if (strcmp(uri
->name
, "printer-uri"))
4279 send_ipp_status(con
, IPP_BAD_REQUEST
,
4280 _("The printer-uri attribute is required"));
4285 * And if the destination is valid...
4288 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4294 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
4295 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
4296 hostname
, sizeof(hostname
), &port
,
4297 resource
, sizeof(resource
));
4299 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
4300 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
4302 send_ipp_status(con
, IPP_NOT_FOUND
,
4303 _("The printer or class was not found."));
4311 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
4313 send_http_error(con
, status
, NULL
);
4319 for (i
= 0; i
< job_ids
->num_values
; i
++)
4321 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
4325 if (i
< job_ids
->num_values
)
4327 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
4328 job_ids
->values
[i
].integer
);
4332 for (i
= 0; i
< job_ids
->num_values
; i
++)
4334 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4336 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4337 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4338 "Job canceled by user.");
4341 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4342 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4348 * Cancel all jobs on all printers...
4351 cupsdCancelJobs(NULL
, username
, purge
);
4353 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
4354 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4364 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4367 send_http_error(con
, status
, printer
);
4373 for (i
= 0; i
< job_ids
->num_values
; i
++)
4375 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
4376 strcasecmp(job
->dest
, printer
->name
))
4380 if (i
< job_ids
->num_values
)
4382 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
4383 job_ids
->values
[i
].integer
);
4387 for (i
= 0; i
< job_ids
->num_values
; i
++)
4389 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4391 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4392 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4393 "Job canceled by user.");
4396 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4397 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4403 * Cancel all of the jobs on the named printer...
4406 cupsdCancelJobs(printer
->name
, username
, purge
);
4408 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
4410 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4415 con
->response
->request
.status
.status_code
= IPP_OK
;
4420 * 'cancel_job()' - Cancel a print job.
4424 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
4425 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4427 ipp_attribute_t
*attr
; /* Current attribute */
4428 int jobid
; /* Job ID */
4429 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4430 username
[HTTP_MAX_URI
], /* Username portion of URI */
4431 host
[HTTP_MAX_URI
], /* Host portion of URI */
4432 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4433 int port
; /* Port portion of URI */
4434 cupsd_job_t
*job
; /* Job information */
4435 cups_ptype_t dtype
; /* Destination type (printer/class) */
4436 cupsd_printer_t
*printer
; /* Printer data */
4437 cupsd_jobaction_t purge
; /* Purge the job? */
4440 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
4441 con
->http
.fd
, uri
->values
[0].string
.text
);
4444 * See if we have a job URI or a printer URI...
4447 if (!strcmp(uri
->name
, "printer-uri"))
4450 * Got a printer URI; see if we also have a job-id attribute...
4453 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4454 IPP_TAG_INTEGER
)) == NULL
)
4456 send_ipp_status(con
, IPP_BAD_REQUEST
,
4457 _("Got a printer-uri attribute but no job-id"));
4461 if ((jobid
= attr
->values
[0].integer
) == 0)
4464 * Find the current job on the specified printer...
4467 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4473 send_ipp_status(con
, IPP_NOT_FOUND
,
4474 _("The printer or class was not found."));
4479 * See if there are any pending jobs...
4482 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4484 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4485 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
4486 !strcasecmp(job
->dest
, printer
->name
))
4494 * No, try stopped jobs...
4497 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4499 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4500 if (job
->state_value
== IPP_JOB_STOPPED
&&
4501 !strcasecmp(job
->dest
, printer
->name
))
4508 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s"),
4518 * Got a job URI; parse it to get the job ID...
4521 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4522 sizeof(scheme
), username
, sizeof(username
), host
,
4523 sizeof(host
), &port
, resource
, sizeof(resource
));
4525 if (strncmp(resource
, "/jobs/", 6))
4531 send_ipp_status(con
, IPP_BAD_REQUEST
,
4532 _("Bad job-uri attribute \"%s\""),
4533 uri
->values
[0].string
.text
);
4537 jobid
= atoi(resource
+ 6);
4541 * Look for the "purge-job" attribute...
4544 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4545 IPP_TAG_BOOLEAN
)) != NULL
)
4546 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4548 purge
= CUPSD_JOB_DEFAULT
;
4551 * See if the job exists...
4554 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4557 * Nope - return a "not found" error...
4560 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
4565 * See if the job is owned by the requesting user...
4568 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4570 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4571 cupsdFindDest(job
->dest
));
4576 * See if the job is already completed, canceled, or aborted; if so,
4577 * we can't cancel...
4580 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4582 switch (job
->state_value
)
4584 case IPP_JOB_CANCELED
:
4585 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4586 _("Job #%d is already canceled - can\'t cancel."),
4590 case IPP_JOB_ABORTED
:
4591 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4592 _("Job #%d is already aborted - can\'t cancel."),
4597 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4598 _("Job #%d is already completed - can\'t cancel."),
4607 * Cancel the job and return...
4610 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4611 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4612 "Job canceled by \"%s\"",
4616 if (purge
== CUPSD_JOB_PURGE
)
4617 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4620 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4623 con
->response
->request
.status
.status_code
= IPP_OK
;
4628 * 'cancel_subscription()' - Cancel a subscription.
4632 cancel_subscription(
4633 cupsd_client_t
*con
, /* I - Client connection */
4634 int sub_id
) /* I - Subscription ID */
4636 http_status_t status
; /* Policy status */
4637 cupsd_subscription_t
*sub
; /* Subscription */
4640 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4641 "cancel_subscription(con=%p[%d], sub_id=%d)",
4642 con
, con
->http
.fd
, sub_id
);
4645 * Is the subscription ID valid?
4648 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4651 * Bad subscription ID...
4654 send_ipp_status(con
, IPP_NOT_FOUND
,
4655 _("notify-subscription-id %d no good"), sub_id
);
4663 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4665 con
, sub
->owner
)) != HTTP_OK
)
4667 send_http_error(con
, status
, sub
->dest
);
4672 * Cancel the subscription...
4675 cupsdDeleteSubscription(sub
, 1);
4677 con
->response
->request
.status
.status_code
= IPP_OK
;
4682 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4685 static int /* O - 1 if OK, 0 if not */
4686 check_rss_recipient(
4687 const char *recipient
) /* I - Recipient URI */
4689 cupsd_subscription_t
*sub
; /* Current subscription */
4692 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4694 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4698 * Compare the URIs up to the first ?...
4701 const char *r1
, *r2
;
4703 for (r1
= recipient
, r2
= sub
->recipient
;
4704 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4716 * 'check_quotas()' - Check quotas for a printer and user.
4719 static int /* O - 1 if OK, 0 if forbidden,
4720 -1 if limit reached */
4721 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4722 cupsd_printer_t
*p
) /* I - Printer or class */
4724 char username
[33], /* Username */
4725 *name
; /* Current user name */
4726 cupsd_quota_t
*q
; /* Quota data */
4727 #ifdef HAVE_MBR_UID_TO_UUID
4729 * Use Apple membership APIs which require that all names represent
4730 * valid user account or group records accessible by the server.
4733 uuid_t usr_uuid
; /* UUID for job requesting user */
4734 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4735 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4736 int mbr_err
; /* Error from membership function */
4737 int is_member
; /* Is this user a member? */
4740 * Use standard POSIX APIs for checking users and groups...
4743 struct passwd
*pw
; /* User password data */
4744 #endif /* HAVE_MBR_UID_TO_UUID */
4747 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4748 con
, con
->http
.fd
, p
, p
->name
);
4751 * Figure out who is printing...
4754 strlcpy(username
, get_username(con
), sizeof(username
));
4757 * Check global active job limits for printers and users...
4760 if (MaxJobsPerPrinter
)
4763 * Check if there are too many pending jobs on this printer...
4766 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4768 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4777 * Check if there are too many pending jobs for this user...
4780 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4782 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4789 * Check against users...
4792 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4795 if (cupsArrayCount(p
->users
))
4797 #ifdef HAVE_MBR_UID_TO_UUID
4799 * Get UUID for job requesting user...
4802 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4808 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4809 "check_quotas: UUID lookup failed for user \"%s\"",
4811 cupsdLogMessage(CUPSD_LOG_INFO
,
4812 "Denying user \"%s\" access to printer \"%s\" "
4813 "(unknown user)...",
4819 * Get UID and GID of requesting user...
4822 pw
= getpwnam(username
);
4824 #endif /* HAVE_MBR_UID_TO_UUID */
4826 for (name
= (char *)cupsArrayFirst(p
->users
);
4828 name
= (char *)cupsArrayNext(p
->users
))
4832 * Check group membership...
4835 #ifdef HAVE_MBR_UID_TO_UUID
4838 if (uuid_parse(name
+ 2, grp_uuid
))
4839 uuid_clear(grp_uuid
);
4841 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
4844 * Invalid ACL entries are ignored for matching; just record a
4845 * warning in the log...
4848 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4849 "check_quotas: UUID lookup failed for ACL entry "
4850 "\"%s\" (err=%d)", name
, mbr_err
);
4851 cupsdLogMessage(CUPSD_LOG_WARN
,
4852 "Access control entry \"%s\" not a valid group name; "
4853 "entry ignored", name
);
4856 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4860 * At this point, there should be no errors, but check anyways...
4863 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4864 "check_quotas: group \"%s\" membership check "
4865 "failed (err=%d)", name
+ 1, mbr_err
);
4870 * Stop if we found a match...
4877 if (cupsdCheckGroup(username
, pw
, name
+ 1))
4879 #endif /* HAVE_MBR_UID_TO_UUID */
4881 #ifdef HAVE_MBR_UID_TO_UUID
4886 if (uuid_parse(name
+ 1, usr2_uuid
))
4887 uuid_clear(usr2_uuid
);
4889 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
4892 * Invalid ACL entries are ignored for matching; just record a
4893 * warning in the log...
4896 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4897 "check_quotas: UUID lookup failed for ACL entry "
4898 "\"%s\" (err=%d)", name
, mbr_err
);
4899 cupsdLogMessage(CUPSD_LOG_WARN
,
4900 "Access control entry \"%s\" not a valid user name; "
4901 "entry ignored", name
);
4904 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4908 else if (!strcasecmp(username
, name
))
4910 #endif /* HAVE_MBR_UID_TO_UUID */
4912 if ((name
!= NULL
) == p
->deny_users
)
4914 cupsdLogMessage(CUPSD_LOG_INFO
,
4915 "Denying user \"%s\" access to printer \"%s\"...",
4925 if (p
->k_limit
|| p
->page_limit
)
4927 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4929 cupsdLogMessage(CUPSD_LOG_ERROR
,
4930 "Unable to allocate quota data for user \"%s\"",
4935 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4936 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4938 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4945 * If we have gotten this far, we're done!
4953 * 'close_job()' - Close a multi-file job.
4957 close_job(cupsd_client_t
*con
, /* I - Client connection */
4958 ipp_attribute_t
*uri
) /* I - Printer URI */
4960 cupsd_job_t
*job
; /* Job */
4961 ipp_attribute_t
*attr
; /* Attribute */
4962 char job_uri
[HTTP_MAX_URI
],
4964 username
[256]; /* User name */
4967 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4968 con
->http
.fd
, uri
->values
[0].string
.text
);
4971 * See if we have a job URI or a printer URI...
4974 if (strcmp(uri
->name
, "printer-uri"))
4977 * job-uri is not supported by Close-Job!
4980 send_ipp_status(con
, IPP_BAD_REQUEST
,
4981 _("Close-Job doesn't support the job-uri attribute."));
4986 * Got a printer URI; see if we also have a job-id attribute...
4989 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4990 IPP_TAG_INTEGER
)) == NULL
)
4992 send_ipp_status(con
, IPP_BAD_REQUEST
,
4993 _("Got a printer-uri attribute but no job-id"));
4997 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
5000 * Nope - return a "not found" error...
5003 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
5004 attr
->values
[0].integer
);
5009 * See if the job is owned by the requesting user...
5012 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
5014 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
5015 cupsdFindDest(job
->dest
));
5020 * Add any ending sheet...
5023 if (cupsdTimeoutJob(job
))
5026 if (job
->state_value
== IPP_JOB_STOPPED
)
5028 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5029 job
->state_value
= IPP_JOB_PENDING
;
5031 else if (job
->state_value
== IPP_JOB_HELD
)
5033 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
5034 IPP_TAG_KEYWORD
)) == NULL
)
5035 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
5037 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
5039 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5040 job
->state_value
= IPP_JOB_PENDING
;
5045 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
5048 * Fill in the response info...
5051 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
5052 LocalPort
, job
->id
);
5053 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
5056 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
5058 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
5061 add_job_state_reasons(con
, job
);
5063 con
->response
->request
.status
.status_code
= IPP_OK
;
5066 * Start the job if necessary...
5074 * 'copy_attribute()' - Copy a single attribute.
5077 static ipp_attribute_t
* /* O - New attribute */
5079 ipp_t
*to
, /* O - Destination request/response */
5080 ipp_attribute_t
*attr
, /* I - Attribute to copy */
5081 int quickcopy
) /* I - Do a quick copy? */
5083 int i
; /* Looping var */
5084 ipp_attribute_t
*toattr
; /* Destination attribute */
5087 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5088 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
5089 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
5092 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
5095 toattr
= ippAddSeparator(to
);
5098 case IPP_TAG_INTEGER
:
5100 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5101 attr
->name
, attr
->num_values
, NULL
);
5103 for (i
= 0; i
< attr
->num_values
; i
++)
5104 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
5107 case IPP_TAG_BOOLEAN
:
5108 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
5109 attr
->num_values
, NULL
);
5111 for (i
= 0; i
< attr
->num_values
; i
++)
5112 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
5115 case IPP_TAG_STRING
:
5118 case IPP_TAG_KEYWORD
:
5120 case IPP_TAG_URISCHEME
:
5121 case IPP_TAG_CHARSET
:
5122 case IPP_TAG_LANGUAGE
:
5123 case IPP_TAG_MIMETYPE
:
5124 toattr
= ippAddStrings(to
, attr
->group_tag
,
5125 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5126 attr
->name
, attr
->num_values
, NULL
, NULL
);
5130 for (i
= 0; i
< attr
->num_values
; i
++)
5131 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5133 else if (attr
->value_tag
& IPP_TAG_COPY
)
5135 for (i
= 0; i
< attr
->num_values
; i
++)
5136 toattr
->values
[i
].string
.text
=
5137 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5141 for (i
= 0; i
< attr
->num_values
; i
++)
5142 toattr
->values
[i
].string
.text
=
5143 _cupsStrRetain(attr
->values
[i
].string
.text
);
5148 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
5149 attr
->values
[0].date
);
5152 case IPP_TAG_RESOLUTION
:
5153 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
5154 attr
->num_values
, IPP_RES_PER_INCH
,
5157 for (i
= 0; i
< attr
->num_values
; i
++)
5159 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
5160 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
5161 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
5165 case IPP_TAG_RANGE
:
5166 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
5167 attr
->num_values
, NULL
, NULL
);
5169 for (i
= 0; i
< attr
->num_values
; i
++)
5171 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
5172 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
5176 case IPP_TAG_TEXTLANG
:
5177 case IPP_TAG_NAMELANG
:
5178 toattr
= ippAddStrings(to
, attr
->group_tag
,
5179 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5180 attr
->name
, attr
->num_values
, NULL
, NULL
);
5184 for (i
= 0; i
< attr
->num_values
; i
++)
5186 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
5187 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5190 else if (attr
->value_tag
& IPP_TAG_COPY
)
5192 for (i
= 0; i
< attr
->num_values
; i
++)
5195 toattr
->values
[i
].string
.charset
=
5196 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
5198 toattr
->values
[i
].string
.charset
=
5199 toattr
->values
[0].string
.charset
;
5201 toattr
->values
[i
].string
.text
=
5202 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5207 for (i
= 0; i
< attr
->num_values
; i
++)
5210 toattr
->values
[i
].string
.charset
=
5211 _cupsStrRetain(attr
->values
[i
].string
.charset
);
5213 toattr
->values
[i
].string
.charset
=
5214 toattr
->values
[0].string
.charset
;
5216 toattr
->values
[i
].string
.text
=
5217 _cupsStrRetain(attr
->values
[i
].string
.text
);
5222 case IPP_TAG_BEGIN_COLLECTION
:
5223 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
5224 attr
->num_values
, NULL
);
5226 for (i
= 0; i
< attr
->num_values
; i
++)
5228 toattr
->values
[i
].collection
= attr
->values
[i
].collection
;
5229 attr
->values
[i
].collection
->use
++;
5234 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5235 attr
->name
, attr
->num_values
, NULL
);
5237 for (i
= 0; i
< attr
->num_values
; i
++)
5239 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
5241 if (toattr
->values
[i
].unknown
.length
> 0)
5243 if ((toattr
->values
[i
].unknown
.data
=
5244 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
5245 toattr
->values
[i
].unknown
.length
= 0;
5247 memcpy(toattr
->values
[i
].unknown
.data
,
5248 attr
->values
[i
].unknown
.data
,
5249 toattr
->values
[i
].unknown
.length
);
5252 break; /* anti-compiler-warning-code */
5260 * 'copy_attrs()' - Copy attributes from one request to another.
5264 copy_attrs(ipp_t
*to
, /* I - Destination request */
5265 ipp_t
*from
, /* I - Source request */
5266 cups_array_t
*ra
, /* I - Requested attributes */
5267 ipp_tag_t group
, /* I - Group to copy */
5268 int quickcopy
, /* I - Do a quick copy? */
5269 cups_array_t
*exclude
) /* I - Attributes to exclude? */
5271 ipp_attribute_t
*fromattr
; /* Source attribute */
5274 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5275 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
5276 to
, from
, ra
, group
, quickcopy
);
5281 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
5284 * Filter attributes as needed...
5287 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
5288 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
5292 (cupsArrayFind(exclude
, fromattr
->name
) ||
5293 cupsArrayFind(exclude
, "all")))
5296 * We need to exclude this attribute for security reasons; we require the
5297 * job-id and job-printer-uri attributes regardless of the security
5298 * settings for IPP conformance.
5300 * Subscription attribute security is handled by copy_subscription_attrs().
5303 if (strcmp(fromattr
->name
, "job-id") &&
5304 strcmp(fromattr
->name
, "job-printer-uri"))
5308 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
5311 * Don't send collection attributes by default to IPP/1.x clients
5312 * since many do not support collections. Also don't send
5313 * media-col-database unless specifically requested by the client.
5316 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
5318 (to
->request
.status
.version
[0] == 1 ||
5319 !strcmp(fromattr
->name
, "media-col-database")))
5322 copy_attribute(to
, fromattr
, quickcopy
);
5329 * 'copy_banner()' - Copy a banner file to the requests directory for the
5333 static int /* O - Size of banner file in kbytes */
5334 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
5335 cupsd_job_t
*job
, /* I - Job information */
5336 const char *name
) /* I - Name of banner */
5338 int i
; /* Looping var */
5339 int kbytes
; /* Size of banner file in kbytes */
5340 char filename
[1024]; /* Job filename */
5341 cupsd_banner_t
*banner
; /* Pointer to banner */
5342 cups_file_t
*in
; /* Input file */
5343 cups_file_t
*out
; /* Output file */
5344 int ch
; /* Character from file */
5345 char attrname
[255], /* Name of attribute */
5346 *s
; /* Pointer into name */
5347 ipp_attribute_t
*attr
; /* Attribute */
5350 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5351 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
5352 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
5353 name
? name
: "(null)");
5356 * Find the banner; return if not found or "none"...
5359 if (!name
|| !strcmp(name
, "none") ||
5360 (banner
= cupsdFindBanner(name
)) == NULL
)
5364 * Open the banner and job files...
5367 if (add_file(con
, job
, banner
->filetype
, 0))
5370 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
5372 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
5374 cupsdLogMessage(CUPSD_LOG_ERROR
,
5375 "Unable to create banner job file %s - %s",
5376 filename
, strerror(errno
));
5381 fchmod(cupsFileNumber(out
), 0640);
5382 fchown(cupsFileNumber(out
), RunUser
, Group
);
5385 * Try the localized banner file under the subdirectory...
5388 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5390 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5393 * Convert ll-cc to ll_CC...
5397 attrname
[3] = toupper(attrname
[3] & 255);
5398 attrname
[4] = toupper(attrname
[4] & 255);
5401 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5404 if (access(filename
, 0) && strlen(attrname
) > 2)
5407 * Wasn't able to find "ll_CC" locale file; try the non-national
5408 * localization banner directory.
5413 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5417 if (access(filename
, 0))
5420 * Use the non-localized banner file.
5423 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5426 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5430 cupsdLogMessage(CUPSD_LOG_ERROR
,
5431 "Unable to open banner template file %s - %s",
5432 filename
, strerror(errno
));
5438 * Parse the file to the end...
5441 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5445 * Get an attribute name...
5448 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5449 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5451 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5461 * Ignore { followed by stuff that is not an attribute name...
5464 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5469 * See if it is defined...
5472 if (attrname
[0] == '?')
5477 if (!strcmp(s
, "printer-name"))
5479 cupsFilePuts(out
, job
->dest
);
5482 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5485 * See if we have a leading question mark...
5488 if (attrname
[0] != '?')
5491 * Nope, write to file as-is; probably a PostScript procedure...
5494 cupsFilePrintf(out
, "{%s}", attrname
);
5501 * Output value(s)...
5504 for (i
= 0; i
< attr
->num_values
; i
++)
5507 cupsFilePutChar(out
, ',');
5509 switch (attr
->value_tag
)
5511 case IPP_TAG_INTEGER
:
5513 if (!strncmp(s
, "time-at-", 8))
5515 struct timeval tv
; /* Time value */
5517 tv
.tv_sec
= attr
->values
[i
].integer
;
5520 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5523 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5526 case IPP_TAG_BOOLEAN
:
5527 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5530 case IPP_TAG_NOVALUE
:
5531 cupsFilePuts(out
, "novalue");
5534 case IPP_TAG_RANGE
:
5535 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5536 attr
->values
[i
].range
.upper
);
5539 case IPP_TAG_RESOLUTION
:
5540 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5541 attr
->values
[i
].resolution
.yres
,
5542 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5547 case IPP_TAG_STRING
:
5550 case IPP_TAG_KEYWORD
:
5551 case IPP_TAG_CHARSET
:
5552 case IPP_TAG_LANGUAGE
:
5553 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
5556 * Need to quote strings for PS banners...
5561 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5563 if (*p
== '(' || *p
== ')' || *p
== '\\')
5565 cupsFilePutChar(out
, '\\');
5566 cupsFilePutChar(out
, *p
);
5568 else if (*p
< 32 || *p
> 126)
5569 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5571 cupsFilePutChar(out
, *p
);
5575 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5579 break; /* anti-compiler-warning-code */
5583 else if (ch
== '\\') /* Quoted char */
5585 ch
= cupsFileGetChar(in
);
5587 if (ch
!= '{') /* Only do special handling for \{ */
5588 cupsFilePutChar(out
, '\\');
5590 cupsFilePutChar(out
, ch
);
5593 cupsFilePutChar(out
, ch
);
5597 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5599 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5600 IPP_TAG_INTEGER
)) != NULL
)
5601 attr
->values
[0].integer
+= kbytes
;
5610 * 'copy_file()' - Copy a PPD file or interface script...
5613 static int /* O - 0 = success, -1 = error */
5614 copy_file(const char *from
, /* I - Source file */
5615 const char *to
) /* I - Destination file */
5617 cups_file_t
*src
, /* Source file */
5618 *dst
; /* Destination file */
5619 int bytes
; /* Bytes to read/write */
5620 char buffer
[2048]; /* Copy buffer */
5623 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5626 * Open the source and destination file for a copy...
5629 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5632 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5639 * Copy the source file to the destination...
5642 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5643 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5651 * Close both files and return...
5656 return (cupsFileClose(dst
));
5661 * 'copy_model()' - Copy a PPD model file, substituting default values
5665 static int /* O - 0 = success, -1 = error */
5666 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5667 const char *from
, /* I - Source file */
5668 const char *to
) /* I - Destination file */
5670 fd_set input
; /* select() input set */
5671 struct timeval timeout
; /* select() timeout */
5672 int maxfd
; /* Max file descriptor for select() */
5673 char tempfile
[1024]; /* Temporary PPD file */
5674 int tempfd
; /* Temporary PPD file descriptor */
5675 int temppid
; /* Process ID of cups-driverd */
5676 int temppipe
[2]; /* Temporary pipes */
5677 char *argv
[4], /* Command-line arguments */
5678 *envp
[MAX_ENV
]; /* Environment */
5679 cups_file_t
*src
, /* Source file */
5680 *dst
; /* Destination file */
5681 ppd_file_t
*ppd
; /* PPD file */
5682 int bytes
, /* Bytes from pipe */
5683 total
; /* Total bytes from pipe */
5684 char buffer
[2048]; /* Copy buffer */
5685 int i
; /* Looping var */
5686 char option
[PPD_MAX_NAME
], /* Option name */
5687 choice
[PPD_MAX_NAME
]; /* Choice name */
5688 ppd_size_t
*size
; /* Default size */
5689 int num_defaults
; /* Number of default options */
5690 cups_option_t
*defaults
; /* Default options */
5691 char cups_protocol
[PPD_MAX_LINE
];
5692 /* cupsProtocol attribute */
5695 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5696 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5700 * Run cups-driverd to get the PPD file...
5703 argv
[0] = "cups-driverd";
5705 argv
[2] = (char *)from
;
5708 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5710 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5711 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5712 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5716 cupsdOpenPipe(temppipe
);
5718 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5719 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5721 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5722 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5733 * Wait up to 30 seconds for the PPD file to be copied...
5738 if (temppipe
[0] > CGIPipes
[0])
5739 maxfd
= temppipe
[0] + 1;
5741 maxfd
= CGIPipes
[0] + 1;
5746 * See if we have data ready...
5750 FD_SET(temppipe
[0], &input
);
5751 FD_SET(CGIPipes
[0], &input
);
5753 timeout
.tv_sec
= 30;
5754 timeout
.tv_usec
= 0;
5756 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5766 * We have timed out...
5772 if (FD_ISSET(temppipe
[0], &input
))
5775 * Read the PPD file from the pipe, and write it to the PPD file.
5778 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5780 if (write(tempfd
, buffer
, bytes
) < bytes
)
5789 if (FD_ISSET(CGIPipes
[0], &input
))
5799 * No data from cups-deviced...
5802 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5808 * Read the source file and see what page sizes are supported...
5811 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5818 * Open the destination (if possible) and set the default options...
5823 cups_protocol
[0] = '\0';
5825 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5828 * Read all of the default lines from the old PPD...
5831 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5832 if (!strncmp(buffer
, "*Default", 8))
5835 * Add the default option...
5838 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5839 choice
, sizeof(choice
)))
5841 ppd_option_t
*ppdo
; /* PPD option */
5845 * Only add the default if the default hasn't already been
5846 * set and the choice exists in the new PPD...
5849 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5850 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5851 ppdFindChoice(ppdo
, choice
))
5852 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5856 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5857 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5861 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5864 * Add the default media sizes...
5867 num_defaults
= cupsAddOption("PageSize", size
->name
,
5868 num_defaults
, &defaults
);
5869 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5870 num_defaults
, &defaults
);
5871 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5872 num_defaults
, &defaults
);
5873 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5874 num_defaults
, &defaults
);
5880 * Open the source file for a copy...
5883 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5885 cupsFreeOptions(num_defaults
, defaults
);
5891 * Open the destination file for a copy...
5894 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5896 cupsFreeOptions(num_defaults
, defaults
);
5903 * Copy the source file to the destination...
5906 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5908 if (!strncmp(buffer
, "*Default", 8))
5911 * Check for an previous default option choice...
5914 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5915 choice
, sizeof(choice
)))
5917 const char *val
; /* Default option value */
5920 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5923 * Substitute the previous choice...
5926 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5931 cupsFilePrintf(dst
, "%s\n", buffer
);
5934 if (cups_protocol
[0])
5935 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5937 cupsFreeOptions(num_defaults
, defaults
);
5940 * Close both files and return...
5947 return (cupsFileClose(dst
));
5952 * 'copy_job_attrs()' - Copy job attributes.
5956 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5957 cupsd_job_t
*job
, /* I - Job */
5958 cups_array_t
*ra
, /* I - Requested attributes array */
5959 cups_array_t
*exclude
) /* I - Private attributes array */
5961 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5965 * Send the requested attributes for each job...
5968 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5969 con
->servername
, con
->serverport
, "/jobs/%d",
5972 if (!cupsArrayFind(exclude
, "all"))
5974 if ((!exclude
|| !cupsArrayFind(exclude
, "document-count")) &&
5975 (!ra
|| cupsArrayFind(ra
, "document-count")))
5976 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5977 "document-count", job
->num_files
);
5979 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
5980 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
5981 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5982 "job-media-progress", job
->progress
);
5984 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
5985 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
5986 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5987 "job-more-info", NULL
, job_uri
);
5989 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5990 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
5991 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5992 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5993 job
->num_files
> 0);
5995 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
5996 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
5997 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5998 "job-printer-up-time", time(NULL
));
6001 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
6002 add_job_state_reasons(con
, job
);
6004 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
6005 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
6006 "job-uri", NULL
, job_uri
);
6008 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
6013 * 'copy_printer_attrs()' - Copy printer attributes.
6018 cupsd_client_t
*con
, /* I - Client connection */
6019 cupsd_printer_t
*printer
, /* I - Printer */
6020 cups_array_t
*ra
) /* I - Requested attributes array */
6022 char printer_uri
[HTTP_MAX_URI
];
6024 char printer_icons
[HTTP_MAX_URI
];
6026 time_t curtime
; /* Current time */
6027 int i
; /* Looping var */
6028 ipp_attribute_t
*history
; /* History collection */
6032 * Copy the printer attributes to the response using requested-attributes
6033 * and document-format attributes that may be provided by the client.
6036 curtime
= time(NULL
);
6038 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
6039 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6040 "marker-change-time", printer
->marker_time
);
6042 if (printer
->num_printers
> 0 &&
6043 (!ra
|| cupsArrayFind(ra
, "member-uris")))
6045 ipp_attribute_t
*member_uris
; /* member-uris attribute */
6046 cupsd_printer_t
*p2
; /* Printer in class */
6047 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
6050 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
6051 IPP_TAG_URI
, "member-uris",
6052 printer
->num_printers
, NULL
,
6055 for (i
= 0; i
< printer
->num_printers
; i
++)
6057 p2
= printer
->printers
[i
];
6059 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
6060 IPP_TAG_URI
)) != NULL
)
6061 member_uris
->values
[i
].string
.text
=
6062 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
6065 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
6066 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
6068 (p2
->type
& CUPS_PRINTER_CLASS
) ?
6069 "/classes/%s" : "/printers/%s", p2
->name
);
6070 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
6076 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
6077 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
6078 "printer-alert", NULL
, printer
->alert
);
6080 if (printer
->alert_description
&&
6081 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
6082 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
6083 "printer-alert-description", NULL
,
6084 printer
->alert_description
);
6086 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
6087 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
6088 ippTimeToDate(curtime
));
6091 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
6093 if (printer
->reg_name
)
6094 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6095 "printer-dns-sd-name", NULL
, printer
->reg_name
);
6097 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
6098 "printer-dns-sd-name", 0);
6100 #endif /* HAVE_DNSSD */
6102 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
6103 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6104 "printer-error-policy", NULL
, printer
->error_policy
);
6106 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
6108 static const char * const errors
[] =/* printer-error-policy-supported values */
6111 "retry-current-job",
6116 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
6117 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6118 "printer-error-policy-supported", NULL
, "retry-current-job");
6120 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6121 "printer-error-policy-supported",
6122 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
6125 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
6127 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
6128 "http", NULL
, con
->servername
, con
->serverport
,
6129 "/icons/%s.png", printer
->name
);
6130 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
6131 NULL
, printer_icons
);
6132 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
6135 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
6136 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
6137 printer
->accepting
);
6139 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
6140 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
6143 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
6144 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6146 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6147 "http", NULL
, con
->servername
, con
->serverport
,
6148 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6149 "/classes/%s" : "/printers/%s", printer
->name
);
6150 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6151 "printer-more-info", NULL
, printer_uri
);
6154 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
6155 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6156 "printer-op-policy", NULL
, printer
->op_policy
);
6158 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
6159 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
6162 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
6163 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6164 "printer-state-change-time", printer
->state_time
);
6166 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
6167 cupsArrayFind(ra
, "printer-state-history"))
6170 * Printer history is only sent if specifically requested, so that
6171 * older CUPS/IPP clients won't barf on the collection attributes.
6174 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
6175 "printer-state-history",
6176 printer
->num_history
, NULL
);
6178 for (i
= 0; i
< printer
->num_history
; i
++)
6179 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
6180 NULL
, IPP_TAG_ZERO
, 0, NULL
);
6183 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
6184 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
6185 "printer-state-message", NULL
, printer
->state_message
);
6187 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
6188 add_printer_state_reasons(con
, printer
);
6190 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
6192 int type
; /* printer-type value */
6196 * Add the CUPS-specific printer-type attribute...
6199 type
= printer
->type
;
6201 if (printer
== DefaultPrinter
)
6202 type
|= CUPS_PRINTER_DEFAULT
;
6204 if (!printer
->accepting
)
6205 type
|= CUPS_PRINTER_REJECTING
;
6207 if (!printer
->shared
)
6208 type
|= CUPS_PRINTER_NOT_SHARED
;
6210 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
6214 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
6215 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6216 "printer-up-time", curtime
);
6218 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
6219 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6221 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6222 "ipp", NULL
, con
->servername
, con
->serverport
,
6223 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6224 "/classes/%s" : "/printers/%s", printer
->name
);
6225 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6226 "printer-uri-supported", NULL
, printer_uri
);
6227 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
6231 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
6232 add_queued_job_count(con
, printer
);
6234 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6235 if (printer
->ppd_attrs
)
6236 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6237 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
6242 * 'copy_subscription_attrs()' - Copy subscription attributes.
6246 copy_subscription_attrs(
6247 cupsd_client_t
*con
, /* I - Client connection */
6248 cupsd_subscription_t
*sub
, /* I - Subscription */
6249 cups_array_t
*ra
, /* I - Requested attributes array */
6250 cups_array_t
*exclude
) /* I - Private attributes array */
6252 ipp_attribute_t
*attr
; /* Current attribute */
6253 char printer_uri
[HTTP_MAX_URI
];
6255 int count
; /* Number of events */
6256 unsigned mask
; /* Current event mask */
6257 const char *name
; /* Current event name */
6260 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6261 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
6262 con
, sub
, ra
, exclude
);
6265 * Copy the subscription attributes to the response using the
6266 * requested-attributes attribute that may be provided by the client.
6269 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
6271 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
6272 (!ra
|| cupsArrayFind(ra
, "notify-events")))
6274 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
6276 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
6279 * Simple event list...
6282 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
6283 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6284 "notify-events", NULL
, name
);
6289 * Complex event list...
6292 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6293 if (sub
->mask
& mask
)
6296 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
6297 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6298 "notify-events", count
, NULL
, NULL
);
6300 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6301 if (sub
->mask
& mask
)
6303 attr
->values
[count
].string
.text
=
6304 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
6311 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
6312 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
6313 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6314 "notify-lease-duration", sub
->lease
);
6316 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
6317 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
6318 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6319 "notify-recipient-uri", NULL
, sub
->recipient
);
6320 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
6321 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
6322 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
6323 "notify-pull-method", NULL
, "ippget");
6325 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
6326 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
6327 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
6328 "notify-subscriber-user-name", NULL
, sub
->owner
);
6330 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
6331 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
6332 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6333 "notify-time-interval", sub
->interval
);
6335 if (sub
->user_data_len
> 0 &&
6336 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
6337 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
6338 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
6339 sub
->user_data
, sub
->user_data_len
);
6342 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
6343 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6344 "notify-job-id", sub
->job
->id
);
6346 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
6348 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6349 "ipp", NULL
, con
->servername
, con
->serverport
,
6350 "/printers/%s", sub
->dest
->name
);
6351 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6352 "notify-printer-uri", NULL
, printer_uri
);
6355 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
6356 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6357 "notify-subscription-id", sub
->id
);
6362 * 'create_job()' - Print a file to a printer or class.
6366 create_job(cupsd_client_t
*con
, /* I - Client connection */
6367 ipp_attribute_t
*uri
) /* I - Printer URI */
6369 cupsd_printer_t
*printer
; /* Printer */
6370 cupsd_job_t
*job
; /* New job */
6373 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
6374 con
->http
.fd
, uri
->values
[0].string
.text
);
6377 * Is the destination valid?
6380 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6386 send_ipp_status(con
, IPP_NOT_FOUND
,
6387 _("The printer or class was not found."));
6392 * Create the job object...
6395 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6398 job
->pending_timeout
= 1;
6401 * Save and log the job...
6404 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6405 job
->dest
, job
->username
);
6410 * 'create_requested_array()' - Create an array for the requested-attributes.
6413 static cups_array_t
* /* O - Array of attributes or NULL */
6414 create_requested_array(ipp_t
*request
) /* I - IPP request */
6416 int i
; /* Looping var */
6417 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6418 cups_array_t
*ra
; /* Requested attributes array */
6419 char *value
; /* Current value */
6423 * Get the requested-attributes attribute, and return NULL if we don't
6427 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6428 IPP_TAG_KEYWORD
)) == NULL
)
6432 * If the attribute contains a single "all" keyword, return NULL...
6435 if (requested
->num_values
== 1 &&
6436 !strcmp(requested
->values
[0].string
.text
, "all"))
6440 * Create an array using "strcmp" as the comparison function...
6443 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6445 for (i
= 0; i
< requested
->num_values
; i
++)
6447 value
= requested
->values
[i
].string
.text
;
6449 if (!strcmp(value
, "job-template"))
6451 cupsArrayAdd(ra
, "copies");
6452 cupsArrayAdd(ra
, "copies-default");
6453 cupsArrayAdd(ra
, "copies-supported");
6454 cupsArrayAdd(ra
, "finishings");
6455 cupsArrayAdd(ra
, "finishings-default");
6456 cupsArrayAdd(ra
, "finishings-supported");
6457 cupsArrayAdd(ra
, "job-hold-until");
6458 cupsArrayAdd(ra
, "job-hold-until-default");
6459 cupsArrayAdd(ra
, "job-hold-until-supported");
6460 cupsArrayAdd(ra
, "job-priority");
6461 cupsArrayAdd(ra
, "job-priority-default");
6462 cupsArrayAdd(ra
, "job-priority-supported");
6463 cupsArrayAdd(ra
, "job-sheets");
6464 cupsArrayAdd(ra
, "job-sheets-default");
6465 cupsArrayAdd(ra
, "job-sheets-supported");
6466 cupsArrayAdd(ra
, "media");
6467 cupsArrayAdd(ra
, "media-default");
6468 cupsArrayAdd(ra
, "media-supported");
6469 cupsArrayAdd(ra
, "multiple-document-handling");
6470 cupsArrayAdd(ra
, "multiple-document-handling-default");
6471 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6472 cupsArrayAdd(ra
, "number-up");
6473 cupsArrayAdd(ra
, "number-up-default");
6474 cupsArrayAdd(ra
, "number-up-supported");
6475 cupsArrayAdd(ra
, "orientation-requested");
6476 cupsArrayAdd(ra
, "orientation-requested-default");
6477 cupsArrayAdd(ra
, "orientation-requested-supported");
6478 cupsArrayAdd(ra
, "page-ranges");
6479 cupsArrayAdd(ra
, "page-ranges-supported");
6480 cupsArrayAdd(ra
, "printer-resolution");
6481 cupsArrayAdd(ra
, "printer-resolution-default");
6482 cupsArrayAdd(ra
, "printer-resolution-supported");
6483 cupsArrayAdd(ra
, "print-quality");
6484 cupsArrayAdd(ra
, "print-quality-default");
6485 cupsArrayAdd(ra
, "print-quality-supported");
6486 cupsArrayAdd(ra
, "sides");
6487 cupsArrayAdd(ra
, "sides-default");
6488 cupsArrayAdd(ra
, "sides-supported");
6490 else if (!strcmp(value
, "job-description"))
6492 cupsArrayAdd(ra
, "date-time-at-completed");
6493 cupsArrayAdd(ra
, "date-time-at-creation");
6494 cupsArrayAdd(ra
, "date-time-at-processing");
6495 cupsArrayAdd(ra
, "job-detailed-status-message");
6496 cupsArrayAdd(ra
, "job-document-access-errors");
6497 cupsArrayAdd(ra
, "job-id");
6498 cupsArrayAdd(ra
, "job-impressions");
6499 cupsArrayAdd(ra
, "job-impressions-completed");
6500 cupsArrayAdd(ra
, "job-k-octets");
6501 cupsArrayAdd(ra
, "job-k-octets-processed");
6502 cupsArrayAdd(ra
, "job-media-progress");
6503 cupsArrayAdd(ra
, "job-media-sheets");
6504 cupsArrayAdd(ra
, "job-media-sheets-completed");
6505 cupsArrayAdd(ra
, "job-message-from-operator");
6506 cupsArrayAdd(ra
, "job-more-info");
6507 cupsArrayAdd(ra
, "job-name");
6508 cupsArrayAdd(ra
, "job-originating-user-name");
6509 cupsArrayAdd(ra
, "job-printer-up-time");
6510 cupsArrayAdd(ra
, "job-printer-uri");
6511 cupsArrayAdd(ra
, "job-state");
6512 cupsArrayAdd(ra
, "job-state-message");
6513 cupsArrayAdd(ra
, "job-state-reasons");
6514 cupsArrayAdd(ra
, "job-uri");
6515 cupsArrayAdd(ra
, "number-of-documents");
6516 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6517 cupsArrayAdd(ra
, "output-device-assigned");
6518 cupsArrayAdd(ra
, "time-at-completed");
6519 cupsArrayAdd(ra
, "time-at-creation");
6520 cupsArrayAdd(ra
, "time-at-processing");
6522 else if (!strcmp(value
, "printer-description"))
6524 cupsArrayAdd(ra
, "charset-configured");
6525 cupsArrayAdd(ra
, "charset-supported");
6526 cupsArrayAdd(ra
, "color-supported");
6527 cupsArrayAdd(ra
, "compression-supported");
6528 cupsArrayAdd(ra
, "document-format-default");
6529 cupsArrayAdd(ra
, "document-format-supported");
6530 cupsArrayAdd(ra
, "generated-natural-language-supported");
6531 cupsArrayAdd(ra
, "ipp-versions-supported");
6532 cupsArrayAdd(ra
, "job-impressions-supported");
6533 cupsArrayAdd(ra
, "job-k-octets-supported");
6534 cupsArrayAdd(ra
, "job-media-sheets-supported");
6535 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6536 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6537 cupsArrayAdd(ra
, "multiple-operation-time-out");
6538 cupsArrayAdd(ra
, "natural-language-configured");
6539 cupsArrayAdd(ra
, "notify-attributes-supported");
6540 cupsArrayAdd(ra
, "notify-lease-duration-default");
6541 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6542 cupsArrayAdd(ra
, "notify-max-events-supported");
6543 cupsArrayAdd(ra
, "notify-events-default");
6544 cupsArrayAdd(ra
, "notify-events-supported");
6545 cupsArrayAdd(ra
, "notify-pull-method-supported");
6546 cupsArrayAdd(ra
, "notify-schemes-supported");
6547 cupsArrayAdd(ra
, "operations-supported");
6548 cupsArrayAdd(ra
, "pages-per-minute");
6549 cupsArrayAdd(ra
, "pages-per-minute-color");
6550 cupsArrayAdd(ra
, "pdl-override-supported");
6551 cupsArrayAdd(ra
, "printer-alert");
6552 cupsArrayAdd(ra
, "printer-alert-description");
6553 cupsArrayAdd(ra
, "printer-commands");
6554 cupsArrayAdd(ra
, "printer-current-time");
6555 cupsArrayAdd(ra
, "printer-driver-installer");
6556 cupsArrayAdd(ra
, "printer-dns-sd-name");
6557 cupsArrayAdd(ra
, "printer-info");
6558 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6559 cupsArrayAdd(ra
, "printer-location");
6560 cupsArrayAdd(ra
, "printer-make-and-model");
6561 cupsArrayAdd(ra
, "printer-message-from-operator");
6562 cupsArrayAdd(ra
, "printer-more-info");
6563 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6564 cupsArrayAdd(ra
, "printer-name");
6565 cupsArrayAdd(ra
, "printer-state");
6566 cupsArrayAdd(ra
, "printer-state-message");
6567 cupsArrayAdd(ra
, "printer-state-reasons");
6568 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6569 cupsArrayAdd(ra
, "printer-type");
6570 cupsArrayAdd(ra
, "printer-up-time");
6571 cupsArrayAdd(ra
, "printer-uri-supported");
6572 cupsArrayAdd(ra
, "queued-job-count");
6573 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6574 cupsArrayAdd(ra
, "uri-authentication-supported");
6575 cupsArrayAdd(ra
, "uri-security-supported");
6577 else if (!strcmp(value
, "printer-defaults"))
6579 char *name
; /* Option name */
6582 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6584 name
= (char *)cupsArrayNext(CommonDefaults
))
6585 cupsArrayAdd(ra
, name
);
6587 else if (!strcmp(value
, "subscription-template"))
6589 cupsArrayAdd(ra
, "notify-attributes");
6590 cupsArrayAdd(ra
, "notify-charset");
6591 cupsArrayAdd(ra
, "notify-events");
6592 cupsArrayAdd(ra
, "notify-lease-duration");
6593 cupsArrayAdd(ra
, "notify-natural-language");
6594 cupsArrayAdd(ra
, "notify-pull-method");
6595 cupsArrayAdd(ra
, "notify-recipient-uri");
6596 cupsArrayAdd(ra
, "notify-time-interval");
6597 cupsArrayAdd(ra
, "notify-user-data");
6600 cupsArrayAdd(ra
, value
);
6608 * 'create_subscription()' - Create a notification subscription.
6612 create_subscription(
6613 cupsd_client_t
*con
, /* I - Client connection */
6614 ipp_attribute_t
*uri
) /* I - Printer URI */
6616 http_status_t status
; /* Policy status */
6617 int i
; /* Looping var */
6618 ipp_attribute_t
*attr
; /* Current attribute */
6619 cups_ptype_t dtype
; /* Destination type (printer/class) */
6620 char scheme
[HTTP_MAX_URI
],
6621 /* Scheme portion of URI */
6622 userpass
[HTTP_MAX_URI
],
6623 /* Username portion of URI */
6625 /* Host portion of URI */
6626 resource
[HTTP_MAX_URI
];
6627 /* Resource portion of URI */
6628 int port
; /* Port portion of URI */
6629 cupsd_printer_t
*printer
; /* Printer/class */
6630 cupsd_job_t
*job
; /* Job */
6631 int jobid
; /* Job ID */
6632 cupsd_subscription_t
*sub
; /* Subscription object */
6633 const char *username
, /* requesting-user-name or
6634 authenticated username */
6635 *recipient
, /* notify-recipient-uri */
6636 *pullmethod
; /* notify-pull-method */
6637 ipp_attribute_t
*user_data
; /* notify-user-data */
6638 int interval
, /* notify-time-interval */
6639 lease
; /* notify-lease-duration */
6640 unsigned mask
; /* notify-events */
6641 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6642 *notify_lease
; /* notify-lease-duration(-default) */
6646 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6648 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6649 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6650 attr
->value_tag
, attr
->name
);
6652 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6657 * Is the destination valid?
6660 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6661 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6662 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6664 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6665 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6666 sizeof(host
), &port
, resource
, sizeof(resource
));
6668 if (!strcmp(resource
, "/"))
6670 dtype
= (cups_ptype_t
)0;
6673 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6675 dtype
= (cups_ptype_t
)0;
6678 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6680 dtype
= CUPS_PRINTER_CLASS
;
6683 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6689 send_ipp_status(con
, IPP_NOT_FOUND
,
6690 _("The printer or class was not found."));
6700 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6703 send_http_error(con
, status
, printer
);
6707 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6709 send_http_error(con
, status
, NULL
);
6714 * Get the user that is requesting the subscription...
6717 username
= get_username(con
);
6720 * Find the first subscription group attribute; return if we have
6724 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6725 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6730 send_ipp_status(con
, IPP_BAD_REQUEST
,
6731 _("No subscription attributes in request"));
6736 * Process the subscription attributes in the request...
6739 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6747 lease
= DefaultLeaseDuration
;
6749 mask
= CUPSD_EVENT_NONE
;
6753 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6755 notify_lease
= ippFindAttribute(printer
->attrs
,
6756 "notify-lease-duration-default",
6760 lease
= notify_lease
->values
[0].integer
;
6764 notify_events
= NULL
;
6765 notify_lease
= NULL
;
6768 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6770 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6771 attr
->value_tag
== IPP_TAG_URI
)
6774 * Validate the recipient scheme against the ServerBin/notifier
6778 char notifier
[1024]; /* Notifier filename */
6781 recipient
= attr
->values
[0].string
.text
;
6783 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6784 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6785 host
, sizeof(host
), &port
,
6786 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6788 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6789 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
6790 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6791 "notify-status-code", IPP_URI_SCHEME
);
6795 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6797 if (access(notifier
, X_OK
))
6799 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6800 _("notify-recipient-uri URI \"%s\" uses unknown "
6801 "scheme"), recipient
);
6802 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6803 "notify-status-code", IPP_URI_SCHEME
);
6807 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6809 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6810 _("notify-recipient-uri URI \"%s\" is already used"),
6812 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6813 "notify-status-code", IPP_ATTRIBUTES
);
6817 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6818 attr
->value_tag
== IPP_TAG_KEYWORD
)
6820 pullmethod
= attr
->values
[0].string
.text
;
6822 if (strcmp(pullmethod
, "ippget"))
6824 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6825 _("Bad notify-pull-method \"%s\""), pullmethod
);
6826 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6827 "notify-status-code", IPP_ATTRIBUTES
);
6831 else if (!strcmp(attr
->name
, "notify-charset") &&
6832 attr
->value_tag
== IPP_TAG_CHARSET
&&
6833 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6834 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6836 send_ipp_status(con
, IPP_CHARSET
,
6837 _("Character set \"%s\" not supported"),
6838 attr
->values
[0].string
.text
);
6841 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6842 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6843 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6845 send_ipp_status(con
, IPP_CHARSET
,
6846 _("Language \"%s\" not supported"),
6847 attr
->values
[0].string
.text
);
6850 else if (!strcmp(attr
->name
, "notify-user-data") &&
6851 attr
->value_tag
== IPP_TAG_STRING
)
6853 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6855 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6856 _("The notify-user-data value is too large "
6857 "(%d > 63 octets)"),
6858 attr
->values
[0].unknown
.length
);
6864 else if (!strcmp(attr
->name
, "notify-events") &&
6865 attr
->value_tag
== IPP_TAG_KEYWORD
)
6866 notify_events
= attr
;
6867 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6868 attr
->value_tag
== IPP_TAG_INTEGER
)
6869 lease
= attr
->values
[0].integer
;
6870 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6871 attr
->value_tag
== IPP_TAG_INTEGER
)
6872 interval
= attr
->values
[0].integer
;
6873 else if (!strcmp(attr
->name
, "notify-job-id") &&
6874 attr
->value_tag
== IPP_TAG_INTEGER
)
6875 jobid
= attr
->values
[0].integer
;
6882 for (i
= 0; i
< notify_events
->num_values
; i
++)
6883 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6887 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6889 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6890 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6891 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6893 if (!recipient
&& !pullmethod
)
6896 if (mask
== CUPSD_EVENT_NONE
)
6899 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6901 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6904 send_ipp_status(con
, IPP_BAD_REQUEST
,
6905 _("notify-events not specified"));
6910 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6912 cupsdLogMessage(CUPSD_LOG_INFO
,
6913 "create_subscription: Limiting notify-lease-duration to "
6916 lease
= MaxLeaseDuration
;
6921 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6923 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found"), jobid
);
6930 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6932 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6933 _("There are too many subscriptions."));
6938 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6941 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6942 "Added subscription %d for printer \"%s\"",
6943 sub
->id
, printer
->name
);
6945 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6948 sub
->interval
= interval
;
6950 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6952 cupsdSetString(&sub
->owner
, username
);
6956 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6957 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6958 sub
->user_data_len
);
6961 ippAddSeparator(con
->response
);
6962 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6963 "notify-subscription-id", sub
->id
);
6965 con
->response
->request
.status
.status_code
= IPP_OK
;
6971 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6976 * 'delete_printer()' - Remove a printer or class from the system.
6980 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6981 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6983 http_status_t status
; /* Policy status */
6984 cups_ptype_t dtype
; /* Destination type (printer/class) */
6985 cupsd_printer_t
*printer
; /* Printer/class */
6986 char filename
[1024]; /* Script/PPD filename */
6989 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6990 con
->http
.fd
, uri
->values
[0].string
.text
);
6993 * Do we have a valid URI?
6996 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7002 send_ipp_status(con
, IPP_NOT_FOUND
,
7003 _("The printer or class was not found."));
7011 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7013 send_http_error(con
, status
, NULL
);
7018 * Remove old jobs...
7021 cupsdCancelJobs(printer
->name
, NULL
, 1);
7024 * Remove old subscriptions and send a "deleted printer" event...
7027 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
7028 "%s \"%s\" deleted by \"%s\".",
7029 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
7030 printer
->name
, get_username(con
));
7032 cupsdExpireSubscriptions(printer
, NULL
);
7035 * Remove any old PPD or script files...
7038 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
7042 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7046 snprintf(filename
, sizeof(filename
), "%s/%s.ipp4", CacheDir
, printer
->name
);
7049 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
7052 snprintf(filename
, sizeof(filename
), "%s/%s.pwg3", CacheDir
, printer
->name
);
7057 * Unregister color profiles...
7060 apple_unregister_profiles(printer
);
7061 #endif /* __APPLE__ */
7063 if (dtype
& CUPS_PRINTER_CLASS
)
7065 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
7066 printer
->name
, get_username(con
));
7068 cupsdDeletePrinter(printer
, 0);
7069 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7073 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
7074 printer
->name
, get_username(con
));
7076 if (cupsdDeletePrinter(printer
, 0))
7077 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7079 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
7082 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
7085 * Return with no errors...
7088 con
->response
->request
.status
.status_code
= IPP_OK
;
7093 * 'get_default()' - Get the default destination.
7097 get_default(cupsd_client_t
*con
) /* I - Client connection */
7099 http_status_t status
; /* Policy status */
7100 cups_array_t
*ra
; /* Requested attributes array */
7103 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
7109 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7111 send_http_error(con
, status
, NULL
);
7117 ra
= create_requested_array(con
->request
);
7119 copy_printer_attrs(con
, DefaultPrinter
, ra
);
7121 cupsArrayDelete(ra
);
7123 con
->response
->request
.status
.status_code
= IPP_OK
;
7126 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
7131 * 'get_devices()' - Get the list of available devices on the local system.
7135 get_devices(cupsd_client_t
*con
) /* I - Client connection */
7137 http_status_t status
; /* Policy status */
7138 ipp_attribute_t
*limit
, /* limit attribute */
7139 *timeout
, /* timeout attribute */
7140 *requested
, /* requested-attributes attribute */
7141 *exclude
, /* exclude-schemes attribute */
7142 *include
; /* include-schemes attribute */
7143 char command
[1024], /* cups-deviced command */
7144 options
[2048], /* Options to pass to command */
7146 /* String for requested attributes */
7148 /* String for excluded schemes */
7150 /* String for included schemes */
7153 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
7159 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7161 send_http_error(con
, status
, NULL
);
7166 * Run cups-deviced command with the given options...
7169 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7170 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
7171 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7173 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
7174 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
7177 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7179 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7182 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7184 exclude_str
[0] = '\0';
7187 url_encode_attr(include
, include_str
, sizeof(include_str
));
7189 include_str
[0] = '\0';
7191 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
7192 snprintf(options
, sizeof(options
),
7193 "%d+%d+%d+%d+%s%s%s%s%s",
7194 con
->request
->request
.op
.request_id
,
7195 limit
? limit
->values
[0].integer
: 0,
7196 timeout
? timeout
->values
[0].integer
: 15,
7199 exclude_str
[0] ? "%20" : "", exclude_str
,
7200 include_str
[0] ? "%20" : "", include_str
);
7202 if (cupsdSendCommand(con
, command
, options
, 1))
7205 * Command started successfully, don't send an IPP response here...
7208 ippDelete(con
->response
);
7209 con
->response
= NULL
;
7214 * Command failed, return "internal error" so the user knows something
7218 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7219 _("cups-deviced failed to execute."));
7225 * 'get_document()' - Get a copy of a job file.
7229 get_document(cupsd_client_t
*con
, /* I - Client connection */
7230 ipp_attribute_t
*uri
) /* I - Job URI */
7232 http_status_t status
; /* Policy status */
7233 ipp_attribute_t
*attr
; /* Current attribute */
7234 int jobid
; /* Job ID */
7235 int docnum
; /* Document number */
7236 cupsd_job_t
*job
; /* Current job */
7237 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7238 username
[HTTP_MAX_URI
], /* Username portion of URI */
7239 host
[HTTP_MAX_URI
], /* Host portion of URI */
7240 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7241 int port
; /* Port portion of URI */
7242 char filename
[1024], /* Filename for document */
7243 format
[1024]; /* Format for document */
7246 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
7247 con
->http
.fd
, uri
->values
[0].string
.text
);
7250 * See if we have a job URI or a printer URI...
7253 if (!strcmp(uri
->name
, "printer-uri"))
7256 * Got a printer URI; see if we also have a job-id attribute...
7259 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7260 IPP_TAG_INTEGER
)) == NULL
)
7262 send_ipp_status(con
, IPP_BAD_REQUEST
,
7263 _("Got a printer-uri attribute but no job-id"));
7267 jobid
= attr
->values
[0].integer
;
7272 * Got a job URI; parse it to get the job ID...
7275 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7276 sizeof(scheme
), username
, sizeof(username
), host
,
7277 sizeof(host
), &port
, resource
, sizeof(resource
));
7279 if (strncmp(resource
, "/jobs/", 6))
7285 send_ipp_status(con
, IPP_BAD_REQUEST
,
7286 _("Bad job-uri attribute \"%s\""),
7287 uri
->values
[0].string
.text
);
7291 jobid
= atoi(resource
+ 6);
7295 * See if the job exists...
7298 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7301 * Nope - return a "not found" error...
7304 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
7312 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
7313 job
->username
)) != HTTP_OK
)
7315 send_http_error(con
, status
, NULL
);
7320 * Get the document number...
7323 if ((attr
= ippFindAttribute(con
->request
, "document-number",
7324 IPP_TAG_INTEGER
)) == NULL
)
7326 send_ipp_status(con
, IPP_BAD_REQUEST
,
7327 _("Missing document-number attribute"));
7331 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
7332 attr
->num_values
> 1)
7334 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
7339 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
7341 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
7343 cupsdLogMessage(CUPSD_LOG_ERROR
,
7344 "Unable to open document %d in job %d - %s", docnum
, jobid
,
7346 send_ipp_status(con
, IPP_NOT_FOUND
,
7347 _("Unable to open document %d in job %d"), docnum
, jobid
);
7351 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7355 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
7356 job
->filetypes
[docnum
- 1]->type
);
7358 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
7360 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
7362 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
7363 IPP_TAG_NAME
)) != NULL
)
7364 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
7365 NULL
, attr
->values
[0].string
.text
);
7370 * 'get_job_attrs()' - Get job attributes.
7374 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
7375 ipp_attribute_t
*uri
) /* I - Job URI */
7377 http_status_t status
; /* Policy status */
7378 ipp_attribute_t
*attr
; /* Current attribute */
7379 int jobid
; /* Job ID */
7380 cupsd_job_t
*job
; /* Current job */
7381 cupsd_printer_t
*printer
; /* Current printer */
7382 cupsd_policy_t
*policy
; /* Current security policy */
7383 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7384 username
[HTTP_MAX_URI
], /* Username portion of URI */
7385 host
[HTTP_MAX_URI
], /* Host portion of URI */
7386 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7387 int port
; /* Port portion of URI */
7388 cups_array_t
*ra
, /* Requested attributes array */
7389 *exclude
; /* Private attributes array */
7392 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7393 con
->http
.fd
, uri
->values
[0].string
.text
);
7396 * See if we have a job URI or a printer URI...
7399 if (!strcmp(uri
->name
, "printer-uri"))
7402 * Got a printer URI; see if we also have a job-id attribute...
7405 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7406 IPP_TAG_INTEGER
)) == NULL
)
7408 send_ipp_status(con
, IPP_BAD_REQUEST
,
7409 _("Got a printer-uri attribute but no job-id"));
7413 jobid
= attr
->values
[0].integer
;
7418 * Got a job URI; parse it to get the job ID...
7421 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7422 sizeof(scheme
), username
, sizeof(username
), host
,
7423 sizeof(host
), &port
, resource
, sizeof(resource
));
7425 if (strncmp(resource
, "/jobs/", 6))
7431 send_ipp_status(con
, IPP_BAD_REQUEST
,
7432 _("Bad job-uri attribute \"%s\""),
7433 uri
->values
[0].string
.text
);
7437 jobid
= atoi(resource
+ 6);
7441 * See if the job exists...
7444 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7447 * Nope - return a "not found" error...
7450 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
7458 if ((printer
= job
->printer
) == NULL
)
7459 printer
= cupsdFindDest(job
->dest
);
7462 policy
= printer
->op_policy_ptr
;
7464 policy
= DefaultPolicyPtr
;
7466 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
7468 send_http_error(con
, status
, NULL
);
7472 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
7475 * Copy attributes...
7480 ra
= create_requested_array(con
->request
);
7481 copy_job_attrs(con
, job
, ra
, exclude
);
7482 cupsArrayDelete(ra
);
7484 con
->response
->request
.status
.status_code
= IPP_OK
;
7489 * 'get_jobs()' - Get a list of jobs for the specified printer.
7493 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7494 ipp_attribute_t
*uri
) /* I - Printer URI */
7496 http_status_t status
; /* Policy status */
7497 ipp_attribute_t
*attr
; /* Current attribute */
7498 const char *dest
; /* Destination */
7499 cups_ptype_t dtype
; /* Destination type (printer/class) */
7500 cups_ptype_t dmask
; /* Destination type mask */
7501 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7502 username
[HTTP_MAX_URI
], /* Username portion of URI */
7503 host
[HTTP_MAX_URI
], /* Host portion of URI */
7504 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7505 int port
; /* Port portion of URI */
7506 int job_comparison
; /* Job comparison */
7507 ipp_jstate_t job_state
; /* job-state value */
7508 int first_job_id
; /* First job ID */
7509 int limit
; /* Maximum number of jobs to return */
7510 int count
; /* Number of jobs that match */
7511 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7512 cupsd_job_t
*job
; /* Current job pointer */
7513 cupsd_printer_t
*printer
; /* Printer */
7514 cups_array_t
*list
; /* Which job list... */
7515 cups_array_t
*ra
, /* Requested attributes array */
7516 *exclude
; /* Private attributes array */
7517 cupsd_policy_t
*policy
; /* Current policy */
7520 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7521 uri
->values
[0].string
.text
);
7524 * Is the destination valid?
7527 if (strcmp(uri
->name
, "printer-uri"))
7529 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request"));
7533 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7534 sizeof(scheme
), username
, sizeof(username
), host
,
7535 sizeof(host
), &port
, resource
, sizeof(resource
));
7537 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7540 dtype
= (cups_ptype_t
)0;
7541 dmask
= (cups_ptype_t
)0;
7544 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7547 dtype
= (cups_ptype_t
)0;
7548 dmask
= CUPS_PRINTER_CLASS
;
7551 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7554 dtype
= CUPS_PRINTER_CLASS
;
7555 dmask
= CUPS_PRINTER_CLASS
;
7558 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7565 send_ipp_status(con
, IPP_NOT_FOUND
,
7566 _("The printer or class was not found."));
7571 dtype
&= CUPS_PRINTER_CLASS
;
7572 dmask
= CUPS_PRINTER_CLASS
;
7580 policy
= printer
->op_policy_ptr
;
7582 policy
= DefaultPolicyPtr
;
7584 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7586 send_http_error(con
, status
, NULL
);
7590 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7593 * See if the "which-jobs" attribute have been specified...
7596 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7597 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7599 send_ipp_status(con
, IPP_CONFLICT
,
7600 _("The %s attribute cannot be provided with job-ids."),
7604 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7606 job_comparison
= -1;
7607 job_state
= IPP_JOB_STOPPED
;
7610 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7613 job_state
= IPP_JOB_CANCELED
;
7616 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7619 job_state
= IPP_JOB_ABORTED
;
7622 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7625 job_state
= IPP_JOB_PENDING
;
7628 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7631 job_state
= IPP_JOB_CANCELED
;
7634 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7637 job_state
= IPP_JOB_PENDING
;
7640 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7643 job_state
= IPP_JOB_HELD
;
7646 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7649 job_state
= IPP_JOB_PROCESSING
;
7650 list
= PrintingJobs
;
7652 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7655 job_state
= IPP_JOB_STOPPED
;
7660 send_ipp_status(con
, IPP_ATTRIBUTES
,
7661 _("The which-jobs value \"%s\" is not supported."),
7662 attr
->values
[0].string
.text
);
7663 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7664 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7669 * See if they want to limit the number of jobs reported...
7672 if ((attr
= ippFindAttribute(con
->request
, "limit",
7673 IPP_TAG_INTEGER
)) != NULL
)
7677 send_ipp_status(con
, IPP_CONFLICT
,
7678 _("The %s attribute cannot be provided with job-ids."),
7683 limit
= attr
->values
[0].integer
;
7688 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7689 IPP_TAG_INTEGER
)) != NULL
)
7693 send_ipp_status(con
, IPP_CONFLICT
,
7694 _("The %s attribute cannot be provided with job-ids."),
7699 first_job_id
= attr
->values
[0].integer
;
7705 * See if we only want to see jobs for a specific user...
7708 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7709 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7711 send_ipp_status(con
, IPP_CONFLICT
,
7712 _("The %s attribute cannot be provided with job-ids."),
7716 else if (attr
&& attr
->values
[0].boolean
)
7717 strlcpy(username
, get_username(con
), sizeof(username
));
7721 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7722 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7725 * IPP conformance - Get-Jobs has a default requested-attributes value of
7726 * "job-id" and "job-uri".
7729 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7730 cupsArrayAdd(ra
, "job-id");
7731 cupsArrayAdd(ra
, "job-uri");
7735 * OK, build a list of jobs for this printer...
7740 int i
; /* Looping var */
7742 for (i
= 0; i
< job_ids
->num_values
; i
++)
7744 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
7748 if (i
< job_ids
->num_values
)
7750 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
7751 job_ids
->values
[i
].integer
);
7755 for (i
= 0; i
< job_ids
->num_values
; i
++)
7757 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7763 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7769 ippAddSeparator(con
->response
);
7771 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7772 job
->printer
->op_policy_ptr
:
7773 policy
, con
, job
->printer
,
7776 copy_job_attrs(con
, job
, ra
, exclude
);
7781 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7782 (limit
<= 0 || count
< limit
) && job
;
7783 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7786 * Filter out jobs that don't match...
7789 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7790 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7791 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7792 job
->username
, job
->state_value
, job
->attrs
);
7794 if (!job
->dest
|| !job
->username
)
7797 if (!job
->dest
|| !job
->username
)
7800 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7801 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7803 if ((job
->dtype
& dmask
) != dtype
&&
7804 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7807 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7808 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7809 (job_comparison
> 0 && job
->state_value
< job_state
))
7812 if (job
->id
< first_job_id
)
7819 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7824 if (username
[0] && strcasecmp(username
, job
->username
))
7828 ippAddSeparator(con
->response
);
7832 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7833 job
->printer
->op_policy_ptr
:
7834 policy
, con
, job
->printer
,
7837 copy_job_attrs(con
, job
, ra
, exclude
);
7840 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7843 cupsArrayDelete(ra
);
7845 con
->response
->request
.status
.status_code
= IPP_OK
;
7850 * 'get_notifications()' - Get events for a subscription.
7854 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7856 int i
, j
; /* Looping vars */
7857 http_status_t status
; /* Policy status */
7858 cupsd_subscription_t
*sub
; /* Subscription */
7859 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7860 *sequences
; /* notify-sequence-numbers */
7861 int min_seq
; /* Minimum sequence number */
7862 int interval
; /* Poll interval */
7865 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7869 * Get subscription attributes...
7872 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7874 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7879 send_ipp_status(con
, IPP_BAD_REQUEST
,
7880 _("Missing notify-subscription-ids attribute"));
7885 * Are the subscription IDs valid?
7888 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7890 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7893 * Bad subscription ID...
7896 send_ipp_status(con
, IPP_NOT_FOUND
,
7897 _("notify-subscription-id %d no good"),
7898 ids
->values
[i
].integer
);
7906 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7908 con
, sub
->owner
)) != HTTP_OK
)
7910 send_http_error(con
, status
, sub
->dest
);
7915 * Check the subscription type and update the interval accordingly.
7918 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7921 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7923 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7929 * Tell the client to poll again in N seconds...
7933 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7934 "notify-get-interval", interval
);
7936 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7937 "printer-up-time", time(NULL
));
7940 * Copy the subscription event attributes to the response.
7943 con
->response
->request
.status
.status_code
=
7944 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7946 for (i
= 0; i
< ids
->num_values
; i
++)
7949 * Get the subscription and sequence number...
7952 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7954 if (sequences
&& i
< sequences
->num_values
)
7955 min_seq
= sequences
->values
[i
].integer
;
7960 * If we don't have any new events, nothing to do here...
7963 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
7967 * Otherwise copy all of the new events...
7970 if (sub
->first_event_id
> min_seq
)
7973 j
= min_seq
- sub
->first_event_id
;
7975 for (; j
< cupsArrayCount(sub
->events
); j
++)
7977 ippAddSeparator(con
->response
);
7979 copy_attrs(con
->response
,
7980 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7981 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7988 * 'get_ppd()' - Get a named PPD from the local system.
7992 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7993 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7995 http_status_t status
; /* Policy status */
7996 cupsd_printer_t
*dest
; /* Destination */
7997 cups_ptype_t dtype
; /* Destination type */
8000 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
8001 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
8003 if (!strcmp(uri
->name
, "ppd-name"))
8006 * Return a PPD file from cups-driverd...
8009 char command
[1024], /* cups-driverd command */
8010 options
[1024], /* Options to pass to command */
8011 ppd_name
[1024]; /* ppd-name */
8018 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8020 send_http_error(con
, status
, NULL
);
8025 * Run cups-driverd command with the given options...
8028 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
8029 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
8030 snprintf(options
, sizeof(options
), "get+%d+%s",
8031 con
->request
->request
.op
.request_id
, ppd_name
);
8033 if (cupsdSendCommand(con
, command
, options
, 0))
8036 * Command started successfully, don't send an IPP response here...
8039 ippDelete(con
->response
);
8040 con
->response
= NULL
;
8045 * Command failed, return "internal error" so the user knows something
8049 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8050 _("cups-driverd failed to execute."));
8053 else if (!strcmp(uri
->name
, "printer-uri") &&
8054 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
8056 int i
; /* Looping var */
8057 char filename
[1024]; /* PPD filename */
8064 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8066 send_http_error(con
, status
, dest
);
8071 * See if we need the PPD for a class or remote printer...
8074 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8077 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
8079 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8080 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8081 "printer-uri", NULL
, dest
->uri
);
8084 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
8086 for (i
= 0; i
< dest
->num_printers
; i
++)
8087 if (!(dest
->printers
[i
]->type
&
8088 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
8090 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8091 dest
->printers
[i
]->name
);
8093 if (!access(filename
, 0))
8097 if (i
< dest
->num_printers
)
8098 dest
= dest
->printers
[i
];
8101 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8102 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8103 "printer-uri", NULL
, dest
->printers
[0]->uri
);
8109 * Found the printer with the PPD file, now see if there is one...
8112 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
8114 send_ipp_status(con
, IPP_NOT_FOUND
,
8115 _("The PPD file \"%s\" could not be opened: %s"),
8116 uri
->values
[0].string
.text
, strerror(errno
));
8120 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
8124 con
->response
->request
.status
.status_code
= IPP_OK
;
8127 send_ipp_status(con
, IPP_NOT_FOUND
,
8128 _("The PPD file \"%s\" could not be found."),
8129 uri
->values
[0].string
.text
);
8134 * 'get_ppds()' - Get the list of PPD files on the local system.
8138 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
8140 http_status_t status
; /* Policy status */
8141 ipp_attribute_t
*limit
, /* Limit attribute */
8142 *device
, /* ppd-device-id attribute */
8143 *language
, /* ppd-natural-language attribute */
8144 *make
, /* ppd-make attribute */
8145 *model
, /* ppd-make-and-model attribute */
8146 *model_number
, /* ppd-model-number attribute */
8147 *product
, /* ppd-product attribute */
8148 *psversion
, /* ppd-psverion attribute */
8149 *type
, /* ppd-type attribute */
8150 *requested
, /* requested-attributes attribute */
8151 *exclude
, /* exclude-schemes attribute */
8152 *include
; /* include-schemes attribute */
8153 char command
[1024], /* cups-driverd command */
8154 options
[4096], /* Options to pass to command */
8155 device_str
[256],/* Escaped ppd-device-id string */
8157 /* Escaped ppd-natural-language */
8158 make_str
[256], /* Escaped ppd-make string */
8159 model_str
[256], /* Escaped ppd-make-and-model string */
8160 model_number_str
[256],
8161 /* ppd-model-number string */
8163 /* Escaped ppd-product string */
8165 /* Escaped ppd-psversion string */
8166 type_str
[256], /* Escaped ppd-type string */
8168 /* String for requested attributes */
8170 /* String for excluded schemes */
8172 /* String for included schemes */
8175 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
8181 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8183 send_http_error(con
, status
, NULL
);
8188 * Run cups-driverd command with the given options...
8191 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
8192 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
8193 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
8195 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
8196 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
8198 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
8200 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
8201 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
8202 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
8203 requested
= ippFindAttribute(con
->request
, "requested-attributes",
8205 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
8207 include
= ippFindAttribute(con
->request
, "include-schemes",
8211 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
8213 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
8216 url_encode_attr(device
, device_str
, sizeof(device_str
));
8218 device_str
[0] = '\0';
8221 url_encode_attr(language
, language_str
, sizeof(language_str
));
8223 language_str
[0] = '\0';
8226 url_encode_attr(make
, make_str
, sizeof(make_str
));
8231 url_encode_attr(model
, model_str
, sizeof(model_str
));
8233 model_str
[0] = '\0';
8236 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
8237 model_number
->values
[0].integer
);
8239 model_number_str
[0] = '\0';
8242 url_encode_attr(product
, product_str
, sizeof(product_str
));
8244 product_str
[0] = '\0';
8247 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
8249 psversion_str
[0] = '\0';
8252 url_encode_attr(type
, type_str
, sizeof(type_str
));
8257 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
8259 exclude_str
[0] = '\0';
8262 url_encode_attr(include
, include_str
, sizeof(include_str
));
8264 include_str
[0] = '\0';
8266 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
8267 snprintf(options
, sizeof(options
),
8268 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
8269 con
->request
->request
.op
.request_id
,
8270 limit
? limit
->values
[0].integer
: 0,
8272 device
? "%20" : "", device_str
,
8273 language
? "%20" : "", language_str
,
8274 make
? "%20" : "", make_str
,
8275 model
? "%20" : "", model_str
,
8276 model_number
? "%20" : "", model_number_str
,
8277 product
? "%20" : "", product_str
,
8278 psversion
? "%20" : "", psversion_str
,
8279 type
? "%20" : "", type_str
,
8280 exclude_str
[0] ? "%20" : "", exclude_str
,
8281 include_str
[0] ? "%20" : "", include_str
);
8283 if (cupsdSendCommand(con
, command
, options
, 0))
8286 * Command started successfully, don't send an IPP response here...
8289 ippDelete(con
->response
);
8290 con
->response
= NULL
;
8295 * Command failed, return "internal error" so the user knows something
8299 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8300 _("cups-driverd failed to execute."));
8306 * 'get_printer_attrs()' - Get printer attributes.
8310 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
8311 ipp_attribute_t
*uri
) /* I - Printer URI */
8313 http_status_t status
; /* Policy status */
8314 cups_ptype_t dtype
; /* Destination type (printer/class) */
8315 cupsd_printer_t
*printer
; /* Printer/class */
8316 cups_array_t
*ra
; /* Requested attributes array */
8319 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
8320 con
->http
.fd
, uri
->values
[0].string
.text
);
8323 * Is the destination valid?
8326 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8332 send_ipp_status(con
, IPP_NOT_FOUND
,
8333 _("The printer or class was not found."));
8341 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8343 send_http_error(con
, status
, printer
);
8348 * Send the attributes...
8351 ra
= create_requested_array(con
->request
);
8353 copy_printer_attrs(con
, printer
, ra
);
8355 cupsArrayDelete(ra
);
8357 con
->response
->request
.status
.status_code
= IPP_OK
;
8362 * 'get_printer_supported()' - Get printer supported values.
8366 get_printer_supported(
8367 cupsd_client_t
*con
, /* I - Client connection */
8368 ipp_attribute_t
*uri
) /* I - Printer URI */
8370 http_status_t status
; /* Policy status */
8371 cups_ptype_t dtype
; /* Destination type (printer/class) */
8372 cupsd_printer_t
*printer
; /* Printer/class */
8375 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
8376 con
->http
.fd
, uri
->values
[0].string
.text
);
8379 * Is the destination valid?
8382 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8388 send_ipp_status(con
, IPP_NOT_FOUND
,
8389 _("The printer or class was not found."));
8397 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8399 send_http_error(con
, status
, printer
);
8404 * Return a list of attributes that can be set via Set-Printer-Attributes.
8407 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8409 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8410 "printer-location", 0);
8412 con
->response
->request
.status
.status_code
= IPP_OK
;
8417 * 'get_printers()' - Get a list of printers or classes.
8421 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8422 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8424 http_status_t status
; /* Policy status */
8425 ipp_attribute_t
*attr
; /* Current attribute */
8426 int limit
; /* Max number of printers to return */
8427 int count
; /* Number of printers that match */
8428 cupsd_printer_t
*printer
; /* Current printer pointer */
8429 int printer_type
, /* printer-type attribute */
8430 printer_mask
; /* printer-type-mask attribute */
8431 char *location
; /* Location string */
8432 const char *username
; /* Current user */
8433 char *first_printer_name
; /* first-printer-name attribute */
8434 cups_array_t
*ra
; /* Requested attributes array */
8435 int local
; /* Local connection? */
8438 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8439 con
->http
.fd
, type
);
8445 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8447 send_http_error(con
, status
, NULL
);
8452 * Check for printers...
8455 if (!Printers
|| !cupsArrayCount(Printers
))
8457 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8462 * See if they want to limit the number of printers reported...
8465 if ((attr
= ippFindAttribute(con
->request
, "limit",
8466 IPP_TAG_INTEGER
)) != NULL
)
8467 limit
= attr
->values
[0].integer
;
8471 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8472 IPP_TAG_NAME
)) != NULL
)
8473 first_printer_name
= attr
->values
[0].string
.text
;
8475 first_printer_name
= NULL
;
8478 * Support filtering...
8481 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8482 IPP_TAG_ENUM
)) != NULL
)
8483 printer_type
= attr
->values
[0].integer
;
8487 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8488 IPP_TAG_ENUM
)) != NULL
)
8489 printer_mask
= attr
->values
[0].integer
;
8493 local
= httpAddrLocalhost(&(con
->clientaddr
));
8495 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8496 IPP_TAG_TEXT
)) != NULL
)
8497 location
= attr
->values
[0].string
.text
;
8501 if (con
->username
[0])
8502 username
= con
->username
;
8503 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8504 IPP_TAG_NAME
)) != NULL
)
8505 username
= attr
->values
[0].string
.text
;
8509 ra
= create_requested_array(con
->request
);
8512 * OK, build a list of printers for this printer...
8515 if (first_printer_name
)
8517 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8518 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8521 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8524 count
< limit
&& printer
;
8525 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8527 if (!local
&& !printer
->shared
)
8530 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8531 (printer
->type
& printer_mask
) == printer_type
&&
8533 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
8536 * If HideImplicitMembers is enabled, see if this printer or class
8537 * is a member of an implicit class...
8540 if (ImplicitClasses
&& HideImplicitMembers
&&
8541 printer
->in_implicit_class
)
8545 * If a username is specified, see if it is allowed or denied
8549 if (cupsArrayCount(printer
->users
) && username
&&
8550 !user_allowed(printer
, username
))
8554 * Add the group separator as needed...
8558 ippAddSeparator(con
->response
);
8563 * Send the attributes...
8566 copy_printer_attrs(con
, printer
, ra
);
8570 cupsArrayDelete(ra
);
8572 con
->response
->request
.status
.status_code
= IPP_OK
;
8577 * 'get_subscription_attrs()' - Get subscription attributes.
8581 get_subscription_attrs(
8582 cupsd_client_t
*con
, /* I - Client connection */
8583 int sub_id
) /* I - Subscription ID */
8585 http_status_t status
; /* Policy status */
8586 cupsd_subscription_t
*sub
; /* Subscription */
8587 cupsd_policy_t
*policy
; /* Current security policy */
8588 cups_array_t
*ra
, /* Requested attributes array */
8589 *exclude
; /* Private attributes array */
8592 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8593 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8594 con
, con
->http
.fd
, sub_id
);
8597 * Is the subscription ID valid?
8600 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8603 * Bad subscription ID...
8606 send_ipp_status(con
, IPP_NOT_FOUND
,
8607 _("notify-subscription-id %d no good"), sub_id
);
8616 policy
= sub
->dest
->op_policy_ptr
;
8618 policy
= DefaultPolicyPtr
;
8620 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
8622 send_http_error(con
, status
, sub
->dest
);
8626 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
8629 * Copy the subscription attributes to the response using the
8630 * requested-attributes attribute that may be provided by the client.
8633 ra
= create_requested_array(con
->request
);
8635 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8637 cupsArrayDelete(ra
);
8639 con
->response
->request
.status
.status_code
= IPP_OK
;
8644 * 'get_subscriptions()' - Get subscriptions.
8648 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8649 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8651 http_status_t status
; /* Policy status */
8652 int count
; /* Number of subscriptions */
8653 int limit
; /* Limit */
8654 cupsd_subscription_t
*sub
; /* Subscription */
8655 cups_array_t
*ra
; /* Requested attributes array */
8656 ipp_attribute_t
*attr
; /* Attribute */
8657 cups_ptype_t dtype
; /* Destination type (printer/class) */
8658 char scheme
[HTTP_MAX_URI
],
8659 /* Scheme portion of URI */
8660 username
[HTTP_MAX_URI
],
8661 /* Username portion of URI */
8663 /* Host portion of URI */
8664 resource
[HTTP_MAX_URI
];
8665 /* Resource portion of URI */
8666 int port
; /* Port portion of URI */
8667 cupsd_job_t
*job
; /* Job pointer */
8668 cupsd_printer_t
*printer
; /* Printer */
8669 cupsd_policy_t
*policy
; /* Policy */
8670 cups_array_t
*exclude
; /* Private attributes array */
8673 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8674 "get_subscriptions(con=%p[%d], uri=%s)",
8675 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8678 * Is the destination valid?
8681 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8682 sizeof(scheme
), username
, sizeof(username
), host
,
8683 sizeof(host
), &port
, resource
, sizeof(resource
));
8685 if (!strcmp(resource
, "/") ||
8686 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8687 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8688 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8693 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8696 job
= cupsdFindJob(atoi(resource
+ 6));
8700 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist"),
8705 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8711 send_ipp_status(con
, IPP_NOT_FOUND
,
8712 _("The printer or class was not found."));
8715 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8716 IPP_TAG_INTEGER
)) != NULL
)
8718 job
= cupsdFindJob(attr
->values
[0].integer
);
8722 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
8723 attr
->values
[0].integer
);
8735 policy
= printer
->op_policy_ptr
;
8737 policy
= DefaultPolicyPtr
;
8739 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
8741 send_http_error(con
, status
, printer
);
8746 * Copy the subscription attributes to the response using the
8747 * requested-attributes attribute that may be provided by the client.
8750 ra
= create_requested_array(con
->request
);
8752 if ((attr
= ippFindAttribute(con
->request
, "limit",
8753 IPP_TAG_INTEGER
)) != NULL
)
8754 limit
= attr
->values
[0].integer
;
8759 * See if we only want to see subscriptions for a specific user...
8762 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8763 IPP_TAG_BOOLEAN
)) != NULL
&&
8764 attr
->values
[0].boolean
)
8765 strlcpy(username
, get_username(con
), sizeof(username
));
8769 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8771 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8772 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8773 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
8775 ippAddSeparator(con
->response
);
8777 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
8778 policy
, con
, sub
->dest
,
8781 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8784 if (limit
&& count
>= limit
)
8788 cupsArrayDelete(ra
);
8791 con
->response
->request
.status
.status_code
= IPP_OK
;
8793 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8798 * 'get_username()' - Get the username associated with a request.
8801 static const char * /* O - Username */
8802 get_username(cupsd_client_t
*con
) /* I - Connection */
8804 ipp_attribute_t
*attr
; /* Attribute */
8807 if (con
->username
[0])
8808 return (con
->username
);
8809 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8810 IPP_TAG_NAME
)) != NULL
)
8811 return (attr
->values
[0].string
.text
);
8813 return ("anonymous");
8818 * 'hold_job()' - Hold a print job.
8822 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8823 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8825 ipp_attribute_t
*attr
; /* Current job-hold-until */
8826 const char *when
; /* New value */
8827 int jobid
; /* Job ID */
8828 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8829 username
[HTTP_MAX_URI
], /* Username portion of URI */
8830 host
[HTTP_MAX_URI
], /* Host portion of URI */
8831 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8832 int port
; /* Port portion of URI */
8833 cupsd_job_t
*job
; /* Job information */
8836 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8837 uri
->values
[0].string
.text
);
8840 * See if we have a job URI or a printer URI...
8843 if (!strcmp(uri
->name
, "printer-uri"))
8846 * Got a printer URI; see if we also have a job-id attribute...
8849 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8850 IPP_TAG_INTEGER
)) == NULL
)
8852 send_ipp_status(con
, IPP_BAD_REQUEST
,
8853 _("Got a printer-uri attribute but no job-id"));
8857 jobid
= attr
->values
[0].integer
;
8862 * Got a job URI; parse it to get the job ID...
8865 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8866 sizeof(scheme
), username
, sizeof(username
), host
,
8867 sizeof(host
), &port
, resource
, sizeof(resource
));
8869 if (strncmp(resource
, "/jobs/", 6))
8875 send_ipp_status(con
, IPP_BAD_REQUEST
,
8876 _("Bad job-uri attribute \"%s\""),
8877 uri
->values
[0].string
.text
);
8881 jobid
= atoi(resource
+ 6);
8885 * See if the job exists...
8888 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8891 * Nope - return a "not found" error...
8894 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
8899 * See if the job is owned by the requesting user...
8902 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8904 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8905 cupsdFindDest(job
->dest
));
8910 * Hold the job and return...
8913 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8914 IPP_TAG_KEYWORD
)) == NULL
)
8915 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8919 when
= attr
->values
[0].string
.text
;
8921 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8922 "Job job-hold-until value changed by user.");
8925 when
= "indefinite";
8927 cupsdSetJobHoldUntil(job
, when
, 1);
8928 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8931 con
->response
->request
.status
.status_code
= IPP_OK
;
8936 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8940 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8941 ipp_attribute_t
*uri
) /* I - Printer URI */
8943 http_status_t status
; /* Policy status */
8944 cups_ptype_t dtype
; /* Destination type (printer/class) */
8945 cupsd_printer_t
*printer
; /* Printer data */
8948 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8949 con
->http
.fd
, uri
->values
[0].string
.text
);
8952 * Is the destination valid?
8955 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8961 send_ipp_status(con
, IPP_NOT_FOUND
,
8962 _("The printer or class was not found."));
8970 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8972 send_http_error(con
, status
, printer
);
8977 * Hold pending/new jobs sent to the printer...
8980 printer
->holding_new_jobs
= 1;
8982 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8983 cupsdAddPrinterHistory(printer
);
8985 if (dtype
& CUPS_PRINTER_CLASS
)
8986 cupsdLogMessage(CUPSD_LOG_INFO
,
8987 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8988 printer
->name
, get_username(con
));
8990 cupsdLogMessage(CUPSD_LOG_INFO
,
8991 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8992 printer
->name
, get_username(con
));
8995 * Everything was ok, so return OK status...
8998 con
->response
->request
.status
.status_code
= IPP_OK
;
9003 * 'move_job()' - Move a job to a new destination.
9007 move_job(cupsd_client_t
*con
, /* I - Client connection */
9008 ipp_attribute_t
*uri
) /* I - Job URI */
9010 http_status_t status
; /* Policy status */
9011 ipp_attribute_t
*attr
; /* Current attribute */
9012 int jobid
; /* Job ID */
9013 cupsd_job_t
*job
; /* Current job */
9014 const char *src
; /* Source printer/class */
9015 cups_ptype_t stype
, /* Source type (printer or class) */
9016 dtype
; /* Destination type (printer/class) */
9017 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
9018 username
[HTTP_MAX_URI
], /* Username portion of URI */
9019 host
[HTTP_MAX_URI
], /* Host portion of URI */
9020 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9021 int port
; /* Port portion of URI */
9022 cupsd_printer_t
*sprinter
, /* Source printer */
9023 *dprinter
; /* Destination printer */
9026 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
9027 uri
->values
[0].string
.text
);
9030 * Get the new printer or class...
9033 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
9034 IPP_TAG_URI
)) == NULL
)
9037 * Need job-printer-uri...
9040 send_ipp_status(con
, IPP_BAD_REQUEST
,
9041 _("job-printer-uri attribute missing"));
9045 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
9051 send_ipp_status(con
, IPP_NOT_FOUND
,
9052 _("The printer or class was not found."));
9057 * See if we have a job URI or a printer URI...
9060 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9061 sizeof(scheme
), username
, sizeof(username
), host
,
9062 sizeof(host
), &port
, resource
, sizeof(resource
));
9064 if (!strcmp(uri
->name
, "printer-uri"))
9067 * Got a printer URI; see if we also have a job-id attribute...
9070 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9071 IPP_TAG_INTEGER
)) == NULL
)
9077 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
9078 &sprinter
)) == NULL
)
9084 send_ipp_status(con
, IPP_NOT_FOUND
,
9085 _("The printer or class was not found."));
9094 * Otherwise, just move a single job...
9097 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
9100 * Nope - return a "not found" error...
9103 send_ipp_status(con
, IPP_NOT_FOUND
,
9104 _("Job #%d does not exist"), attr
->values
[0].integer
);
9110 * Job found, initialize source pointers...
9121 * Got a job URI; parse it to get the job ID...
9124 if (strncmp(resource
, "/jobs/", 6))
9130 send_ipp_status(con
, IPP_BAD_REQUEST
,
9131 _("Bad job-uri attribute \"%s\""),
9132 uri
->values
[0].string
.text
);
9137 * See if the job exists...
9140 jobid
= atoi(resource
+ 6);
9142 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9145 * Nope - return a "not found" error...
9148 send_ipp_status(con
, IPP_NOT_FOUND
,
9149 _("Job #%d does not exist"), jobid
);
9155 * Job found, initialize source pointers...
9164 * Check the policy of the destination printer...
9167 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
9168 job
? job
->username
: NULL
)) != HTTP_OK
)
9170 send_http_error(con
, status
, dprinter
);
9175 * Now move the job or jobs...
9181 * See if the job has been completed...
9184 if (job
->state_value
> IPP_JOB_STOPPED
)
9187 * Return a "not-possible" error...
9190 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9191 _("Job #%d is finished and cannot be altered"),
9197 * See if the job is owned by the requesting user...
9200 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9202 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9203 cupsdFindDest(job
->dest
));
9208 * Move the job to a different printer or class...
9211 cupsdMoveJob(job
, dprinter
);
9216 * Got the source printer, now look through the jobs...
9219 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
9221 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
9224 * See if the job is pointing at the source printer or has not been
9228 if (strcasecmp(job
->dest
, src
) ||
9229 job
->state_value
> IPP_JOB_STOPPED
)
9233 * See if the job can be moved by the requesting user...
9236 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9240 * Move the job to a different printer or class...
9243 cupsdMoveJob(job
, dprinter
);
9248 * Start jobs if possible...
9254 * Return with "everything is OK" status...
9257 con
->response
->request
.status
.status_code
= IPP_OK
;
9262 * 'ppd_parse_line()' - Parse a PPD default line.
9265 static int /* O - 0 on success, -1 on failure */
9266 ppd_parse_line(const char *line
, /* I - Line */
9267 char *option
, /* O - Option name */
9268 int olen
, /* I - Size of option name */
9269 char *choice
, /* O - Choice name */
9270 int clen
) /* I - Size of choice name */
9273 * Verify this is a default option line...
9276 if (strncmp(line
, "*Default", 8))
9280 * Read the option name...
9283 for (line
+= 8, olen
--;
9284 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9295 * Skip everything else up to the colon (:)...
9298 while (*line
&& *line
!= ':')
9307 * Now grab the option choice, skipping leading whitespace...
9310 while (isspace(*line
& 255))
9314 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9325 * Return with no errors...
9333 * 'print_job()' - Print a file to a printer or class.
9337 print_job(cupsd_client_t
*con
, /* I - Client connection */
9338 ipp_attribute_t
*uri
) /* I - Printer URI */
9340 ipp_attribute_t
*attr
; /* Current attribute */
9341 ipp_attribute_t
*format
; /* Document-format attribute */
9342 const char *default_format
; /* document-format-default value */
9343 cupsd_job_t
*job
; /* New job */
9344 char filename
[1024]; /* Job filename */
9345 mime_type_t
*filetype
; /* Type of file */
9346 char super
[MIME_MAX_SUPER
], /* Supertype of file */
9347 type
[MIME_MAX_TYPE
], /* Subtype of file */
9348 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9349 /* Textual name of mime type */
9350 cupsd_printer_t
*printer
; /* Printer data */
9351 struct stat fileinfo
; /* File information */
9352 int kbytes
; /* Size of file */
9353 int compression
; /* Document compression */
9356 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
9357 uri
->values
[0].string
.text
);
9360 * Validate print file attributes, for now just document-format and
9361 * compression (CUPS only supports "none" and "gzip")...
9364 compression
= CUPS_FILE_NONE
;
9366 if ((attr
= ippFindAttribute(con
->request
, "compression",
9367 IPP_TAG_KEYWORD
)) != NULL
)
9369 if (strcmp(attr
->values
[0].string
.text
, "none")
9371 && strcmp(attr
->values
[0].string
.text
, "gzip")
9372 #endif /* HAVE_LIBZ */
9375 send_ipp_status(con
, IPP_ATTRIBUTES
,
9376 _("Unsupported compression \"%s\""),
9377 attr
->values
[0].string
.text
);
9378 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9379 "compression", NULL
, attr
->values
[0].string
.text
);
9384 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9385 compression
= CUPS_FILE_GZIP
;
9386 #endif /* HAVE_LIBZ */
9390 * Do we have a file to print?
9395 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
9400 * Is the destination valid?
9403 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
9409 send_ipp_status(con
, IPP_NOT_FOUND
,
9410 _("The printer or class was not found."));
9415 * Is it a format we support?
9418 if ((format
= ippFindAttribute(con
->request
, "document-format",
9419 IPP_TAG_MIMETYPE
)) != NULL
)
9422 * Grab format from client...
9425 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9428 send_ipp_status(con
, IPP_BAD_REQUEST
,
9429 _("Bad document-format \"%s\""),
9430 format
->values
[0].string
.text
);
9434 else if ((default_format
= cupsGetOption("document-format",
9435 printer
->num_options
,
9436 printer
->options
)) != NULL
)
9439 * Use default document format...
9442 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9444 send_ipp_status(con
, IPP_BAD_REQUEST
,
9445 _("Bad document-format \"%s\""),
9456 strcpy(super
, "application");
9457 strcpy(type
, "octet-stream");
9460 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9463 * Auto-type the file...
9466 ipp_attribute_t
*doc_name
; /* document-name attribute */
9469 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9471 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9472 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9473 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9477 filetype
= mimeType(MimeDatabase
, super
, type
);
9479 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9480 filetype
->super
, filetype
->type
);
9483 filetype
= mimeType(MimeDatabase
, super
, type
);
9487 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9490 * Replace the document-format attribute value with the auto-typed or
9494 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9499 _cupsStrFree(format
->values
[0].string
.text
);
9501 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9504 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9505 "document-format", NULL
, mimetype
);
9509 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9510 _("Unsupported document-format \"%s\""),
9511 format
? format
->values
[0].string
.text
:
9512 "application/octet-stream");
9513 cupsdLogMessage(CUPSD_LOG_INFO
,
9514 "Hint: Do you have the raw file printing rules enabled?");
9517 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9518 "document-format", NULL
, format
->values
[0].string
.text
);
9524 * Read any embedded job ticket info from PS files...
9527 if (!strcasecmp(filetype
->super
, "application") &&
9528 (!strcasecmp(filetype
->type
, "postscript") ||
9529 !strcasecmp(filetype
->type
, "pdf")))
9530 read_job_ticket(con
);
9533 * Create the job object...
9536 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9540 * Update quota data...
9543 if (stat(con
->filename
, &fileinfo
))
9546 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9548 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9550 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9551 IPP_TAG_INTEGER
)) != NULL
)
9552 attr
->values
[0].integer
+= kbytes
;
9555 * Add the job file...
9558 if (add_file(con
, job
, filetype
, compression
))
9561 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9563 rename(con
->filename
, filename
);
9564 cupsdClearString(&con
->filename
);
9567 * See if we need to add the ending sheet...
9570 if (cupsdTimeoutJob(job
))
9574 * Log and save the job...
9577 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9578 "File of type %s/%s queued by \"%s\".",
9579 filetype
->super
, filetype
->type
, job
->username
);
9580 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9581 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9582 job
->dest
, job
->username
);
9585 * Start the job if possible...
9593 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9595 * This function only gets called when printing a single PDF or PostScript
9596 * file using the Print-Job operation. It doesn't work for Create-Job +
9597 * Send-File, since the job attributes need to be set at job creation
9598 * time for banners to work. The embedded job ticket stuff is here
9599 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9600 * options and IPP attributes which otherwise would be lost.
9602 * The format of a job ticket is simple:
9604 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9606 * %cupsJobTicket: attr1=value1
9607 * %cupsJobTicket: attr2=value2
9609 * %cupsJobTicket: attrN=valueN
9611 * Job ticket lines must appear immediately after the first line that
9612 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9613 * stops looking for job ticket info when it finds a line that does not begin
9614 * with "%cupsJobTicket:".
9616 * The maximum length of a job ticket line, including the prefix, is
9617 * 255 characters to conform with the Adobe DSC.
9619 * Read-only attributes are rejected with a notice to the error log in
9620 * case a malicious user tries anything. Since the job ticket is read
9621 * prior to attribute validation in print_job(), job ticket attributes
9622 * will go through the same validation as IPP attributes...
9626 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9628 cups_file_t
*fp
; /* File to read from */
9629 char line
[256]; /* Line data */
9630 int num_options
; /* Number of options */
9631 cups_option_t
*options
; /* Options */
9632 ipp_t
*ticket
; /* New attributes */
9633 ipp_attribute_t
*attr
, /* Current attribute */
9634 *attr2
, /* Job attribute */
9635 *prev2
; /* Previous job attribute */
9639 * First open the print file...
9642 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9644 cupsdLogMessage(CUPSD_LOG_ERROR
,
9645 "Unable to open print file for job ticket - %s",
9651 * Skip the first line...
9654 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9656 cupsdLogMessage(CUPSD_LOG_ERROR
,
9657 "Unable to read from print file for job ticket - %s",
9663 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9666 * Not a DSC-compliant file, so no job ticket info will be available...
9674 * Read job ticket info from the file...
9680 while (cupsFileGets(fp
, line
, sizeof(line
)))
9683 * Stop at the first non-ticket line...
9686 if (strncmp(line
, "%cupsJobTicket:", 15))
9690 * Add the options to the option array...
9693 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9697 * Done with the file; see if we have any options...
9702 if (num_options
== 0)
9706 * OK, convert the options to an attribute list, and apply them to
9711 cupsEncodeOptions(ticket
, num_options
, options
);
9714 * See what the user wants to change.
9717 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9719 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9722 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9723 !strcmp(attr
->name
, "job-originating-user-name") ||
9724 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9725 !strcmp(attr
->name
, "job-k-octets") ||
9726 !strcmp(attr
->name
, "job-id") ||
9727 !strncmp(attr
->name
, "job-state", 9) ||
9728 !strncmp(attr
->name
, "time-at-", 8))
9729 continue; /* Read-only attrs */
9731 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9732 IPP_TAG_ZERO
)) != NULL
)
9735 * Some other value; first free the old value...
9738 if (con
->request
->attrs
== attr2
)
9740 con
->request
->attrs
= attr2
->next
;
9745 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9746 if (prev2
->next
== attr2
)
9748 prev2
->next
= attr2
->next
;
9753 if (con
->request
->last
== attr2
)
9754 con
->request
->last
= prev2
;
9756 _ippFreeAttr(attr2
);
9760 * Add new option by copying it...
9763 copy_attribute(con
->request
, attr
, 0);
9767 * Then free the attribute list and option array...
9771 cupsFreeOptions(num_options
, options
);
9776 * 'reject_jobs()' - Reject print jobs to a printer.
9780 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9781 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9783 http_status_t status
; /* Policy status */
9784 cups_ptype_t dtype
; /* Destination type (printer/class) */
9785 cupsd_printer_t
*printer
; /* Printer data */
9786 ipp_attribute_t
*attr
; /* printer-state-message text */
9789 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9790 con
->http
.fd
, uri
->values
[0].string
.text
);
9793 * Is the destination valid?
9796 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9802 send_ipp_status(con
, IPP_NOT_FOUND
,
9803 _("The printer or class was not found."));
9811 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9813 send_http_error(con
, status
, printer
);
9818 * Reject jobs sent to the printer...
9821 printer
->accepting
= 0;
9823 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9824 IPP_TAG_TEXT
)) == NULL
)
9825 strcpy(printer
->state_message
, "Rejecting Jobs");
9827 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9828 sizeof(printer
->state_message
));
9830 cupsdAddPrinterHistory(printer
);
9832 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9833 "No longer accepting jobs.");
9835 if (dtype
& CUPS_PRINTER_CLASS
)
9837 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9839 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9840 printer
->name
, get_username(con
));
9844 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9846 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9847 printer
->name
, get_username(con
));
9851 * Everything was ok, so return OK status...
9854 con
->response
->request
.status
.status_code
= IPP_OK
;
9859 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9863 release_held_new_jobs(
9864 cupsd_client_t
*con
, /* I - Connection */
9865 ipp_attribute_t
*uri
) /* I - Printer URI */
9867 http_status_t status
; /* Policy status */
9868 cups_ptype_t dtype
; /* Destination type (printer/class) */
9869 cupsd_printer_t
*printer
; /* Printer data */
9872 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9873 con
->http
.fd
, uri
->values
[0].string
.text
);
9876 * Is the destination valid?
9879 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9885 send_ipp_status(con
, IPP_NOT_FOUND
,
9886 _("The printer or class was not found."));
9894 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9896 send_http_error(con
, status
, printer
);
9901 * Hold pending/new jobs sent to the printer...
9904 printer
->holding_new_jobs
= 0;
9906 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9907 cupsdAddPrinterHistory(printer
);
9909 if (dtype
& CUPS_PRINTER_CLASS
)
9910 cupsdLogMessage(CUPSD_LOG_INFO
,
9911 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9912 printer
->name
, get_username(con
));
9914 cupsdLogMessage(CUPSD_LOG_INFO
,
9915 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9916 printer
->name
, get_username(con
));
9919 * Everything was ok, so return OK status...
9922 con
->response
->request
.status
.status_code
= IPP_OK
;
9927 * 'release_job()' - Release a held print job.
9931 release_job(cupsd_client_t
*con
, /* I - Client connection */
9932 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9934 ipp_attribute_t
*attr
; /* Current attribute */
9935 int jobid
; /* Job ID */
9936 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9937 username
[HTTP_MAX_URI
], /* Username portion of URI */
9938 host
[HTTP_MAX_URI
], /* Host portion of URI */
9939 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9940 int port
; /* Port portion of URI */
9941 cupsd_job_t
*job
; /* Job information */
9944 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9945 con
->http
.fd
, uri
->values
[0].string
.text
);
9948 * See if we have a job URI or a printer URI...
9951 if (!strcmp(uri
->name
, "printer-uri"))
9954 * Got a printer URI; see if we also have a job-id attribute...
9957 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9958 IPP_TAG_INTEGER
)) == NULL
)
9960 send_ipp_status(con
, IPP_BAD_REQUEST
,
9961 _("Got a printer-uri attribute but no job-id"));
9965 jobid
= attr
->values
[0].integer
;
9970 * Got a job URI; parse it to get the job ID...
9973 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9974 sizeof(scheme
), username
, sizeof(username
), host
,
9975 sizeof(host
), &port
, resource
, sizeof(resource
));
9977 if (strncmp(resource
, "/jobs/", 6))
9983 send_ipp_status(con
, IPP_BAD_REQUEST
,
9984 _("Bad job-uri attribute \"%s\""),
9985 uri
->values
[0].string
.text
);
9989 jobid
= atoi(resource
+ 6);
9993 * See if the job exists...
9996 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9999 * Nope - return a "not found" error...
10002 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10007 * See if job is "held"...
10010 if (job
->state_value
!= IPP_JOB_HELD
)
10013 * Nope - return a "not possible" error...
10016 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held"), jobid
);
10021 * See if the job is owned by the requesting user...
10024 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10026 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10027 cupsdFindDest(job
->dest
));
10032 * Reset the job-hold-until value to "no-hold"...
10035 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10036 IPP_TAG_KEYWORD
)) == NULL
)
10037 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10041 _cupsStrFree(attr
->values
[0].string
.text
);
10043 attr
->value_tag
= IPP_TAG_KEYWORD
;
10044 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
10046 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10047 "Job job-hold-until value changed by user.");
10051 * Release the job and return...
10054 cupsdReleaseJob(job
);
10056 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10057 "Job released by user.");
10059 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
10061 con
->response
->request
.status
.status_code
= IPP_OK
;
10068 * 'renew_subscription()' - Renew an existing subscription...
10072 renew_subscription(
10073 cupsd_client_t
*con
, /* I - Client connection */
10074 int sub_id
) /* I - Subscription ID */
10076 http_status_t status
; /* Policy status */
10077 cupsd_subscription_t
*sub
; /* Subscription */
10078 ipp_attribute_t
*lease
; /* notify-lease-duration */
10081 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
10082 "renew_subscription(con=%p[%d], sub_id=%d)",
10083 con
, con
->http
.fd
, sub_id
);
10086 * Is the subscription ID valid?
10089 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
10092 * Bad subscription ID...
10095 send_ipp_status(con
, IPP_NOT_FOUND
,
10096 _("notify-subscription-id %d no good"), sub_id
);
10103 * Job subscriptions cannot be renewed...
10106 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10107 _("Job subscriptions cannot be renewed"));
10115 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
10117 con
, sub
->owner
)) != HTTP_OK
)
10119 send_http_error(con
, status
, sub
->dest
);
10124 * Renew the subscription...
10127 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
10130 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
10132 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
10134 cupsdLogMessage(CUPSD_LOG_INFO
,
10135 "renew_subscription: Limiting notify-lease-duration to "
10138 sub
->lease
= MaxLeaseDuration
;
10141 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
10143 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
10145 con
->response
->request
.status
.status_code
= IPP_OK
;
10147 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
10148 "notify-lease-duration", sub
->lease
);
10153 * 'restart_job()' - Restart an old print job.
10157 restart_job(cupsd_client_t
*con
, /* I - Client connection */
10158 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
10160 ipp_attribute_t
*attr
; /* Current attribute */
10161 int jobid
; /* Job ID */
10162 cupsd_job_t
*job
; /* Job information */
10163 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
10164 username
[HTTP_MAX_URI
], /* Username portion of URI */
10165 host
[HTTP_MAX_URI
], /* Host portion of URI */
10166 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10167 int port
; /* Port portion of URI */
10170 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
10171 con
->http
.fd
, uri
->values
[0].string
.text
);
10174 * See if we have a job URI or a printer URI...
10177 if (!strcmp(uri
->name
, "printer-uri"))
10180 * Got a printer URI; see if we also have a job-id attribute...
10183 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10184 IPP_TAG_INTEGER
)) == NULL
)
10186 send_ipp_status(con
, IPP_BAD_REQUEST
,
10187 _("Got a printer-uri attribute but no job-id"));
10191 jobid
= attr
->values
[0].integer
;
10196 * Got a job URI; parse it to get the job ID...
10199 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10200 sizeof(scheme
), username
, sizeof(username
), host
,
10201 sizeof(host
), &port
, resource
, sizeof(resource
));
10203 if (strncmp(resource
, "/jobs/", 6))
10209 send_ipp_status(con
, IPP_BAD_REQUEST
,
10210 _("Bad job-uri attribute \"%s\""),
10211 uri
->values
[0].string
.text
);
10215 jobid
= atoi(resource
+ 6);
10219 * See if the job exists...
10222 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10225 * Nope - return a "not found" error...
10228 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10233 * See if job is in any of the "completed" states...
10236 if (job
->state_value
<= IPP_JOB_PROCESSING
)
10239 * Nope - return a "not possible" error...
10242 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete"),
10248 * See if we have retained the job files...
10253 if (!job
->attrs
|| job
->num_files
== 0)
10256 * Nope - return a "not possible" error...
10259 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10260 _("Job #%d cannot be restarted - no files"), jobid
);
10265 * See if the job is owned by the requesting user...
10268 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10270 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10271 cupsdFindDest(job
->dest
));
10276 * See if the job-hold-until attribute is specified...
10279 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
10280 IPP_TAG_KEYWORD
)) == NULL
)
10281 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
10283 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
10286 * Return the job to a held state...
10289 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
10290 "Restarted by \"%s\" with job-hold-until=%s.",
10291 username
, attr
->values
[0].string
.text
);
10292 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10294 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
10295 NULL
, job
, "Job restarted by user with job-hold-until=%s",
10296 attr
->values
[0].string
.text
);
10301 * Restart the job...
10304 cupsdRestartJob(job
);
10308 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
10310 con
->response
->request
.status
.status_code
= IPP_OK
;
10315 * 'save_auth_info()' - Save authentication information for a job.
10320 cupsd_client_t
*con
, /* I - Client connection */
10321 cupsd_job_t
*job
, /* I - Job */
10322 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
10324 int i
; /* Looping var */
10325 char filename
[1024]; /* Job authentication filename */
10326 cups_file_t
*fp
; /* Job authentication file */
10327 char line
[2048]; /* Line for file */
10328 cupsd_printer_t
*dest
; /* Destination printer/class */
10332 * This function saves the in-memory authentication information for
10333 * a job so that it can be used to authenticate with a remote host.
10334 * The information is stored in a file that is readable only by the
10335 * root user. The fields are Base-64 encoded, each on a separate line,
10336 * followed by random number (up to 1024) of newlines to limit the
10337 * amount of information that is exposed.
10339 * Because of the potential for exposing of authentication information,
10340 * this functionality is only enabled when running cupsd as root.
10342 * This caching only works for the Basic and BasicDigest authentication
10343 * types. Digest authentication cannot be cached this way, and in
10344 * the future Kerberos authentication may make all of this obsolete.
10346 * Authentication information is saved whenever an authenticated
10347 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
10350 * This information is deleted after a job is completed or canceled,
10351 * so reprints may require subsequent re-authentication.
10357 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
10361 * Create the authentication file and change permissions...
10364 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
10365 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
10367 cupsdLogMessage(CUPSD_LOG_ERROR
,
10368 "Unable to save authentication info to \"%s\" - %s",
10369 filename
, strerror(errno
));
10373 fchown(cupsFileNumber(fp
), 0, 0);
10374 fchmod(cupsFileNumber(fp
), 0400);
10376 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
10379 * Write 1 to 3 auth values...
10382 cupsdClearString(&job
->auth_username
);
10383 cupsdClearString(&job
->auth_domain
);
10384 cupsdClearString(&job
->auth_password
);
10386 for (i
= 0; i
< auth_info
->num_values
; i
++)
10388 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
10389 strlen(auth_info
->values
[i
].string
.text
));
10390 cupsFilePrintf(fp
, "%s\n", line
);
10392 if (!strcmp(dest
->auth_info_required
[i
], "username"))
10393 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
10394 auth_info
->values
[i
].string
.text
);
10395 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
10396 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
10397 auth_info
->values
[i
].string
.text
);
10398 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
10399 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
10400 auth_info
->values
[i
].string
.text
);
10403 else if (con
->username
[0])
10406 * Write the authenticated username...
10409 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
10410 cupsFilePrintf(fp
, "%s\n", line
);
10412 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
10413 cupsdClearString(&job
->auth_domain
);
10416 * Write the authenticated password...
10419 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10420 cupsFilePrintf(fp
, "%s\n", line
);
10422 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
10426 * Write a random number of newlines to the end of the file...
10429 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10430 cupsFilePutChar(fp
, '\n');
10433 * Close the file and return...
10438 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10439 # ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
10440 if (con
->have_gss
&&
10441 (con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
|| con
->gss_creds
))
10443 if (con
->have_gss
&& con
->gss_creds
)
10444 # endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
10445 save_krb5_creds(con
, job
);
10446 else if (job
->ccname
)
10447 cupsdClearString(&(job
->ccname
));
10448 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10452 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10454 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
10458 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
10459 cupsd_job_t
*job
) /* I - Job */
10462 * Get the credentials...
10465 job
->ccache
= cupsdCopyKrb5Creds(con
);
10468 * Add the KRB5CCNAME environment variable to the job so that the
10469 * backend can use the credentials when printing.
10474 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
10475 krb5_cc_get_name(KerberosContext
, job
->ccache
));
10477 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
10480 cupsdClearString(&(job
->ccname
));
10482 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10486 * 'send_document()' - Send a file to a printer or class.
10490 send_document(cupsd_client_t
*con
, /* I - Client connection */
10491 ipp_attribute_t
*uri
) /* I - Printer URI */
10493 ipp_attribute_t
*attr
; /* Current attribute */
10494 ipp_attribute_t
*format
; /* Request's document-format attribute */
10495 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10496 const char *default_format
;/* document-format-default value */
10497 int jobid
; /* Job ID number */
10498 cupsd_job_t
*job
; /* Current job */
10499 char job_uri
[HTTP_MAX_URI
],
10501 scheme
[HTTP_MAX_URI
],
10502 /* Method portion of URI */
10503 username
[HTTP_MAX_URI
],
10504 /* Username portion of URI */
10505 host
[HTTP_MAX_URI
],
10506 /* Host portion of URI */
10507 resource
[HTTP_MAX_URI
];
10508 /* Resource portion of URI */
10509 int port
; /* Port portion of URI */
10510 mime_type_t
*filetype
; /* Type of file */
10511 char super
[MIME_MAX_SUPER
],
10512 /* Supertype of file */
10513 type
[MIME_MAX_TYPE
],
10514 /* Subtype of file */
10515 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10516 /* Textual name of mime type */
10517 char filename
[1024]; /* Job filename */
10518 cupsd_printer_t
*printer
; /* Current printer */
10519 struct stat fileinfo
; /* File information */
10520 int kbytes
; /* Size of file */
10521 int compression
; /* Type of compression */
10522 int start_job
; /* Start the job? */
10525 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10526 con
->http
.fd
, uri
->values
[0].string
.text
);
10529 * See if we have a job URI or a printer URI...
10532 if (!strcmp(uri
->name
, "printer-uri"))
10535 * Got a printer URI; see if we also have a job-id attribute...
10538 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10539 IPP_TAG_INTEGER
)) == NULL
)
10541 send_ipp_status(con
, IPP_BAD_REQUEST
,
10542 _("Got a printer-uri attribute but no job-id"));
10546 jobid
= attr
->values
[0].integer
;
10551 * Got a job URI; parse it to get the job ID...
10554 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10555 sizeof(scheme
), username
, sizeof(username
), host
,
10556 sizeof(host
), &port
, resource
, sizeof(resource
));
10558 if (strncmp(resource
, "/jobs/", 6))
10564 send_ipp_status(con
, IPP_BAD_REQUEST
,
10565 _("Bad job-uri attribute \"%s\""),
10566 uri
->values
[0].string
.text
);
10570 jobid
= atoi(resource
+ 6);
10574 * See if the job exists...
10577 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10580 * Nope - return a "not found" error...
10583 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10587 printer
= cupsdFindDest(job
->dest
);
10590 * See if the job is owned by the requesting user...
10593 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10595 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10596 cupsdFindDest(job
->dest
));
10601 * OK, see if the client is sending the document compressed - CUPS
10602 * only supports "none" and "gzip".
10605 compression
= CUPS_FILE_NONE
;
10607 if ((attr
= ippFindAttribute(con
->request
, "compression",
10608 IPP_TAG_KEYWORD
)) != NULL
)
10610 if (strcmp(attr
->values
[0].string
.text
, "none")
10612 && strcmp(attr
->values
[0].string
.text
, "gzip")
10613 #endif /* HAVE_LIBZ */
10616 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\""),
10617 attr
->values
[0].string
.text
);
10618 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10619 "compression", NULL
, attr
->values
[0].string
.text
);
10624 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10625 compression
= CUPS_FILE_GZIP
;
10626 #endif /* HAVE_LIBZ */
10630 * Do we have a file to print?
10633 if (!con
->filename
)
10636 * Check for an empty request with "last-document" set to true, which is
10637 * used to close an "open" job by RFC 2911, section 3.3.2.
10640 if (job
->num_files
> 0 &&
10641 (attr
= ippFindAttribute(con
->request
, "last-document",
10642 IPP_TAG_BOOLEAN
)) != NULL
&&
10643 attr
->values
[0].boolean
)
10644 goto last_document
;
10646 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
10651 * Is it a format we support?
10654 if ((format
= ippFindAttribute(con
->request
, "document-format",
10655 IPP_TAG_MIMETYPE
)) != NULL
)
10658 * Grab format from client...
10661 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10664 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
10665 format
->values
[0].string
.text
);
10669 else if ((default_format
= cupsGetOption("document-format",
10670 printer
->num_options
,
10671 printer
->options
)) != NULL
)
10674 * Use default document format...
10677 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10679 send_ipp_status(con
, IPP_BAD_REQUEST
,
10680 _("Could not scan type \"%s\""),
10688 * No document format attribute? Auto-type it!
10691 strcpy(super
, "application");
10692 strcpy(type
, "octet-stream");
10695 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10698 * Auto-type the file...
10701 ipp_attribute_t
*doc_name
; /* document-name attribute */
10704 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10706 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10707 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10708 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10712 filetype
= mimeType(MimeDatabase
, super
, type
);
10715 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10716 filetype
->super
, filetype
->type
);
10719 filetype
= mimeType(MimeDatabase
, super
, type
);
10724 * Replace the document-format attribute value with the auto-typed or
10728 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10731 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10732 IPP_TAG_MIMETYPE
)) != NULL
)
10734 _cupsStrFree(jformat
->values
[0].string
.text
);
10736 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10739 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10740 "document-format", NULL
, mimetype
);
10742 else if (!filetype
)
10744 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10745 _("Unsupported format \'%s/%s\'"), super
, type
);
10746 cupsdLogMessage(CUPSD_LOG_INFO
,
10747 "Hint: Do you have the raw file printing rules enabled?");
10750 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10751 "document-format", NULL
, format
->values
[0].string
.text
);
10756 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10758 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10761 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10762 _("Unsupported format \'%s\'"), mimetype
);
10764 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10765 "document-format", NULL
, mimetype
);
10771 * Add the file to the job...
10776 if (add_file(con
, job
, filetype
, compression
))
10779 if (stat(con
->filename
, &fileinfo
))
10782 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10784 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10786 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10787 IPP_TAG_INTEGER
)) != NULL
)
10788 attr
->values
[0].integer
+= kbytes
;
10790 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10792 rename(con
->filename
, filename
);
10794 cupsdClearString(&con
->filename
);
10796 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10797 filetype
->super
, filetype
->type
, job
->username
);
10800 * Start the job if this is the last document...
10805 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10806 IPP_TAG_BOOLEAN
)) != NULL
&&
10807 attr
->values
[0].boolean
)
10810 * See if we need to add the ending sheet...
10813 if (cupsdTimeoutJob(job
))
10816 if (job
->state_value
== IPP_JOB_STOPPED
)
10818 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10819 job
->state_value
= IPP_JOB_PENDING
;
10821 else if (job
->state_value
== IPP_JOB_HELD
)
10823 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10824 IPP_TAG_KEYWORD
)) == NULL
)
10825 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10827 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10829 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10830 job
->state_value
= IPP_JOB_PENDING
;
10835 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10841 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10842 IPP_TAG_KEYWORD
)) == NULL
)
10843 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10845 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10847 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10848 job
->state_value
= IPP_JOB_HELD
;
10849 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10852 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10859 * Fill in the response info...
10862 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10865 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10868 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10870 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10872 add_job_state_reasons(con
, job
);
10874 con
->response
->request
.status
.status_code
= IPP_OK
;
10877 * Start the job if necessary...
10886 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10891 cupsd_client_t
*con
, /* I - Client connection */
10892 http_status_t status
, /* I - HTTP status code */
10893 cupsd_printer_t
*printer
) /* I - Printer, if any */
10895 ipp_attribute_t
*uri
; /* Request URI, if any */
10898 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10899 IPP_TAG_URI
)) == NULL
)
10900 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10902 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10903 "Returning HTTP %s for %s (%s) from %s",
10904 httpStatus(status
),
10905 ippOpString(con
->request
->request
.op
.operation_id
),
10906 uri
? uri
->values
[0].string
.text
: "no URI",
10907 con
->http
.hostname
);
10911 int auth_type
; /* Type of authentication required */
10914 auth_type
= CUPSD_AUTH_NONE
;
10916 if (status
== HTTP_UNAUTHORIZED
&&
10917 printer
->num_auth_info_required
> 0 &&
10918 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10920 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10921 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10922 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10925 * Creating and authenticating jobs requires Kerberos...
10928 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10933 * Use policy/location-defined authentication requirements...
10936 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10937 cupsd_location_t
*auth
; /* Pointer to authentication element */
10940 if (printer
->type
& CUPS_PRINTER_CLASS
)
10941 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10943 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10945 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10946 auth
->type
== CUPSD_AUTH_NONE
)
10947 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10949 con
->request
->request
.op
.operation_id
:
10954 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10955 auth_type
= DefaultAuthType
;
10957 auth_type
= auth
->type
;
10961 cupsdSendError(con
, status
, auth_type
);
10964 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10966 ippDelete(con
->response
);
10967 con
->response
= NULL
;
10974 * 'send_ipp_status()' - Send a status back to the IPP client.
10978 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10979 ipp_status_t status
, /* I - IPP status code */
10980 const char *message
,/* I - Status message */
10981 ...) /* I - Additional args as needed */
10983 va_list ap
; /* Pointer to additional args */
10984 char formatted
[1024]; /* Formatted errror message */
10987 va_start(ap
, message
);
10988 vsnprintf(formatted
, sizeof(formatted
),
10989 _cupsLangString(con
->language
, message
), ap
);
10992 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10993 ippOpString(con
->request
->request
.op
.operation_id
),
10994 ippErrorString(status
), formatted
);
10996 con
->response
->request
.status
.status_code
= status
;
10998 if (ippFindAttribute(con
->response
, "attributes-charset",
10999 IPP_TAG_ZERO
) == NULL
)
11000 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
11001 "attributes-charset", NULL
, "utf-8");
11003 if (ippFindAttribute(con
->response
, "attributes-natural-language",
11004 IPP_TAG_ZERO
) == NULL
)
11005 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
11006 "attributes-natural-language", NULL
, DefaultLanguage
);
11008 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
11009 "status-message", NULL
, formatted
);
11014 * 'set_default()' - Set the default destination...
11018 set_default(cupsd_client_t
*con
, /* I - Client connection */
11019 ipp_attribute_t
*uri
) /* I - Printer URI */
11021 http_status_t status
; /* Policy status */
11022 cups_ptype_t dtype
; /* Destination type (printer/class) */
11023 cupsd_printer_t
*printer
, /* Printer */
11024 *oldprinter
; /* Old default printer */
11027 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
11028 con
->http
.fd
, uri
->values
[0].string
.text
);
11031 * Is the destination valid?
11034 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11040 send_ipp_status(con
, IPP_NOT_FOUND
,
11041 _("The printer or class was not found."));
11049 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
11051 send_http_error(con
, status
, NULL
);
11056 * Set it as the default...
11059 oldprinter
= DefaultPrinter
;
11060 DefaultPrinter
= printer
;
11063 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
11064 "%s is no longer the default printer.", oldprinter
->name
);
11066 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
11067 "%s is now the default printer.", printer
->name
);
11069 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
11070 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
11072 cupsdLogMessage(CUPSD_LOG_INFO
,
11073 "Default destination set to \"%s\" by \"%s\".",
11074 printer
->name
, get_username(con
));
11077 * Everything was ok, so return OK status...
11080 con
->response
->request
.status
.status_code
= IPP_OK
;
11085 * 'set_job_attrs()' - Set job attributes.
11089 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
11090 ipp_attribute_t
*uri
) /* I - Job URI */
11092 ipp_attribute_t
*attr
, /* Current attribute */
11093 *attr2
; /* Job attribute */
11094 int jobid
; /* Job ID */
11095 cupsd_job_t
*job
; /* Current job */
11096 char scheme
[HTTP_MAX_URI
],
11097 /* Method portion of URI */
11098 username
[HTTP_MAX_URI
],
11099 /* Username portion of URI */
11100 host
[HTTP_MAX_URI
],
11101 /* Host portion of URI */
11102 resource
[HTTP_MAX_URI
];
11103 /* Resource portion of URI */
11104 int port
; /* Port portion of URI */
11105 int event
; /* Events? */
11106 int check_jobs
; /* Check jobs? */
11109 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
11110 con
->http
.fd
, uri
->values
[0].string
.text
);
11113 * Start with "everything is OK" status...
11116 con
->response
->request
.status
.status_code
= IPP_OK
;
11119 * See if we have a job URI or a printer URI...
11122 if (!strcmp(uri
->name
, "printer-uri"))
11125 * Got a printer URI; see if we also have a job-id attribute...
11128 if ((attr
= ippFindAttribute(con
->request
, "job-id",
11129 IPP_TAG_INTEGER
)) == NULL
)
11131 send_ipp_status(con
, IPP_BAD_REQUEST
,
11132 _("Got a printer-uri attribute but no job-id"));
11136 jobid
= attr
->values
[0].integer
;
11141 * Got a job URI; parse it to get the job ID...
11144 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
11145 sizeof(scheme
), username
, sizeof(username
), host
,
11146 sizeof(host
), &port
, resource
, sizeof(resource
));
11148 if (strncmp(resource
, "/jobs/", 6))
11154 send_ipp_status(con
, IPP_BAD_REQUEST
,
11155 _("Bad job-uri attribute \"%s\""),
11156 uri
->values
[0].string
.text
);
11160 jobid
= atoi(resource
+ 6);
11164 * See if the job exists...
11167 if ((job
= cupsdFindJob(jobid
)) == NULL
)
11170 * Nope - return a "not found" error...
11173 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
11178 * See if the job has been completed...
11181 if (job
->state_value
> IPP_JOB_STOPPED
)
11184 * Return a "not-possible" error...
11187 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11188 _("Job #%d is finished and cannot be altered"), jobid
);
11193 * See if the job is owned by the requesting user...
11196 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
11198 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
11199 cupsdFindDest(job
->dest
));
11204 * See what the user wants to change.
11212 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11214 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
11217 if (!strcmp(attr
->name
, "attributes-charset") ||
11218 !strcmp(attr
->name
, "attributes-natural-language") ||
11219 !strcmp(attr
->name
, "document-compression") ||
11220 !strcmp(attr
->name
, "document-format") ||
11221 !strcmp(attr
->name
, "job-detailed-status-messages") ||
11222 !strcmp(attr
->name
, "job-document-access-errors") ||
11223 !strcmp(attr
->name
, "job-id") ||
11224 !strcmp(attr
->name
, "job-impressions-completed") ||
11225 !strcmp(attr
->name
, "job-k-octets") ||
11226 !strcmp(attr
->name
, "job-originating-host-name") ||
11227 !strcmp(attr
->name
, "job-originating-user-name") ||
11228 !strcmp(attr
->name
, "job-printer-up-time") ||
11229 !strcmp(attr
->name
, "job-printer-uri") ||
11230 !strcmp(attr
->name
, "job-sheets") ||
11231 !strcmp(attr
->name
, "job-state-message") ||
11232 !strcmp(attr
->name
, "job-state-reasons") ||
11233 !strcmp(attr
->name
, "job-uri") ||
11234 !strcmp(attr
->name
, "number-of-documents") ||
11235 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
11236 !strcmp(attr
->name
, "output-device-assigned") ||
11237 !strncmp(attr
->name
, "date-time-at-", 13) ||
11238 !strncmp(attr
->name
, "job-k-octets", 12) ||
11239 !strncmp(attr
->name
, "job-media-sheets", 16) ||
11240 !strncmp(attr
->name
, "time-at-", 8))
11246 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
11247 _("%s cannot be changed."), attr
->name
);
11249 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11250 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11255 if (!strcmp(attr
->name
, "job-priority"))
11258 * Change the job priority...
11261 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11263 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value"));
11265 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11266 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11268 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
11270 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11271 _("Job is completed and cannot be changed."));
11274 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11276 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
11277 attr
->values
[0].integer
);
11278 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
11281 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
11282 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
11285 else if (!strcmp(attr
->name
, "job-state"))
11288 * Change the job state...
11291 if (attr
->value_tag
!= IPP_TAG_ENUM
)
11293 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value"));
11295 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11296 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11300 switch (attr
->values
[0].integer
)
11302 case IPP_JOB_PENDING
:
11303 case IPP_JOB_HELD
:
11304 if (job
->state_value
> IPP_JOB_HELD
)
11306 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11307 _("Job state cannot be changed."));
11310 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11312 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11313 attr
->values
[0].integer
);
11314 cupsdSetJobState(job
, attr
->values
[0].integer
,
11316 "Job state changed by \"%s\"", username
);
11321 case IPP_JOB_PROCESSING
:
11322 case IPP_JOB_STOPPED
:
11323 if (job
->state_value
!= attr
->values
[0].integer
)
11325 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11326 _("Job state cannot be changed."));
11331 case IPP_JOB_CANCELED
:
11332 case IPP_JOB_ABORTED
:
11333 case IPP_JOB_COMPLETED
:
11334 if (job
->state_value
> IPP_JOB_PROCESSING
)
11336 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11337 _("Job state cannot be changed."));
11340 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11342 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11343 attr
->values
[0].integer
);
11344 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
11346 "Job state changed by \"%s\"", username
);
11353 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
11355 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11356 IPP_TAG_ZERO
)) != NULL
)
11359 * Some other value; first free the old value...
11362 if (job
->attrs
->prev
)
11363 job
->attrs
->prev
->next
= attr2
->next
;
11365 job
->attrs
->attrs
= attr2
->next
;
11367 if (job
->attrs
->last
== attr2
)
11368 job
->attrs
->last
= job
->attrs
->prev
;
11370 _ippFreeAttr(attr2
);
11373 * Then copy the attribute...
11376 copy_attribute(job
->attrs
, attr
, 0);
11379 * See if the job-name or job-hold-until is being changed.
11382 if (!strcmp(attr
->name
, "job-hold-until"))
11384 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
11385 attr
->values
[0].string
.text
);
11386 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
11388 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
11390 cupsdReleaseJob(job
);
11394 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
11395 "Job held by \"%s\".", username
);
11397 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
11400 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
11403 * Delete the attribute...
11406 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11407 IPP_TAG_ZERO
)) != NULL
)
11409 if (job
->attrs
->prev
)
11410 job
->attrs
->prev
->next
= attr2
->next
;
11412 job
->attrs
->attrs
= attr2
->next
;
11414 if (attr2
== job
->attrs
->last
)
11415 job
->attrs
->last
= job
->attrs
->prev
;
11417 _ippFreeAttr(attr2
);
11419 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11425 * Add new option by copying it...
11428 copy_attribute(job
->attrs
, attr
, 0);
11430 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11439 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11442 * Send events as needed...
11445 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11446 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11447 cupsdFindDest(job
->dest
), job
,
11448 "Job priority changed by user.");
11450 if (event
& CUPSD_EVENT_JOB_STATE
)
11451 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11452 job
->state_value
== IPP_JOB_HELD
?
11453 "Job held by user." : "Job restarted by user.");
11455 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11456 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11457 "Job options changed by user.");
11460 * Start jobs if possible...
11469 * 'set_printer_attrs()' - Set printer attributes.
11473 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11474 ipp_attribute_t
*uri
) /* I - Printer */
11476 http_status_t status
; /* Policy status */
11477 cups_ptype_t dtype
; /* Destination type (printer/class) */
11478 cupsd_printer_t
*printer
; /* Printer/class */
11479 ipp_attribute_t
*attr
; /* Printer attribute */
11480 int changed
= 0; /* Was anything changed? */
11483 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11484 con
->http
.fd
, uri
->values
[0].string
.text
);
11487 * Is the destination valid?
11490 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11496 send_ipp_status(con
, IPP_NOT_FOUND
,
11497 _("The printer or class was not found."));
11505 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11507 send_http_error(con
, status
, printer
);
11512 * Return a list of attributes that can be set via Set-Printer-Attributes.
11515 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11516 IPP_TAG_TEXT
)) != NULL
)
11518 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11522 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11523 IPP_TAG_TEXT
)) != NULL
)
11525 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11530 * Update the printer attributes and return...
11535 cupsdSetPrinterAttrs(printer
);
11536 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11538 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11539 "Printer \"%s\" description or location changed by \"%s\".",
11540 printer
->name
, get_username(con
));
11542 cupsdLogMessage(CUPSD_LOG_INFO
,
11543 "Printer \"%s\" description or location changed by \"%s\".",
11544 printer
->name
, get_username(con
));
11547 con
->response
->request
.status
.status_code
= IPP_OK
;
11552 * 'set_printer_defaults()' - Set printer default options from a request.
11556 set_printer_defaults(
11557 cupsd_client_t
*con
, /* I - Client connection */
11558 cupsd_printer_t
*printer
) /* I - Printer */
11560 int i
; /* Looping var */
11561 ipp_attribute_t
*attr
; /* Current attribute */
11562 int namelen
; /* Length of attribute name */
11563 char name
[256], /* New attribute name */
11564 value
[256]; /* String version of integer attrs */
11567 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11570 * Skip non-printer attributes...
11573 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11576 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11578 if (!strcmp(attr
->name
, "job-sheets-default"))
11581 * Only allow keywords and names...
11584 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11588 * Only allow job-sheets-default to be set when running without a
11589 * system high classification level...
11592 if (Classification
)
11595 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11597 if (attr
->num_values
> 1)
11598 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11600 cupsdSetString(&printer
->job_sheets
[1], "none");
11602 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11604 cupsdFreeStrings(&(printer
->users
));
11606 printer
->deny_users
= 0;
11608 if (attr
->value_tag
== IPP_TAG_NAME
&&
11609 (attr
->num_values
> 1 ||
11610 strcmp(attr
->values
[0].string
.text
, "all")))
11612 for (i
= 0; i
< attr
->num_values
; i
++)
11613 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11616 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11618 cupsdFreeStrings(&(printer
->users
));
11620 printer
->deny_users
= 1;
11622 if (attr
->value_tag
== IPP_TAG_NAME
&&
11623 (attr
->num_values
> 1 ||
11624 strcmp(attr
->values
[0].string
.text
, "none")))
11626 for (i
= 0; i
< attr
->num_values
; i
++)
11627 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11630 else if (!strcmp(attr
->name
, "job-quota-period"))
11632 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11635 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11636 attr
->values
[0].integer
);
11637 cupsdFreeQuotas(printer
);
11639 printer
->quota_period
= attr
->values
[0].integer
;
11641 else if (!strcmp(attr
->name
, "job-k-limit"))
11643 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11646 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11647 attr
->values
[0].integer
);
11648 cupsdFreeQuotas(printer
);
11650 printer
->k_limit
= attr
->values
[0].integer
;
11652 else if (!strcmp(attr
->name
, "job-page-limit"))
11654 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11657 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11658 attr
->values
[0].integer
);
11659 cupsdFreeQuotas(printer
);
11661 printer
->page_limit
= attr
->values
[0].integer
;
11663 else if (!strcmp(attr
->name
, "printer-op-policy"))
11665 cupsd_policy_t
*p
; /* Policy */
11668 if (attr
->value_tag
!= IPP_TAG_NAME
)
11671 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11673 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11674 "Setting printer-op-policy to \"%s\"...",
11675 attr
->values
[0].string
.text
);
11676 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11677 printer
->op_policy_ptr
= p
;
11681 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11682 _("Unknown printer-op-policy \"%s\"."),
11683 attr
->values
[0].string
.text
);
11687 else if (!strcmp(attr
->name
, "printer-error-policy"))
11689 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11692 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11693 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
11694 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11695 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11696 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11698 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11699 _("Unknown printer-error-policy \"%s\"."),
11700 attr
->values
[0].string
.text
);
11704 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11705 "Setting printer-error-policy to \"%s\"...",
11706 attr
->values
[0].string
.text
);
11707 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11711 * Skip any other non-default attributes...
11714 namelen
= strlen(attr
->name
);
11715 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11716 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11720 * OK, anything else must be a user-defined default...
11723 strlcpy(name
, attr
->name
, sizeof(name
));
11724 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11726 switch (attr
->value_tag
)
11728 case IPP_TAG_DELETEATTR
:
11729 printer
->num_options
= cupsRemoveOption(name
,
11730 printer
->num_options
,
11731 &(printer
->options
));
11732 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11733 "Deleting %s", attr
->name
);
11736 case IPP_TAG_NAME
:
11737 case IPP_TAG_KEYWORD
:
11739 printer
->num_options
= cupsAddOption(name
,
11740 attr
->values
[0].string
.text
,
11741 printer
->num_options
,
11742 &(printer
->options
));
11743 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11744 "Setting %s to \"%s\"...", attr
->name
,
11745 attr
->values
[0].string
.text
);
11748 case IPP_TAG_BOOLEAN
:
11749 printer
->num_options
= cupsAddOption(name
,
11750 attr
->values
[0].boolean
?
11752 printer
->num_options
,
11753 &(printer
->options
));
11754 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11755 "Setting %s to %s...", attr
->name
,
11756 attr
->values
[0].boolean
? "true" : "false");
11759 case IPP_TAG_INTEGER
:
11760 case IPP_TAG_ENUM
:
11761 sprintf(value
, "%d", attr
->values
[0].integer
);
11762 printer
->num_options
= cupsAddOption(name
, value
,
11763 printer
->num_options
,
11764 &(printer
->options
));
11765 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11766 "Setting %s to %s...", attr
->name
, value
);
11769 case IPP_TAG_RANGE
:
11770 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11771 attr
->values
[0].range
.upper
);
11772 printer
->num_options
= cupsAddOption(name
, value
,
11773 printer
->num_options
,
11774 &(printer
->options
));
11775 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11776 "Setting %s to %s...", attr
->name
, value
);
11779 case IPP_TAG_RESOLUTION
:
11780 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11781 attr
->values
[0].resolution
.yres
,
11782 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11784 printer
->num_options
= cupsAddOption(name
, value
,
11785 printer
->num_options
,
11786 &(printer
->options
));
11787 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11788 "Setting %s to %s...", attr
->name
, value
);
11792 /* Do nothing for other values */
11800 * 'start_printer()' - Start a printer.
11804 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11805 ipp_attribute_t
*uri
) /* I - Printer URI */
11807 int i
; /* Temporary variable */
11808 http_status_t status
; /* Policy status */
11809 cups_ptype_t dtype
; /* Destination type (printer/class) */
11810 cupsd_printer_t
*printer
; /* Printer data */
11813 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11814 con
->http
.fd
, uri
->values
[0].string
.text
);
11817 * Is the destination valid?
11820 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11826 send_ipp_status(con
, IPP_NOT_FOUND
,
11827 _("The printer or class was not found."));
11835 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11837 send_http_error(con
, status
, printer
);
11842 * Start the printer...
11845 printer
->state_message
[0] = '\0';
11847 cupsdStartPrinter(printer
, 1);
11849 if (dtype
& CUPS_PRINTER_CLASS
)
11850 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11851 printer
->name
, get_username(con
));
11853 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11854 printer
->name
, get_username(con
));
11862 if ((i
= check_quotas(con
, printer
)) < 0)
11864 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
11869 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
11874 * Everything was ok, so return OK status...
11877 con
->response
->request
.status
.status_code
= IPP_OK
;
11882 * 'stop_printer()' - Stop a printer.
11886 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11887 ipp_attribute_t
*uri
) /* I - Printer URI */
11889 http_status_t status
; /* Policy status */
11890 cups_ptype_t dtype
; /* Destination type (printer/class) */
11891 cupsd_printer_t
*printer
; /* Printer data */
11892 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11895 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11896 con
->http
.fd
, uri
->values
[0].string
.text
);
11899 * Is the destination valid?
11902 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11908 send_ipp_status(con
, IPP_NOT_FOUND
,
11909 _("The printer or class was not found."));
11917 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11919 send_http_error(con
, status
, printer
);
11924 * Stop the printer...
11927 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11928 IPP_TAG_TEXT
)) == NULL
)
11929 strcpy(printer
->state_message
, "Paused");
11932 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11933 sizeof(printer
->state_message
));
11936 cupsdStopPrinter(printer
, 1);
11938 if (dtype
& CUPS_PRINTER_CLASS
)
11939 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11940 printer
->name
, get_username(con
));
11942 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11943 printer
->name
, get_username(con
));
11946 * Everything was ok, so return OK status...
11949 con
->response
->request
.status
.status_code
= IPP_OK
;
11954 * 'url_encode_attr()' - URL-encode a string attribute.
11958 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11959 char *buffer
,/* I - String buffer */
11960 int bufsize
)/* I - Size of buffer */
11962 int i
; /* Looping var */
11963 char *bufptr
, /* Pointer into buffer */
11964 *bufend
; /* End of buffer */
11967 strlcpy(buffer
, attr
->name
, bufsize
);
11968 bufptr
= buffer
+ strlen(buffer
);
11969 bufend
= buffer
+ bufsize
- 1;
11971 for (i
= 0; i
< attr
->num_values
; i
++)
11973 if (bufptr
>= bufend
)
11981 if (bufptr
>= bufend
)
11986 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11987 bufptr
, bufend
- bufptr
+ 1);
11989 if (bufptr
>= bufend
)
12000 * 'url_encode_string()' - URL-encode a string.
12003 static char * /* O - End of string */
12004 url_encode_string(const char *s
, /* I - String */
12005 char *buffer
, /* I - String buffer */
12006 int bufsize
) /* I - Size of buffer */
12008 char *bufptr
, /* Pointer into buffer */
12009 *bufend
; /* End of buffer */
12010 static const char *hex
= "0123456789ABCDEF";
12015 bufend
= buffer
+ bufsize
- 1;
12017 while (*s
&& bufptr
< bufend
)
12019 if (*s
== ' ' || *s
== '%' || *s
== '+')
12021 if (bufptr
>= (bufend
- 2))
12025 *bufptr
++ = hex
[(*s
>> 4) & 15];
12026 *bufptr
++ = hex
[*s
& 15];
12030 else if (*s
== '\'' || *s
== '\\')
12032 if (bufptr
>= (bufend
- 1))
12049 * 'user_allowed()' - See if a user is allowed to print to a queue.
12052 static int /* O - 0 if not allowed, 1 if allowed */
12053 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
12054 const char *username
) /* I - Username */
12056 struct passwd
*pw
; /* User password data */
12057 char baseuser
[256], /* Base username */
12058 *baseptr
, /* Pointer to "@" in base username */
12059 *name
; /* Current user name */
12062 if (cupsArrayCount(p
->users
) == 0)
12065 if (!strcmp(username
, "root"))
12068 if (strchr(username
, '@'))
12071 * Strip @REALM for username check...
12074 strlcpy(baseuser
, username
, sizeof(baseuser
));
12076 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
12079 username
= baseuser
;
12082 pw
= getpwnam(username
);
12085 for (name
= (char *)cupsArrayFirst(p
->users
);
12087 name
= (char *)cupsArrayNext(p
->users
))
12089 if (name
[0] == '@')
12092 * Check group membership...
12095 if (cupsdCheckGroup(username
, pw
, name
+ 1))
12098 else if (name
[0] == '#')
12104 if (cupsdCheckGroup(username
, pw
, name
))
12107 else if (!strcasecmp(username
, name
))
12111 return ((name
!= NULL
) != p
->deny_users
);
12116 * 'validate_job()' - Validate printer options and destination.
12120 validate_job(cupsd_client_t
*con
, /* I - Client connection */
12121 ipp_attribute_t
*uri
) /* I - Printer URI */
12123 http_status_t status
; /* Policy status */
12124 ipp_attribute_t
*attr
, /* Current attribute */
12125 *auth_info
; /* auth-info attribute */
12126 ipp_attribute_t
*format
; /* Document-format attribute */
12127 cups_ptype_t dtype
; /* Destination type (printer/class) */
12128 char super
[MIME_MAX_SUPER
],
12129 /* Supertype of file */
12130 type
[MIME_MAX_TYPE
];
12131 /* Subtype of file */
12132 cupsd_printer_t
*printer
; /* Printer */
12135 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
12136 con
->http
.fd
, uri
->values
[0].string
.text
);
12139 * OK, see if the client is sending the document compressed - CUPS
12140 * doesn't support compression yet...
12143 if ((attr
= ippFindAttribute(con
->request
, "compression",
12144 IPP_TAG_KEYWORD
)) != NULL
)
12146 if (strcmp(attr
->values
[0].string
.text
, "none")
12148 && strcmp(attr
->values
[0].string
.text
, "gzip")
12149 #endif /* HAVE_LIBZ */
12152 send_ipp_status(con
, IPP_ATTRIBUTES
,
12153 _("Unsupported compression \"%s\""),
12154 attr
->values
[0].string
.text
);
12155 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
12156 "compression", NULL
, attr
->values
[0].string
.text
);
12162 * Is it a format we support?
12165 if ((format
= ippFindAttribute(con
->request
, "document-format",
12166 IPP_TAG_MIMETYPE
)) != NULL
)
12168 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
12171 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
12172 format
->values
[0].string
.text
);
12176 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
12177 !mimeType(MimeDatabase
, super
, type
))
12179 cupsdLogMessage(CUPSD_LOG_INFO
,
12180 "Hint: Do you have the raw file printing rules enabled?");
12181 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
12182 _("Unsupported document-format \"%s\""),
12183 format
->values
[0].string
.text
);
12184 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
12185 "document-format", NULL
, format
->values
[0].string
.text
);
12191 * Is the destination valid?
12194 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
12200 send_ipp_status(con
, IPP_NOT_FOUND
,
12201 _("The printer or class was not found."));
12209 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
12211 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
12213 send_http_error(con
, status
, printer
);
12216 else if (printer
->num_auth_info_required
== 1 &&
12217 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
12220 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
12224 else if (auth_info
&& !con
->http
.tls
&&
12225 !httpAddrLocalhost(con
->http
.hostaddr
))
12228 * Require encryption of auth-info over non-local connections...
12231 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
12234 #endif /* HAVE_SSL */
12237 * Everything was ok, so return OK status...
12240 con
->response
->request
.status
.status_code
= IPP_OK
;
12245 * 'validate_name()' - Make sure the printer name only contains valid chars.
12248 static int /* O - 0 if name is no good, 1 if good */
12249 validate_name(const char *name
) /* I - Name to check */
12251 const char *ptr
; /* Pointer into name */
12255 * Scan the whole name...
12258 for (ptr
= name
; *ptr
; ptr
++)
12259 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
12263 * All the characters are good; validate the length, too...
12266 return ((ptr
- name
) < 128);
12271 * 'validate_user()' - Validate the user for the request.
12274 static int /* O - 1 if permitted, 0 otherwise */
12275 validate_user(cupsd_job_t
*job
, /* I - Job */
12276 cupsd_client_t
*con
, /* I - Client connection */
12277 const char *owner
, /* I - Owner of job/resource */
12278 char *username
, /* O - Authenticated username */
12279 int userlen
) /* I - Length of username */
12281 cupsd_printer_t
*printer
; /* Printer for job */
12284 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
12285 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
12287 job
->id
, con
? con
->http
.fd
: 0,
12288 owner
? owner
: "(null)", username
, userlen
);
12291 * Validate input...
12294 if (!con
|| !owner
|| !username
|| userlen
<= 0)
12298 * Get the best authenticated username that is available.
12301 strlcpy(username
, get_username(con
), userlen
);
12304 * Check the username against the owner...
12307 printer
= cupsdFindDest(job
->dest
);
12309 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
12310 con
, owner
) == HTTP_OK
);
12315 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".