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 does not exist."));
916 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
918 send_http_error(con
, status
, printer
);
923 * Accept jobs sent to the printer...
926 printer
->accepting
= 1;
927 printer
->state_message
[0] = '\0';
929 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
930 "Now accepting jobs.");
932 if (dtype
& CUPS_PRINTER_CLASS
)
934 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
936 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
937 printer
->name
, get_username(con
));
941 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
943 cupsdLogMessage(CUPSD_LOG_INFO
,
944 "Printer \"%s\" now accepting jobs (\"%s\").",
945 printer
->name
, get_username(con
));
949 * Everything was ok, so return OK status...
952 con
->response
->request
.status
.status_code
= IPP_OK
;
957 * 'add_class()' - Add a class to the system.
961 add_class(cupsd_client_t
*con
, /* I - Client connection */
962 ipp_attribute_t
*uri
) /* I - URI of class */
964 http_status_t status
; /* Policy status */
965 int i
; /* Looping var */
966 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
967 username
[HTTP_MAX_URI
], /* Username portion of URI */
968 host
[HTTP_MAX_URI
], /* Host portion of URI */
969 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
970 int port
; /* Port portion of URI */
971 cupsd_printer_t
*pclass
, /* Class */
972 *member
; /* Member printer/class */
973 cups_ptype_t dtype
; /* Destination type */
974 ipp_attribute_t
*attr
; /* Printer attribute */
975 int modify
; /* Non-zero if we just modified */
976 char newname
[IPP_MAX_NAME
]; /* New class name */
977 int need_restart_job
; /* Need to restart job? */
980 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
981 con
->http
.fd
, uri
->values
[0].string
.text
);
984 * Do we have a valid URI?
987 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
988 sizeof(scheme
), username
, sizeof(username
), host
,
989 sizeof(host
), &port
, resource
, sizeof(resource
));
992 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
995 * No, return an error...
998 send_ipp_status(con
, IPP_BAD_REQUEST
,
999 _("The printer-uri must be of the form "
1000 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
1005 * Do we have a valid printer name?
1008 if (!validate_name(resource
+ 9))
1011 * No, return an error...
1014 send_ipp_status(con
, IPP_BAD_REQUEST
,
1015 _("The printer-uri \"%s\" contains invalid characters."),
1016 uri
->values
[0].string
.text
);
1021 * See if the class already exists; if not, create a new class...
1024 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1027 * Class doesn't exist; see if we have a printer of the same name...
1030 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
1031 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
1034 * Yes, return an error...
1037 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1038 _("A printer named \"%s\" already exists."),
1044 * No, check the default policy and then add the class...
1047 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1049 send_http_error(con
, status
, NULL
);
1053 pclass
= cupsdAddClass(resource
+ 9);
1056 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1059 * Check the default policy, then rename the implicit class to "AnyClass"
1063 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1065 send_http_error(con
, status
, NULL
);
1069 if (ImplicitAnyClasses
)
1071 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1072 cupsdRenamePrinter(pclass
, newname
);
1075 cupsdDeletePrinter(pclass
, 1);
1078 * Add the class as a new local class...
1081 pclass
= cupsdAddClass(resource
+ 9);
1084 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1087 * Check the default policy, then rename the remote class to "Class"...
1090 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1092 send_http_error(con
, status
, NULL
);
1096 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1097 cupsdRenamePrinter(pclass
, newname
);
1100 * Add the class as a new local class...
1103 pclass
= cupsdAddClass(resource
+ 9);
1106 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1109 send_http_error(con
, status
, pclass
);
1116 * Look for attributes and copy them over as needed...
1119 need_restart_job
= 0;
1121 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1122 IPP_TAG_TEXT
)) != NULL
)
1123 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1125 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1126 IPP_TAG_TEXT
)) != NULL
)
1127 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1129 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1130 IPP_TAG_BOOLEAN
)) != NULL
&&
1131 attr
->values
[0].boolean
!= pclass
->accepting
)
1133 cupsdLogMessage(CUPSD_LOG_INFO
,
1134 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1135 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1137 pclass
->accepting
= attr
->values
[0].boolean
;
1139 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1140 pclass
->accepting
? "Now" : "No longer");
1143 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1144 IPP_TAG_BOOLEAN
)) != NULL
)
1146 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1147 cupsdDeregisterPrinter(pclass
, 1);
1149 cupsdLogMessage(CUPSD_LOG_INFO
,
1150 "Setting %s printer-is-shared to %d (was %d.)",
1151 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1153 pclass
->shared
= attr
->values
[0].boolean
;
1156 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1157 IPP_TAG_ENUM
)) != NULL
)
1159 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1160 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1162 send_ipp_status(con
, IPP_BAD_REQUEST
,
1163 _("Attempt to set %s printer-state to bad value %d."),
1164 pclass
->name
, attr
->values
[0].integer
);
1168 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1169 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1171 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1172 cupsdStopPrinter(pclass
, 0);
1175 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1176 need_restart_job
= 1;
1179 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1180 IPP_TAG_TEXT
)) != NULL
)
1182 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1183 sizeof(pclass
->state_message
));
1185 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1186 pclass
->state_message
);
1188 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1189 IPP_TAG_URI
)) != NULL
)
1192 * Clear the printer array as needed...
1195 need_restart_job
= 1;
1197 if (pclass
->num_printers
> 0)
1199 free(pclass
->printers
);
1200 pclass
->num_printers
= 0;
1204 * Add each printer or class that is listed...
1207 for (i
= 0; i
< attr
->num_values
; i
++)
1210 * Search for the printer or class URI...
1213 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1219 send_ipp_status(con
, IPP_NOT_FOUND
,
1220 _("The printer or class does not exist."));
1223 else if (dtype
& CUPS_PRINTER_CLASS
)
1225 send_ipp_status(con
, IPP_BAD_REQUEST
,
1226 _("Nested classes are not allowed."));
1231 * Add it to the class...
1234 cupsdAddPrinterToClass(pclass
, member
);
1238 set_printer_defaults(con
, pclass
);
1240 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1241 IPP_TAG_KEYWORD
)) != NULL
)
1242 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1245 * Update the printer class attributes and return...
1248 cupsdSetPrinterAttrs(pclass
);
1249 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1251 if (need_restart_job
&& pclass
->job
)
1254 * Reset the current job to a "pending" status...
1257 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1258 "Job restarted because the class was modified.");
1261 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1265 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1266 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1267 pclass
->name
, get_username(con
));
1269 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1270 pclass
->name
, get_username(con
));
1274 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1275 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1276 pclass
->name
, get_username(con
));
1278 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1279 pclass
->name
, get_username(con
));
1282 con
->response
->request
.status
.status_code
= IPP_OK
;
1287 * 'add_file()' - Add a file to a job.
1290 static int /* O - 0 on success, -1 on error */
1291 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1292 cupsd_job_t
*job
, /* I - Job to add to */
1293 mime_type_t
*filetype
, /* I - Type of file */
1294 int compression
) /* I - Compression */
1296 mime_type_t
**filetypes
; /* New filetypes array... */
1297 int *compressions
; /* New compressions array... */
1300 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1301 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1302 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1303 filetype
->super
, filetype
->type
, compression
);
1306 * Add the file to the job...
1309 if (job
->num_files
== 0)
1311 compressions
= (int *)malloc(sizeof(int));
1312 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1316 compressions
= (int *)realloc(job
->compressions
,
1317 (job
->num_files
+ 1) * sizeof(int));
1318 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1319 (job
->num_files
+ 1) *
1320 sizeof(mime_type_t
*));
1323 if (!compressions
|| !filetypes
)
1325 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1326 "Job aborted because the scheduler ran out of memory.");
1329 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1330 _("Unable to allocate memory for file types."));
1335 job
->compressions
= compressions
;
1336 job
->compressions
[job
->num_files
] = compression
;
1337 job
->filetypes
= filetypes
;
1338 job
->filetypes
[job
->num_files
] = filetype
;
1343 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1350 * 'add_job()' - Add a job to a print queue.
1353 static cupsd_job_t
* /* O - Job object */
1354 add_job(cupsd_client_t
*con
, /* I - Client connection */
1355 cupsd_printer_t
*printer
, /* I - Destination printer */
1356 mime_type_t
*filetype
) /* I - First print file type, if any */
1358 http_status_t status
; /* Policy status */
1359 ipp_attribute_t
*attr
, /* Current attribute */
1360 *auth_info
; /* auth-info attribute */
1361 const char *val
; /* Default option value */
1362 int priority
; /* Job priority */
1363 cupsd_job_t
*job
; /* Current job */
1364 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1365 int kbytes
; /* Size of print file */
1366 int i
; /* Looping var */
1367 int lowerpagerange
; /* Page range bound */
1368 int exact
; /* Did we have an exact match? */
1369 ipp_attribute_t
*media_col
, /* media-col attribute */
1370 *media_margin
; /* media-*-margin attribute */
1371 ipp_t
*unsup_col
; /* media-col in unsupported response */
1374 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1375 con
, con
->http
.fd
, printer
, printer
->name
,
1376 filetype
, filetype
? filetype
->super
: "none",
1377 filetype
? filetype
->type
: "none");
1380 * Check remote printing to non-shared printer...
1383 if (!printer
->shared
&&
1384 strcasecmp(con
->http
.hostname
, "localhost") &&
1385 strcasecmp(con
->http
.hostname
, ServerName
))
1387 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1388 _("The printer or class is not shared."));
1396 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1398 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1400 send_http_error(con
, status
, printer
);
1403 else if (printer
->num_auth_info_required
== 1 &&
1404 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1407 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1411 else if (auth_info
&& !con
->http
.tls
&&
1412 !httpAddrLocalhost(con
->http
.hostaddr
))
1415 * Require encryption of auth-info over non-local connections...
1418 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1421 #endif /* HAVE_SSL */
1424 * See if the printer is accepting jobs...
1427 if (!printer
->accepting
)
1429 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1430 _("Destination \"%s\" is not accepting jobs."),
1436 * Validate job template attributes; for now just document-format,
1437 * copies, number-up, and page-ranges...
1440 if (filetype
&& printer
->filetypes
&&
1441 !cupsArrayFind(printer
->filetypes
, filetype
))
1443 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1444 /* MIME media type string */
1447 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1450 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1451 _("Unsupported format \"%s\"."), mimetype
);
1453 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1454 "document-format", NULL
, mimetype
);
1459 if ((attr
= ippFindAttribute(con
->request
, "copies",
1460 IPP_TAG_INTEGER
)) != NULL
)
1462 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1464 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1465 attr
->values
[0].integer
);
1466 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1467 "copies", attr
->values
[0].integer
);
1472 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1473 IPP_TAG_ZERO
)) != NULL
)
1475 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1476 attr
->value_tag
!= IPP_TAG_NAME
)
1478 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1482 if (attr
->num_values
> 2)
1484 send_ipp_status(con
, IPP_BAD_REQUEST
,
1485 _("Too many job-sheets values (%d > 2)."),
1490 for (i
= 0; i
< attr
->num_values
; i
++)
1491 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1492 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1494 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1495 attr
->values
[i
].string
.text
);
1500 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1501 IPP_TAG_INTEGER
)) != NULL
)
1503 if (attr
->values
[0].integer
!= 1 &&
1504 attr
->values
[0].integer
!= 2 &&
1505 attr
->values
[0].integer
!= 4 &&
1506 attr
->values
[0].integer
!= 6 &&
1507 attr
->values
[0].integer
!= 9 &&
1508 attr
->values
[0].integer
!= 16)
1510 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1511 attr
->values
[0].integer
);
1512 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1513 "number-up", attr
->values
[0].integer
);
1518 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1519 IPP_TAG_RANGE
)) != NULL
)
1521 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1523 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1524 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1526 send_ipp_status(con
, IPP_BAD_REQUEST
,
1527 _("Bad page-ranges values %d-%d."),
1528 attr
->values
[i
].range
.lower
,
1529 attr
->values
[i
].range
.upper
);
1533 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1538 * Do media selection as needed...
1541 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1542 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1543 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1546 (media_col
= ippFindAttribute(con
->request
, "media-col",
1547 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1549 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1551 unsup_col
= ippNew();
1552 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1553 "media-bottom-margin",
1554 IPP_TAG_INTEGER
)) != NULL
)
1555 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1556 "media-bottom-margin", media_margin
->values
[0].integer
);
1558 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1559 "media-left-margin",
1560 IPP_TAG_INTEGER
)) != NULL
)
1561 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1562 "media-left-margin", media_margin
->values
[0].integer
);
1564 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1565 "media-right-margin",
1566 IPP_TAG_INTEGER
)) != NULL
)
1567 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1568 "media-right-margin", media_margin
->values
[0].integer
);
1570 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1572 IPP_TAG_INTEGER
)) != NULL
)
1573 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1574 "media-top-margin", media_margin
->values
[0].integer
);
1576 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1578 ippDelete(unsup_col
);
1583 * Make sure we aren't over our limit...
1586 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1589 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1591 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1595 if ((i
= check_quotas(con
, printer
)) < 0)
1597 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1602 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1607 * Create the job and set things up...
1610 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1611 IPP_TAG_INTEGER
)) != NULL
)
1612 priority
= attr
->values
[0].integer
;
1615 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1616 printer
->options
)) != NULL
)
1617 priority
= atoi(val
);
1621 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1625 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1626 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1629 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1631 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1632 _("Unable to add job for destination \"%s\"."),
1637 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1638 CUPS_PRINTER_REMOTE
);
1639 job
->attrs
= con
->request
;
1641 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1643 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1645 add_job_uuid(con
, job
);
1646 apply_printer_defaults(printer
, job
);
1648 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1650 if (con
->username
[0])
1652 cupsdSetString(&job
->username
, con
->username
);
1655 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1659 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1660 "add_job: requesting-user-name=\"%s\"",
1661 attr
->values
[0].string
.text
);
1663 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1666 cupsdSetString(&job
->username
, "anonymous");
1669 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1670 "job-originating-user-name", NULL
, job
->username
);
1673 attr
->group_tag
= IPP_TAG_JOB
;
1674 _cupsStrFree(attr
->name
);
1675 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1678 if (con
->username
[0] || auth_info
)
1680 save_auth_info(con
, job
, auth_info
);
1683 * Remove the auth-info attribute from the attribute data...
1687 ippDeleteAttribute(job
->attrs
, auth_info
);
1690 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1691 IPP_TAG_ZERO
)) != NULL
)
1694 * Request contains a job-originating-host-name attribute; validate it...
1697 if (attr
->value_tag
!= IPP_TAG_NAME
||
1698 attr
->num_values
!= 1 ||
1699 strcmp(con
->http
.hostname
, "localhost"))
1702 * Can't override the value if we aren't connected via localhost.
1703 * Also, we can only have 1 value and it must be a name value.
1706 switch (attr
->value_tag
)
1708 case IPP_TAG_STRING
:
1709 case IPP_TAG_TEXTLANG
:
1710 case IPP_TAG_NAMELANG
:
1713 case IPP_TAG_KEYWORD
:
1715 case IPP_TAG_URISCHEME
:
1716 case IPP_TAG_CHARSET
:
1717 case IPP_TAG_LANGUAGE
:
1718 case IPP_TAG_MIMETYPE
:
1720 * Free old strings...
1723 for (i
= 0; i
< attr
->num_values
; i
++)
1725 _cupsStrFree(attr
->values
[i
].string
.text
);
1726 attr
->values
[i
].string
.text
= NULL
;
1727 if (attr
->values
[i
].string
.charset
)
1729 _cupsStrFree(attr
->values
[i
].string
.charset
);
1730 attr
->values
[i
].string
.charset
= NULL
;
1739 * Use the default connection hostname instead...
1742 attr
->value_tag
= IPP_TAG_NAME
;
1743 attr
->num_values
= 1;
1744 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1747 attr
->group_tag
= IPP_TAG_JOB
;
1752 * No job-originating-host-name attribute, so use the hostname from
1756 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1757 "job-originating-host-name", NULL
, con
->http
.hostname
);
1760 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1762 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1763 "time-at-processing", 0);
1764 attr
->value_tag
= IPP_TAG_NOVALUE
;
1765 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1766 "time-at-completed", 0);
1767 attr
->value_tag
= IPP_TAG_NOVALUE
;
1770 * Add remaining job attributes...
1773 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1774 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1775 "job-state", IPP_JOB_STOPPED
);
1776 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1777 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1778 "job-media-sheets-completed", 0);
1779 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1782 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1783 IPP_TAG_INTEGER
)) != NULL
)
1784 attr
->values
[0].integer
= 0;
1786 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1788 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1789 IPP_TAG_KEYWORD
)) == NULL
)
1790 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1793 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1794 printer
->options
)) == NULL
)
1797 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1798 "job-hold-until", NULL
, val
);
1800 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1803 * Hold job until specified time...
1806 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1808 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1809 job
->state_value
= IPP_JOB_HELD
;
1811 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1813 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1814 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1815 job
->state_value
= IPP_JOB_HELD
;
1819 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1820 job
->state_value
= IPP_JOB_PENDING
;
1823 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1827 * Add job sheets options...
1830 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1831 IPP_TAG_ZERO
)) == NULL
)
1833 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1834 "Adding default job-sheets values \"%s,%s\"...",
1835 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1837 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1839 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1840 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1843 job
->job_sheets
= attr
;
1846 * Enforce classification level if set...
1851 cupsdLogMessage(CUPSD_LOG_INFO
,
1852 "Classification=\"%s\", ClassifyOverride=%d",
1853 Classification
? Classification
: "(null)",
1856 if (ClassifyOverride
)
1858 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1859 (attr
->num_values
== 1 ||
1860 !strcmp(attr
->values
[1].string
.text
, "none")))
1863 * Force the leading banner to have the classification on it...
1866 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1868 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1869 "job-sheets=\"%s,none\", "
1870 "job-originating-user-name=\"%s\"",
1871 Classification
, job
->username
);
1873 else if (attr
->num_values
== 2 &&
1874 strcmp(attr
->values
[0].string
.text
,
1875 attr
->values
[1].string
.text
) &&
1876 strcmp(attr
->values
[0].string
.text
, "none") &&
1877 strcmp(attr
->values
[1].string
.text
, "none"))
1880 * Can't put two different security markings on the same document!
1883 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1885 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1886 "job-sheets=\"%s,%s\", "
1887 "job-originating-user-name=\"%s\"",
1888 attr
->values
[0].string
.text
,
1889 attr
->values
[1].string
.text
, job
->username
);
1891 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1892 strcmp(attr
->values
[0].string
.text
, "none") &&
1893 (attr
->num_values
== 1 ||
1894 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1895 strcmp(attr
->values
[1].string
.text
, "none"))))
1897 if (attr
->num_values
== 1)
1898 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1899 "CLASSIFICATION OVERRIDDEN "
1900 "job-sheets=\"%s\", "
1901 "job-originating-user-name=\"%s\"",
1902 attr
->values
[0].string
.text
, job
->username
);
1904 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1905 "CLASSIFICATION OVERRIDDEN "
1906 "job-sheets=\"%s,%s\",fffff "
1907 "job-originating-user-name=\"%s\"",
1908 attr
->values
[0].string
.text
,
1909 attr
->values
[1].string
.text
, job
->username
);
1912 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1913 (attr
->num_values
== 1 ||
1914 strcmp(attr
->values
[1].string
.text
, Classification
)))
1917 * Force the banner to have the classification on it...
1920 if (attr
->num_values
> 1 &&
1921 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1923 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1924 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1928 if (attr
->num_values
== 1 ||
1929 strcmp(attr
->values
[0].string
.text
, "none"))
1930 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1932 if (attr
->num_values
> 1 &&
1933 strcmp(attr
->values
[1].string
.text
, "none"))
1934 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1937 if (attr
->num_values
> 1)
1938 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1939 "CLASSIFICATION FORCED "
1940 "job-sheets=\"%s,%s\", "
1941 "job-originating-user-name=\"%s\"",
1942 attr
->values
[0].string
.text
,
1943 attr
->values
[1].string
.text
, job
->username
);
1945 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1946 "CLASSIFICATION FORCED "
1947 "job-sheets=\"%s\", "
1948 "job-originating-user-name=\"%s\"",
1949 Classification
, job
->username
);
1954 * See if we need to add the starting sheet...
1957 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1959 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1960 attr
->values
[0].string
.text
);
1962 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1964 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1965 "Aborting job because the start banner could not be "
1970 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1973 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1974 IPP_TAG_ZERO
)) != NULL
)
1975 job
->job_sheets
= attr
;
1978 * Fill in the response info...
1981 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1982 LocalPort
, job
->id
);
1984 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1987 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1989 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1991 add_job_state_reasons(con
, job
);
1993 con
->response
->request
.status
.status_code
= IPP_OK
;
1996 * Add any job subscriptions...
1999 add_job_subscriptions(con
, job
);
2002 * Set all but the first two attributes to the job attributes group...
2005 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
2006 attr
->group_tag
= IPP_TAG_JOB
;
2009 * Fire the "job created" event...
2012 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
2015 * Return the new job...
2023 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
2024 * upon the job and printer state...
2028 add_job_state_reasons(
2029 cupsd_client_t
*con
, /* I - Client connection */
2030 cupsd_job_t
*job
) /* I - Job info */
2032 cupsd_printer_t
*dest
; /* Destination printer */
2035 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
2036 con
, con
->http
.fd
, job
? job
->id
: 0);
2038 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
2040 case IPP_JOB_PENDING
:
2041 dest
= cupsdFindDest(job
->dest
);
2043 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
2044 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2045 "job-state-reasons", NULL
, "printer-stopped");
2047 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2048 "job-state-reasons", NULL
, "none");
2052 if (ippFindAttribute(job
->attrs
, "job-hold-until",
2053 IPP_TAG_KEYWORD
) != NULL
||
2054 ippFindAttribute(job
->attrs
, "job-hold-until",
2055 IPP_TAG_NAME
) != NULL
)
2056 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2057 "job-state-reasons", NULL
, "job-hold-until-specified");
2059 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2060 "job-state-reasons", NULL
, "job-incoming");
2063 case IPP_JOB_PROCESSING
:
2064 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2065 "job-state-reasons", NULL
, "job-printing");
2068 case IPP_JOB_STOPPED
:
2069 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2070 "job-state-reasons", NULL
, "job-stopped");
2073 case IPP_JOB_CANCELED
:
2074 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2075 "job-state-reasons", NULL
, "job-canceled-by-user");
2078 case IPP_JOB_ABORTED
:
2079 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2080 "job-state-reasons", NULL
, "aborted-by-system");
2083 case IPP_JOB_COMPLETED
:
2084 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2085 "job-state-reasons", NULL
, "job-completed-successfully");
2092 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2096 add_job_subscriptions(
2097 cupsd_client_t
*con
, /* I - Client connection */
2098 cupsd_job_t
*job
) /* I - Newly created job */
2100 int i
; /* Looping var */
2101 ipp_attribute_t
*prev
, /* Previous attribute */
2102 *next
, /* Next attribute */
2103 *attr
; /* Current attribute */
2104 cupsd_subscription_t
*sub
; /* Subscription object */
2105 const char *recipient
, /* notify-recipient-uri */
2106 *pullmethod
; /* notify-pull-method */
2107 ipp_attribute_t
*user_data
; /* notify-user-data */
2108 int interval
; /* notify-time-interval */
2109 unsigned mask
; /* notify-events */
2113 * Find the first subscription group attribute; return if we have
2117 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2118 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2125 * Process the subscription attributes in the request...
2134 mask
= CUPSD_EVENT_NONE
;
2136 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2138 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2139 attr
->value_tag
== IPP_TAG_URI
)
2142 * Validate the recipient scheme against the ServerBin/notifier
2146 char notifier
[1024], /* Notifier filename */
2147 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2148 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2149 host
[HTTP_MAX_URI
], /* Host portion of URI */
2150 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2151 int port
; /* Port portion of URI */
2154 recipient
= attr
->values
[0].string
.text
;
2156 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2157 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2158 host
, sizeof(host
), &port
,
2159 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2161 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2162 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2163 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2164 "notify-status-code", IPP_URI_SCHEME
);
2168 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2170 if (access(notifier
, X_OK
))
2172 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2173 _("notify-recipient-uri URI \"%s\" uses unknown "
2174 "scheme."), recipient
);
2175 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2176 "notify-status-code", IPP_URI_SCHEME
);
2180 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2182 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2183 _("notify-recipient-uri URI \"%s\" is already used."),
2185 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2186 "notify-status-code", IPP_ATTRIBUTES
);
2190 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2191 attr
->value_tag
== IPP_TAG_KEYWORD
)
2193 pullmethod
= attr
->values
[0].string
.text
;
2195 if (strcmp(pullmethod
, "ippget"))
2197 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2198 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2199 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2200 "notify-status-code", IPP_ATTRIBUTES
);
2204 else if (!strcmp(attr
->name
, "notify-charset") &&
2205 attr
->value_tag
== IPP_TAG_CHARSET
&&
2206 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2207 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2209 send_ipp_status(con
, IPP_CHARSET
,
2210 _("Character set \"%s\" not supported."),
2211 attr
->values
[0].string
.text
);
2214 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2215 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2216 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2218 send_ipp_status(con
, IPP_CHARSET
,
2219 _("Language \"%s\" not supported."),
2220 attr
->values
[0].string
.text
);
2223 else if (!strcmp(attr
->name
, "notify-user-data") &&
2224 attr
->value_tag
== IPP_TAG_STRING
)
2226 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2228 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2229 _("The notify-user-data value is too large "
2230 "(%d > 63 octets)."),
2231 attr
->values
[0].unknown
.length
);
2237 else if (!strcmp(attr
->name
, "notify-events") &&
2238 attr
->value_tag
== IPP_TAG_KEYWORD
)
2240 for (i
= 0; i
< attr
->num_values
; i
++)
2241 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2243 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2245 send_ipp_status(con
, IPP_BAD_REQUEST
,
2246 _("The notify-lease-duration attribute cannot be "
2247 "used with job subscriptions."));
2250 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2251 attr
->value_tag
== IPP_TAG_INTEGER
)
2252 interval
= attr
->values
[0].integer
;
2257 if (!recipient
&& !pullmethod
)
2260 if (mask
== CUPSD_EVENT_NONE
)
2261 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2263 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2264 recipient
, 0)) != NULL
)
2266 sub
->interval
= interval
;
2268 cupsdSetString(&sub
->owner
, job
->username
);
2272 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2273 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2274 sub
->user_data_len
);
2277 ippAddSeparator(con
->response
);
2278 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2279 "notify-subscription-id", sub
->id
);
2281 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2289 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2292 * Remove all of the subscription attributes from the job request...
2294 * TODO: Optimize this since subscription groups have to come at the
2295 * end of the request...
2298 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2302 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2303 attr
->group_tag
== IPP_TAG_ZERO
)
2306 * Free and remove this attribute...
2314 job
->attrs
->attrs
= next
;
2320 job
->attrs
->last
= prev
;
2321 job
->attrs
->current
= prev
;
2326 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2328 * See RFC 4122 for the definition of UUIDs and the format.
2332 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2333 cupsd_job_t
*job
) /* I - Job */
2335 char uuid
[64]; /* job-uuid string */
2339 * Add a job-uuid attribute if none exists...
2342 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2343 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2344 cupsdMakeUUID(job
->dest
, job
->id
, uuid
, sizeof(uuid
)));
2349 * 'add_printer()' - Add a printer to the system.
2353 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2354 ipp_attribute_t
*uri
) /* I - URI of printer */
2356 http_status_t status
; /* Policy status */
2357 int i
; /* Looping var */
2358 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2359 username
[HTTP_MAX_URI
], /* Username portion of URI */
2360 host
[HTTP_MAX_URI
], /* Host portion of URI */
2361 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2362 int port
; /* Port portion of URI */
2363 cupsd_printer_t
*printer
; /* Printer/class */
2364 ipp_attribute_t
*attr
; /* Printer attribute */
2365 cups_file_t
*fp
; /* Script/PPD file */
2366 char line
[1024]; /* Line from file... */
2367 char srcfile
[1024], /* Source Script/PPD file */
2368 dstfile
[1024]; /* Destination Script/PPD file */
2369 int modify
; /* Non-zero if we are modifying */
2370 char newname
[IPP_MAX_NAME
]; /* New printer name */
2371 int changed_driver
, /* Changed the PPD/interface script? */
2372 need_restart_job
, /* Need to restart job? */
2373 set_device_uri
, /* Did we set the device URI? */
2374 set_port_monitor
; /* Did we set the port monitor? */
2377 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2378 con
->http
.fd
, uri
->values
[0].string
.text
);
2381 * Do we have a valid URI?
2384 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2385 sizeof(scheme
), username
, sizeof(username
), host
,
2386 sizeof(host
), &port
, resource
, sizeof(resource
));
2388 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2391 * No, return an error...
2394 send_ipp_status(con
, IPP_BAD_REQUEST
,
2395 _("The printer-uri must be of the form "
2396 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2401 * Do we have a valid printer name?
2404 if (!validate_name(resource
+ 10))
2407 * No, return an error...
2410 send_ipp_status(con
, IPP_BAD_REQUEST
,
2411 _("The printer-uri \"%s\" contains invalid characters."),
2412 uri
->values
[0].string
.text
);
2417 * See if the printer already exists; if not, create a new printer...
2420 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2423 * Printer doesn't exist; see if we have a class of the same name...
2426 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2427 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2430 * Yes, return an error...
2433 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2434 _("A class named \"%s\" already exists."),
2440 * No, check the default policy then add the printer...
2443 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2445 send_http_error(con
, status
, NULL
);
2449 printer
= cupsdAddPrinter(resource
+ 10);
2452 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2455 * Check the default policy, then rename the implicit printer to
2456 * "AnyPrinter" or delete it...
2459 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2461 send_http_error(con
, status
, NULL
);
2465 if (ImplicitAnyClasses
)
2467 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2468 cupsdRenamePrinter(printer
, newname
);
2471 cupsdDeletePrinter(printer
, 1);
2474 * Add the printer as a new local printer...
2477 printer
= cupsdAddPrinter(resource
+ 10);
2480 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2483 * Check the default policy, then rename the remote printer to
2484 * "Printer@server"...
2487 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2489 send_http_error(con
, status
, NULL
);
2493 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2495 cupsdRenamePrinter(printer
, newname
);
2498 * Add the printer as a new local printer...
2501 printer
= cupsdAddPrinter(resource
+ 10);
2504 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2507 send_http_error(con
, status
, printer
);
2514 * Look for attributes and copy them over as needed...
2518 need_restart_job
= 0;
2520 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2521 IPP_TAG_TEXT
)) != NULL
)
2522 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2524 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2525 IPP_TAG_TEXT
)) != NULL
)
2526 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2530 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2531 IPP_TAG_URI
)) != NULL
)
2534 * Do we have a valid device URI?
2537 http_uri_status_t uri_status
; /* URI separation status */
2538 char old_device_uri
[1024];
2539 /* Old device URI */
2542 need_restart_job
= 1;
2544 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2545 attr
->values
[0].string
.text
,
2546 scheme
, sizeof(scheme
),
2547 username
, sizeof(username
),
2548 host
, sizeof(host
), &port
,
2549 resource
, sizeof(resource
));
2551 if (uri_status
< HTTP_URI_OK
)
2553 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2554 attr
->values
[0].string
.text
);
2555 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2556 "add_printer: httpSeparateURI returned %d", uri_status
);
2560 if (!strcmp(scheme
, "file"))
2563 * See if the administrator has enabled file devices...
2566 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2569 * File devices are disabled and the URL is not file:/dev/null...
2572 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2573 _("File device URIs have been disabled. "
2574 "To enable, see the FileDevice directive in "
2575 "\"%s/cupsd.conf\"."),
2583 * See if the backend exists and is executable...
2586 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2587 if (access(srcfile
, X_OK
))
2590 * Could not find device in list!
2593 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2594 _("Bad device-uri scheme \"%s\"."), scheme
);
2599 if (printer
->sanitized_device_uri
)
2600 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2601 sizeof(old_device_uri
));
2603 old_device_uri
[0] = '\0';
2605 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2607 cupsdLogMessage(CUPSD_LOG_INFO
,
2608 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2609 printer
->name
, printer
->sanitized_device_uri
,
2615 set_port_monitor
= 0;
2617 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2618 IPP_TAG_NAME
)) != NULL
)
2620 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2623 need_restart_job
= 1;
2625 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2629 for (i
= 0; i
< supported
->num_values
; i
++)
2630 if (!strcmp(supported
->values
[i
].string
.text
,
2631 attr
->values
[0].string
.text
))
2635 if (!supported
|| i
>= supported
->num_values
)
2637 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2638 attr
->values
[0].string
.text
);
2642 cupsdLogMessage(CUPSD_LOG_INFO
,
2643 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2644 printer
->name
, attr
->values
[0].string
.text
,
2645 printer
->port_monitor
? printer
->port_monitor
: "none");
2647 if (strcmp(attr
->values
[0].string
.text
, "none"))
2648 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2650 cupsdClearString(&printer
->port_monitor
);
2652 set_port_monitor
= 1;
2655 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2656 IPP_TAG_BOOLEAN
)) != NULL
&&
2657 attr
->values
[0].boolean
!= printer
->accepting
)
2659 cupsdLogMessage(CUPSD_LOG_INFO
,
2660 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2661 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2663 printer
->accepting
= attr
->values
[0].boolean
;
2665 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2666 "%s accepting jobs.",
2667 printer
->accepting
? "Now" : "No longer");
2670 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2671 IPP_TAG_BOOLEAN
)) != NULL
)
2673 if (printer
->shared
&& !attr
->values
[0].boolean
)
2674 cupsdDeregisterPrinter(printer
, 1);
2676 cupsdLogMessage(CUPSD_LOG_INFO
,
2677 "Setting %s printer-is-shared to %d (was %d.)",
2678 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2680 printer
->shared
= attr
->values
[0].boolean
;
2683 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2684 IPP_TAG_ENUM
)) != NULL
)
2686 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2687 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2689 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2690 attr
->values
[0].integer
);
2694 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2695 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2697 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2698 cupsdStopPrinter(printer
, 0);
2701 need_restart_job
= 1;
2702 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2706 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2707 IPP_TAG_TEXT
)) != NULL
)
2709 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2710 sizeof(printer
->state_message
));
2712 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2713 printer
->state_message
);
2716 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2717 IPP_TAG_KEYWORD
)) != NULL
)
2719 if (attr
->num_values
>
2720 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2722 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2723 _("Too many printer-state-reasons values (%d > %d)."),
2725 (int)(sizeof(printer
->reasons
) /
2726 sizeof(printer
->reasons
[0])));
2730 for (i
= 0; i
< printer
->num_reasons
; i
++)
2731 _cupsStrFree(printer
->reasons
[i
]);
2733 printer
->num_reasons
= 0;
2734 for (i
= 0; i
< attr
->num_values
; i
++)
2736 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2739 printer
->reasons
[printer
->num_reasons
] =
2740 _cupsStrRetain(attr
->values
[i
].string
.text
);
2741 printer
->num_reasons
++;
2743 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2744 printer
->state
!= IPP_PRINTER_STOPPED
)
2746 cupsdLogMessage(CUPSD_LOG_INFO
,
2747 "Setting %s printer-state to %d (was %d.)",
2748 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2749 cupsdStopPrinter(printer
, 0);
2753 if (PrintcapFormat
== PRINTCAP_PLIST
)
2754 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2756 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2757 "Printer \"%s\" state changed.", printer
->name
);
2760 set_printer_defaults(con
, printer
);
2762 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2763 IPP_TAG_KEYWORD
)) != NULL
)
2764 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2767 * See if we have all required attributes...
2770 if (!printer
->device_uri
)
2771 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2774 * See if we have an interface script or PPD file attached to the request...
2779 need_restart_job
= 1;
2782 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2784 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2787 * Yes; get the first line from it...
2791 cupsFileGets(fp
, line
, sizeof(line
));
2795 * Then see what kind of file it is...
2798 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2801 if (!strncmp(line
, "*PPD-Adobe", 10))
2804 * The new file is a PPD file, so remove any old interface script
2805 * that might be lying around...
2813 * This must be an interface script, so move the file over to the
2814 * interfaces directory and make it executable...
2817 if (copy_file(srcfile
, dstfile
))
2819 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2820 _("Unable to copy interface script - %s"),
2825 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2826 "Copied interface script successfully");
2827 chmod(dstfile
, 0755);
2830 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2833 if (!strncmp(line
, "*PPD-Adobe", 10))
2836 * The new file is a PPD file, so move the file over to the
2837 * ppd directory and make it readable by all...
2840 if (copy_file(srcfile
, dstfile
))
2842 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2843 _("Unable to copy PPD file - %s"),
2848 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2849 "Copied PPD file successfully");
2850 chmod(dstfile
, 0644);
2855 * This must be an interface script, so remove any old PPD file that
2856 * may be lying around...
2863 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2864 IPP_TAG_NAME
)) != NULL
)
2866 need_restart_job
= 1;
2869 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2872 * Raw driver, remove any existing PPD or interface script files.
2875 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2879 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2889 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2893 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2896 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2898 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2902 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2903 "Copied PPD file successfully");
2904 chmod(dstfile
, 0644);
2911 * If we changed the PPD/interface script, then remove the printer's cache
2912 * file and clear the printer-state-reasons...
2915 char cache_name
[1024]; /* Cache filename for printer attrs */
2917 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2921 cupsdSetPrinterReasons(printer
, "none");
2925 * (Re)register color profiles...
2930 apple_unregister_profiles(printer
);
2931 apple_register_profiles(printer
);
2933 #endif /* __APPLE__ */
2937 * If we set the device URI but not the port monitor, check which port
2938 * monitor to use by default...
2941 if (set_device_uri
&& !set_port_monitor
)
2943 ppd_file_t
*ppd
; /* PPD file */
2944 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2947 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2948 sizeof(scheme
), username
, sizeof(username
), host
,
2949 sizeof(host
), &port
, resource
, sizeof(resource
));
2951 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2953 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2955 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2957 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2958 if (!strcmp(scheme
, ppdattr
->spec
))
2960 cupsdLogMessage(CUPSD_LOG_INFO
,
2961 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2962 printer
->name
, ppdattr
->value
,
2963 printer
->port_monitor
? printer
->port_monitor
2966 if (strcmp(ppdattr
->value
, "none"))
2967 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2969 cupsdClearString(&printer
->port_monitor
);
2979 * Update the printer attributes and return...
2982 cupsdSetPrinterAttrs(printer
);
2983 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2985 if (need_restart_job
&& printer
->job
)
2988 * Restart the current job...
2991 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2992 "Job restarted because the printer was modified.");
2995 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2999 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
3000 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
3001 printer
->name
, get_username(con
));
3003 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
3004 printer
->name
, get_username(con
));
3008 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
3009 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
3010 printer
->name
, get_username(con
));
3012 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
3013 printer
->name
, get_username(con
));
3016 con
->response
->request
.status
.status_code
= IPP_OK
;
3021 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
3022 * based upon the printer state...
3026 add_printer_state_reasons(
3027 cupsd_client_t
*con
, /* I - Client connection */
3028 cupsd_printer_t
*p
) /* I - Printer info */
3030 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3031 "add_printer_state_reasons(%p[%d], %p[%s])",
3032 con
, con
->http
.fd
, p
, p
->name
);
3034 if (p
->num_reasons
== 0)
3035 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3036 "printer-state-reasons", NULL
, "none");
3038 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3039 "printer-state-reasons", p
->num_reasons
, NULL
,
3040 (const char * const *)p
->reasons
);
3045 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
3046 * the specified printer or class.
3050 add_queued_job_count(
3051 cupsd_client_t
*con
, /* I - Client connection */
3052 cupsd_printer_t
*p
) /* I - Printer or class */
3054 int count
; /* Number of jobs on destination */
3057 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3058 con
, con
->http
.fd
, p
, p
->name
);
3060 count
= cupsdGetPrinterJobCount(p
->name
);
3062 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3063 "queued-job-count", count
);
3069 * 'apple_init_profile()' - Initialize a color profile.
3074 ppd_file_t
*ppd
, /* I - PPD file */
3075 cups_array_t
*languages
, /* I - Languages in the PPD file */
3076 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3077 CFMutableDictionaryRef profile
, /* I - Profile dictionary */
3079 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3080 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3081 unsigned id
, /* I - Profile ID */
3082 const char *name
, /* I - Profile name */
3083 const char *text
, /* I - Profile UI text */
3084 const char *iccfile
) /* I - ICC filename */
3086 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3087 CFURLRef url
; /* URL for profile filename */
3088 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3089 CFMutableDictionaryRef dict
; /* Dictionary for name */
3090 char *language
; /* Current language */
3091 ppd_attr_t
*attr
; /* Profile attribute */
3092 CFStringRef cflang
, /* Language string */
3093 cftext
; /* Localized text */
3097 * Build the profile name dictionary...
3100 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3101 &kCFTypeDictionaryKeyCallBacks
,
3102 &kCFTypeDictionaryValueCallBacks
);
3104 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3105 kCFStringEncodingUTF8
);
3109 CFDictionarySetValue(dict
, CFSTR("en_US"), cftext
);
3116 * Find localized names for the color profiles...
3119 cupsArraySave(ppd
->sorted_attrs
);
3121 for (language
= (char *)cupsArrayFirst(languages
);
3123 language
= (char *)cupsArrayNext(languages
))
3127 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3129 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3132 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3134 if (attr
&& attr
->text
[0])
3136 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3137 kCFStringEncodingUTF8
);
3138 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3139 kCFStringEncodingUTF8
);
3141 if (cflang
&& cftext
)
3142 CFDictionarySetValue(dict
, cflang
, cftext
);
3152 cupsArrayRestore(ppd
->sorted_attrs
);
3156 * Fill in the profile data...
3159 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3162 url
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
3163 (const UInt8
*)iccfile
,
3164 strlen(iccfile
), false);
3168 CFDictionarySetValue(profile
, kColorSyncDeviceProfileURL
, url
);
3173 CFDictionarySetValue(profile
, kColorSyncDeviceModeDescriptions
, dict
);
3177 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3178 profile
->profileID
= id
;
3179 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3180 profile
->profileName
= dict
;
3183 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3184 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3185 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3190 * 'apple_register_profiles()' - Register color profiles for a printer.
3194 apple_register_profiles(
3195 cupsd_printer_t
*p
) /* I - Printer */
3197 int i
; /* Looping var */
3198 char ppdfile
[1024], /* PPD filename */
3199 iccfile
[1024], /* ICC filename */
3200 selector
[PPD_MAX_NAME
];
3201 /* Profile selection string */
3202 ppd_file_t
*ppd
; /* PPD file */
3203 ppd_attr_t
*attr
, /* Profile attributes */
3204 *profileid_attr
,/* cupsProfileID attribute */
3205 *q1_attr
, /* ColorModel (or other) qualifier */
3206 *q2_attr
, /* MediaType (or other) qualifier */
3207 *q3_attr
; /* Resolution (or other) qualifier */
3208 char q_keyword
[PPD_MAX_NAME
];
3209 /* Qualifier keyword */
3210 const char *q1_choice
, /* ColorModel (or other) choice */
3211 *q2_choice
, /* MediaType (or other) choice */
3212 *q3_choice
; /* Resolution (or other) choice */
3213 const char *profile_key
; /* Profile keyword */
3214 ppd_option_t
*cm_option
; /* Color model option */
3215 ppd_choice_t
*cm_choice
; /* Color model choice */
3216 int num_profiles
; /* Number of profiles */
3217 OSStatus error
= 0; /* Last error */
3218 unsigned device_id
, /* Printer device ID */
3219 profile_id
, /* Profile ID */
3220 default_profile_id
= 0;
3221 /* Default profile ID */
3222 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3223 CFStringRef printer_name
; /* Printer name string */
3224 cups_array_t
*languages
; /* Languages array */
3225 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3226 CFMutableDictionaryRef profiles
, /* Dictionary of profiles */
3227 profile
; /* Current profile info dictionary */
3228 CFStringRef dict_key
; /* Key in factory profile dictionary */
3230 CMDeviceScope scope
= /* Scope of the registration */
3232 kCFPreferencesAnyUser
,
3233 kCFPreferencesCurrentHost
3235 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3236 CMDeviceProfileInfo
*profile
; /* Current profile */
3237 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3241 * Make sure ColorSync is available...
3244 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3245 if (ColorSyncRegisterDevice
== NULL
)
3249 if (CMRegisterColorDevice
== NULL
)
3251 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3254 * Try opening the PPD file for this printer...
3257 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3258 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3262 * See if we have any profiles...
3265 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3266 profile_key
= "APTiogaProfile";
3269 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3270 profile_key
= "cupsICCProfile";
3273 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3274 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3276 if (attr
->value
[0] != '/')
3277 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3280 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3282 if (access(iccfile
, 0))
3288 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3290 * Create a dictionary for the factory profiles...
3293 profiles
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3294 &kCFTypeDictionaryKeyCallBacks
,
3295 &kCFTypeDictionaryValueCallBacks
);
3298 cupsdLogMessage(CUPSD_LOG_ERROR
,
3299 "Unable to allocate memory for factory profiles.");
3303 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3306 * If we have profiles, add them...
3309 if (num_profiles
> 0)
3311 if (profile_key
[0] == 'A')
3314 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3318 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3320 default_profile_id
= atoi(attr
->value
);
3322 q1_choice
= q2_choice
= q3_choice
= NULL
;
3327 * For CUPS PPDs, figure out the default profile selector values...
3330 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3331 attr
->value
&& attr
->value
[0])
3333 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3334 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3336 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3337 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3339 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3340 q1_choice
= q1_attr
->value
;
3344 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3345 attr
->value
&& attr
->value
[0])
3347 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3348 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3351 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3353 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3354 q2_choice
= q2_attr
->value
;
3358 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3359 attr
->value
&& attr
->value
[0])
3361 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3362 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3365 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3367 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3368 q3_choice
= q3_attr
->value
;
3373 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3375 * Build the array of profiles...
3377 * Note: This calloc actually requests slightly more memory than needed.
3380 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3382 cupsdLogMessage(CUPSD_LOG_ERROR
,
3383 "Unable to allocate memory for factory profiles.");
3388 profiles
->profileCount
= num_profiles
;
3389 profile
= profiles
->profiles
;
3390 # endif /* !HAVE_COLORSYNCREGISTERDEVICE */
3393 * Loop through the profiles listed in the PPD...
3396 languages
= _ppdGetLanguages(ppd
);
3398 for (attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3400 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3401 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3404 * Add this profile...
3407 if (attr
->value
[0] != '/')
3408 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3411 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3413 if (access(iccfile
, 0))
3416 if (profile_key
[0] == 'c')
3418 cupsArraySave(ppd
->sorted_attrs
);
3420 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3421 attr
->spec
)) != NULL
&&
3422 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3423 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3425 profile_id
= _ppdHashName(attr
->spec
);
3427 cupsArrayRestore(ppd
->sorted_attrs
);
3430 profile_id
= atoi(attr
->spec
);
3432 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3433 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3434 &kCFTypeDictionaryKeyCallBacks
,
3435 &kCFTypeDictionaryValueCallBacks
);
3438 cupsdLogMessage(CUPSD_LOG_ERROR
,
3439 "Unable to allocate memory for color profile.");
3440 CFRelease(profiles
);
3445 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3446 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3448 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3449 CFSTR("%u"), profile_id
);
3452 CFDictionarySetValue(profiles
, dict_key
, profile
);
3453 CFRelease(dict_key
);
3459 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3460 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3463 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3466 * See if this is the default profile...
3469 if (!default_profile_id
&& q1_choice
&& q2_choice
&& q3_choice
)
3471 snprintf(selector
, sizeof(selector
), "%s.%s.%s", q1_choice
, q2_choice
,
3473 if (!strcmp(selector
, attr
->spec
))
3474 default_profile_id
= profile_id
;
3477 if (!default_profile_id
&& q1_choice
&& q2_choice
)
3479 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
, q2_choice
);
3480 if (!strcmp(selector
, attr
->spec
))
3481 default_profile_id
= profile_id
;
3484 if (!default_profile_id
&& q1_choice
&& q3_choice
)
3486 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
, q3_choice
);
3487 if (!strcmp(selector
, attr
->spec
))
3488 default_profile_id
= profile_id
;
3491 if (!default_profile_id
&& q1_choice
)
3493 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3494 if (!strcmp(selector
, attr
->spec
))
3495 default_profile_id
= profile_id
;
3498 if (!default_profile_id
&& q2_choice
&& q3_choice
)
3500 snprintf(selector
, sizeof(selector
), ".%s.%s", q2_choice
, q3_choice
);
3501 if (!strcmp(selector
, attr
->spec
))
3502 default_profile_id
= profile_id
;
3505 if (!default_profile_id
&& q2_choice
)
3507 snprintf(selector
, sizeof(selector
), ".%s.", q2_choice
);
3508 if (!strcmp(selector
, attr
->spec
))
3509 default_profile_id
= profile_id
;
3512 if (!default_profile_id
&& q3_choice
)
3514 snprintf(selector
, sizeof(selector
), "..%s", q3_choice
);
3515 if (!strcmp(selector
, attr
->spec
))
3516 default_profile_id
= profile_id
;
3520 _ppdFreeLanguages(languages
);
3522 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3525 * Extract profiles from ColorModel option...
3528 const char *profile_name
; /* Name of generic profile */
3531 num_profiles
= cm_option
->num_choices
;
3533 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3535 * Create an array for the factory profiles...
3538 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3540 cupsdLogMessage(CUPSD_LOG_ERROR
,
3541 "Unable to allocate memory for factory profiles.");
3546 profiles
->profileCount
= num_profiles
;
3547 profile
= profiles
->profiles
;
3548 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3550 for (i
= cm_option
->num_choices
, cm_choice
= cm_option
->choices
;
3554 if (!strcmp(cm_choice
->choice
, "Gray") ||
3555 !strcmp(cm_choice
->choice
, "Black"))
3556 profile_name
= "Gray";
3557 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3558 !strcmp(cm_choice
->choice
, "CMY"))
3559 profile_name
= "RGB";
3560 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3561 !strcmp(cm_choice
->choice
, "KCMY"))
3562 profile_name
= "CMYK";
3564 profile_name
= "DeviceN";
3566 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3567 profile_id
= _ppdHashName(selector
);
3569 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3570 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3571 &kCFTypeDictionaryKeyCallBacks
,
3572 &kCFTypeDictionaryValueCallBacks
);
3575 cupsdLogMessage(CUPSD_LOG_ERROR
,
3576 "Unable to allocate memory for color profile.");
3577 CFRelease(profiles
);
3582 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3583 cm_choice
->text
, NULL
);
3585 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3586 CFSTR("%u"), profile_id
);
3589 CFDictionarySetValue(profiles
, dict_key
, profile
);
3590 CFRelease(dict_key
);
3596 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3597 cm_choice
->text
, NULL
);
3599 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3601 if (cm_choice
->marked
)
3602 default_profile_id
= profile_id
;
3608 * Use the default colorspace...
3611 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3613 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3615 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3617 * Add the grayscale profile first. We always have a grayscale profile.
3620 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3621 &kCFTypeDictionaryKeyCallBacks
,
3622 &kCFTypeDictionaryValueCallBacks
);
3626 cupsdLogMessage(CUPSD_LOG_ERROR
,
3627 "Unable to allocate memory for color profile.");
3628 CFRelease(profiles
);
3633 profile_id
= _ppdHashName("Gray..");
3634 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "Gray", "Gray", NULL
);
3636 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3640 CFDictionarySetValue(profiles
, dict_key
, profile
);
3641 CFRelease(dict_key
);
3647 * Then add the RGB/CMYK/DeviceN color profile...
3650 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3651 &kCFTypeDictionaryKeyCallBacks
,
3652 &kCFTypeDictionaryValueCallBacks
);
3656 cupsdLogMessage(CUPSD_LOG_ERROR
,
3657 "Unable to allocate memory for color profile.");
3658 CFRelease(profiles
);
3663 switch (ppd
->colorspace
)
3667 profile_id
= _ppdHashName("RGB..");
3668 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "RGB", "RGB",
3673 profile_id
= _ppdHashName("CMYK..");
3674 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "CMYK", "CMYK",
3683 profile_id
= _ppdHashName("DeviceN..");
3684 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "DeviceN",
3689 if (CFDictionaryGetCount(profile
) > 0)
3691 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3692 CFSTR("%u"), profile_id
);
3695 CFDictionarySetValue(profiles
, dict_key
, profile
);
3696 CFRelease(dict_key
);
3704 * Create an array for the factory profiles...
3707 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3709 cupsdLogMessage(CUPSD_LOG_ERROR
,
3710 "Unable to allocate memory for factory profiles.");
3715 profiles
->profileCount
= num_profiles
;
3718 * Add the grayscale profile first. We always have a grayscale profile.
3721 profile_id
= _ppdHashName("Gray..");
3722 apple_init_profile(ppd
, NULL
, profiles
->profiles
, profile_id
, "Gray",
3726 * Then add the RGB/CMYK/DeviceN color profile...
3729 switch (ppd
->colorspace
)
3733 profile_id
= _ppdHashName("RGB..");
3734 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3735 "RGB", "RGB", NULL
);
3739 profile_id
= _ppdHashName("CMYK..");
3740 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3741 "CMYK", "CMYK", NULL
);
3749 profile_id
= _ppdHashName("DeviceN..");
3750 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3751 "DeviceN", "DeviceN", NULL
);
3754 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3757 if (num_profiles
> 0)
3760 * Make sure we have a default profile ID...
3763 if (!default_profile_id
)
3764 default_profile_id
= profile_id
; /* Last profile */
3766 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3767 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3768 default_profile_id
);
3771 CFDictionarySetValue(profiles
, kColorSyncDeviceDefaultProfileID
,
3773 CFRelease(dict_key
);
3775 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3778 * Get the device ID hash and pathelogical name dictionary.
3781 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3784 device_id
= _ppdHashName(p
->name
);
3785 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3786 &kCFTypeDictionaryKeyCallBacks
,
3787 &kCFTypeDictionaryValueCallBacks
);
3788 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3789 p
->name
, kCFStringEncodingUTF8
);
3791 if (device_name
&& printer_name
)
3793 CFDictionarySetValue(device_name
, CFSTR("en_US"), printer_name
);
3796 * Register the device with ColorSync...
3799 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3800 CFTypeRef deviceDictKeys
[] =
3802 kColorSyncDeviceDescriptions
,
3803 kColorSyncFactoryProfiles
,
3804 kColorSyncDeviceUserScope
,
3805 kColorSyncDeviceHostScope
3807 CFTypeRef deviceDictVals
[] =
3808 { /* Device values */
3811 kCFPreferencesAnyUser
,
3812 kCFPreferencesCurrentHost
3814 CFDictionaryRef deviceDict
; /* Device dictionary */
3815 CFStringRef printerUUID
; /* Printer UUID */
3816 CFUUIDRef deviceUUID
; /* Device UUID */
3818 deviceDict
= CFDictionaryCreate(kCFAllocatorDefault
,
3819 (const void **)deviceDictKeys
,
3820 (const void **)deviceDictVals
,
3821 sizeof(deviceDictKeys
) /
3822 sizeof(deviceDictKeys
[0]),
3823 &kCFTypeDictionaryKeyCallBacks
,
3824 &kCFTypeDictionaryValueCallBacks
);
3825 printerUUID
= CFStringCreateWithCString(kCFAllocatorDefault
,
3826 p
->uuid
+ 9, /* Skip urn:uuid: */
3827 kCFStringEncodingUTF8
);
3830 deviceUUID
= CFUUIDCreateFromString(kCFAllocatorDefault
, printerUUID
);
3831 CFRelease(printerUUID
);
3833 if (!deviceDict
|| !deviceUUID
||
3834 !ColorSyncRegisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
,
3842 CFRelease(deviceUUID
);
3845 CFRelease(deviceDict
);
3848 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3849 device_name
, &scope
);
3852 * Register the profiles...
3856 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3857 default_profile_id
, profiles
);
3858 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3868 cupsdLogMessage(CUPSD_LOG_ERROR
,
3869 "Unable to register ICC color profiles for \"%s\": %d",
3870 p
->name
, (int)error
);
3873 CFRelease(printer_name
);
3876 CFRelease(device_name
);
3880 * Free any memory we used...
3883 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3884 CFRelease(profiles
);
3887 if (num_profiles
> 0)
3889 for (profile
= profiles
->profiles
;
3891 profile
++, num_profiles
--)
3892 CFRelease(profile
->profileName
);
3896 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3903 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3908 apple_unregister_profiles(
3909 cupsd_printer_t
*p
) /* I - Printer */
3912 * Make sure ColorSync is available...
3915 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3916 if (ColorSyncUnregisterDevice
!= NULL
)
3919 * Because we may have registered the printer profiles using a prior device
3920 * ID-based UUID, remove both the old style UUID and current UUID for the
3924 CFStringRef printerUUID
; /* Printer UUID */
3925 CFUUIDRef deviceUUID
; /* Device UUID */
3927 deviceUUID
= ColorSyncCreateUUIDFromUInt32(_ppdHashName(p
->name
));
3930 ColorSyncUnregisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
);
3931 CFRelease(deviceUUID
);
3934 printerUUID
= CFStringCreateWithCString(kCFAllocatorDefault
, p
->uuid
+ 9,
3935 kCFStringEncodingUTF8
);
3938 deviceUUID
= CFUUIDCreateFromString(kCFAllocatorDefault
, printerUUID
);
3941 ColorSyncUnregisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
);
3942 CFRelease(deviceUUID
);
3945 CFRelease(printerUUID
);
3950 if (CMUnregisterColorDevice
!= NULL
)
3951 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3952 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3954 #endif /* __APPLE__ */
3958 * 'apply_printer_defaults()' - Apply printer default options to a job.
3962 apply_printer_defaults(
3963 cupsd_printer_t
*printer
, /* I - Printer */
3964 cupsd_job_t
*job
) /* I - Job */
3966 int i
, /* Looping var */
3967 num_options
; /* Number of default options */
3968 cups_option_t
*options
, /* Default options */
3969 *option
; /* Current option */
3973 * Collect all of the default options and add the missing ones to the
3977 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3978 option
= printer
->options
;
3981 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3983 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3988 * Encode these options as attributes in the job object...
3991 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3992 cupsFreeOptions(num_options
, options
);
3997 * 'authenticate_job()' - Set job authentication info.
4001 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
4002 ipp_attribute_t
*uri
) /* I - Job URI */
4004 ipp_attribute_t
*attr
, /* job-id attribute */
4005 *auth_info
; /* auth-info attribute */
4006 int jobid
; /* Job ID */
4007 cupsd_job_t
*job
; /* Current job */
4008 char scheme
[HTTP_MAX_URI
],
4009 /* Method portion of URI */
4010 username
[HTTP_MAX_URI
],
4011 /* Username portion of URI */
4013 /* Host portion of URI */
4014 resource
[HTTP_MAX_URI
];
4015 /* Resource portion of URI */
4016 int port
; /* Port portion of URI */
4019 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
4020 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
4023 * Start with "everything is OK" status...
4026 con
->response
->request
.status
.status_code
= IPP_OK
;
4029 * See if we have a job URI or a printer URI...
4032 if (!strcmp(uri
->name
, "printer-uri"))
4035 * Got a printer URI; see if we also have a job-id attribute...
4038 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4039 IPP_TAG_INTEGER
)) == NULL
)
4041 send_ipp_status(con
, IPP_BAD_REQUEST
,
4042 _("Got a printer-uri attribute but no job-id."));
4046 jobid
= attr
->values
[0].integer
;
4051 * Got a job URI; parse it to get the job ID...
4054 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4055 sizeof(scheme
), username
, sizeof(username
), host
,
4056 sizeof(host
), &port
, resource
, sizeof(resource
));
4058 if (strncmp(resource
, "/jobs/", 6))
4064 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
4065 uri
->values
[0].string
.text
);
4069 jobid
= atoi(resource
+ 6);
4073 * See if the job exists...
4076 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4079 * Nope - return a "not found" error...
4082 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
4087 * See if the job has been completed...
4090 if (job
->state_value
!= IPP_JOB_HELD
)
4093 * Return a "not-possible" error...
4096 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4097 _("Job #%d is not held for authentication."),
4103 * See if we have already authenticated...
4106 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
4108 if (!con
->username
[0] && !auth_info
)
4110 cupsd_printer_t
*printer
; /* Job destination */
4114 * No auth data. If we need to authenticate via Kerberos, send a
4115 * HTTP auth challenge, otherwise just return an IPP error...
4118 printer
= cupsdFindDest(job
->dest
);
4120 if (printer
&& printer
->num_auth_info_required
> 0 &&
4121 !strcmp(printer
->auth_info_required
[0], "negotiate"))
4122 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
4124 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
4125 _("No authentication information provided."));
4130 * See if the job is owned by the requesting user...
4133 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4135 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4136 cupsdFindDest(job
->dest
));
4141 * Save the authentication information for this job...
4144 save_auth_info(con
, job
, auth_info
);
4147 * Reset the job-hold-until value to "no-hold"...
4150 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4151 IPP_TAG_KEYWORD
)) == NULL
)
4152 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4156 attr
->value_tag
= IPP_TAG_KEYWORD
;
4157 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
4161 * Release the job and return...
4164 cupsdReleaseJob(job
);
4166 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
4168 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
4175 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
4179 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
4180 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4182 int i
; /* Looping var */
4183 http_status_t status
; /* Policy status */
4184 cups_ptype_t dtype
; /* Destination type */
4185 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4186 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
4187 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
4188 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4189 int port
; /* Port portion of URI */
4190 ipp_attribute_t
*attr
; /* Attribute in request */
4191 const char *username
= NULL
; /* Username */
4192 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
4194 cupsd_printer_t
*printer
; /* Printer */
4195 ipp_attribute_t
*job_ids
; /* job-ids attribute */
4196 cupsd_job_t
*job
; /* Job */
4199 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
4200 con
->http
.fd
, uri
->values
[0].string
.text
);
4203 * Get the jobs to cancel/purge...
4206 switch (con
->request
->request
.op
.operation_id
)
4208 case IPP_PURGE_JOBS
:
4210 * Get the username (if any) for the jobs we want to cancel (only if
4211 * "my-jobs" is specified...
4214 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
4215 IPP_TAG_BOOLEAN
)) != NULL
&&
4216 attr
->values
[0].boolean
)
4218 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4219 IPP_TAG_NAME
)) != NULL
)
4220 username
= attr
->values
[0].string
.text
;
4223 send_ipp_status(con
, IPP_BAD_REQUEST
,
4224 _("Missing requesting-user-name attribute."));
4230 * Look for the "purge-jobs" attribute...
4233 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
4234 IPP_TAG_BOOLEAN
)) != NULL
)
4235 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4237 purge
= CUPSD_JOB_PURGE
;
4240 case IPP_CANCEL_MY_JOBS
:
4241 if (con
->username
[0])
4242 username
= con
->username
;
4243 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4244 IPP_TAG_NAME
)) != NULL
)
4245 username
= attr
->values
[0].string
.text
;
4248 send_ipp_status(con
, IPP_BAD_REQUEST
,
4249 _("Missing requesting-user-name attribute."));
4257 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
4260 * See if we have a printer URI...
4263 if (strcmp(uri
->name
, "printer-uri"))
4265 send_ipp_status(con
, IPP_BAD_REQUEST
,
4266 _("The printer-uri attribute is required."));
4271 * And if the destination is valid...
4274 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4280 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
4281 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
4282 hostname
, sizeof(hostname
), &port
,
4283 resource
, sizeof(resource
));
4285 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
4286 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
4288 send_ipp_status(con
, IPP_NOT_FOUND
,
4289 _("The printer or class does not exist."));
4297 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
4299 send_http_error(con
, status
, NULL
);
4305 for (i
= 0; i
< job_ids
->num_values
; i
++)
4307 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
4311 if (i
< job_ids
->num_values
)
4313 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4314 job_ids
->values
[i
].integer
);
4318 for (i
= 0; i
< job_ids
->num_values
; i
++)
4320 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4322 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4323 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4324 "Job canceled by user.");
4327 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4328 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4334 * Cancel all jobs on all printers...
4337 cupsdCancelJobs(NULL
, username
, purge
);
4339 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
4340 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4350 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4353 send_http_error(con
, status
, printer
);
4359 for (i
= 0; i
< job_ids
->num_values
; i
++)
4361 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
4362 strcasecmp(job
->dest
, printer
->name
))
4366 if (i
< job_ids
->num_values
)
4368 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4369 job_ids
->values
[i
].integer
);
4373 for (i
= 0; i
< job_ids
->num_values
; i
++)
4375 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4377 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4378 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4379 "Job canceled by user.");
4382 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4383 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4389 * Cancel all of the jobs on the named printer...
4392 cupsdCancelJobs(printer
->name
, username
, purge
);
4394 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
4396 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4401 con
->response
->request
.status
.status_code
= IPP_OK
;
4406 * 'cancel_job()' - Cancel a print job.
4410 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
4411 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4413 ipp_attribute_t
*attr
; /* Current attribute */
4414 int jobid
; /* Job ID */
4415 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4416 username
[HTTP_MAX_URI
], /* Username portion of URI */
4417 host
[HTTP_MAX_URI
], /* Host portion of URI */
4418 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4419 int port
; /* Port portion of URI */
4420 cupsd_job_t
*job
; /* Job information */
4421 cups_ptype_t dtype
; /* Destination type (printer/class) */
4422 cupsd_printer_t
*printer
; /* Printer data */
4423 cupsd_jobaction_t purge
; /* Purge the job? */
4426 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
4427 con
->http
.fd
, uri
->values
[0].string
.text
);
4430 * See if we have a job URI or a printer URI...
4433 if (!strcmp(uri
->name
, "printer-uri"))
4436 * Got a printer URI; see if we also have a job-id attribute...
4439 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4440 IPP_TAG_INTEGER
)) == NULL
)
4442 send_ipp_status(con
, IPP_BAD_REQUEST
,
4443 _("Got a printer-uri attribute but no job-id."));
4447 if ((jobid
= attr
->values
[0].integer
) == 0)
4450 * Find the current job on the specified printer...
4453 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4459 send_ipp_status(con
, IPP_NOT_FOUND
,
4460 _("The printer or class does not exist."));
4465 * See if there are any pending jobs...
4468 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4470 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4471 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
4472 !strcasecmp(job
->dest
, printer
->name
))
4480 * No, try stopped jobs...
4483 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4485 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4486 if (job
->state_value
== IPP_JOB_STOPPED
&&
4487 !strcasecmp(job
->dest
, printer
->name
))
4494 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
4504 * Got a job URI; parse it to get the job ID...
4507 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4508 sizeof(scheme
), username
, sizeof(username
), host
,
4509 sizeof(host
), &port
, resource
, sizeof(resource
));
4511 if (strncmp(resource
, "/jobs/", 6))
4517 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
4518 uri
->values
[0].string
.text
);
4522 jobid
= atoi(resource
+ 6);
4526 * Look for the "purge-job" attribute...
4529 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4530 IPP_TAG_BOOLEAN
)) != NULL
)
4531 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4533 purge
= CUPSD_JOB_DEFAULT
;
4536 * See if the job exists...
4539 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4542 * Nope - return a "not found" error...
4545 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
4550 * See if the job is owned by the requesting user...
4553 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4555 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4556 cupsdFindDest(job
->dest
));
4561 * See if the job is already completed, canceled, or aborted; if so,
4562 * we can't cancel...
4565 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4567 switch (job
->state_value
)
4569 case IPP_JOB_CANCELED
:
4570 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4571 _("Job #%d is already canceled - can\'t cancel."),
4575 case IPP_JOB_ABORTED
:
4576 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4577 _("Job #%d is already aborted - can\'t cancel."),
4582 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4583 _("Job #%d is already completed - can\'t cancel."),
4592 * Cancel the job and return...
4595 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4596 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4597 "Job canceled by \"%s\"",
4601 if (purge
== CUPSD_JOB_PURGE
)
4602 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4605 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4608 con
->response
->request
.status
.status_code
= IPP_OK
;
4613 * 'cancel_subscription()' - Cancel a subscription.
4617 cancel_subscription(
4618 cupsd_client_t
*con
, /* I - Client connection */
4619 int sub_id
) /* I - Subscription ID */
4621 http_status_t status
; /* Policy status */
4622 cupsd_subscription_t
*sub
; /* Subscription */
4625 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4626 "cancel_subscription(con=%p[%d], sub_id=%d)",
4627 con
, con
->http
.fd
, sub_id
);
4630 * Is the subscription ID valid?
4633 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4636 * Bad subscription ID...
4639 send_ipp_status(con
, IPP_NOT_FOUND
,
4640 _("Subscription #%d does not exist."), sub_id
);
4648 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4650 con
, sub
->owner
)) != HTTP_OK
)
4652 send_http_error(con
, status
, sub
->dest
);
4657 * Cancel the subscription...
4660 cupsdDeleteSubscription(sub
, 1);
4662 con
->response
->request
.status
.status_code
= IPP_OK
;
4667 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4670 static int /* O - 1 if OK, 0 if not */
4671 check_rss_recipient(
4672 const char *recipient
) /* I - Recipient URI */
4674 cupsd_subscription_t
*sub
; /* Current subscription */
4677 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4679 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4683 * Compare the URIs up to the first ?...
4686 const char *r1
, *r2
;
4688 for (r1
= recipient
, r2
= sub
->recipient
;
4689 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4701 * 'check_quotas()' - Check quotas for a printer and user.
4704 static int /* O - 1 if OK, 0 if forbidden,
4705 -1 if limit reached */
4706 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4707 cupsd_printer_t
*p
) /* I - Printer or class */
4709 char username
[33], /* Username */
4710 *name
; /* Current user name */
4711 cupsd_quota_t
*q
; /* Quota data */
4712 #ifdef HAVE_MBR_UID_TO_UUID
4714 * Use Apple membership APIs which require that all names represent
4715 * valid user account or group records accessible by the server.
4718 uuid_t usr_uuid
; /* UUID for job requesting user */
4719 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4720 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4721 int mbr_err
; /* Error from membership function */
4722 int is_member
; /* Is this user a member? */
4725 * Use standard POSIX APIs for checking users and groups...
4728 struct passwd
*pw
; /* User password data */
4729 #endif /* HAVE_MBR_UID_TO_UUID */
4732 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4733 con
, con
->http
.fd
, p
, p
->name
);
4736 * Figure out who is printing...
4739 strlcpy(username
, get_username(con
), sizeof(username
));
4742 * Check global active job limits for printers and users...
4745 if (MaxJobsPerPrinter
)
4748 * Check if there are too many pending jobs on this printer...
4751 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4753 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4762 * Check if there are too many pending jobs for this user...
4765 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4767 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4774 * Check against users...
4777 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4780 if (cupsArrayCount(p
->users
))
4782 #ifdef HAVE_MBR_UID_TO_UUID
4784 * Get UUID for job requesting user...
4787 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4793 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4794 "check_quotas: UUID lookup failed for user \"%s\"",
4796 cupsdLogMessage(CUPSD_LOG_INFO
,
4797 "Denying user \"%s\" access to printer \"%s\" "
4798 "(unknown user)...",
4804 * Get UID and GID of requesting user...
4807 pw
= getpwnam(username
);
4809 #endif /* HAVE_MBR_UID_TO_UUID */
4811 for (name
= (char *)cupsArrayFirst(p
->users
);
4813 name
= (char *)cupsArrayNext(p
->users
))
4817 * Check group membership...
4820 #ifdef HAVE_MBR_UID_TO_UUID
4823 if (uuid_parse(name
+ 2, grp_uuid
))
4824 uuid_clear(grp_uuid
);
4826 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
4829 * Invalid ACL entries are ignored for matching; just record a
4830 * warning in the log...
4833 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4834 "check_quotas: UUID lookup failed for ACL entry "
4835 "\"%s\" (err=%d)", name
, mbr_err
);
4836 cupsdLogMessage(CUPSD_LOG_WARN
,
4837 "Access control entry \"%s\" not a valid group name; "
4838 "entry ignored", name
);
4841 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4845 * At this point, there should be no errors, but check anyways...
4848 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4849 "check_quotas: group \"%s\" membership check "
4850 "failed (err=%d)", name
+ 1, mbr_err
);
4855 * Stop if we found a match...
4862 if (cupsdCheckGroup(username
, pw
, name
+ 1))
4864 #endif /* HAVE_MBR_UID_TO_UUID */
4866 #ifdef HAVE_MBR_UID_TO_UUID
4871 if (uuid_parse(name
+ 1, usr2_uuid
))
4872 uuid_clear(usr2_uuid
);
4874 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
4877 * Invalid ACL entries are ignored for matching; just record a
4878 * warning in the log...
4881 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4882 "check_quotas: UUID lookup failed for ACL entry "
4883 "\"%s\" (err=%d)", name
, mbr_err
);
4884 cupsdLogMessage(CUPSD_LOG_WARN
,
4885 "Access control entry \"%s\" not a valid user name; "
4886 "entry ignored", name
);
4889 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4893 else if (!strcasecmp(username
, name
))
4895 #endif /* HAVE_MBR_UID_TO_UUID */
4897 if ((name
!= NULL
) == p
->deny_users
)
4899 cupsdLogMessage(CUPSD_LOG_INFO
,
4900 "Denying user \"%s\" access to printer \"%s\"...",
4910 if (p
->k_limit
|| p
->page_limit
)
4912 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4914 cupsdLogMessage(CUPSD_LOG_ERROR
,
4915 "Unable to allocate quota data for user \"%s\"",
4920 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4921 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4923 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4930 * If we have gotten this far, we're done!
4938 * 'close_job()' - Close a multi-file job.
4942 close_job(cupsd_client_t
*con
, /* I - Client connection */
4943 ipp_attribute_t
*uri
) /* I - Printer URI */
4945 cupsd_job_t
*job
; /* Job */
4946 ipp_attribute_t
*attr
; /* Attribute */
4947 char job_uri
[HTTP_MAX_URI
],
4949 username
[256]; /* User name */
4952 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4953 con
->http
.fd
, uri
->values
[0].string
.text
);
4956 * See if we have a job URI or a printer URI...
4959 if (strcmp(uri
->name
, "printer-uri"))
4962 * job-uri is not supported by Close-Job!
4965 send_ipp_status(con
, IPP_BAD_REQUEST
,
4966 _("Close-Job doesn't support the job-uri attribute."));
4971 * Got a printer URI; see if we also have a job-id attribute...
4974 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4975 IPP_TAG_INTEGER
)) == NULL
)
4977 send_ipp_status(con
, IPP_BAD_REQUEST
,
4978 _("Got a printer-uri attribute but no job-id."));
4982 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4985 * Nope - return a "not found" error...
4988 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4989 attr
->values
[0].integer
);
4994 * See if the job is owned by the requesting user...
4997 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4999 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
5000 cupsdFindDest(job
->dest
));
5005 * Add any ending sheet...
5008 if (cupsdTimeoutJob(job
))
5011 if (job
->state_value
== IPP_JOB_STOPPED
)
5013 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5014 job
->state_value
= IPP_JOB_PENDING
;
5016 else if (job
->state_value
== IPP_JOB_HELD
)
5018 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
5019 IPP_TAG_KEYWORD
)) == NULL
)
5020 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
5022 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
5024 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5025 job
->state_value
= IPP_JOB_PENDING
;
5030 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
5033 * Fill in the response info...
5036 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
5037 LocalPort
, job
->id
);
5038 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
5041 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
5043 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
5046 add_job_state_reasons(con
, job
);
5048 con
->response
->request
.status
.status_code
= IPP_OK
;
5051 * Start the job if necessary...
5059 * 'copy_attribute()' - Copy a single attribute.
5062 static ipp_attribute_t
* /* O - New attribute */
5064 ipp_t
*to
, /* O - Destination request/response */
5065 ipp_attribute_t
*attr
, /* I - Attribute to copy */
5066 int quickcopy
) /* I - Do a quick copy? */
5068 int i
; /* Looping var */
5069 ipp_attribute_t
*toattr
; /* Destination attribute */
5072 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5073 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
5074 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
5077 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
5080 toattr
= ippAddSeparator(to
);
5083 case IPP_TAG_INTEGER
:
5085 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5086 attr
->name
, attr
->num_values
, NULL
);
5088 for (i
= 0; i
< attr
->num_values
; i
++)
5089 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
5092 case IPP_TAG_BOOLEAN
:
5093 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
5094 attr
->num_values
, NULL
);
5096 for (i
= 0; i
< attr
->num_values
; i
++)
5097 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
5100 case IPP_TAG_STRING
:
5103 case IPP_TAG_KEYWORD
:
5105 case IPP_TAG_URISCHEME
:
5106 case IPP_TAG_CHARSET
:
5107 case IPP_TAG_LANGUAGE
:
5108 case IPP_TAG_MIMETYPE
:
5109 toattr
= ippAddStrings(to
, attr
->group_tag
,
5110 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5111 attr
->name
, attr
->num_values
, NULL
, NULL
);
5115 for (i
= 0; i
< attr
->num_values
; i
++)
5116 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5118 else if (attr
->value_tag
& IPP_TAG_COPY
)
5120 for (i
= 0; i
< attr
->num_values
; i
++)
5121 toattr
->values
[i
].string
.text
=
5122 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5126 for (i
= 0; i
< attr
->num_values
; i
++)
5127 toattr
->values
[i
].string
.text
=
5128 _cupsStrRetain(attr
->values
[i
].string
.text
);
5133 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
5134 attr
->values
[0].date
);
5137 case IPP_TAG_RESOLUTION
:
5138 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
5139 attr
->num_values
, IPP_RES_PER_INCH
,
5142 for (i
= 0; i
< attr
->num_values
; i
++)
5144 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
5145 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
5146 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
5150 case IPP_TAG_RANGE
:
5151 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
5152 attr
->num_values
, NULL
, NULL
);
5154 for (i
= 0; i
< attr
->num_values
; i
++)
5156 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
5157 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
5161 case IPP_TAG_TEXTLANG
:
5162 case IPP_TAG_NAMELANG
:
5163 toattr
= ippAddStrings(to
, attr
->group_tag
,
5164 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5165 attr
->name
, attr
->num_values
, NULL
, NULL
);
5169 for (i
= 0; i
< attr
->num_values
; i
++)
5171 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
5172 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5175 else if (attr
->value_tag
& IPP_TAG_COPY
)
5177 for (i
= 0; i
< attr
->num_values
; i
++)
5180 toattr
->values
[i
].string
.charset
=
5181 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
5183 toattr
->values
[i
].string
.charset
=
5184 toattr
->values
[0].string
.charset
;
5186 toattr
->values
[i
].string
.text
=
5187 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5192 for (i
= 0; i
< attr
->num_values
; i
++)
5195 toattr
->values
[i
].string
.charset
=
5196 _cupsStrRetain(attr
->values
[i
].string
.charset
);
5198 toattr
->values
[i
].string
.charset
=
5199 toattr
->values
[0].string
.charset
;
5201 toattr
->values
[i
].string
.text
=
5202 _cupsStrRetain(attr
->values
[i
].string
.text
);
5207 case IPP_TAG_BEGIN_COLLECTION
:
5208 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
5209 attr
->num_values
, NULL
);
5211 for (i
= 0; i
< attr
->num_values
; i
++)
5213 toattr
->values
[i
].collection
= attr
->values
[i
].collection
;
5214 attr
->values
[i
].collection
->use
++;
5219 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5220 attr
->name
, attr
->num_values
, NULL
);
5222 for (i
= 0; i
< attr
->num_values
; i
++)
5224 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
5226 if (toattr
->values
[i
].unknown
.length
> 0)
5228 if ((toattr
->values
[i
].unknown
.data
=
5229 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
5230 toattr
->values
[i
].unknown
.length
= 0;
5232 memcpy(toattr
->values
[i
].unknown
.data
,
5233 attr
->values
[i
].unknown
.data
,
5234 toattr
->values
[i
].unknown
.length
);
5237 break; /* anti-compiler-warning-code */
5245 * 'copy_attrs()' - Copy attributes from one request to another.
5249 copy_attrs(ipp_t
*to
, /* I - Destination request */
5250 ipp_t
*from
, /* I - Source request */
5251 cups_array_t
*ra
, /* I - Requested attributes */
5252 ipp_tag_t group
, /* I - Group to copy */
5253 int quickcopy
, /* I - Do a quick copy? */
5254 cups_array_t
*exclude
) /* I - Attributes to exclude? */
5256 ipp_attribute_t
*fromattr
; /* Source attribute */
5259 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5260 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
5261 to
, from
, ra
, group
, quickcopy
);
5266 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
5269 * Filter attributes as needed...
5272 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
5273 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
5277 (cupsArrayFind(exclude
, fromattr
->name
) ||
5278 cupsArrayFind(exclude
, "all")))
5281 * We need to exclude this attribute for security reasons; we require the
5282 * job-id and job-printer-uri attributes regardless of the security
5283 * settings for IPP conformance.
5285 * Subscription attribute security is handled by copy_subscription_attrs().
5288 if (strcmp(fromattr
->name
, "job-id") &&
5289 strcmp(fromattr
->name
, "job-printer-uri"))
5293 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
5296 * Don't send collection attributes by default to IPP/1.x clients
5297 * since many do not support collections. Also don't send
5298 * media-col-database unless specifically requested by the client.
5301 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
5303 (to
->request
.status
.version
[0] == 1 ||
5304 !strcmp(fromattr
->name
, "media-col-database")))
5307 copy_attribute(to
, fromattr
, quickcopy
);
5314 * 'copy_banner()' - Copy a banner file to the requests directory for the
5318 static int /* O - Size of banner file in kbytes */
5319 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
5320 cupsd_job_t
*job
, /* I - Job information */
5321 const char *name
) /* I - Name of banner */
5323 int i
; /* Looping var */
5324 int kbytes
; /* Size of banner file in kbytes */
5325 char filename
[1024]; /* Job filename */
5326 cupsd_banner_t
*banner
; /* Pointer to banner */
5327 cups_file_t
*in
; /* Input file */
5328 cups_file_t
*out
; /* Output file */
5329 int ch
; /* Character from file */
5330 char attrname
[255], /* Name of attribute */
5331 *s
; /* Pointer into name */
5332 ipp_attribute_t
*attr
; /* Attribute */
5335 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5336 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
5337 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
5338 name
? name
: "(null)");
5341 * Find the banner; return if not found or "none"...
5344 if (!name
|| !strcmp(name
, "none") ||
5345 (banner
= cupsdFindBanner(name
)) == NULL
)
5349 * Open the banner and job files...
5352 if (add_file(con
, job
, banner
->filetype
, 0))
5355 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
5357 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
5359 cupsdLogMessage(CUPSD_LOG_ERROR
,
5360 "Unable to create banner job file %s - %s",
5361 filename
, strerror(errno
));
5366 fchmod(cupsFileNumber(out
), 0640);
5367 fchown(cupsFileNumber(out
), RunUser
, Group
);
5370 * Try the localized banner file under the subdirectory...
5373 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5375 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5378 * Convert ll-cc to ll_CC...
5382 attrname
[3] = toupper(attrname
[3] & 255);
5383 attrname
[4] = toupper(attrname
[4] & 255);
5386 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5389 if (access(filename
, 0) && strlen(attrname
) > 2)
5392 * Wasn't able to find "ll_CC" locale file; try the non-national
5393 * localization banner directory.
5398 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5402 if (access(filename
, 0))
5405 * Use the non-localized banner file.
5408 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5411 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5415 cupsdLogMessage(CUPSD_LOG_ERROR
,
5416 "Unable to open banner template file %s - %s",
5417 filename
, strerror(errno
));
5423 * Parse the file to the end...
5426 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5430 * Get an attribute name...
5433 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5434 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5436 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5446 * Ignore { followed by stuff that is not an attribute name...
5449 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5454 * See if it is defined...
5457 if (attrname
[0] == '?')
5462 if (!strcmp(s
, "printer-name"))
5464 cupsFilePuts(out
, job
->dest
);
5467 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5470 * See if we have a leading question mark...
5473 if (attrname
[0] != '?')
5476 * Nope, write to file as-is; probably a PostScript procedure...
5479 cupsFilePrintf(out
, "{%s}", attrname
);
5486 * Output value(s)...
5489 for (i
= 0; i
< attr
->num_values
; i
++)
5492 cupsFilePutChar(out
, ',');
5494 switch (attr
->value_tag
)
5496 case IPP_TAG_INTEGER
:
5498 if (!strncmp(s
, "time-at-", 8))
5500 struct timeval tv
; /* Time value */
5502 tv
.tv_sec
= attr
->values
[i
].integer
;
5505 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5508 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5511 case IPP_TAG_BOOLEAN
:
5512 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5515 case IPP_TAG_NOVALUE
:
5516 cupsFilePuts(out
, "novalue");
5519 case IPP_TAG_RANGE
:
5520 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5521 attr
->values
[i
].range
.upper
);
5524 case IPP_TAG_RESOLUTION
:
5525 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5526 attr
->values
[i
].resolution
.yres
,
5527 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5532 case IPP_TAG_STRING
:
5535 case IPP_TAG_KEYWORD
:
5536 case IPP_TAG_CHARSET
:
5537 case IPP_TAG_LANGUAGE
:
5538 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
5541 * Need to quote strings for PS banners...
5546 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5548 if (*p
== '(' || *p
== ')' || *p
== '\\')
5550 cupsFilePutChar(out
, '\\');
5551 cupsFilePutChar(out
, *p
);
5553 else if (*p
< 32 || *p
> 126)
5554 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5556 cupsFilePutChar(out
, *p
);
5560 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5564 break; /* anti-compiler-warning-code */
5568 else if (ch
== '\\') /* Quoted char */
5570 ch
= cupsFileGetChar(in
);
5572 if (ch
!= '{') /* Only do special handling for \{ */
5573 cupsFilePutChar(out
, '\\');
5575 cupsFilePutChar(out
, ch
);
5578 cupsFilePutChar(out
, ch
);
5582 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5584 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5585 IPP_TAG_INTEGER
)) != NULL
)
5586 attr
->values
[0].integer
+= kbytes
;
5595 * 'copy_file()' - Copy a PPD file or interface script...
5598 static int /* O - 0 = success, -1 = error */
5599 copy_file(const char *from
, /* I - Source file */
5600 const char *to
) /* I - Destination file */
5602 cups_file_t
*src
, /* Source file */
5603 *dst
; /* Destination file */
5604 int bytes
; /* Bytes to read/write */
5605 char buffer
[2048]; /* Copy buffer */
5608 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5611 * Open the source and destination file for a copy...
5614 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5617 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5624 * Copy the source file to the destination...
5627 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5628 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5636 * Close both files and return...
5641 return (cupsFileClose(dst
));
5646 * 'copy_model()' - Copy a PPD model file, substituting default values
5650 static int /* O - 0 = success, -1 = error */
5651 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5652 const char *from
, /* I - Source file */
5653 const char *to
) /* I - Destination file */
5655 fd_set input
; /* select() input set */
5656 struct timeval timeout
; /* select() timeout */
5657 int maxfd
; /* Max file descriptor for select() */
5658 char tempfile
[1024]; /* Temporary PPD file */
5659 int tempfd
; /* Temporary PPD file descriptor */
5660 int temppid
; /* Process ID of cups-driverd */
5661 int temppipe
[2]; /* Temporary pipes */
5662 char *argv
[4], /* Command-line arguments */
5663 *envp
[MAX_ENV
]; /* Environment */
5664 cups_file_t
*src
, /* Source file */
5665 *dst
; /* Destination file */
5666 ppd_file_t
*ppd
; /* PPD file */
5667 int bytes
, /* Bytes from pipe */
5668 total
; /* Total bytes from pipe */
5669 char buffer
[2048]; /* Copy buffer */
5670 int i
; /* Looping var */
5671 char option
[PPD_MAX_NAME
], /* Option name */
5672 choice
[PPD_MAX_NAME
]; /* Choice name */
5673 ppd_size_t
*size
; /* Default size */
5674 int num_defaults
; /* Number of default options */
5675 cups_option_t
*defaults
; /* Default options */
5676 char cups_protocol
[PPD_MAX_LINE
];
5677 /* cupsProtocol attribute */
5680 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5681 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5685 * Run cups-driverd to get the PPD file...
5688 argv
[0] = "cups-driverd";
5690 argv
[2] = (char *)from
;
5693 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5695 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5696 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5697 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5701 cupsdOpenPipe(temppipe
);
5703 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5704 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5706 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5707 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5718 * Wait up to 30 seconds for the PPD file to be copied...
5723 if (temppipe
[0] > CGIPipes
[0])
5724 maxfd
= temppipe
[0] + 1;
5726 maxfd
= CGIPipes
[0] + 1;
5731 * See if we have data ready...
5735 FD_SET(temppipe
[0], &input
);
5736 FD_SET(CGIPipes
[0], &input
);
5738 timeout
.tv_sec
= 30;
5739 timeout
.tv_usec
= 0;
5741 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5751 * We have timed out...
5757 if (FD_ISSET(temppipe
[0], &input
))
5760 * Read the PPD file from the pipe, and write it to the PPD file.
5763 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5765 if (write(tempfd
, buffer
, bytes
) < bytes
)
5774 if (FD_ISSET(CGIPipes
[0], &input
))
5784 * No data from cups-deviced...
5787 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5793 * Read the source file and see what page sizes are supported...
5796 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5803 * Open the destination (if possible) and set the default options...
5808 cups_protocol
[0] = '\0';
5810 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5813 * Read all of the default lines from the old PPD...
5816 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5817 if (!strncmp(buffer
, "*Default", 8))
5820 * Add the default option...
5823 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5824 choice
, sizeof(choice
)))
5826 ppd_option_t
*ppdo
; /* PPD option */
5830 * Only add the default if the default hasn't already been
5831 * set and the choice exists in the new PPD...
5834 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5835 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5836 ppdFindChoice(ppdo
, choice
))
5837 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5841 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5842 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5846 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5849 * Add the default media sizes...
5852 num_defaults
= cupsAddOption("PageSize", size
->name
,
5853 num_defaults
, &defaults
);
5854 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5855 num_defaults
, &defaults
);
5856 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5857 num_defaults
, &defaults
);
5858 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5859 num_defaults
, &defaults
);
5865 * Open the source file for a copy...
5868 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5870 cupsFreeOptions(num_defaults
, defaults
);
5876 * Open the destination file for a copy...
5879 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5881 cupsFreeOptions(num_defaults
, defaults
);
5888 * Copy the source file to the destination...
5891 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5893 if (!strncmp(buffer
, "*Default", 8))
5896 * Check for an previous default option choice...
5899 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5900 choice
, sizeof(choice
)))
5902 const char *val
; /* Default option value */
5905 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5908 * Substitute the previous choice...
5911 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5916 cupsFilePrintf(dst
, "%s\n", buffer
);
5919 if (cups_protocol
[0])
5920 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5922 cupsFreeOptions(num_defaults
, defaults
);
5925 * Close both files and return...
5932 return (cupsFileClose(dst
));
5937 * 'copy_job_attrs()' - Copy job attributes.
5941 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5942 cupsd_job_t
*job
, /* I - Job */
5943 cups_array_t
*ra
, /* I - Requested attributes array */
5944 cups_array_t
*exclude
) /* I - Private attributes array */
5946 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5950 * Send the requested attributes for each job...
5953 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5954 con
->servername
, con
->serverport
, "/jobs/%d",
5957 if (!cupsArrayFind(exclude
, "all"))
5959 if ((!exclude
|| !cupsArrayFind(exclude
, "document-count")) &&
5960 (!ra
|| cupsArrayFind(ra
, "document-count")))
5961 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5962 "document-count", job
->num_files
);
5964 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
5965 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
5966 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5967 "job-media-progress", job
->progress
);
5969 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
5970 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
5971 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5972 "job-more-info", NULL
, job_uri
);
5974 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5975 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
5976 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5977 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5978 job
->num_files
> 0);
5980 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
5981 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
5982 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5983 "job-printer-up-time", time(NULL
));
5986 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5987 add_job_state_reasons(con
, job
);
5989 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5990 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5991 "job-uri", NULL
, job_uri
);
5993 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
5998 * 'copy_printer_attrs()' - Copy printer attributes.
6003 cupsd_client_t
*con
, /* I - Client connection */
6004 cupsd_printer_t
*printer
, /* I - Printer */
6005 cups_array_t
*ra
) /* I - Requested attributes array */
6007 char printer_uri
[HTTP_MAX_URI
];
6009 char printer_icons
[HTTP_MAX_URI
];
6011 time_t curtime
; /* Current time */
6012 int i
; /* Looping var */
6016 * Copy the printer attributes to the response using requested-attributes
6017 * and document-format attributes that may be provided by the client.
6020 curtime
= time(NULL
);
6022 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
6023 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6024 "marker-change-time", printer
->marker_time
);
6026 if (printer
->num_printers
> 0 &&
6027 (!ra
|| cupsArrayFind(ra
, "member-uris")))
6029 ipp_attribute_t
*member_uris
; /* member-uris attribute */
6030 cupsd_printer_t
*p2
; /* Printer in class */
6031 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
6034 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
6035 IPP_TAG_URI
, "member-uris",
6036 printer
->num_printers
, NULL
,
6039 for (i
= 0; i
< printer
->num_printers
; i
++)
6041 p2
= printer
->printers
[i
];
6043 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
6044 IPP_TAG_URI
)) != NULL
)
6045 member_uris
->values
[i
].string
.text
=
6046 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
6049 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
6050 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
6052 (p2
->type
& CUPS_PRINTER_CLASS
) ?
6053 "/classes/%s" : "/printers/%s", p2
->name
);
6054 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
6060 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
6061 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
6062 "printer-alert", NULL
, printer
->alert
);
6064 if (printer
->alert_description
&&
6065 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
6066 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
6067 "printer-alert-description", NULL
,
6068 printer
->alert_description
);
6070 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
6071 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
6072 ippTimeToDate(curtime
));
6075 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
6077 if (printer
->reg_name
)
6078 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6079 "printer-dns-sd-name", NULL
, printer
->reg_name
);
6081 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
6082 "printer-dns-sd-name", 0);
6084 #endif /* HAVE_DNSSD */
6086 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
6087 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6088 "printer-error-policy", NULL
, printer
->error_policy
);
6090 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
6092 static const char * const errors
[] =/* printer-error-policy-supported values */
6095 "retry-current-job",
6100 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
6101 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6102 "printer-error-policy-supported", NULL
, "retry-current-job");
6104 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6105 "printer-error-policy-supported",
6106 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
6109 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
6111 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
6112 "http", NULL
, con
->servername
, con
->serverport
,
6113 "/icons/%s.png", printer
->name
);
6114 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
6115 NULL
, printer_icons
);
6116 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
6119 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
6120 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
6121 printer
->accepting
);
6123 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
6124 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
6127 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
6128 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6130 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6131 "http", NULL
, con
->servername
, con
->serverport
,
6132 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6133 "/classes/%s" : "/printers/%s", printer
->name
);
6134 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6135 "printer-more-info", NULL
, printer_uri
);
6138 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
6139 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6140 "printer-op-policy", NULL
, printer
->op_policy
);
6142 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
6143 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
6146 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
6147 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6148 "printer-state-change-time", printer
->state_time
);
6150 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
6151 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
6152 "printer-state-message", NULL
, printer
->state_message
);
6154 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
6155 add_printer_state_reasons(con
, printer
);
6157 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
6159 int type
; /* printer-type value */
6162 * Add the CUPS-specific printer-type attribute...
6165 type
= printer
->type
;
6167 if (printer
== DefaultPrinter
)
6168 type
|= CUPS_PRINTER_DEFAULT
;
6170 if (!printer
->accepting
)
6171 type
|= CUPS_PRINTER_REJECTING
;
6173 if (!printer
->shared
)
6174 type
|= CUPS_PRINTER_NOT_SHARED
;
6176 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
6180 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
6181 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6182 "printer-up-time", curtime
);
6184 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
6185 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6187 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6188 "ipp", NULL
, con
->servername
, con
->serverport
,
6189 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6190 "/classes/%s" : "/printers/%s", printer
->name
);
6191 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6192 "printer-uri-supported", NULL
, printer_uri
);
6193 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
6197 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
6198 add_queued_job_count(con
, printer
);
6200 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6201 if (printer
->ppd_attrs
)
6202 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6203 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
6208 * 'copy_subscription_attrs()' - Copy subscription attributes.
6212 copy_subscription_attrs(
6213 cupsd_client_t
*con
, /* I - Client connection */
6214 cupsd_subscription_t
*sub
, /* I - Subscription */
6215 cups_array_t
*ra
, /* I - Requested attributes array */
6216 cups_array_t
*exclude
) /* I - Private attributes array */
6218 ipp_attribute_t
*attr
; /* Current attribute */
6219 char printer_uri
[HTTP_MAX_URI
];
6221 int count
; /* Number of events */
6222 unsigned mask
; /* Current event mask */
6223 const char *name
; /* Current event name */
6226 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6227 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
6228 con
, sub
, ra
, exclude
);
6231 * Copy the subscription attributes to the response using the
6232 * requested-attributes attribute that may be provided by the client.
6235 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
6237 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
6238 (!ra
|| cupsArrayFind(ra
, "notify-events")))
6240 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
6242 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
6245 * Simple event list...
6248 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
6249 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6250 "notify-events", NULL
, name
);
6255 * Complex event list...
6258 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6259 if (sub
->mask
& mask
)
6262 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
6263 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6264 "notify-events", count
, NULL
, NULL
);
6266 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6267 if (sub
->mask
& mask
)
6269 attr
->values
[count
].string
.text
=
6270 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
6277 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
6278 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
6279 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6280 "notify-lease-duration", sub
->lease
);
6282 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
6283 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
6284 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6285 "notify-recipient-uri", NULL
, sub
->recipient
);
6286 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
6287 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
6288 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
6289 "notify-pull-method", NULL
, "ippget");
6291 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
6292 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
6293 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
6294 "notify-subscriber-user-name", NULL
, sub
->owner
);
6296 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
6297 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
6298 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6299 "notify-time-interval", sub
->interval
);
6301 if (sub
->user_data_len
> 0 &&
6302 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
6303 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
6304 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
6305 sub
->user_data
, sub
->user_data_len
);
6308 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
6309 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6310 "notify-job-id", sub
->job
->id
);
6312 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
6314 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6315 "ipp", NULL
, con
->servername
, con
->serverport
,
6316 "/printers/%s", sub
->dest
->name
);
6317 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6318 "notify-printer-uri", NULL
, printer_uri
);
6321 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
6322 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6323 "notify-subscription-id", sub
->id
);
6328 * 'create_job()' - Print a file to a printer or class.
6332 create_job(cupsd_client_t
*con
, /* I - Client connection */
6333 ipp_attribute_t
*uri
) /* I - Printer URI */
6335 cupsd_printer_t
*printer
; /* Printer */
6336 cupsd_job_t
*job
; /* New job */
6339 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
6340 con
->http
.fd
, uri
->values
[0].string
.text
);
6343 * Is the destination valid?
6346 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6352 send_ipp_status(con
, IPP_NOT_FOUND
,
6353 _("The printer or class does not exist."));
6358 * Create the job object...
6361 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6364 job
->pending_timeout
= 1;
6367 * Save and log the job...
6370 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6371 job
->dest
, job
->username
);
6376 * 'create_requested_array()' - Create an array for the requested-attributes.
6379 static cups_array_t
* /* O - Array of attributes or NULL */
6380 create_requested_array(ipp_t
*request
) /* I - IPP request */
6382 int i
; /* Looping var */
6383 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6384 cups_array_t
*ra
; /* Requested attributes array */
6385 char *value
; /* Current value */
6389 * Get the requested-attributes attribute, and return NULL if we don't
6393 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6394 IPP_TAG_KEYWORD
)) == NULL
)
6398 * If the attribute contains a single "all" keyword, return NULL...
6401 if (requested
->num_values
== 1 &&
6402 !strcmp(requested
->values
[0].string
.text
, "all"))
6406 * Create an array using "strcmp" as the comparison function...
6409 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6411 for (i
= 0; i
< requested
->num_values
; i
++)
6413 value
= requested
->values
[i
].string
.text
;
6415 if (!strcmp(value
, "job-template"))
6417 cupsArrayAdd(ra
, "copies");
6418 cupsArrayAdd(ra
, "copies-default");
6419 cupsArrayAdd(ra
, "copies-supported");
6420 cupsArrayAdd(ra
, "finishings");
6421 cupsArrayAdd(ra
, "finishings-default");
6422 cupsArrayAdd(ra
, "finishings-supported");
6423 cupsArrayAdd(ra
, "job-hold-until");
6424 cupsArrayAdd(ra
, "job-hold-until-default");
6425 cupsArrayAdd(ra
, "job-hold-until-supported");
6426 cupsArrayAdd(ra
, "job-priority");
6427 cupsArrayAdd(ra
, "job-priority-default");
6428 cupsArrayAdd(ra
, "job-priority-supported");
6429 cupsArrayAdd(ra
, "job-sheets");
6430 cupsArrayAdd(ra
, "job-sheets-default");
6431 cupsArrayAdd(ra
, "job-sheets-supported");
6432 cupsArrayAdd(ra
, "media");
6433 cupsArrayAdd(ra
, "media-default");
6434 cupsArrayAdd(ra
, "media-supported");
6435 cupsArrayAdd(ra
, "multiple-document-handling");
6436 cupsArrayAdd(ra
, "multiple-document-handling-default");
6437 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6438 cupsArrayAdd(ra
, "number-up");
6439 cupsArrayAdd(ra
, "number-up-default");
6440 cupsArrayAdd(ra
, "number-up-supported");
6441 cupsArrayAdd(ra
, "orientation-requested");
6442 cupsArrayAdd(ra
, "orientation-requested-default");
6443 cupsArrayAdd(ra
, "orientation-requested-supported");
6444 cupsArrayAdd(ra
, "page-ranges");
6445 cupsArrayAdd(ra
, "page-ranges-supported");
6446 cupsArrayAdd(ra
, "printer-resolution");
6447 cupsArrayAdd(ra
, "printer-resolution-default");
6448 cupsArrayAdd(ra
, "printer-resolution-supported");
6449 cupsArrayAdd(ra
, "print-quality");
6450 cupsArrayAdd(ra
, "print-quality-default");
6451 cupsArrayAdd(ra
, "print-quality-supported");
6452 cupsArrayAdd(ra
, "sides");
6453 cupsArrayAdd(ra
, "sides-default");
6454 cupsArrayAdd(ra
, "sides-supported");
6456 else if (!strcmp(value
, "job-description"))
6458 cupsArrayAdd(ra
, "date-time-at-completed");
6459 cupsArrayAdd(ra
, "date-time-at-creation");
6460 cupsArrayAdd(ra
, "date-time-at-processing");
6461 cupsArrayAdd(ra
, "job-detailed-status-message");
6462 cupsArrayAdd(ra
, "job-document-access-errors");
6463 cupsArrayAdd(ra
, "job-id");
6464 cupsArrayAdd(ra
, "job-impressions");
6465 cupsArrayAdd(ra
, "job-impressions-completed");
6466 cupsArrayAdd(ra
, "job-k-octets");
6467 cupsArrayAdd(ra
, "job-k-octets-processed");
6468 cupsArrayAdd(ra
, "job-media-progress");
6469 cupsArrayAdd(ra
, "job-media-sheets");
6470 cupsArrayAdd(ra
, "job-media-sheets-completed");
6471 cupsArrayAdd(ra
, "job-message-from-operator");
6472 cupsArrayAdd(ra
, "job-more-info");
6473 cupsArrayAdd(ra
, "job-name");
6474 cupsArrayAdd(ra
, "job-originating-user-name");
6475 cupsArrayAdd(ra
, "job-printer-up-time");
6476 cupsArrayAdd(ra
, "job-printer-uri");
6477 cupsArrayAdd(ra
, "job-state");
6478 cupsArrayAdd(ra
, "job-state-message");
6479 cupsArrayAdd(ra
, "job-state-reasons");
6480 cupsArrayAdd(ra
, "job-uri");
6481 cupsArrayAdd(ra
, "number-of-documents");
6482 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6483 cupsArrayAdd(ra
, "output-device-assigned");
6484 cupsArrayAdd(ra
, "time-at-completed");
6485 cupsArrayAdd(ra
, "time-at-creation");
6486 cupsArrayAdd(ra
, "time-at-processing");
6488 else if (!strcmp(value
, "printer-description"))
6490 cupsArrayAdd(ra
, "charset-configured");
6491 cupsArrayAdd(ra
, "charset-supported");
6492 cupsArrayAdd(ra
, "color-supported");
6493 cupsArrayAdd(ra
, "compression-supported");
6494 cupsArrayAdd(ra
, "document-format-default");
6495 cupsArrayAdd(ra
, "document-format-supported");
6496 cupsArrayAdd(ra
, "generated-natural-language-supported");
6497 cupsArrayAdd(ra
, "ipp-versions-supported");
6498 cupsArrayAdd(ra
, "job-impressions-supported");
6499 cupsArrayAdd(ra
, "job-k-octets-supported");
6500 cupsArrayAdd(ra
, "job-media-sheets-supported");
6501 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6502 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6503 cupsArrayAdd(ra
, "multiple-operation-time-out");
6504 cupsArrayAdd(ra
, "natural-language-configured");
6505 cupsArrayAdd(ra
, "notify-attributes-supported");
6506 cupsArrayAdd(ra
, "notify-lease-duration-default");
6507 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6508 cupsArrayAdd(ra
, "notify-max-events-supported");
6509 cupsArrayAdd(ra
, "notify-events-default");
6510 cupsArrayAdd(ra
, "notify-events-supported");
6511 cupsArrayAdd(ra
, "notify-pull-method-supported");
6512 cupsArrayAdd(ra
, "notify-schemes-supported");
6513 cupsArrayAdd(ra
, "operations-supported");
6514 cupsArrayAdd(ra
, "pages-per-minute");
6515 cupsArrayAdd(ra
, "pages-per-minute-color");
6516 cupsArrayAdd(ra
, "pdl-override-supported");
6517 cupsArrayAdd(ra
, "printer-alert");
6518 cupsArrayAdd(ra
, "printer-alert-description");
6519 cupsArrayAdd(ra
, "printer-commands");
6520 cupsArrayAdd(ra
, "printer-current-time");
6521 cupsArrayAdd(ra
, "printer-driver-installer");
6522 cupsArrayAdd(ra
, "printer-dns-sd-name");
6523 cupsArrayAdd(ra
, "printer-info");
6524 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6525 cupsArrayAdd(ra
, "printer-location");
6526 cupsArrayAdd(ra
, "printer-make-and-model");
6527 cupsArrayAdd(ra
, "printer-message-from-operator");
6528 cupsArrayAdd(ra
, "printer-more-info");
6529 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6530 cupsArrayAdd(ra
, "printer-name");
6531 cupsArrayAdd(ra
, "printer-state");
6532 cupsArrayAdd(ra
, "printer-state-message");
6533 cupsArrayAdd(ra
, "printer-state-reasons");
6534 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6535 cupsArrayAdd(ra
, "printer-type");
6536 cupsArrayAdd(ra
, "printer-up-time");
6537 cupsArrayAdd(ra
, "printer-uri-supported");
6538 cupsArrayAdd(ra
, "queued-job-count");
6539 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6540 cupsArrayAdd(ra
, "uri-authentication-supported");
6541 cupsArrayAdd(ra
, "uri-security-supported");
6543 else if (!strcmp(value
, "printer-defaults"))
6545 char *name
; /* Option name */
6548 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6550 name
= (char *)cupsArrayNext(CommonDefaults
))
6551 cupsArrayAdd(ra
, name
);
6553 else if (!strcmp(value
, "subscription-template"))
6555 cupsArrayAdd(ra
, "notify-attributes");
6556 cupsArrayAdd(ra
, "notify-charset");
6557 cupsArrayAdd(ra
, "notify-events");
6558 cupsArrayAdd(ra
, "notify-lease-duration");
6559 cupsArrayAdd(ra
, "notify-natural-language");
6560 cupsArrayAdd(ra
, "notify-pull-method");
6561 cupsArrayAdd(ra
, "notify-recipient-uri");
6562 cupsArrayAdd(ra
, "notify-time-interval");
6563 cupsArrayAdd(ra
, "notify-user-data");
6566 cupsArrayAdd(ra
, value
);
6574 * 'create_subscription()' - Create a notification subscription.
6578 create_subscription(
6579 cupsd_client_t
*con
, /* I - Client connection */
6580 ipp_attribute_t
*uri
) /* I - Printer URI */
6582 http_status_t status
; /* Policy status */
6583 int i
; /* Looping var */
6584 ipp_attribute_t
*attr
; /* Current attribute */
6585 cups_ptype_t dtype
; /* Destination type (printer/class) */
6586 char scheme
[HTTP_MAX_URI
],
6587 /* Scheme portion of URI */
6588 userpass
[HTTP_MAX_URI
],
6589 /* Username portion of URI */
6591 /* Host portion of URI */
6592 resource
[HTTP_MAX_URI
];
6593 /* Resource portion of URI */
6594 int port
; /* Port portion of URI */
6595 cupsd_printer_t
*printer
; /* Printer/class */
6596 cupsd_job_t
*job
; /* Job */
6597 int jobid
; /* Job ID */
6598 cupsd_subscription_t
*sub
; /* Subscription object */
6599 const char *username
, /* requesting-user-name or
6600 authenticated username */
6601 *recipient
, /* notify-recipient-uri */
6602 *pullmethod
; /* notify-pull-method */
6603 ipp_attribute_t
*user_data
; /* notify-user-data */
6604 int interval
, /* notify-time-interval */
6605 lease
; /* notify-lease-duration */
6606 unsigned mask
; /* notify-events */
6607 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6608 *notify_lease
; /* notify-lease-duration(-default) */
6612 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6614 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6615 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6616 attr
->value_tag
, attr
->name
);
6618 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6623 * Is the destination valid?
6626 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6627 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6628 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6630 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6631 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6632 sizeof(host
), &port
, resource
, sizeof(resource
));
6634 if (!strcmp(resource
, "/"))
6636 dtype
= (cups_ptype_t
)0;
6639 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6641 dtype
= (cups_ptype_t
)0;
6644 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6646 dtype
= CUPS_PRINTER_CLASS
;
6649 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6655 send_ipp_status(con
, IPP_NOT_FOUND
,
6656 _("The printer or class does not exist."));
6666 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6669 send_http_error(con
, status
, printer
);
6673 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6675 send_http_error(con
, status
, NULL
);
6680 * Get the user that is requesting the subscription...
6683 username
= get_username(con
);
6686 * Find the first subscription group attribute; return if we have
6690 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6691 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6696 send_ipp_status(con
, IPP_BAD_REQUEST
,
6697 _("No subscription attributes in request."));
6702 * Process the subscription attributes in the request...
6705 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6713 lease
= DefaultLeaseDuration
;
6715 mask
= CUPSD_EVENT_NONE
;
6719 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6721 notify_lease
= ippFindAttribute(printer
->attrs
,
6722 "notify-lease-duration-default",
6726 lease
= notify_lease
->values
[0].integer
;
6730 notify_events
= NULL
;
6731 notify_lease
= NULL
;
6734 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6736 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6737 attr
->value_tag
== IPP_TAG_URI
)
6740 * Validate the recipient scheme against the ServerBin/notifier
6744 char notifier
[1024]; /* Notifier filename */
6747 recipient
= attr
->values
[0].string
.text
;
6749 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6750 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6751 host
, sizeof(host
), &port
,
6752 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6754 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6755 _("Bad notify-recipient-uri \"%s\"."), recipient
);
6756 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6757 "notify-status-code", IPP_URI_SCHEME
);
6761 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6763 if (access(notifier
, X_OK
))
6765 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6766 _("notify-recipient-uri URI \"%s\" uses unknown "
6767 "scheme."), recipient
);
6768 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6769 "notify-status-code", IPP_URI_SCHEME
);
6773 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6775 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6776 _("notify-recipient-uri URI \"%s\" is already used."),
6778 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6779 "notify-status-code", IPP_ATTRIBUTES
);
6783 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6784 attr
->value_tag
== IPP_TAG_KEYWORD
)
6786 pullmethod
= attr
->values
[0].string
.text
;
6788 if (strcmp(pullmethod
, "ippget"))
6790 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6791 _("Bad notify-pull-method \"%s\"."), pullmethod
);
6792 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6793 "notify-status-code", IPP_ATTRIBUTES
);
6797 else if (!strcmp(attr
->name
, "notify-charset") &&
6798 attr
->value_tag
== IPP_TAG_CHARSET
&&
6799 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6800 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6802 send_ipp_status(con
, IPP_CHARSET
,
6803 _("Character set \"%s\" not supported."),
6804 attr
->values
[0].string
.text
);
6807 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6808 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6809 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6811 send_ipp_status(con
, IPP_CHARSET
,
6812 _("Language \"%s\" not supported."),
6813 attr
->values
[0].string
.text
);
6816 else if (!strcmp(attr
->name
, "notify-user-data") &&
6817 attr
->value_tag
== IPP_TAG_STRING
)
6819 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6821 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6822 _("The notify-user-data value is too large "
6823 "(%d > 63 octets)."),
6824 attr
->values
[0].unknown
.length
);
6830 else if (!strcmp(attr
->name
, "notify-events") &&
6831 attr
->value_tag
== IPP_TAG_KEYWORD
)
6832 notify_events
= attr
;
6833 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6834 attr
->value_tag
== IPP_TAG_INTEGER
)
6835 lease
= attr
->values
[0].integer
;
6836 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6837 attr
->value_tag
== IPP_TAG_INTEGER
)
6838 interval
= attr
->values
[0].integer
;
6839 else if (!strcmp(attr
->name
, "notify-job-id") &&
6840 attr
->value_tag
== IPP_TAG_INTEGER
)
6841 jobid
= attr
->values
[0].integer
;
6848 for (i
= 0; i
< notify_events
->num_values
; i
++)
6849 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6853 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6855 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6856 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6857 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6859 if (!recipient
&& !pullmethod
)
6862 if (mask
== CUPSD_EVENT_NONE
)
6865 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6867 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6870 send_ipp_status(con
, IPP_BAD_REQUEST
,
6871 _("notify-events not specified."));
6876 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6878 cupsdLogMessage(CUPSD_LOG_INFO
,
6879 "create_subscription: Limiting notify-lease-duration to "
6882 lease
= MaxLeaseDuration
;
6887 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6889 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6897 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6899 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6900 _("There are too many subscriptions."));
6905 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
6908 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6909 "Added subscription #%d for printer \"%s\".",
6910 sub
->id
, printer
->name
);
6912 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
6915 sub
->interval
= interval
;
6917 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6919 cupsdSetString(&sub
->owner
, username
);
6923 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6924 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6925 sub
->user_data_len
);
6928 ippAddSeparator(con
->response
);
6929 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6930 "notify-subscription-id", sub
->id
);
6932 con
->response
->request
.status
.status_code
= IPP_OK
;
6938 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6943 * 'delete_printer()' - Remove a printer or class from the system.
6947 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6948 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6950 http_status_t status
; /* Policy status */
6951 cups_ptype_t dtype
; /* Destination type (printer/class) */
6952 cupsd_printer_t
*printer
; /* Printer/class */
6953 char filename
[1024]; /* Script/PPD filename */
6956 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6957 con
->http
.fd
, uri
->values
[0].string
.text
);
6960 * Do we have a valid URI?
6963 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6969 send_ipp_status(con
, IPP_NOT_FOUND
,
6970 _("The printer or class does not exist."));
6978 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6980 send_http_error(con
, status
, NULL
);
6985 * Remove old jobs...
6988 cupsdCancelJobs(printer
->name
, NULL
, 1);
6991 * Remove old subscriptions and send a "deleted printer" event...
6994 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6995 "%s \"%s\" deleted by \"%s\".",
6996 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6997 printer
->name
, get_username(con
));
6999 cupsdExpireSubscriptions(printer
, NULL
);
7002 * Remove any old PPD or script files...
7005 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
7009 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7013 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
7016 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
7021 * Unregister color profiles...
7024 apple_unregister_profiles(printer
);
7025 #endif /* __APPLE__ */
7027 if (dtype
& CUPS_PRINTER_CLASS
)
7029 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
7030 printer
->name
, get_username(con
));
7032 cupsdDeletePrinter(printer
, 0);
7033 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7037 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
7038 printer
->name
, get_username(con
));
7040 if (cupsdDeletePrinter(printer
, 0))
7041 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7043 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
7046 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
7049 * Return with no errors...
7052 con
->response
->request
.status
.status_code
= IPP_OK
;
7057 * 'get_default()' - Get the default destination.
7061 get_default(cupsd_client_t
*con
) /* I - Client connection */
7063 http_status_t status
; /* Policy status */
7064 cups_array_t
*ra
; /* Requested attributes array */
7067 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
7073 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7075 send_http_error(con
, status
, NULL
);
7081 ra
= create_requested_array(con
->request
);
7083 copy_printer_attrs(con
, DefaultPrinter
, ra
);
7085 cupsArrayDelete(ra
);
7087 con
->response
->request
.status
.status_code
= IPP_OK
;
7090 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
7095 * 'get_devices()' - Get the list of available devices on the local system.
7099 get_devices(cupsd_client_t
*con
) /* I - Client connection */
7101 http_status_t status
; /* Policy status */
7102 ipp_attribute_t
*limit
, /* limit attribute */
7103 *timeout
, /* timeout attribute */
7104 *requested
, /* requested-attributes attribute */
7105 *exclude
, /* exclude-schemes attribute */
7106 *include
; /* include-schemes attribute */
7107 char command
[1024], /* cups-deviced command */
7108 options
[2048], /* Options to pass to command */
7110 /* String for requested attributes */
7112 /* String for excluded schemes */
7114 /* String for included schemes */
7117 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
7123 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7125 send_http_error(con
, status
, NULL
);
7130 * Run cups-deviced command with the given options...
7133 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7134 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
7135 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7137 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
7138 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
7141 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7143 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7146 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7148 exclude_str
[0] = '\0';
7151 url_encode_attr(include
, include_str
, sizeof(include_str
));
7153 include_str
[0] = '\0';
7155 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
7156 snprintf(options
, sizeof(options
),
7157 "%d+%d+%d+%d+%s%s%s%s%s",
7158 con
->request
->request
.op
.request_id
,
7159 limit
? limit
->values
[0].integer
: 0,
7160 timeout
? timeout
->values
[0].integer
: 15,
7163 exclude_str
[0] ? "%20" : "", exclude_str
,
7164 include_str
[0] ? "%20" : "", include_str
);
7166 if (cupsdSendCommand(con
, command
, options
, 1))
7169 * Command started successfully, don't send an IPP response here...
7172 ippDelete(con
->response
);
7173 con
->response
= NULL
;
7178 * Command failed, return "internal error" so the user knows something
7182 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7183 _("cups-deviced failed to execute."));
7189 * 'get_document()' - Get a copy of a job file.
7193 get_document(cupsd_client_t
*con
, /* I - Client connection */
7194 ipp_attribute_t
*uri
) /* I - Job URI */
7196 http_status_t status
; /* Policy status */
7197 ipp_attribute_t
*attr
; /* Current attribute */
7198 int jobid
; /* Job ID */
7199 int docnum
; /* Document number */
7200 cupsd_job_t
*job
; /* Current job */
7201 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7202 username
[HTTP_MAX_URI
], /* Username portion of URI */
7203 host
[HTTP_MAX_URI
], /* Host portion of URI */
7204 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7205 int port
; /* Port portion of URI */
7206 char filename
[1024], /* Filename for document */
7207 format
[1024]; /* Format for document */
7210 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
7211 con
->http
.fd
, uri
->values
[0].string
.text
);
7214 * See if we have a job URI or a printer URI...
7217 if (!strcmp(uri
->name
, "printer-uri"))
7220 * Got a printer URI; see if we also have a job-id attribute...
7223 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7224 IPP_TAG_INTEGER
)) == NULL
)
7226 send_ipp_status(con
, IPP_BAD_REQUEST
,
7227 _("Got a printer-uri attribute but no job-id."));
7231 jobid
= attr
->values
[0].integer
;
7236 * Got a job URI; parse it to get the job ID...
7239 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7240 sizeof(scheme
), username
, sizeof(username
), host
,
7241 sizeof(host
), &port
, resource
, sizeof(resource
));
7243 if (strncmp(resource
, "/jobs/", 6))
7249 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7250 uri
->values
[0].string
.text
);
7254 jobid
= atoi(resource
+ 6);
7258 * See if the job exists...
7261 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7264 * Nope - return a "not found" error...
7267 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7275 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
7276 job
->username
)) != HTTP_OK
)
7278 send_http_error(con
, status
, NULL
);
7283 * Get the document number...
7286 if ((attr
= ippFindAttribute(con
->request
, "document-number",
7287 IPP_TAG_INTEGER
)) == NULL
)
7289 send_ipp_status(con
, IPP_BAD_REQUEST
,
7290 _("Missing document-number attribute."));
7294 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
7295 attr
->num_values
> 1)
7297 send_ipp_status(con
, IPP_NOT_FOUND
,
7298 _("Document #%d does not exist in job #%d."), docnum
,
7303 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
7305 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
7307 cupsdLogMessage(CUPSD_LOG_ERROR
,
7308 "Unable to open document %d in job %d - %s", docnum
, jobid
,
7310 send_ipp_status(con
, IPP_NOT_FOUND
,
7311 _("Unable to open document #%d in job #%d."), docnum
,
7316 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7320 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
7321 job
->filetypes
[docnum
- 1]->type
);
7323 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
7325 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
7327 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
7328 IPP_TAG_NAME
)) != NULL
)
7329 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
7330 NULL
, attr
->values
[0].string
.text
);
7335 * 'get_job_attrs()' - Get job attributes.
7339 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
7340 ipp_attribute_t
*uri
) /* I - Job URI */
7342 http_status_t status
; /* Policy status */
7343 ipp_attribute_t
*attr
; /* Current attribute */
7344 int jobid
; /* Job ID */
7345 cupsd_job_t
*job
; /* Current job */
7346 cupsd_printer_t
*printer
; /* Current printer */
7347 cupsd_policy_t
*policy
; /* Current security policy */
7348 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7349 username
[HTTP_MAX_URI
], /* Username portion of URI */
7350 host
[HTTP_MAX_URI
], /* Host portion of URI */
7351 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7352 int port
; /* Port portion of URI */
7353 cups_array_t
*ra
, /* Requested attributes array */
7354 *exclude
; /* Private attributes array */
7357 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7358 con
->http
.fd
, uri
->values
[0].string
.text
);
7361 * See if we have a job URI or a printer URI...
7364 if (!strcmp(uri
->name
, "printer-uri"))
7367 * Got a printer URI; see if we also have a job-id attribute...
7370 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7371 IPP_TAG_INTEGER
)) == NULL
)
7373 send_ipp_status(con
, IPP_BAD_REQUEST
,
7374 _("Got a printer-uri attribute but no job-id."));
7378 jobid
= attr
->values
[0].integer
;
7383 * Got a job URI; parse it to get the job ID...
7386 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7387 sizeof(scheme
), username
, sizeof(username
), host
,
7388 sizeof(host
), &port
, resource
, sizeof(resource
));
7390 if (strncmp(resource
, "/jobs/", 6))
7396 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7397 uri
->values
[0].string
.text
);
7401 jobid
= atoi(resource
+ 6);
7405 * See if the job exists...
7408 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7411 * Nope - return a "not found" error...
7414 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7422 if ((printer
= job
->printer
) == NULL
)
7423 printer
= cupsdFindDest(job
->dest
);
7426 policy
= printer
->op_policy_ptr
;
7428 policy
= DefaultPolicyPtr
;
7430 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
7432 send_http_error(con
, status
, NULL
);
7436 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
7439 * Copy attributes...
7444 ra
= create_requested_array(con
->request
);
7445 copy_job_attrs(con
, job
, ra
, exclude
);
7446 cupsArrayDelete(ra
);
7448 con
->response
->request
.status
.status_code
= IPP_OK
;
7453 * 'get_jobs()' - Get a list of jobs for the specified printer.
7457 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7458 ipp_attribute_t
*uri
) /* I - Printer URI */
7460 http_status_t status
; /* Policy status */
7461 ipp_attribute_t
*attr
; /* Current attribute */
7462 const char *dest
; /* Destination */
7463 cups_ptype_t dtype
; /* Destination type (printer/class) */
7464 cups_ptype_t dmask
; /* Destination type mask */
7465 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7466 username
[HTTP_MAX_URI
], /* Username portion of URI */
7467 host
[HTTP_MAX_URI
], /* Host portion of URI */
7468 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7469 int port
; /* Port portion of URI */
7470 int job_comparison
; /* Job comparison */
7471 ipp_jstate_t job_state
; /* job-state value */
7472 int first_job_id
; /* First job ID */
7473 int limit
; /* Maximum number of jobs to return */
7474 int count
; /* Number of jobs that match */
7475 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7476 cupsd_job_t
*job
; /* Current job pointer */
7477 cupsd_printer_t
*printer
; /* Printer */
7478 cups_array_t
*list
; /* Which job list... */
7479 cups_array_t
*ra
, /* Requested attributes array */
7480 *exclude
; /* Private attributes array */
7481 cupsd_policy_t
*policy
; /* Current policy */
7484 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7485 uri
->values
[0].string
.text
);
7488 * Is the destination valid?
7491 if (strcmp(uri
->name
, "printer-uri"))
7493 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
7497 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7498 sizeof(scheme
), username
, sizeof(username
), host
,
7499 sizeof(host
), &port
, resource
, sizeof(resource
));
7501 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7504 dtype
= (cups_ptype_t
)0;
7505 dmask
= (cups_ptype_t
)0;
7508 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7511 dtype
= (cups_ptype_t
)0;
7512 dmask
= CUPS_PRINTER_CLASS
;
7515 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7518 dtype
= CUPS_PRINTER_CLASS
;
7519 dmask
= CUPS_PRINTER_CLASS
;
7522 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7529 send_ipp_status(con
, IPP_NOT_FOUND
,
7530 _("The printer or class does not exist."));
7535 dtype
&= CUPS_PRINTER_CLASS
;
7536 dmask
= CUPS_PRINTER_CLASS
;
7544 policy
= printer
->op_policy_ptr
;
7546 policy
= DefaultPolicyPtr
;
7548 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7550 send_http_error(con
, status
, NULL
);
7554 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7557 * See if the "which-jobs" attribute have been specified...
7560 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7561 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7563 send_ipp_status(con
, IPP_CONFLICT
,
7564 _("The %s attribute cannot be provided with job-ids."),
7568 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7570 job_comparison
= -1;
7571 job_state
= IPP_JOB_STOPPED
;
7574 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7577 job_state
= IPP_JOB_CANCELED
;
7580 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7583 job_state
= IPP_JOB_ABORTED
;
7586 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7589 job_state
= IPP_JOB_PENDING
;
7592 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7595 job_state
= IPP_JOB_CANCELED
;
7598 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7601 job_state
= IPP_JOB_PENDING
;
7604 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7607 job_state
= IPP_JOB_HELD
;
7610 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7613 job_state
= IPP_JOB_PROCESSING
;
7614 list
= PrintingJobs
;
7616 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7619 job_state
= IPP_JOB_STOPPED
;
7624 send_ipp_status(con
, IPP_ATTRIBUTES
,
7625 _("The which-jobs value \"%s\" is not supported."),
7626 attr
->values
[0].string
.text
);
7627 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7628 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7633 * See if they want to limit the number of jobs reported...
7636 if ((attr
= ippFindAttribute(con
->request
, "limit",
7637 IPP_TAG_INTEGER
)) != NULL
)
7641 send_ipp_status(con
, IPP_CONFLICT
,
7642 _("The %s attribute cannot be provided with job-ids."),
7647 limit
= attr
->values
[0].integer
;
7652 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7653 IPP_TAG_INTEGER
)) != NULL
)
7657 send_ipp_status(con
, IPP_CONFLICT
,
7658 _("The %s attribute cannot be provided with job-ids."),
7663 first_job_id
= attr
->values
[0].integer
;
7669 * See if we only want to see jobs for a specific user...
7672 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7673 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7675 send_ipp_status(con
, IPP_CONFLICT
,
7676 _("The %s attribute cannot be provided with job-ids."),
7680 else if (attr
&& attr
->values
[0].boolean
)
7681 strlcpy(username
, get_username(con
), sizeof(username
));
7685 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7686 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7689 * IPP conformance - Get-Jobs has a default requested-attributes value of
7690 * "job-id" and "job-uri".
7693 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7694 cupsArrayAdd(ra
, "job-id");
7695 cupsArrayAdd(ra
, "job-uri");
7699 * OK, build a list of jobs for this printer...
7704 int i
; /* Looping var */
7706 for (i
= 0; i
< job_ids
->num_values
; i
++)
7708 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
7712 if (i
< job_ids
->num_values
)
7714 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7715 job_ids
->values
[i
].integer
);
7719 for (i
= 0; i
< job_ids
->num_values
; i
++)
7721 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7727 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7733 ippAddSeparator(con
->response
);
7735 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7736 job
->printer
->op_policy_ptr
:
7737 policy
, con
, job
->printer
,
7740 copy_job_attrs(con
, job
, ra
, exclude
);
7745 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7746 (limit
<= 0 || count
< limit
) && job
;
7747 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7750 * Filter out jobs that don't match...
7753 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7754 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7755 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7756 job
->username
, job
->state_value
, job
->attrs
);
7758 if (!job
->dest
|| !job
->username
)
7761 if (!job
->dest
|| !job
->username
)
7764 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7765 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7767 if ((job
->dtype
& dmask
) != dtype
&&
7768 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7771 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7772 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7773 (job_comparison
> 0 && job
->state_value
< job_state
))
7776 if (job
->id
< first_job_id
)
7783 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7788 if (username
[0] && strcasecmp(username
, job
->username
))
7792 ippAddSeparator(con
->response
);
7796 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7797 job
->printer
->op_policy_ptr
:
7798 policy
, con
, job
->printer
,
7801 copy_job_attrs(con
, job
, ra
, exclude
);
7804 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7807 cupsArrayDelete(ra
);
7809 con
->response
->request
.status
.status_code
= IPP_OK
;
7814 * 'get_notifications()' - Get events for a subscription.
7818 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7820 int i
, j
; /* Looping vars */
7821 http_status_t status
; /* Policy status */
7822 cupsd_subscription_t
*sub
; /* Subscription */
7823 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7824 *sequences
; /* notify-sequence-numbers */
7825 int min_seq
; /* Minimum sequence number */
7826 int interval
; /* Poll interval */
7829 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7833 * Get subscription attributes...
7836 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7838 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7843 send_ipp_status(con
, IPP_BAD_REQUEST
,
7844 _("Missing notify-subscription-ids attribute."));
7849 * Are the subscription IDs valid?
7852 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7854 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7857 * Bad subscription ID...
7860 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7861 ids
->values
[i
].integer
);
7869 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7871 con
, sub
->owner
)) != HTTP_OK
)
7873 send_http_error(con
, status
, sub
->dest
);
7878 * Check the subscription type and update the interval accordingly.
7881 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7884 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7886 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7892 * Tell the client to poll again in N seconds...
7896 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7897 "notify-get-interval", interval
);
7899 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7900 "printer-up-time", time(NULL
));
7903 * Copy the subscription event attributes to the response.
7906 con
->response
->request
.status
.status_code
=
7907 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7909 for (i
= 0; i
< ids
->num_values
; i
++)
7912 * Get the subscription and sequence number...
7915 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7917 if (sequences
&& i
< sequences
->num_values
)
7918 min_seq
= sequences
->values
[i
].integer
;
7923 * If we don't have any new events, nothing to do here...
7926 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
7930 * Otherwise copy all of the new events...
7933 if (sub
->first_event_id
> min_seq
)
7936 j
= min_seq
- sub
->first_event_id
;
7938 for (; j
< cupsArrayCount(sub
->events
); j
++)
7940 ippAddSeparator(con
->response
);
7942 copy_attrs(con
->response
,
7943 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7944 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7951 * 'get_ppd()' - Get a named PPD from the local system.
7955 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7956 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7958 http_status_t status
; /* Policy status */
7959 cupsd_printer_t
*dest
; /* Destination */
7960 cups_ptype_t dtype
; /* Destination type */
7963 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7964 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7966 if (!strcmp(uri
->name
, "ppd-name"))
7969 * Return a PPD file from cups-driverd...
7972 char command
[1024], /* cups-driverd command */
7973 options
[1024], /* Options to pass to command */
7974 ppd_name
[1024]; /* ppd-name */
7981 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7983 send_http_error(con
, status
, NULL
);
7988 * Run cups-driverd command with the given options...
7991 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7992 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7993 snprintf(options
, sizeof(options
), "get+%d+%s",
7994 con
->request
->request
.op
.request_id
, ppd_name
);
7996 if (cupsdSendCommand(con
, command
, options
, 0))
7999 * Command started successfully, don't send an IPP response here...
8002 ippDelete(con
->response
);
8003 con
->response
= NULL
;
8008 * Command failed, return "internal error" so the user knows something
8012 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8013 _("cups-driverd failed to execute."));
8016 else if (!strcmp(uri
->name
, "printer-uri") &&
8017 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
8019 int i
; /* Looping var */
8020 char filename
[1024]; /* PPD filename */
8027 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8029 send_http_error(con
, status
, dest
);
8034 * See if we need the PPD for a class or remote printer...
8037 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8040 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
8042 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8043 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8044 "printer-uri", NULL
, dest
->uri
);
8047 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
8049 for (i
= 0; i
< dest
->num_printers
; i
++)
8050 if (!(dest
->printers
[i
]->type
&
8051 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
8053 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8054 dest
->printers
[i
]->name
);
8056 if (!access(filename
, 0))
8060 if (i
< dest
->num_printers
)
8061 dest
= dest
->printers
[i
];
8064 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8065 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8066 "printer-uri", NULL
, dest
->printers
[0]->uri
);
8072 * Found the printer with the PPD file, now see if there is one...
8075 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
8077 send_ipp_status(con
, IPP_NOT_FOUND
,
8078 _("The PPD file \"%s\" could not be opened: %s"),
8079 uri
->values
[0].string
.text
, strerror(errno
));
8083 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
8087 con
->response
->request
.status
.status_code
= IPP_OK
;
8090 send_ipp_status(con
, IPP_NOT_FOUND
,
8091 _("The PPD file \"%s\" could not be found."),
8092 uri
->values
[0].string
.text
);
8097 * 'get_ppds()' - Get the list of PPD files on the local system.
8101 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
8103 http_status_t status
; /* Policy status */
8104 ipp_attribute_t
*limit
, /* Limit attribute */
8105 *device
, /* ppd-device-id attribute */
8106 *language
, /* ppd-natural-language attribute */
8107 *make
, /* ppd-make attribute */
8108 *model
, /* ppd-make-and-model attribute */
8109 *model_number
, /* ppd-model-number attribute */
8110 *product
, /* ppd-product attribute */
8111 *psversion
, /* ppd-psverion attribute */
8112 *type
, /* ppd-type attribute */
8113 *requested
, /* requested-attributes attribute */
8114 *exclude
, /* exclude-schemes attribute */
8115 *include
; /* include-schemes attribute */
8116 char command
[1024], /* cups-driverd command */
8117 options
[4096], /* Options to pass to command */
8118 device_str
[256],/* Escaped ppd-device-id string */
8120 /* Escaped ppd-natural-language */
8121 make_str
[256], /* Escaped ppd-make string */
8122 model_str
[256], /* Escaped ppd-make-and-model string */
8123 model_number_str
[256],
8124 /* ppd-model-number string */
8126 /* Escaped ppd-product string */
8128 /* Escaped ppd-psversion string */
8129 type_str
[256], /* Escaped ppd-type string */
8131 /* String for requested attributes */
8133 /* String for excluded schemes */
8135 /* String for included schemes */
8138 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
8144 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8146 send_http_error(con
, status
, NULL
);
8151 * Run cups-driverd command with the given options...
8154 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
8155 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
8156 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
8158 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
8159 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
8161 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
8163 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
8164 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
8165 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
8166 requested
= ippFindAttribute(con
->request
, "requested-attributes",
8168 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
8170 include
= ippFindAttribute(con
->request
, "include-schemes",
8174 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
8176 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
8179 url_encode_attr(device
, device_str
, sizeof(device_str
));
8181 device_str
[0] = '\0';
8184 url_encode_attr(language
, language_str
, sizeof(language_str
));
8186 language_str
[0] = '\0';
8189 url_encode_attr(make
, make_str
, sizeof(make_str
));
8194 url_encode_attr(model
, model_str
, sizeof(model_str
));
8196 model_str
[0] = '\0';
8199 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
8200 model_number
->values
[0].integer
);
8202 model_number_str
[0] = '\0';
8205 url_encode_attr(product
, product_str
, sizeof(product_str
));
8207 product_str
[0] = '\0';
8210 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
8212 psversion_str
[0] = '\0';
8215 url_encode_attr(type
, type_str
, sizeof(type_str
));
8220 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
8222 exclude_str
[0] = '\0';
8225 url_encode_attr(include
, include_str
, sizeof(include_str
));
8227 include_str
[0] = '\0';
8229 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
8230 snprintf(options
, sizeof(options
),
8231 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
8232 con
->request
->request
.op
.request_id
,
8233 limit
? limit
->values
[0].integer
: 0,
8235 device
? "%20" : "", device_str
,
8236 language
? "%20" : "", language_str
,
8237 make
? "%20" : "", make_str
,
8238 model
? "%20" : "", model_str
,
8239 model_number
? "%20" : "", model_number_str
,
8240 product
? "%20" : "", product_str
,
8241 psversion
? "%20" : "", psversion_str
,
8242 type
? "%20" : "", type_str
,
8243 exclude_str
[0] ? "%20" : "", exclude_str
,
8244 include_str
[0] ? "%20" : "", include_str
);
8246 if (cupsdSendCommand(con
, command
, options
, 0))
8249 * Command started successfully, don't send an IPP response here...
8252 ippDelete(con
->response
);
8253 con
->response
= NULL
;
8258 * Command failed, return "internal error" so the user knows something
8262 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8263 _("cups-driverd failed to execute."));
8269 * 'get_printer_attrs()' - Get printer attributes.
8273 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
8274 ipp_attribute_t
*uri
) /* I - Printer URI */
8276 http_status_t status
; /* Policy status */
8277 cups_ptype_t dtype
; /* Destination type (printer/class) */
8278 cupsd_printer_t
*printer
; /* Printer/class */
8279 cups_array_t
*ra
; /* Requested attributes array */
8282 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
8283 con
->http
.fd
, uri
->values
[0].string
.text
);
8286 * Is the destination valid?
8289 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8295 send_ipp_status(con
, IPP_NOT_FOUND
,
8296 _("The printer or class does not exist."));
8304 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8306 send_http_error(con
, status
, printer
);
8311 * Send the attributes...
8314 ra
= create_requested_array(con
->request
);
8316 copy_printer_attrs(con
, printer
, ra
);
8318 cupsArrayDelete(ra
);
8320 con
->response
->request
.status
.status_code
= IPP_OK
;
8325 * 'get_printer_supported()' - Get printer supported values.
8329 get_printer_supported(
8330 cupsd_client_t
*con
, /* I - Client connection */
8331 ipp_attribute_t
*uri
) /* I - Printer URI */
8333 http_status_t status
; /* Policy status */
8334 cups_ptype_t dtype
; /* Destination type (printer/class) */
8335 cupsd_printer_t
*printer
; /* Printer/class */
8338 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
8339 con
->http
.fd
, uri
->values
[0].string
.text
);
8342 * Is the destination valid?
8345 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8351 send_ipp_status(con
, IPP_NOT_FOUND
,
8352 _("The printer or class does not exist."));
8360 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8362 send_http_error(con
, status
, printer
);
8367 * Return a list of attributes that can be set via Set-Printer-Attributes.
8370 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8372 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8373 "printer-location", 0);
8375 con
->response
->request
.status
.status_code
= IPP_OK
;
8380 * 'get_printers()' - Get a list of printers or classes.
8384 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8385 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8387 http_status_t status
; /* Policy status */
8388 ipp_attribute_t
*attr
; /* Current attribute */
8389 int limit
; /* Max number of printers to return */
8390 int count
; /* Number of printers that match */
8391 cupsd_printer_t
*printer
; /* Current printer pointer */
8392 int printer_type
, /* printer-type attribute */
8393 printer_mask
; /* printer-type-mask attribute */
8394 char *location
; /* Location string */
8395 const char *username
; /* Current user */
8396 char *first_printer_name
; /* first-printer-name attribute */
8397 cups_array_t
*ra
; /* Requested attributes array */
8398 int local
; /* Local connection? */
8401 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8402 con
->http
.fd
, type
);
8408 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8410 send_http_error(con
, status
, NULL
);
8415 * Check for printers...
8418 if (!Printers
|| !cupsArrayCount(Printers
))
8420 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8425 * See if they want to limit the number of printers reported...
8428 if ((attr
= ippFindAttribute(con
->request
, "limit",
8429 IPP_TAG_INTEGER
)) != NULL
)
8430 limit
= attr
->values
[0].integer
;
8434 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8435 IPP_TAG_NAME
)) != NULL
)
8436 first_printer_name
= attr
->values
[0].string
.text
;
8438 first_printer_name
= NULL
;
8441 * Support filtering...
8444 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8445 IPP_TAG_ENUM
)) != NULL
)
8446 printer_type
= attr
->values
[0].integer
;
8450 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8451 IPP_TAG_ENUM
)) != NULL
)
8452 printer_mask
= attr
->values
[0].integer
;
8456 local
= httpAddrLocalhost(&(con
->clientaddr
));
8458 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8459 IPP_TAG_TEXT
)) != NULL
)
8460 location
= attr
->values
[0].string
.text
;
8464 if (con
->username
[0])
8465 username
= con
->username
;
8466 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8467 IPP_TAG_NAME
)) != NULL
)
8468 username
= attr
->values
[0].string
.text
;
8472 ra
= create_requested_array(con
->request
);
8475 * OK, build a list of printers for this printer...
8478 if (first_printer_name
)
8480 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8481 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8484 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8487 count
< limit
&& printer
;
8488 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8490 if (!local
&& !printer
->shared
)
8493 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8494 (printer
->type
& printer_mask
) == printer_type
&&
8496 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
8499 * If HideImplicitMembers is enabled, see if this printer or class
8500 * is a member of an implicit class...
8503 if (ImplicitClasses
&& HideImplicitMembers
&&
8504 printer
->in_implicit_class
)
8508 * If a username is specified, see if it is allowed or denied
8512 if (cupsArrayCount(printer
->users
) && username
&&
8513 !user_allowed(printer
, username
))
8517 * Add the group separator as needed...
8521 ippAddSeparator(con
->response
);
8526 * Send the attributes...
8529 copy_printer_attrs(con
, printer
, ra
);
8533 cupsArrayDelete(ra
);
8535 con
->response
->request
.status
.status_code
= IPP_OK
;
8540 * 'get_subscription_attrs()' - Get subscription attributes.
8544 get_subscription_attrs(
8545 cupsd_client_t
*con
, /* I - Client connection */
8546 int sub_id
) /* I - Subscription ID */
8548 http_status_t status
; /* Policy status */
8549 cupsd_subscription_t
*sub
; /* Subscription */
8550 cupsd_policy_t
*policy
; /* Current security policy */
8551 cups_array_t
*ra
, /* Requested attributes array */
8552 *exclude
; /* Private attributes array */
8555 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8556 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8557 con
, con
->http
.fd
, sub_id
);
8560 * Is the subscription ID valid?
8563 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8566 * Bad subscription ID...
8569 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8579 policy
= sub
->dest
->op_policy_ptr
;
8581 policy
= DefaultPolicyPtr
;
8583 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
8585 send_http_error(con
, status
, sub
->dest
);
8589 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
8592 * Copy the subscription attributes to the response using the
8593 * requested-attributes attribute that may be provided by the client.
8596 ra
= create_requested_array(con
->request
);
8598 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8600 cupsArrayDelete(ra
);
8602 con
->response
->request
.status
.status_code
= IPP_OK
;
8607 * 'get_subscriptions()' - Get subscriptions.
8611 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8612 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8614 http_status_t status
; /* Policy status */
8615 int count
; /* Number of subscriptions */
8616 int limit
; /* Limit */
8617 cupsd_subscription_t
*sub
; /* Subscription */
8618 cups_array_t
*ra
; /* Requested attributes array */
8619 ipp_attribute_t
*attr
; /* Attribute */
8620 cups_ptype_t dtype
; /* Destination type (printer/class) */
8621 char scheme
[HTTP_MAX_URI
],
8622 /* Scheme portion of URI */
8623 username
[HTTP_MAX_URI
],
8624 /* Username portion of URI */
8626 /* Host portion of URI */
8627 resource
[HTTP_MAX_URI
];
8628 /* Resource portion of URI */
8629 int port
; /* Port portion of URI */
8630 cupsd_job_t
*job
; /* Job pointer */
8631 cupsd_printer_t
*printer
; /* Printer */
8632 cupsd_policy_t
*policy
; /* Policy */
8633 cups_array_t
*exclude
; /* Private attributes array */
8636 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8637 "get_subscriptions(con=%p[%d], uri=%s)",
8638 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8641 * Is the destination valid?
8644 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8645 sizeof(scheme
), username
, sizeof(username
), host
,
8646 sizeof(host
), &port
, resource
, sizeof(resource
));
8648 if (!strcmp(resource
, "/") ||
8649 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8650 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8651 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8656 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8659 job
= cupsdFindJob(atoi(resource
+ 6));
8663 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
8664 atoi(resource
+ 6));
8668 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8674 send_ipp_status(con
, IPP_NOT_FOUND
,
8675 _("The printer or class does not exist."));
8678 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8679 IPP_TAG_INTEGER
)) != NULL
)
8681 job
= cupsdFindJob(attr
->values
[0].integer
);
8685 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
8686 attr
->values
[0].integer
);
8698 policy
= printer
->op_policy_ptr
;
8700 policy
= DefaultPolicyPtr
;
8702 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
8704 send_http_error(con
, status
, printer
);
8709 * Copy the subscription attributes to the response using the
8710 * requested-attributes attribute that may be provided by the client.
8713 ra
= create_requested_array(con
->request
);
8715 if ((attr
= ippFindAttribute(con
->request
, "limit",
8716 IPP_TAG_INTEGER
)) != NULL
)
8717 limit
= attr
->values
[0].integer
;
8722 * See if we only want to see subscriptions for a specific user...
8725 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8726 IPP_TAG_BOOLEAN
)) != NULL
&&
8727 attr
->values
[0].boolean
)
8728 strlcpy(username
, get_username(con
), sizeof(username
));
8732 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8734 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8735 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8736 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
8738 ippAddSeparator(con
->response
);
8740 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
8741 policy
, con
, sub
->dest
,
8744 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8747 if (limit
&& count
>= limit
)
8751 cupsArrayDelete(ra
);
8754 con
->response
->request
.status
.status_code
= IPP_OK
;
8756 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8761 * 'get_username()' - Get the username associated with a request.
8764 static const char * /* O - Username */
8765 get_username(cupsd_client_t
*con
) /* I - Connection */
8767 ipp_attribute_t
*attr
; /* Attribute */
8770 if (con
->username
[0])
8771 return (con
->username
);
8772 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8773 IPP_TAG_NAME
)) != NULL
)
8774 return (attr
->values
[0].string
.text
);
8776 return ("anonymous");
8781 * 'hold_job()' - Hold a print job.
8785 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8786 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8788 ipp_attribute_t
*attr
; /* Current job-hold-until */
8789 const char *when
; /* New value */
8790 int jobid
; /* Job ID */
8791 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8792 username
[HTTP_MAX_URI
], /* Username portion of URI */
8793 host
[HTTP_MAX_URI
], /* Host portion of URI */
8794 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8795 int port
; /* Port portion of URI */
8796 cupsd_job_t
*job
; /* Job information */
8799 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8800 uri
->values
[0].string
.text
);
8803 * See if we have a job URI or a printer URI...
8806 if (!strcmp(uri
->name
, "printer-uri"))
8809 * Got a printer URI; see if we also have a job-id attribute...
8812 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8813 IPP_TAG_INTEGER
)) == NULL
)
8815 send_ipp_status(con
, IPP_BAD_REQUEST
,
8816 _("Got a printer-uri attribute but no job-id."));
8820 jobid
= attr
->values
[0].integer
;
8825 * Got a job URI; parse it to get the job ID...
8828 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8829 sizeof(scheme
), username
, sizeof(username
), host
,
8830 sizeof(host
), &port
, resource
, sizeof(resource
));
8832 if (strncmp(resource
, "/jobs/", 6))
8838 send_ipp_status(con
, IPP_BAD_REQUEST
,
8839 _("Bad job-uri \"%s\"."),
8840 uri
->values
[0].string
.text
);
8844 jobid
= atoi(resource
+ 6);
8848 * See if the job exists...
8851 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8854 * Nope - return a "not found" error...
8857 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8862 * See if the job is owned by the requesting user...
8865 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8867 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8868 cupsdFindDest(job
->dest
));
8873 * Hold the job and return...
8876 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8877 IPP_TAG_KEYWORD
)) == NULL
)
8878 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8882 when
= attr
->values
[0].string
.text
;
8884 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8885 "Job job-hold-until value changed by user.");
8888 when
= "indefinite";
8890 cupsdSetJobHoldUntil(job
, when
, 1);
8891 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8894 con
->response
->request
.status
.status_code
= IPP_OK
;
8899 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8903 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8904 ipp_attribute_t
*uri
) /* I - Printer URI */
8906 http_status_t status
; /* Policy status */
8907 cups_ptype_t dtype
; /* Destination type (printer/class) */
8908 cupsd_printer_t
*printer
; /* Printer data */
8911 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8912 con
->http
.fd
, uri
->values
[0].string
.text
);
8915 * Is the destination valid?
8918 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8924 send_ipp_status(con
, IPP_NOT_FOUND
,
8925 _("The printer or class does not exist."));
8933 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8935 send_http_error(con
, status
, printer
);
8940 * Hold pending/new jobs sent to the printer...
8943 printer
->holding_new_jobs
= 1;
8945 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8947 if (dtype
& CUPS_PRINTER_CLASS
)
8948 cupsdLogMessage(CUPSD_LOG_INFO
,
8949 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8950 printer
->name
, get_username(con
));
8952 cupsdLogMessage(CUPSD_LOG_INFO
,
8953 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8954 printer
->name
, get_username(con
));
8957 * Everything was ok, so return OK status...
8960 con
->response
->request
.status
.status_code
= IPP_OK
;
8965 * 'move_job()' - Move a job to a new destination.
8969 move_job(cupsd_client_t
*con
, /* I - Client connection */
8970 ipp_attribute_t
*uri
) /* I - Job URI */
8972 http_status_t status
; /* Policy status */
8973 ipp_attribute_t
*attr
; /* Current attribute */
8974 int jobid
; /* Job ID */
8975 cupsd_job_t
*job
; /* Current job */
8976 const char *src
; /* Source printer/class */
8977 cups_ptype_t stype
, /* Source type (printer or class) */
8978 dtype
; /* Destination type (printer/class) */
8979 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8980 username
[HTTP_MAX_URI
], /* Username portion of URI */
8981 host
[HTTP_MAX_URI
], /* Host portion of URI */
8982 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8983 int port
; /* Port portion of URI */
8984 cupsd_printer_t
*sprinter
, /* Source printer */
8985 *dprinter
; /* Destination printer */
8988 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8989 uri
->values
[0].string
.text
);
8992 * Get the new printer or class...
8995 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8996 IPP_TAG_URI
)) == NULL
)
8999 * Need job-printer-uri...
9002 send_ipp_status(con
, IPP_BAD_REQUEST
,
9003 _("job-printer-uri attribute missing."));
9007 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
9013 send_ipp_status(con
, IPP_NOT_FOUND
,
9014 _("The printer or class does not exist."));
9019 * See if we have a job URI or a printer URI...
9022 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9023 sizeof(scheme
), username
, sizeof(username
), host
,
9024 sizeof(host
), &port
, resource
, sizeof(resource
));
9026 if (!strcmp(uri
->name
, "printer-uri"))
9029 * Got a printer URI; see if we also have a job-id attribute...
9032 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9033 IPP_TAG_INTEGER
)) == NULL
)
9039 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
9040 &sprinter
)) == NULL
)
9046 send_ipp_status(con
, IPP_NOT_FOUND
,
9047 _("The printer or class does not exist."));
9056 * Otherwise, just move a single job...
9059 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
9062 * Nope - return a "not found" error...
9065 send_ipp_status(con
, IPP_NOT_FOUND
,
9066 _("Job #%d does not exist."), attr
->values
[0].integer
);
9072 * Job found, initialize source pointers...
9083 * Got a job URI; parse it to get the job ID...
9086 if (strncmp(resource
, "/jobs/", 6))
9092 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9093 uri
->values
[0].string
.text
);
9098 * See if the job exists...
9101 jobid
= atoi(resource
+ 6);
9103 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9106 * Nope - return a "not found" error...
9109 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9115 * Job found, initialize source pointers...
9124 * Check the policy of the destination printer...
9127 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
9128 job
? job
->username
: NULL
)) != HTTP_OK
)
9130 send_http_error(con
, status
, dprinter
);
9135 * Now move the job or jobs...
9141 * See if the job has been completed...
9144 if (job
->state_value
> IPP_JOB_STOPPED
)
9147 * Return a "not-possible" error...
9150 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9151 _("Job #%d is finished and cannot be altered."),
9157 * See if the job is owned by the requesting user...
9160 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9162 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9163 cupsdFindDest(job
->dest
));
9168 * Move the job to a different printer or class...
9171 cupsdMoveJob(job
, dprinter
);
9176 * Got the source printer, now look through the jobs...
9179 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
9181 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
9184 * See if the job is pointing at the source printer or has not been
9188 if (strcasecmp(job
->dest
, src
) ||
9189 job
->state_value
> IPP_JOB_STOPPED
)
9193 * See if the job can be moved by the requesting user...
9196 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9200 * Move the job to a different printer or class...
9203 cupsdMoveJob(job
, dprinter
);
9208 * Start jobs if possible...
9214 * Return with "everything is OK" status...
9217 con
->response
->request
.status
.status_code
= IPP_OK
;
9222 * 'ppd_parse_line()' - Parse a PPD default line.
9225 static int /* O - 0 on success, -1 on failure */
9226 ppd_parse_line(const char *line
, /* I - Line */
9227 char *option
, /* O - Option name */
9228 int olen
, /* I - Size of option name */
9229 char *choice
, /* O - Choice name */
9230 int clen
) /* I - Size of choice name */
9233 * Verify this is a default option line...
9236 if (strncmp(line
, "*Default", 8))
9240 * Read the option name...
9243 for (line
+= 8, olen
--;
9244 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9255 * Skip everything else up to the colon (:)...
9258 while (*line
&& *line
!= ':')
9267 * Now grab the option choice, skipping leading whitespace...
9270 while (isspace(*line
& 255))
9274 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9285 * Return with no errors...
9293 * 'print_job()' - Print a file to a printer or class.
9297 print_job(cupsd_client_t
*con
, /* I - Client connection */
9298 ipp_attribute_t
*uri
) /* I - Printer URI */
9300 ipp_attribute_t
*attr
; /* Current attribute */
9301 ipp_attribute_t
*format
; /* Document-format attribute */
9302 const char *default_format
; /* document-format-default value */
9303 cupsd_job_t
*job
; /* New job */
9304 char filename
[1024]; /* Job filename */
9305 mime_type_t
*filetype
; /* Type of file */
9306 char super
[MIME_MAX_SUPER
], /* Supertype of file */
9307 type
[MIME_MAX_TYPE
], /* Subtype of file */
9308 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9309 /* Textual name of mime type */
9310 cupsd_printer_t
*printer
; /* Printer data */
9311 struct stat fileinfo
; /* File information */
9312 int kbytes
; /* Size of file */
9313 int compression
; /* Document compression */
9316 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
9317 uri
->values
[0].string
.text
);
9320 * Validate print file attributes, for now just document-format and
9321 * compression (CUPS only supports "none" and "gzip")...
9324 compression
= CUPS_FILE_NONE
;
9326 if ((attr
= ippFindAttribute(con
->request
, "compression",
9327 IPP_TAG_KEYWORD
)) != NULL
)
9329 if (strcmp(attr
->values
[0].string
.text
, "none")
9331 && strcmp(attr
->values
[0].string
.text
, "gzip")
9332 #endif /* HAVE_LIBZ */
9335 send_ipp_status(con
, IPP_ATTRIBUTES
,
9336 _("Unsupported compression \"%s\"."),
9337 attr
->values
[0].string
.text
);
9338 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9339 "compression", NULL
, attr
->values
[0].string
.text
);
9344 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9345 compression
= CUPS_FILE_GZIP
;
9346 #endif /* HAVE_LIBZ */
9350 * Do we have a file to print?
9355 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9360 * Is the destination valid?
9363 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
9369 send_ipp_status(con
, IPP_NOT_FOUND
,
9370 _("The printer or class does not exist."));
9375 * Is it a format we support?
9378 if ((format
= ippFindAttribute(con
->request
, "document-format",
9379 IPP_TAG_MIMETYPE
)) != NULL
)
9382 * Grab format from client...
9385 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9388 send_ipp_status(con
, IPP_BAD_REQUEST
,
9389 _("Bad document-format \"%s\"."),
9390 format
->values
[0].string
.text
);
9394 else if ((default_format
= cupsGetOption("document-format",
9395 printer
->num_options
,
9396 printer
->options
)) != NULL
)
9399 * Use default document format...
9402 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9404 send_ipp_status(con
, IPP_BAD_REQUEST
,
9405 _("Bad document-format \"%s\"."),
9416 strcpy(super
, "application");
9417 strcpy(type
, "octet-stream");
9420 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9423 * Auto-type the file...
9426 ipp_attribute_t
*doc_name
; /* document-name attribute */
9429 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9431 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9432 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9433 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9437 filetype
= mimeType(MimeDatabase
, super
, type
);
9439 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9440 filetype
->super
, filetype
->type
);
9443 filetype
= mimeType(MimeDatabase
, super
, type
);
9447 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9450 * Replace the document-format attribute value with the auto-typed or
9454 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9459 _cupsStrFree(format
->values
[0].string
.text
);
9461 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9464 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9465 "document-format", NULL
, mimetype
);
9469 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9470 _("Unsupported document-format \"%s\"."),
9471 format
? format
->values
[0].string
.text
:
9472 "application/octet-stream");
9473 cupsdLogMessage(CUPSD_LOG_INFO
,
9474 "Hint: Do you have the raw file printing rules enabled?");
9477 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9478 "document-format", NULL
, format
->values
[0].string
.text
);
9484 * Read any embedded job ticket info from PS files...
9487 if (!strcasecmp(filetype
->super
, "application") &&
9488 (!strcasecmp(filetype
->type
, "postscript") ||
9489 !strcasecmp(filetype
->type
, "pdf")))
9490 read_job_ticket(con
);
9493 * Create the job object...
9496 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9500 * Update quota data...
9503 if (stat(con
->filename
, &fileinfo
))
9506 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9508 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9510 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9511 IPP_TAG_INTEGER
)) != NULL
)
9512 attr
->values
[0].integer
+= kbytes
;
9515 * Add the job file...
9518 if (add_file(con
, job
, filetype
, compression
))
9521 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9523 rename(con
->filename
, filename
);
9524 cupsdClearString(&con
->filename
);
9527 * See if we need to add the ending sheet...
9530 if (cupsdTimeoutJob(job
))
9534 * Log and save the job...
9537 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9538 "File of type %s/%s queued by \"%s\".",
9539 filetype
->super
, filetype
->type
, job
->username
);
9540 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9541 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9542 job
->dest
, job
->username
);
9545 * Start the job if possible...
9553 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9555 * This function only gets called when printing a single PDF or PostScript
9556 * file using the Print-Job operation. It doesn't work for Create-Job +
9557 * Send-File, since the job attributes need to be set at job creation
9558 * time for banners to work. The embedded job ticket stuff is here
9559 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9560 * options and IPP attributes which otherwise would be lost.
9562 * The format of a job ticket is simple:
9564 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9566 * %cupsJobTicket: attr1=value1
9567 * %cupsJobTicket: attr2=value2
9569 * %cupsJobTicket: attrN=valueN
9571 * Job ticket lines must appear immediately after the first line that
9572 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9573 * stops looking for job ticket info when it finds a line that does not begin
9574 * with "%cupsJobTicket:".
9576 * The maximum length of a job ticket line, including the prefix, is
9577 * 255 characters to conform with the Adobe DSC.
9579 * Read-only attributes are rejected with a notice to the error log in
9580 * case a malicious user tries anything. Since the job ticket is read
9581 * prior to attribute validation in print_job(), job ticket attributes
9582 * will go through the same validation as IPP attributes...
9586 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9588 cups_file_t
*fp
; /* File to read from */
9589 char line
[256]; /* Line data */
9590 int num_options
; /* Number of options */
9591 cups_option_t
*options
; /* Options */
9592 ipp_t
*ticket
; /* New attributes */
9593 ipp_attribute_t
*attr
, /* Current attribute */
9594 *attr2
, /* Job attribute */
9595 *prev2
; /* Previous job attribute */
9599 * First open the print file...
9602 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9604 cupsdLogMessage(CUPSD_LOG_ERROR
,
9605 "Unable to open print file for job ticket - %s",
9611 * Skip the first line...
9614 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9616 cupsdLogMessage(CUPSD_LOG_ERROR
,
9617 "Unable to read from print file for job ticket - %s",
9623 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9626 * Not a DSC-compliant file, so no job ticket info will be available...
9634 * Read job ticket info from the file...
9640 while (cupsFileGets(fp
, line
, sizeof(line
)))
9643 * Stop at the first non-ticket line...
9646 if (strncmp(line
, "%cupsJobTicket:", 15))
9650 * Add the options to the option array...
9653 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9657 * Done with the file; see if we have any options...
9662 if (num_options
== 0)
9666 * OK, convert the options to an attribute list, and apply them to
9671 cupsEncodeOptions(ticket
, num_options
, options
);
9674 * See what the user wants to change.
9677 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9679 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9682 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9683 !strcmp(attr
->name
, "job-originating-user-name") ||
9684 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9685 !strcmp(attr
->name
, "job-k-octets") ||
9686 !strcmp(attr
->name
, "job-id") ||
9687 !strncmp(attr
->name
, "job-state", 9) ||
9688 !strncmp(attr
->name
, "time-at-", 8))
9689 continue; /* Read-only attrs */
9691 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9692 IPP_TAG_ZERO
)) != NULL
)
9695 * Some other value; first free the old value...
9698 if (con
->request
->attrs
== attr2
)
9700 con
->request
->attrs
= attr2
->next
;
9705 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9706 if (prev2
->next
== attr2
)
9708 prev2
->next
= attr2
->next
;
9713 if (con
->request
->last
== attr2
)
9714 con
->request
->last
= prev2
;
9716 _ippFreeAttr(attr2
);
9720 * Add new option by copying it...
9723 copy_attribute(con
->request
, attr
, 0);
9727 * Then free the attribute list and option array...
9731 cupsFreeOptions(num_options
, options
);
9736 * 'reject_jobs()' - Reject print jobs to a printer.
9740 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9741 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9743 http_status_t status
; /* Policy status */
9744 cups_ptype_t dtype
; /* Destination type (printer/class) */
9745 cupsd_printer_t
*printer
; /* Printer data */
9746 ipp_attribute_t
*attr
; /* printer-state-message text */
9749 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9750 con
->http
.fd
, uri
->values
[0].string
.text
);
9753 * Is the destination valid?
9756 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9762 send_ipp_status(con
, IPP_NOT_FOUND
,
9763 _("The printer or class does not exist."));
9771 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9773 send_http_error(con
, status
, printer
);
9778 * Reject jobs sent to the printer...
9781 printer
->accepting
= 0;
9783 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9784 IPP_TAG_TEXT
)) == NULL
)
9785 strcpy(printer
->state_message
, "Rejecting Jobs");
9787 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9788 sizeof(printer
->state_message
));
9790 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9791 "No longer accepting jobs.");
9793 if (dtype
& CUPS_PRINTER_CLASS
)
9795 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9797 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9798 printer
->name
, get_username(con
));
9802 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9804 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9805 printer
->name
, get_username(con
));
9809 * Everything was ok, so return OK status...
9812 con
->response
->request
.status
.status_code
= IPP_OK
;
9817 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9821 release_held_new_jobs(
9822 cupsd_client_t
*con
, /* I - Connection */
9823 ipp_attribute_t
*uri
) /* I - Printer URI */
9825 http_status_t status
; /* Policy status */
9826 cups_ptype_t dtype
; /* Destination type (printer/class) */
9827 cupsd_printer_t
*printer
; /* Printer data */
9830 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9831 con
->http
.fd
, uri
->values
[0].string
.text
);
9834 * Is the destination valid?
9837 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9843 send_ipp_status(con
, IPP_NOT_FOUND
,
9844 _("The printer or class does not exist."));
9852 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9854 send_http_error(con
, status
, printer
);
9859 * Hold pending/new jobs sent to the printer...
9862 printer
->holding_new_jobs
= 0;
9864 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9866 if (dtype
& CUPS_PRINTER_CLASS
)
9867 cupsdLogMessage(CUPSD_LOG_INFO
,
9868 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9869 printer
->name
, get_username(con
));
9871 cupsdLogMessage(CUPSD_LOG_INFO
,
9872 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9873 printer
->name
, get_username(con
));
9876 * Everything was ok, so return OK status...
9879 con
->response
->request
.status
.status_code
= IPP_OK
;
9884 * 'release_job()' - Release a held print job.
9888 release_job(cupsd_client_t
*con
, /* I - Client connection */
9889 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9891 ipp_attribute_t
*attr
; /* Current attribute */
9892 int jobid
; /* Job ID */
9893 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9894 username
[HTTP_MAX_URI
], /* Username portion of URI */
9895 host
[HTTP_MAX_URI
], /* Host portion of URI */
9896 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9897 int port
; /* Port portion of URI */
9898 cupsd_job_t
*job
; /* Job information */
9901 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9902 con
->http
.fd
, uri
->values
[0].string
.text
);
9905 * See if we have a job URI or a printer URI...
9908 if (!strcmp(uri
->name
, "printer-uri"))
9911 * Got a printer URI; see if we also have a job-id attribute...
9914 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9915 IPP_TAG_INTEGER
)) == NULL
)
9917 send_ipp_status(con
, IPP_BAD_REQUEST
,
9918 _("Got a printer-uri attribute but no job-id."));
9922 jobid
= attr
->values
[0].integer
;
9927 * Got a job URI; parse it to get the job ID...
9930 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9931 sizeof(scheme
), username
, sizeof(username
), host
,
9932 sizeof(host
), &port
, resource
, sizeof(resource
));
9934 if (strncmp(resource
, "/jobs/", 6))
9940 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9941 uri
->values
[0].string
.text
);
9945 jobid
= atoi(resource
+ 6);
9949 * See if the job exists...
9952 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9955 * Nope - return a "not found" error...
9958 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9963 * See if job is "held"...
9966 if (job
->state_value
!= IPP_JOB_HELD
)
9969 * Nope - return a "not possible" error...
9972 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
9977 * See if the job is owned by the requesting user...
9980 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9982 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9983 cupsdFindDest(job
->dest
));
9988 * Reset the job-hold-until value to "no-hold"...
9991 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9992 IPP_TAG_KEYWORD
)) == NULL
)
9993 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9997 _cupsStrFree(attr
->values
[0].string
.text
);
9999 attr
->value_tag
= IPP_TAG_KEYWORD
;
10000 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
10002 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10003 "Job job-hold-until value changed by user.");
10007 * Release the job and return...
10010 cupsdReleaseJob(job
);
10012 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10013 "Job released by user.");
10015 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
10017 con
->response
->request
.status
.status_code
= IPP_OK
;
10024 * 'renew_subscription()' - Renew an existing subscription...
10028 renew_subscription(
10029 cupsd_client_t
*con
, /* I - Client connection */
10030 int sub_id
) /* I - Subscription ID */
10032 http_status_t status
; /* Policy status */
10033 cupsd_subscription_t
*sub
; /* Subscription */
10034 ipp_attribute_t
*lease
; /* notify-lease-duration */
10037 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
10038 "renew_subscription(con=%p[%d], sub_id=%d)",
10039 con
, con
->http
.fd
, sub_id
);
10042 * Is the subscription ID valid?
10045 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
10048 * Bad subscription ID...
10051 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
10059 * Job subscriptions cannot be renewed...
10062 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10063 _("Job subscriptions cannot be renewed."));
10071 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
10073 con
, sub
->owner
)) != HTTP_OK
)
10075 send_http_error(con
, status
, sub
->dest
);
10080 * Renew the subscription...
10083 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
10086 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
10088 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
10090 cupsdLogMessage(CUPSD_LOG_INFO
,
10091 "renew_subscription: Limiting notify-lease-duration to "
10094 sub
->lease
= MaxLeaseDuration
;
10097 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
10099 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
10101 con
->response
->request
.status
.status_code
= IPP_OK
;
10103 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
10104 "notify-lease-duration", sub
->lease
);
10109 * 'restart_job()' - Restart an old print job.
10113 restart_job(cupsd_client_t
*con
, /* I - Client connection */
10114 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
10116 ipp_attribute_t
*attr
; /* Current attribute */
10117 int jobid
; /* Job ID */
10118 cupsd_job_t
*job
; /* Job information */
10119 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
10120 username
[HTTP_MAX_URI
], /* Username portion of URI */
10121 host
[HTTP_MAX_URI
], /* Host portion of URI */
10122 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10123 int port
; /* Port portion of URI */
10126 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
10127 con
->http
.fd
, uri
->values
[0].string
.text
);
10130 * See if we have a job URI or a printer URI...
10133 if (!strcmp(uri
->name
, "printer-uri"))
10136 * Got a printer URI; see if we also have a job-id attribute...
10139 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10140 IPP_TAG_INTEGER
)) == NULL
)
10142 send_ipp_status(con
, IPP_BAD_REQUEST
,
10143 _("Got a printer-uri attribute but no job-id."));
10147 jobid
= attr
->values
[0].integer
;
10152 * Got a job URI; parse it to get the job ID...
10155 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10156 sizeof(scheme
), username
, sizeof(username
), host
,
10157 sizeof(host
), &port
, resource
, sizeof(resource
));
10159 if (strncmp(resource
, "/jobs/", 6))
10165 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10166 uri
->values
[0].string
.text
);
10170 jobid
= atoi(resource
+ 6);
10174 * See if the job exists...
10177 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10180 * Nope - return a "not found" error...
10183 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10188 * See if job is in any of the "completed" states...
10191 if (job
->state_value
<= IPP_JOB_PROCESSING
)
10194 * Nope - return a "not possible" error...
10197 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
10203 * See if we have retained the job files...
10208 if (!job
->attrs
|| job
->num_files
== 0)
10211 * Nope - return a "not possible" error...
10214 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10215 _("Job #%d cannot be restarted - no files."), jobid
);
10220 * See if the job is owned by the requesting user...
10223 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10225 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10226 cupsdFindDest(job
->dest
));
10231 * See if the job-hold-until attribute is specified...
10234 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
10235 IPP_TAG_KEYWORD
)) == NULL
)
10236 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
10238 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
10241 * Return the job to a held state...
10244 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
10245 "Restarted by \"%s\" with job-hold-until=%s.",
10246 username
, attr
->values
[0].string
.text
);
10247 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10249 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
10250 NULL
, job
, "Job restarted by user with job-hold-until=%s",
10251 attr
->values
[0].string
.text
);
10256 * Restart the job...
10259 cupsdRestartJob(job
);
10263 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
10265 con
->response
->request
.status
.status_code
= IPP_OK
;
10270 * 'save_auth_info()' - Save authentication information for a job.
10275 cupsd_client_t
*con
, /* I - Client connection */
10276 cupsd_job_t
*job
, /* I - Job */
10277 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
10279 int i
; /* Looping var */
10280 char filename
[1024]; /* Job authentication filename */
10281 cups_file_t
*fp
; /* Job authentication file */
10282 char line
[2048]; /* Line for file */
10283 cupsd_printer_t
*dest
; /* Destination printer/class */
10287 * This function saves the in-memory authentication information for
10288 * a job so that it can be used to authenticate with a remote host.
10289 * The information is stored in a file that is readable only by the
10290 * root user. The fields are Base-64 encoded, each on a separate line,
10291 * followed by random number (up to 1024) of newlines to limit the
10292 * amount of information that is exposed.
10294 * Because of the potential for exposing of authentication information,
10295 * this functionality is only enabled when running cupsd as root.
10297 * This caching only works for the Basic and BasicDigest authentication
10298 * types. Digest authentication cannot be cached this way, and in
10299 * the future Kerberos authentication may make all of this obsolete.
10301 * Authentication information is saved whenever an authenticated
10302 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
10305 * This information is deleted after a job is completed or canceled,
10306 * so reprints may require subsequent re-authentication.
10312 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
10316 * Create the authentication file and change permissions...
10319 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
10320 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
10322 cupsdLogMessage(CUPSD_LOG_ERROR
,
10323 "Unable to save authentication info to \"%s\" - %s",
10324 filename
, strerror(errno
));
10328 fchown(cupsFileNumber(fp
), 0, 0);
10329 fchmod(cupsFileNumber(fp
), 0400);
10331 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
10334 * Write 1 to 3 auth values...
10337 cupsdClearString(&job
->auth_username
);
10338 cupsdClearString(&job
->auth_domain
);
10339 cupsdClearString(&job
->auth_password
);
10341 for (i
= 0; i
< auth_info
->num_values
; i
++)
10343 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
10344 strlen(auth_info
->values
[i
].string
.text
));
10345 cupsFilePrintf(fp
, "%s\n", line
);
10347 if (!strcmp(dest
->auth_info_required
[i
], "username"))
10348 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
10349 auth_info
->values
[i
].string
.text
);
10350 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
10351 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
10352 auth_info
->values
[i
].string
.text
);
10353 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
10354 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
10355 auth_info
->values
[i
].string
.text
);
10358 else if (con
->username
[0])
10361 * Write the authenticated username...
10364 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
10365 cupsFilePrintf(fp
, "%s\n", line
);
10367 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
10368 cupsdClearString(&job
->auth_domain
);
10371 * Write the authenticated password...
10374 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10375 cupsFilePrintf(fp
, "%s\n", line
);
10377 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
10381 * Write a random number of newlines to the end of the file...
10384 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10385 cupsFilePutChar(fp
, '\n');
10388 * Close the file and return...
10393 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10394 # ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
10395 if (con
->have_gss
&&
10396 (con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
|| con
->gss_creds
))
10398 if (con
->have_gss
&& con
->gss_creds
)
10399 # endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
10400 save_krb5_creds(con
, job
);
10401 else if (job
->ccname
)
10402 cupsdClearString(&(job
->ccname
));
10403 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10407 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10409 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
10413 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
10414 cupsd_job_t
*job
) /* I - Job */
10417 * Get the credentials...
10420 job
->ccache
= cupsdCopyKrb5Creds(con
);
10423 * Add the KRB5CCNAME environment variable to the job so that the
10424 * backend can use the credentials when printing.
10429 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
10430 krb5_cc_get_name(KerberosContext
, job
->ccache
));
10432 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
10435 cupsdClearString(&(job
->ccname
));
10437 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10441 * 'send_document()' - Send a file to a printer or class.
10445 send_document(cupsd_client_t
*con
, /* I - Client connection */
10446 ipp_attribute_t
*uri
) /* I - Printer URI */
10448 ipp_attribute_t
*attr
; /* Current attribute */
10449 ipp_attribute_t
*format
; /* Request's document-format attribute */
10450 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10451 const char *default_format
;/* document-format-default value */
10452 int jobid
; /* Job ID number */
10453 cupsd_job_t
*job
; /* Current job */
10454 char job_uri
[HTTP_MAX_URI
],
10456 scheme
[HTTP_MAX_URI
],
10457 /* Method portion of URI */
10458 username
[HTTP_MAX_URI
],
10459 /* Username portion of URI */
10460 host
[HTTP_MAX_URI
],
10461 /* Host portion of URI */
10462 resource
[HTTP_MAX_URI
];
10463 /* Resource portion of URI */
10464 int port
; /* Port portion of URI */
10465 mime_type_t
*filetype
; /* Type of file */
10466 char super
[MIME_MAX_SUPER
],
10467 /* Supertype of file */
10468 type
[MIME_MAX_TYPE
],
10469 /* Subtype of file */
10470 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10471 /* Textual name of mime type */
10472 char filename
[1024]; /* Job filename */
10473 cupsd_printer_t
*printer
; /* Current printer */
10474 struct stat fileinfo
; /* File information */
10475 int kbytes
; /* Size of file */
10476 int compression
; /* Type of compression */
10477 int start_job
; /* Start the job? */
10480 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10481 con
->http
.fd
, uri
->values
[0].string
.text
);
10484 * See if we have a job URI or a printer URI...
10487 if (!strcmp(uri
->name
, "printer-uri"))
10490 * Got a printer URI; see if we also have a job-id attribute...
10493 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10494 IPP_TAG_INTEGER
)) == NULL
)
10496 send_ipp_status(con
, IPP_BAD_REQUEST
,
10497 _("Got a printer-uri attribute but no job-id."));
10501 jobid
= attr
->values
[0].integer
;
10506 * Got a job URI; parse it to get the job ID...
10509 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10510 sizeof(scheme
), username
, sizeof(username
), host
,
10511 sizeof(host
), &port
, resource
, sizeof(resource
));
10513 if (strncmp(resource
, "/jobs/", 6))
10519 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10520 uri
->values
[0].string
.text
);
10524 jobid
= atoi(resource
+ 6);
10528 * See if the job exists...
10531 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10534 * Nope - return a "not found" error...
10537 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10541 printer
= cupsdFindDest(job
->dest
);
10544 * See if the job is owned by the requesting user...
10547 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10549 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10550 cupsdFindDest(job
->dest
));
10555 * OK, see if the client is sending the document compressed - CUPS
10556 * only supports "none" and "gzip".
10559 compression
= CUPS_FILE_NONE
;
10561 if ((attr
= ippFindAttribute(con
->request
, "compression",
10562 IPP_TAG_KEYWORD
)) != NULL
)
10564 if (strcmp(attr
->values
[0].string
.text
, "none")
10566 && strcmp(attr
->values
[0].string
.text
, "gzip")
10567 #endif /* HAVE_LIBZ */
10570 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
10571 attr
->values
[0].string
.text
);
10572 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10573 "compression", NULL
, attr
->values
[0].string
.text
);
10578 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10579 compression
= CUPS_FILE_GZIP
;
10580 #endif /* HAVE_LIBZ */
10584 * Do we have a file to print?
10587 if (!con
->filename
)
10590 * Check for an empty request with "last-document" set to true, which is
10591 * used to close an "open" job by RFC 2911, section 3.3.2.
10594 if (job
->num_files
> 0 &&
10595 (attr
= ippFindAttribute(con
->request
, "last-document",
10596 IPP_TAG_BOOLEAN
)) != NULL
&&
10597 attr
->values
[0].boolean
)
10598 goto last_document
;
10600 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
10605 * Is it a format we support?
10608 if ((format
= ippFindAttribute(con
->request
, "document-format",
10609 IPP_TAG_MIMETYPE
)) != NULL
)
10612 * Grab format from client...
10615 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10618 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
10619 format
->values
[0].string
.text
);
10623 else if ((default_format
= cupsGetOption("document-format",
10624 printer
->num_options
,
10625 printer
->options
)) != NULL
)
10628 * Use default document format...
10631 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10633 send_ipp_status(con
, IPP_BAD_REQUEST
,
10634 _("Bad document-format-default \"%s\"."), default_format
);
10641 * No document format attribute? Auto-type it!
10644 strcpy(super
, "application");
10645 strcpy(type
, "octet-stream");
10648 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10651 * Auto-type the file...
10654 ipp_attribute_t
*doc_name
; /* document-name attribute */
10657 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10659 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10660 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10661 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10665 filetype
= mimeType(MimeDatabase
, super
, type
);
10668 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10669 filetype
->super
, filetype
->type
);
10672 filetype
= mimeType(MimeDatabase
, super
, type
);
10677 * Replace the document-format attribute value with the auto-typed or
10681 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10684 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10685 IPP_TAG_MIMETYPE
)) != NULL
)
10687 _cupsStrFree(jformat
->values
[0].string
.text
);
10689 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10692 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10693 "document-format", NULL
, mimetype
);
10695 else if (!filetype
)
10697 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10698 _("Unsupported document-format \"%s/%s\"."), super
, type
);
10699 cupsdLogMessage(CUPSD_LOG_INFO
,
10700 "Hint: Do you have the raw file printing rules enabled?");
10703 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10704 "document-format", NULL
, format
->values
[0].string
.text
);
10709 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10711 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10714 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10715 _("Unsupported document-format \"%s\"."), mimetype
);
10717 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10718 "document-format", NULL
, mimetype
);
10724 * Add the file to the job...
10729 if (add_file(con
, job
, filetype
, compression
))
10732 if (stat(con
->filename
, &fileinfo
))
10735 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10737 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10739 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10740 IPP_TAG_INTEGER
)) != NULL
)
10741 attr
->values
[0].integer
+= kbytes
;
10743 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10745 rename(con
->filename
, filename
);
10747 cupsdClearString(&con
->filename
);
10749 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10750 filetype
->super
, filetype
->type
, job
->username
);
10753 * Start the job if this is the last document...
10758 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10759 IPP_TAG_BOOLEAN
)) != NULL
&&
10760 attr
->values
[0].boolean
)
10763 * See if we need to add the ending sheet...
10766 if (cupsdTimeoutJob(job
))
10769 if (job
->state_value
== IPP_JOB_STOPPED
)
10771 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10772 job
->state_value
= IPP_JOB_PENDING
;
10774 else if (job
->state_value
== IPP_JOB_HELD
)
10776 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10777 IPP_TAG_KEYWORD
)) == NULL
)
10778 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10780 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10782 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10783 job
->state_value
= IPP_JOB_PENDING
;
10788 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10794 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10795 IPP_TAG_KEYWORD
)) == NULL
)
10796 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10798 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10800 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10801 job
->state_value
= IPP_JOB_HELD
;
10802 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10805 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10812 * Fill in the response info...
10815 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10818 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10821 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10823 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10825 add_job_state_reasons(con
, job
);
10827 con
->response
->request
.status
.status_code
= IPP_OK
;
10830 * Start the job if necessary...
10839 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10844 cupsd_client_t
*con
, /* I - Client connection */
10845 http_status_t status
, /* I - HTTP status code */
10846 cupsd_printer_t
*printer
) /* I - Printer, if any */
10848 ipp_attribute_t
*uri
; /* Request URI, if any */
10851 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10852 IPP_TAG_URI
)) == NULL
)
10853 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10855 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10856 "Returning HTTP %s for %s (%s) from %s",
10857 httpStatus(status
),
10858 ippOpString(con
->request
->request
.op
.operation_id
),
10859 uri
? uri
->values
[0].string
.text
: "no URI",
10860 con
->http
.hostname
);
10864 int auth_type
; /* Type of authentication required */
10867 auth_type
= CUPSD_AUTH_NONE
;
10869 if (status
== HTTP_UNAUTHORIZED
&&
10870 printer
->num_auth_info_required
> 0 &&
10871 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10873 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10874 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10875 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10878 * Creating and authenticating jobs requires Kerberos...
10881 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10886 * Use policy/location-defined authentication requirements...
10889 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10890 cupsd_location_t
*auth
; /* Pointer to authentication element */
10893 if (printer
->type
& CUPS_PRINTER_CLASS
)
10894 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10896 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10898 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10899 auth
->type
== CUPSD_AUTH_NONE
)
10900 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10902 con
->request
->request
.op
.operation_id
:
10907 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10908 auth_type
= DefaultAuthType
;
10910 auth_type
= auth
->type
;
10914 cupsdSendError(con
, status
, auth_type
);
10917 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10919 ippDelete(con
->response
);
10920 con
->response
= NULL
;
10927 * 'send_ipp_status()' - Send a status back to the IPP client.
10931 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10932 ipp_status_t status
, /* I - IPP status code */
10933 const char *message
,/* I - Status message */
10934 ...) /* I - Additional args as needed */
10936 va_list ap
; /* Pointer to additional args */
10937 char formatted
[1024]; /* Formatted errror message */
10940 va_start(ap
, message
);
10941 vsnprintf(formatted
, sizeof(formatted
),
10942 _cupsLangString(con
->language
, message
), ap
);
10945 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10946 ippOpString(con
->request
->request
.op
.operation_id
),
10947 ippErrorString(status
), formatted
);
10949 con
->response
->request
.status
.status_code
= status
;
10951 if (ippFindAttribute(con
->response
, "attributes-charset",
10952 IPP_TAG_ZERO
) == NULL
)
10953 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10954 "attributes-charset", NULL
, "utf-8");
10956 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10957 IPP_TAG_ZERO
) == NULL
)
10958 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10959 "attributes-natural-language", NULL
, DefaultLanguage
);
10961 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10962 "status-message", NULL
, formatted
);
10967 * 'set_default()' - Set the default destination...
10971 set_default(cupsd_client_t
*con
, /* I - Client connection */
10972 ipp_attribute_t
*uri
) /* I - Printer URI */
10974 http_status_t status
; /* Policy status */
10975 cups_ptype_t dtype
; /* Destination type (printer/class) */
10976 cupsd_printer_t
*printer
, /* Printer */
10977 *oldprinter
; /* Old default printer */
10980 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10981 con
->http
.fd
, uri
->values
[0].string
.text
);
10984 * Is the destination valid?
10987 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10993 send_ipp_status(con
, IPP_NOT_FOUND
,
10994 _("The printer or class does not exist."));
11002 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
11004 send_http_error(con
, status
, NULL
);
11009 * Set it as the default...
11012 oldprinter
= DefaultPrinter
;
11013 DefaultPrinter
= printer
;
11016 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
11017 "%s is no longer the default printer.", oldprinter
->name
);
11019 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
11020 "%s is now the default printer.", printer
->name
);
11022 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
11023 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
11025 cupsdLogMessage(CUPSD_LOG_INFO
,
11026 "Default destination set to \"%s\" by \"%s\".",
11027 printer
->name
, get_username(con
));
11030 * Everything was ok, so return OK status...
11033 con
->response
->request
.status
.status_code
= IPP_OK
;
11038 * 'set_job_attrs()' - Set job attributes.
11042 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
11043 ipp_attribute_t
*uri
) /* I - Job URI */
11045 ipp_attribute_t
*attr
, /* Current attribute */
11046 *attr2
; /* Job attribute */
11047 int jobid
; /* Job ID */
11048 cupsd_job_t
*job
; /* Current job */
11049 char scheme
[HTTP_MAX_URI
],
11050 /* Method portion of URI */
11051 username
[HTTP_MAX_URI
],
11052 /* Username portion of URI */
11053 host
[HTTP_MAX_URI
],
11054 /* Host portion of URI */
11055 resource
[HTTP_MAX_URI
];
11056 /* Resource portion of URI */
11057 int port
; /* Port portion of URI */
11058 int event
; /* Events? */
11059 int check_jobs
; /* Check jobs? */
11062 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
11063 con
->http
.fd
, uri
->values
[0].string
.text
);
11066 * Start with "everything is OK" status...
11069 con
->response
->request
.status
.status_code
= IPP_OK
;
11072 * See if we have a job URI or a printer URI...
11075 if (!strcmp(uri
->name
, "printer-uri"))
11078 * Got a printer URI; see if we also have a job-id attribute...
11081 if ((attr
= ippFindAttribute(con
->request
, "job-id",
11082 IPP_TAG_INTEGER
)) == NULL
)
11084 send_ipp_status(con
, IPP_BAD_REQUEST
,
11085 _("Got a printer-uri attribute but no job-id."));
11089 jobid
= attr
->values
[0].integer
;
11094 * Got a job URI; parse it to get the job ID...
11097 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
11098 sizeof(scheme
), username
, sizeof(username
), host
,
11099 sizeof(host
), &port
, resource
, sizeof(resource
));
11101 if (strncmp(resource
, "/jobs/", 6))
11107 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
11108 uri
->values
[0].string
.text
);
11112 jobid
= atoi(resource
+ 6);
11116 * See if the job exists...
11119 if ((job
= cupsdFindJob(jobid
)) == NULL
)
11122 * Nope - return a "not found" error...
11125 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
11130 * See if the job has been completed...
11133 if (job
->state_value
> IPP_JOB_STOPPED
)
11136 * Return a "not-possible" error...
11139 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11140 _("Job #%d is finished and cannot be altered."), jobid
);
11145 * See if the job is owned by the requesting user...
11148 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
11150 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
11151 cupsdFindDest(job
->dest
));
11156 * See what the user wants to change.
11164 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11166 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
11169 if (!strcmp(attr
->name
, "attributes-charset") ||
11170 !strcmp(attr
->name
, "attributes-natural-language") ||
11171 !strcmp(attr
->name
, "document-compression") ||
11172 !strcmp(attr
->name
, "document-format") ||
11173 !strcmp(attr
->name
, "job-detailed-status-messages") ||
11174 !strcmp(attr
->name
, "job-document-access-errors") ||
11175 !strcmp(attr
->name
, "job-id") ||
11176 !strcmp(attr
->name
, "job-impressions-completed") ||
11177 !strcmp(attr
->name
, "job-k-octets") ||
11178 !strcmp(attr
->name
, "job-originating-host-name") ||
11179 !strcmp(attr
->name
, "job-originating-user-name") ||
11180 !strcmp(attr
->name
, "job-printer-up-time") ||
11181 !strcmp(attr
->name
, "job-printer-uri") ||
11182 !strcmp(attr
->name
, "job-sheets") ||
11183 !strcmp(attr
->name
, "job-state-message") ||
11184 !strcmp(attr
->name
, "job-state-reasons") ||
11185 !strcmp(attr
->name
, "job-uri") ||
11186 !strcmp(attr
->name
, "number-of-documents") ||
11187 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
11188 !strcmp(attr
->name
, "output-device-assigned") ||
11189 !strncmp(attr
->name
, "date-time-at-", 13) ||
11190 !strncmp(attr
->name
, "job-k-octets", 12) ||
11191 !strncmp(attr
->name
, "job-media-sheets", 16) ||
11192 !strncmp(attr
->name
, "time-at-", 8))
11198 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
11199 _("%s cannot be changed."), attr
->name
);
11201 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11202 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11207 if (!strcmp(attr
->name
, "job-priority"))
11210 * Change the job priority...
11213 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11215 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
11217 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11218 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11220 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
11222 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11223 _("Job is completed and cannot be changed."));
11226 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11228 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
11229 attr
->values
[0].integer
);
11230 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
11233 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
11234 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
11237 else if (!strcmp(attr
->name
, "job-state"))
11240 * Change the job state...
11243 if (attr
->value_tag
!= IPP_TAG_ENUM
)
11245 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
11247 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11248 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11252 switch (attr
->values
[0].integer
)
11254 case IPP_JOB_PENDING
:
11255 case IPP_JOB_HELD
:
11256 if (job
->state_value
> IPP_JOB_HELD
)
11258 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11259 _("Job state cannot be changed."));
11262 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11264 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11265 attr
->values
[0].integer
);
11266 cupsdSetJobState(job
, attr
->values
[0].integer
,
11268 "Job state changed by \"%s\"", username
);
11273 case IPP_JOB_PROCESSING
:
11274 case IPP_JOB_STOPPED
:
11275 if (job
->state_value
!= attr
->values
[0].integer
)
11277 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11278 _("Job state cannot be changed."));
11283 case IPP_JOB_CANCELED
:
11284 case IPP_JOB_ABORTED
:
11285 case IPP_JOB_COMPLETED
:
11286 if (job
->state_value
> IPP_JOB_PROCESSING
)
11288 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11289 _("Job state cannot be changed."));
11292 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11294 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11295 attr
->values
[0].integer
);
11296 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
11298 "Job state changed by \"%s\"", username
);
11305 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
11307 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11308 IPP_TAG_ZERO
)) != NULL
)
11311 * Some other value; first free the old value...
11314 if (job
->attrs
->prev
)
11315 job
->attrs
->prev
->next
= attr2
->next
;
11317 job
->attrs
->attrs
= attr2
->next
;
11319 if (job
->attrs
->last
== attr2
)
11320 job
->attrs
->last
= job
->attrs
->prev
;
11322 _ippFreeAttr(attr2
);
11325 * Then copy the attribute...
11328 copy_attribute(job
->attrs
, attr
, 0);
11331 * See if the job-name or job-hold-until is being changed.
11334 if (!strcmp(attr
->name
, "job-hold-until"))
11336 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
11337 attr
->values
[0].string
.text
);
11338 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
11340 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
11342 cupsdReleaseJob(job
);
11346 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
11347 "Job held by \"%s\".", username
);
11349 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
11352 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
11355 * Delete the attribute...
11358 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11359 IPP_TAG_ZERO
)) != NULL
)
11361 if (job
->attrs
->prev
)
11362 job
->attrs
->prev
->next
= attr2
->next
;
11364 job
->attrs
->attrs
= attr2
->next
;
11366 if (attr2
== job
->attrs
->last
)
11367 job
->attrs
->last
= job
->attrs
->prev
;
11369 _ippFreeAttr(attr2
);
11371 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11377 * Add new option by copying it...
11380 copy_attribute(job
->attrs
, attr
, 0);
11382 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11391 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11394 * Send events as needed...
11397 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11398 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11399 cupsdFindDest(job
->dest
), job
,
11400 "Job priority changed by user.");
11402 if (event
& CUPSD_EVENT_JOB_STATE
)
11403 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11404 job
->state_value
== IPP_JOB_HELD
?
11405 "Job held by user." : "Job restarted by user.");
11407 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11408 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11409 "Job options changed by user.");
11412 * Start jobs if possible...
11421 * 'set_printer_attrs()' - Set printer attributes.
11425 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11426 ipp_attribute_t
*uri
) /* I - Printer */
11428 http_status_t status
; /* Policy status */
11429 cups_ptype_t dtype
; /* Destination type (printer/class) */
11430 cupsd_printer_t
*printer
; /* Printer/class */
11431 ipp_attribute_t
*attr
; /* Printer attribute */
11432 int changed
= 0; /* Was anything changed? */
11435 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11436 con
->http
.fd
, uri
->values
[0].string
.text
);
11439 * Is the destination valid?
11442 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11448 send_ipp_status(con
, IPP_NOT_FOUND
,
11449 _("The printer or class does not exist."));
11457 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11459 send_http_error(con
, status
, printer
);
11464 * Return a list of attributes that can be set via Set-Printer-Attributes.
11467 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11468 IPP_TAG_TEXT
)) != NULL
)
11470 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11474 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11475 IPP_TAG_TEXT
)) != NULL
)
11477 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11482 * Update the printer attributes and return...
11487 cupsdSetPrinterAttrs(printer
);
11488 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11490 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11491 "Printer \"%s\" description or location changed by \"%s\".",
11492 printer
->name
, get_username(con
));
11494 cupsdLogMessage(CUPSD_LOG_INFO
,
11495 "Printer \"%s\" description or location changed by \"%s\".",
11496 printer
->name
, get_username(con
));
11499 con
->response
->request
.status
.status_code
= IPP_OK
;
11504 * 'set_printer_defaults()' - Set printer default options from a request.
11508 set_printer_defaults(
11509 cupsd_client_t
*con
, /* I - Client connection */
11510 cupsd_printer_t
*printer
) /* I - Printer */
11512 int i
; /* Looping var */
11513 ipp_attribute_t
*attr
; /* Current attribute */
11514 int namelen
; /* Length of attribute name */
11515 char name
[256], /* New attribute name */
11516 value
[256]; /* String version of integer attrs */
11519 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11522 * Skip non-printer attributes...
11525 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11528 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11530 if (!strcmp(attr
->name
, "job-sheets-default"))
11533 * Only allow keywords and names...
11536 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11540 * Only allow job-sheets-default to be set when running without a
11541 * system high classification level...
11544 if (Classification
)
11547 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11549 if (attr
->num_values
> 1)
11550 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11552 cupsdSetString(&printer
->job_sheets
[1], "none");
11554 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11556 cupsdFreeStrings(&(printer
->users
));
11558 printer
->deny_users
= 0;
11560 if (attr
->value_tag
== IPP_TAG_NAME
&&
11561 (attr
->num_values
> 1 ||
11562 strcmp(attr
->values
[0].string
.text
, "all")))
11564 for (i
= 0; i
< attr
->num_values
; i
++)
11565 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11568 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11570 cupsdFreeStrings(&(printer
->users
));
11572 printer
->deny_users
= 1;
11574 if (attr
->value_tag
== IPP_TAG_NAME
&&
11575 (attr
->num_values
> 1 ||
11576 strcmp(attr
->values
[0].string
.text
, "none")))
11578 for (i
= 0; i
< attr
->num_values
; i
++)
11579 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11582 else if (!strcmp(attr
->name
, "job-quota-period"))
11584 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11587 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11588 attr
->values
[0].integer
);
11589 cupsdFreeQuotas(printer
);
11591 printer
->quota_period
= attr
->values
[0].integer
;
11593 else if (!strcmp(attr
->name
, "job-k-limit"))
11595 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11598 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11599 attr
->values
[0].integer
);
11600 cupsdFreeQuotas(printer
);
11602 printer
->k_limit
= attr
->values
[0].integer
;
11604 else if (!strcmp(attr
->name
, "job-page-limit"))
11606 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11609 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11610 attr
->values
[0].integer
);
11611 cupsdFreeQuotas(printer
);
11613 printer
->page_limit
= attr
->values
[0].integer
;
11615 else if (!strcmp(attr
->name
, "printer-op-policy"))
11617 cupsd_policy_t
*p
; /* Policy */
11620 if (attr
->value_tag
!= IPP_TAG_NAME
)
11623 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11625 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11626 "Setting printer-op-policy to \"%s\"...",
11627 attr
->values
[0].string
.text
);
11628 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11629 printer
->op_policy_ptr
= p
;
11633 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11634 _("Unknown printer-op-policy \"%s\"."),
11635 attr
->values
[0].string
.text
);
11639 else if (!strcmp(attr
->name
, "printer-error-policy"))
11641 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11644 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11645 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
11646 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11647 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11648 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11650 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11651 _("Unknown printer-error-policy \"%s\"."),
11652 attr
->values
[0].string
.text
);
11656 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11657 "Setting printer-error-policy to \"%s\"...",
11658 attr
->values
[0].string
.text
);
11659 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11663 * Skip any other non-default attributes...
11666 namelen
= strlen(attr
->name
);
11667 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11668 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11672 * OK, anything else must be a user-defined default...
11675 strlcpy(name
, attr
->name
, sizeof(name
));
11676 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11678 switch (attr
->value_tag
)
11680 case IPP_TAG_DELETEATTR
:
11681 printer
->num_options
= cupsRemoveOption(name
,
11682 printer
->num_options
,
11683 &(printer
->options
));
11684 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11685 "Deleting %s", attr
->name
);
11688 case IPP_TAG_NAME
:
11689 case IPP_TAG_KEYWORD
:
11691 printer
->num_options
= cupsAddOption(name
,
11692 attr
->values
[0].string
.text
,
11693 printer
->num_options
,
11694 &(printer
->options
));
11695 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11696 "Setting %s to \"%s\"...", attr
->name
,
11697 attr
->values
[0].string
.text
);
11700 case IPP_TAG_BOOLEAN
:
11701 printer
->num_options
= cupsAddOption(name
,
11702 attr
->values
[0].boolean
?
11704 printer
->num_options
,
11705 &(printer
->options
));
11706 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11707 "Setting %s to %s...", attr
->name
,
11708 attr
->values
[0].boolean
? "true" : "false");
11711 case IPP_TAG_INTEGER
:
11712 case IPP_TAG_ENUM
:
11713 sprintf(value
, "%d", attr
->values
[0].integer
);
11714 printer
->num_options
= cupsAddOption(name
, value
,
11715 printer
->num_options
,
11716 &(printer
->options
));
11717 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11718 "Setting %s to %s...", attr
->name
, value
);
11721 case IPP_TAG_RANGE
:
11722 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11723 attr
->values
[0].range
.upper
);
11724 printer
->num_options
= cupsAddOption(name
, value
,
11725 printer
->num_options
,
11726 &(printer
->options
));
11727 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11728 "Setting %s to %s...", attr
->name
, value
);
11731 case IPP_TAG_RESOLUTION
:
11732 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11733 attr
->values
[0].resolution
.yres
,
11734 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11736 printer
->num_options
= cupsAddOption(name
, value
,
11737 printer
->num_options
,
11738 &(printer
->options
));
11739 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11740 "Setting %s to %s...", attr
->name
, value
);
11744 /* Do nothing for other values */
11752 * 'start_printer()' - Start a printer.
11756 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11757 ipp_attribute_t
*uri
) /* I - Printer URI */
11759 int i
; /* Temporary variable */
11760 http_status_t status
; /* Policy status */
11761 cups_ptype_t dtype
; /* Destination type (printer/class) */
11762 cupsd_printer_t
*printer
; /* Printer data */
11765 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11766 con
->http
.fd
, uri
->values
[0].string
.text
);
11769 * Is the destination valid?
11772 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11778 send_ipp_status(con
, IPP_NOT_FOUND
,
11779 _("The printer or class does not exist."));
11787 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11789 send_http_error(con
, status
, printer
);
11794 * Start the printer...
11797 printer
->state_message
[0] = '\0';
11799 cupsdStartPrinter(printer
, 1);
11801 if (dtype
& CUPS_PRINTER_CLASS
)
11802 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11803 printer
->name
, get_username(con
));
11805 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11806 printer
->name
, get_username(con
));
11814 if ((i
= check_quotas(con
, printer
)) < 0)
11816 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
11821 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
11826 * Everything was ok, so return OK status...
11829 con
->response
->request
.status
.status_code
= IPP_OK
;
11834 * 'stop_printer()' - Stop a printer.
11838 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11839 ipp_attribute_t
*uri
) /* I - Printer URI */
11841 http_status_t status
; /* Policy status */
11842 cups_ptype_t dtype
; /* Destination type (printer/class) */
11843 cupsd_printer_t
*printer
; /* Printer data */
11844 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11847 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11848 con
->http
.fd
, uri
->values
[0].string
.text
);
11851 * Is the destination valid?
11854 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11860 send_ipp_status(con
, IPP_NOT_FOUND
,
11861 _("The printer or class does not exist."));
11869 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11871 send_http_error(con
, status
, printer
);
11876 * Stop the printer...
11879 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11880 IPP_TAG_TEXT
)) == NULL
)
11881 strcpy(printer
->state_message
, "Paused");
11884 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11885 sizeof(printer
->state_message
));
11888 cupsdStopPrinter(printer
, 1);
11890 if (dtype
& CUPS_PRINTER_CLASS
)
11891 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11892 printer
->name
, get_username(con
));
11894 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11895 printer
->name
, get_username(con
));
11898 * Everything was ok, so return OK status...
11901 con
->response
->request
.status
.status_code
= IPP_OK
;
11906 * 'url_encode_attr()' - URL-encode a string attribute.
11910 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11911 char *buffer
,/* I - String buffer */
11912 int bufsize
)/* I - Size of buffer */
11914 int i
; /* Looping var */
11915 char *bufptr
, /* Pointer into buffer */
11916 *bufend
; /* End of buffer */
11919 strlcpy(buffer
, attr
->name
, bufsize
);
11920 bufptr
= buffer
+ strlen(buffer
);
11921 bufend
= buffer
+ bufsize
- 1;
11923 for (i
= 0; i
< attr
->num_values
; i
++)
11925 if (bufptr
>= bufend
)
11933 if (bufptr
>= bufend
)
11938 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11939 bufptr
, bufend
- bufptr
+ 1);
11941 if (bufptr
>= bufend
)
11952 * 'url_encode_string()' - URL-encode a string.
11955 static char * /* O - End of string */
11956 url_encode_string(const char *s
, /* I - String */
11957 char *buffer
, /* I - String buffer */
11958 int bufsize
) /* I - Size of buffer */
11960 char *bufptr
, /* Pointer into buffer */
11961 *bufend
; /* End of buffer */
11962 static const char *hex
= "0123456789ABCDEF";
11967 bufend
= buffer
+ bufsize
- 1;
11969 while (*s
&& bufptr
< bufend
)
11971 if (*s
== ' ' || *s
== '%' || *s
== '+')
11973 if (bufptr
>= (bufend
- 2))
11977 *bufptr
++ = hex
[(*s
>> 4) & 15];
11978 *bufptr
++ = hex
[*s
& 15];
11982 else if (*s
== '\'' || *s
== '\\')
11984 if (bufptr
>= (bufend
- 1))
12001 * 'user_allowed()' - See if a user is allowed to print to a queue.
12004 static int /* O - 0 if not allowed, 1 if allowed */
12005 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
12006 const char *username
) /* I - Username */
12008 struct passwd
*pw
; /* User password data */
12009 char baseuser
[256], /* Base username */
12010 *baseptr
, /* Pointer to "@" in base username */
12011 *name
; /* Current user name */
12014 if (cupsArrayCount(p
->users
) == 0)
12017 if (!strcmp(username
, "root"))
12020 if (strchr(username
, '@'))
12023 * Strip @REALM for username check...
12026 strlcpy(baseuser
, username
, sizeof(baseuser
));
12028 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
12031 username
= baseuser
;
12034 pw
= getpwnam(username
);
12037 for (name
= (char *)cupsArrayFirst(p
->users
);
12039 name
= (char *)cupsArrayNext(p
->users
))
12041 if (name
[0] == '@')
12044 * Check group membership...
12047 if (cupsdCheckGroup(username
, pw
, name
+ 1))
12050 else if (name
[0] == '#')
12056 if (cupsdCheckGroup(username
, pw
, name
))
12059 else if (!strcasecmp(username
, name
))
12063 return ((name
!= NULL
) != p
->deny_users
);
12068 * 'validate_job()' - Validate printer options and destination.
12072 validate_job(cupsd_client_t
*con
, /* I - Client connection */
12073 ipp_attribute_t
*uri
) /* I - Printer URI */
12075 http_status_t status
; /* Policy status */
12076 ipp_attribute_t
*attr
, /* Current attribute */
12077 *auth_info
; /* auth-info attribute */
12078 ipp_attribute_t
*format
; /* Document-format attribute */
12079 cups_ptype_t dtype
; /* Destination type (printer/class) */
12080 char super
[MIME_MAX_SUPER
],
12081 /* Supertype of file */
12082 type
[MIME_MAX_TYPE
];
12083 /* Subtype of file */
12084 cupsd_printer_t
*printer
; /* Printer */
12087 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
12088 con
->http
.fd
, uri
->values
[0].string
.text
);
12091 * OK, see if the client is sending the document compressed - CUPS
12092 * doesn't support compression yet...
12095 if ((attr
= ippFindAttribute(con
->request
, "compression",
12096 IPP_TAG_KEYWORD
)) != NULL
)
12098 if (strcmp(attr
->values
[0].string
.text
, "none")
12100 && strcmp(attr
->values
[0].string
.text
, "gzip")
12101 #endif /* HAVE_LIBZ */
12104 send_ipp_status(con
, IPP_ATTRIBUTES
,
12105 _("Unsupported compression \"%s\"."),
12106 attr
->values
[0].string
.text
);
12107 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
12108 "compression", NULL
, attr
->values
[0].string
.text
);
12114 * Is it a format we support?
12117 if ((format
= ippFindAttribute(con
->request
, "document-format",
12118 IPP_TAG_MIMETYPE
)) != NULL
)
12120 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
12123 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
12124 format
->values
[0].string
.text
);
12128 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
12129 !mimeType(MimeDatabase
, super
, type
))
12131 cupsdLogMessage(CUPSD_LOG_INFO
,
12132 "Hint: Do you have the raw file printing rules enabled?");
12133 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
12134 _("Unsupported document-format \"%s\"."),
12135 format
->values
[0].string
.text
);
12136 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
12137 "document-format", NULL
, format
->values
[0].string
.text
);
12143 * Is the destination valid?
12146 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
12152 send_ipp_status(con
, IPP_NOT_FOUND
,
12153 _("The printer or class does not exist."));
12161 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
12163 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
12165 send_http_error(con
, status
, printer
);
12168 else if (printer
->num_auth_info_required
== 1 &&
12169 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
12172 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
12176 else if (auth_info
&& !con
->http
.tls
&&
12177 !httpAddrLocalhost(con
->http
.hostaddr
))
12180 * Require encryption of auth-info over non-local connections...
12183 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
12186 #endif /* HAVE_SSL */
12189 * Everything was ok, so return OK status...
12192 con
->response
->request
.status
.status_code
= IPP_OK
;
12197 * 'validate_name()' - Make sure the printer name only contains valid chars.
12200 static int /* O - 0 if name is no good, 1 if good */
12201 validate_name(const char *name
) /* I - Name to check */
12203 const char *ptr
; /* Pointer into name */
12207 * Scan the whole name...
12210 for (ptr
= name
; *ptr
; ptr
++)
12211 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
12215 * All the characters are good; validate the length, too...
12218 return ((ptr
- name
) < 128);
12223 * 'validate_user()' - Validate the user for the request.
12226 static int /* O - 1 if permitted, 0 otherwise */
12227 validate_user(cupsd_job_t
*job
, /* I - Job */
12228 cupsd_client_t
*con
, /* I - Client connection */
12229 const char *owner
, /* I - Owner of job/resource */
12230 char *username
, /* O - Authenticated username */
12231 int userlen
) /* I - Length of username */
12233 cupsd_printer_t
*printer
; /* Printer for job */
12236 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
12237 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
12239 job
->id
, con
? con
->http
.fd
: 0,
12240 owner
? owner
: "(null)", username
, userlen
);
12243 * Validate input...
12246 if (!con
|| !owner
|| !username
|| userlen
<= 0)
12250 * Get the best authenticated username that is available.
12253 strlcpy(username
, get_username(con
), userlen
);
12256 * Check the username against the owner...
12259 printer
= cupsdFindDest(job
->dest
);
12261 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
12262 con
, owner
) == HTTP_OK
);
12267 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".