2 * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2010 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 # include <CoreFoundation/CoreFoundation.h>
120 # ifdef HAVE_MEMBERSHIP_H
121 # include <membership.h>
122 # endif /* HAVE_MEMBERSHIP_H */
123 # ifdef HAVE_MEMBERSHIPPRIV_H
124 # include <membershipPriv.h>
126 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
127 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
128 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
129 # endif /* HAVE_MEMBERSHIPPRIV_H */
130 #endif /* __APPLE__ */
137 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
138 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
139 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
140 mime_type_t
*filetype
, int compression
);
141 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
142 mime_type_t
*filetype
);
143 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
144 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
145 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
146 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
147 static void add_printer_state_reasons(cupsd_client_t
*con
,
149 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
151 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
152 CMDeviceProfileInfo
*profile
, unsigned id
,
153 const char *name
, const char *text
,
154 const char *iccfile
);
155 static void apple_register_profiles(cupsd_printer_t
*p
);
156 static void apple_unregister_profiles(cupsd_printer_t
*p
);
157 #endif /* __APPLE__ */
158 static void apply_printer_defaults(cupsd_printer_t
*printer
,
160 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
161 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
162 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
163 static void cancel_subscription(cupsd_client_t
*con
, int id
);
164 static int check_rss_recipient(const char *recipient
);
165 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
166 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
168 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
169 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
170 ipp_tag_t group
, int quickcopy
,
171 cups_array_t
*exclude
);
172 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
174 static int copy_file(const char *from
, const char *to
);
175 static int copy_model(cupsd_client_t
*con
, const char *from
,
177 static void copy_job_attrs(cupsd_client_t
*con
,
179 cups_array_t
*ra
, cups_array_t
*exclude
);
180 static void copy_printer_attrs(cupsd_client_t
*con
,
181 cupsd_printer_t
*printer
,
183 static void copy_subscription_attrs(cupsd_client_t
*con
,
184 cupsd_subscription_t
*sub
,
186 cups_array_t
*exclude
);
187 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
188 static cups_array_t
*create_requested_array(ipp_t
*request
);
189 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
191 static void get_default(cupsd_client_t
*con
);
192 static void get_devices(cupsd_client_t
*con
);
193 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
194 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
195 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
196 static void get_notifications(cupsd_client_t
*con
);
197 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static void get_ppds(cupsd_client_t
*con
);
199 static void get_printers(cupsd_client_t
*con
, int type
);
200 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
201 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
202 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
203 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
204 static const char *get_username(cupsd_client_t
*con
);
205 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
206 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
207 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
208 static int ppd_parse_line(const char *line
, char *option
, int olen
,
209 char *choice
, int clen
);
210 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
211 static void read_job_ticket(cupsd_client_t
*con
);
212 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
213 static void release_held_new_jobs(cupsd_client_t
*con
,
214 ipp_attribute_t
*uri
);
215 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
216 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
217 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
218 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
219 ipp_attribute_t
*auth_info
);
220 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
221 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
222 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
223 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
224 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
225 cupsd_printer_t
*printer
);
226 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
227 const char *message
, ...)
229 __attribute__ ((__format__ (__printf__
, 3, 4)))
230 # endif /* __GNUC__ */
232 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
233 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
234 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
235 static void set_printer_defaults(cupsd_client_t
*con
,
236 cupsd_printer_t
*printer
);
237 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
238 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
239 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
241 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
242 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
243 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
244 static int validate_name(const char *name
);
245 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
246 const char *owner
, char *username
,
251 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
254 int /* O - 1 on success, 0 on failure */
255 cupsdProcessIPPRequest(
256 cupsd_client_t
*con
) /* I - Client connection */
258 ipp_tag_t group
; /* Current group tag */
259 ipp_attribute_t
*attr
; /* Current attribute */
260 ipp_attribute_t
*charset
; /* Character set attribute */
261 ipp_attribute_t
*language
; /* Language attribute */
262 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
263 ipp_attribute_t
*username
; /* requesting-user-name attr */
264 int sub_id
; /* Subscription ID */
267 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
268 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
269 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
272 * First build an empty response message for this request...
275 con
->response
= ippNew();
277 con
->response
->request
.status
.version
[0] =
278 con
->request
->request
.op
.version
[0];
279 con
->response
->request
.status
.version
[1] =
280 con
->request
->request
.op
.version
[1];
281 con
->response
->request
.status
.request_id
=
282 con
->request
->request
.op
.request_id
;
285 * Then validate the request header and required attributes...
288 if (con
->request
->request
.any
.version
[0] != 1 &&
289 con
->request
->request
.any
.version
[0] != 2)
292 * Return an error, since we only support IPP 1.x and 2.x.
295 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
296 "%04X %s Bad request version number %d.%d",
297 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
298 con
->request
->request
.any
.version
[0],
299 con
->request
->request
.any
.version
[1]);
301 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
302 _("Bad request version number %d.%d"),
303 con
->request
->request
.any
.version
[0],
304 con
->request
->request
.any
.version
[1]);
306 else if (con
->request
->request
.any
.request_id
< 1)
309 * Return an error, since request IDs must be between 1 and 2^31-1
312 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
313 "%04X %s Bad request ID %d",
314 IPP_BAD_REQUEST
, con
->http
.hostname
,
315 con
->request
->request
.any
.request_id
);
317 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d"),
318 con
->request
->request
.any
.request_id
);
320 else if (!con
->request
->attrs
)
322 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
323 "%04X %s No attributes in request",
324 IPP_BAD_REQUEST
, con
->http
.hostname
);
326 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request"));
331 * Make sure that the attributes are provided in the correct order and
332 * don't repeat groups...
335 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
338 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
341 * Out of order; return an error...
344 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
345 "%04X %s Attribute groups are out of order",
346 IPP_BAD_REQUEST
, con
->http
.hostname
);
348 send_ipp_status(con
, IPP_BAD_REQUEST
,
349 _("Attribute groups are out of order (%x < %x)"),
350 attr
->group_tag
, group
);
354 group
= attr
->group_tag
;
359 * Then make sure that the first three attributes are:
362 * attributes-natural-language
363 * printer-uri/job-uri
366 attr
= con
->request
->attrs
;
367 if (attr
&& attr
->name
&&
368 !strcmp(attr
->name
, "attributes-charset") &&
369 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
377 if (attr
&& attr
->name
&&
378 !strcmp(attr
->name
, "attributes-natural-language") &&
379 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
384 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
385 IPP_TAG_URI
)) != NULL
)
387 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
388 IPP_TAG_URI
)) != NULL
)
390 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
391 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
396 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
397 "attributes-charset", NULL
,
398 charset
->values
[0].string
.text
);
400 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
401 "attributes-charset", NULL
, "utf-8");
404 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
405 "attributes-natural-language", NULL
,
406 language
->values
[0].string
.text
);
408 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
409 "attributes-natural-language", NULL
, DefaultLanguage
);
412 strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
413 strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
416 * Bad character set...
419 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
420 charset
->values
[0].string
.text
);
421 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
422 "%04X %s Unsupported attributes-charset value \"%s\"",
423 IPP_CHARSET
, con
->http
.hostname
,
424 charset
->values
[0].string
.text
);
425 send_ipp_status(con
, IPP_BAD_REQUEST
,
426 _("Unsupported character set \"%s\""),
427 charset
->values
[0].string
.text
);
429 else if (!charset
|| !language
||
431 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
432 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
433 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
434 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
435 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
438 * Return an error, since attributes-charset,
439 * attributes-natural-language, and printer-uri/job-uri are required
440 * for all operations.
445 cupsdLogMessage(CUPSD_LOG_ERROR
,
446 "Missing attributes-charset attribute");
448 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
449 "%04X %s Missing attributes-charset attribute",
450 IPP_BAD_REQUEST
, con
->http
.hostname
);
455 cupsdLogMessage(CUPSD_LOG_ERROR
,
456 "Missing attributes-natural-language attribute");
458 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
459 "%04X %s Missing attributes-natural-language attribute",
460 IPP_BAD_REQUEST
, con
->http
.hostname
);
465 cupsdLogMessage(CUPSD_LOG_ERROR
,
466 "Missing printer-uri, job-uri, or ppd-name "
469 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
470 "%04X %s Missing printer-uri, job-uri, or ppd-name "
471 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
474 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
476 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
477 cupsdLogMessage(CUPSD_LOG_DEBUG
,
478 "attr \"%s\": group_tag = %x, value_tag = %x",
479 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
482 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
484 send_ipp_status(con
, IPP_BAD_REQUEST
,
485 _("Missing required attributes"));
490 * OK, all the checks pass so far; make sure requesting-user-name is
491 * not "root" from a remote host...
494 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
495 IPP_TAG_NAME
)) != NULL
)
498 * Check for root user...
501 if (!strcmp(username
->values
[0].string
.text
, "root") &&
502 strcasecmp(con
->http
.hostname
, "localhost") &&
503 strcmp(con
->username
, "root"))
506 * Remote unauthenticated user masquerading as local root...
509 _cupsStrFree(username
->values
[0].string
.text
);
510 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
514 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
515 IPP_TAG_INTEGER
)) != NULL
)
516 sub_id
= attr
->values
[0].integer
;
521 * Then try processing the operation...
525 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
526 ippOpString(con
->request
->request
.op
.operation_id
),
527 uri
->values
[0].string
.text
);
529 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
530 ippOpString(con
->request
->request
.op
.operation_id
));
532 switch (con
->request
->request
.op
.operation_id
)
538 case IPP_VALIDATE_JOB
:
539 validate_job(con
, uri
);
542 case IPP_CREATE_JOB
:
543 create_job(con
, uri
);
546 case IPP_SEND_DOCUMENT
:
547 send_document(con
, uri
);
550 case IPP_CANCEL_JOB
:
551 cancel_job(con
, uri
);
554 case IPP_GET_JOB_ATTRIBUTES
:
555 get_job_attrs(con
, uri
);
562 case IPP_GET_PRINTER_ATTRIBUTES
:
563 get_printer_attrs(con
, uri
);
566 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
567 get_printer_supported(con
, uri
);
574 case IPP_RELEASE_JOB
:
575 release_job(con
, uri
);
578 case IPP_RESTART_JOB
:
579 restart_job(con
, uri
);
582 case IPP_PAUSE_PRINTER
:
583 stop_printer(con
, uri
);
586 case IPP_RESUME_PRINTER
:
587 start_printer(con
, uri
);
590 case IPP_PURGE_JOBS
:
591 case IPP_CANCEL_JOBS
:
592 case IPP_CANCEL_MY_JOBS
:
593 cancel_all_jobs(con
, uri
);
596 case IPP_SET_JOB_ATTRIBUTES
:
597 set_job_attrs(con
, uri
);
600 case IPP_SET_PRINTER_ATTRIBUTES
:
601 set_printer_attrs(con
, uri
);
604 case IPP_HOLD_NEW_JOBS
:
605 hold_new_jobs(con
, uri
);
608 case IPP_RELEASE_HELD_NEW_JOBS
:
609 release_held_new_jobs(con
, uri
);
616 case CUPS_GET_DEFAULT
:
620 case CUPS_GET_PRINTERS
:
621 get_printers(con
, 0);
624 case CUPS_GET_CLASSES
:
625 get_printers(con
, CUPS_PRINTER_CLASS
);
628 case CUPS_ADD_PRINTER
:
629 add_printer(con
, uri
);
632 case CUPS_DELETE_PRINTER
:
633 delete_printer(con
, uri
);
636 case CUPS_ADD_CLASS
:
640 case CUPS_DELETE_CLASS
:
641 delete_printer(con
, uri
);
644 case CUPS_ACCEPT_JOBS
:
645 case IPP_ENABLE_PRINTER
:
646 accept_jobs(con
, uri
);
649 case CUPS_REJECT_JOBS
:
650 case IPP_DISABLE_PRINTER
:
651 reject_jobs(con
, uri
);
654 case CUPS_SET_DEFAULT
:
655 set_default(con
, uri
);
658 case CUPS_GET_DEVICES
:
662 case CUPS_GET_DOCUMENT
:
663 get_document(con
, uri
);
678 case CUPS_AUTHENTICATE_JOB
:
679 authenticate_job(con
, uri
);
682 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
683 case IPP_CREATE_JOB_SUBSCRIPTION
:
684 create_subscription(con
, uri
);
687 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
688 get_subscription_attrs(con
, sub_id
);
691 case IPP_GET_SUBSCRIPTIONS
:
692 get_subscriptions(con
, uri
);
695 case IPP_RENEW_SUBSCRIPTION
:
696 renew_subscription(con
, sub_id
);
699 case IPP_CANCEL_SUBSCRIPTION
:
700 cancel_subscription(con
, sub_id
);
703 case IPP_GET_NOTIFICATIONS
:
704 get_notifications(con
);
708 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
709 "%04X %s Operation %04X (%s) not supported",
710 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
711 con
->request
->request
.op
.operation_id
,
712 ippOpString(con
->request
->request
.op
.operation_id
));
714 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
715 _("%s not supported"),
717 con
->request
->request
.op
.operation_id
));
727 * Sending data from the scheduler...
730 cupsdLogMessage(con
->response
->request
.status
.status_code
731 >= IPP_BAD_REQUEST
&&
732 con
->response
->request
.status
.status_code
733 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
734 "Returning IPP %s for %s (%s) from %s",
735 ippErrorString(con
->response
->request
.status
.status_code
),
736 ippOpString(con
->request
->request
.op
.operation_id
),
737 uri
? uri
->values
[0].string
.text
: "no URI",
740 if (LogLevel
== CUPSD_LOG_DEBUG2
)
741 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
742 "cupsdProcessIPPRequest: ippLength(response)=%ld",
743 (long)ippLength(con
->response
));
745 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
747 #ifdef CUPSD_USE_CHUNKING
749 * Because older versions of CUPS (1.1.17 and older) and some IPP
750 * clients do not implement chunking properly, we cannot use
751 * chunking by default. This may become the default in future
752 * CUPS releases, or we might add a configuration directive for
756 if (con
->http
.version
== HTTP_1_1
)
758 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
761 if (cupsdFlushHeader(con
) < 0)
764 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
767 #endif /* CUPSD_USE_CHUNKING */
769 size_t length
; /* Length of response */
772 length
= ippLength(con
->response
);
774 if (con
->file
>= 0 && !con
->pipe_pid
)
776 struct stat fileinfo
; /* File information */
779 if (!fstat(con
->file
, &fileinfo
))
780 length
+= fileinfo
.st_size
;
783 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
784 CUPS_LLCAST length
) < 0)
787 if (cupsdFlushHeader(con
) < 0)
790 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
791 con
->http
.data_remaining
= length
;
793 if (con
->http
.data_remaining
<= INT_MAX
)
794 con
->http
._data_remaining
= con
->http
.data_remaining
;
796 con
->http
._data_remaining
= INT_MAX
;
799 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
800 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
803 * Tell the caller the response header was sent successfully...
811 * Tell the caller the response header could not be sent...
820 * Sending data from a subprocess like cups-deviced; tell the caller
821 * everything is A-OK so far...
830 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
833 int /* O - 0 on success, -1 on error */
834 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
836 cupsd_printer_t
*printer
; /* Destination printer or class */
837 ipp_attribute_t
*attr
; /* job-sheets attribute */
838 int kbytes
; /* Kilobytes in banner */
841 job
->pending_timeout
= 0;
844 * See if we need to add the ending sheet...
847 if (!cupsdLoadJob(job
))
850 printer
= cupsdFindDest(job
->dest
);
851 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
854 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
855 attr
&& attr
->num_values
> 1)
861 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
862 attr
->values
[1].string
.text
);
864 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
867 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
875 * 'accept_jobs()' - Accept print jobs to a printer.
879 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
880 ipp_attribute_t
*uri
) /* I - Printer or class URI */
882 http_status_t status
; /* Policy status */
883 cups_ptype_t dtype
; /* Destination type (printer/class) */
884 cupsd_printer_t
*printer
; /* Printer data */
887 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
888 con
->http
.fd
, uri
->values
[0].string
.text
);
891 * Is the destination valid?
894 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
900 send_ipp_status(con
, IPP_NOT_FOUND
,
901 _("The printer or class was not found."));
909 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
911 send_http_error(con
, status
, printer
);
916 * Accept jobs sent to the printer...
919 printer
->accepting
= 1;
920 printer
->state_message
[0] = '\0';
922 cupsdAddPrinterHistory(printer
);
924 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
925 "Now accepting jobs.");
927 if (dtype
& CUPS_PRINTER_CLASS
)
929 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
931 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
932 printer
->name
, get_username(con
));
936 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
938 cupsdLogMessage(CUPSD_LOG_INFO
,
939 "Printer \"%s\" now accepting jobs (\"%s\").",
940 printer
->name
, get_username(con
));
944 * Everything was ok, so return OK status...
947 con
->response
->request
.status
.status_code
= IPP_OK
;
952 * 'add_class()' - Add a class to the system.
956 add_class(cupsd_client_t
*con
, /* I - Client connection */
957 ipp_attribute_t
*uri
) /* I - URI of class */
959 http_status_t status
; /* Policy status */
960 int i
; /* Looping var */
961 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
962 username
[HTTP_MAX_URI
], /* Username portion of URI */
963 host
[HTTP_MAX_URI
], /* Host portion of URI */
964 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
965 int port
; /* Port portion of URI */
966 cupsd_printer_t
*pclass
, /* Class */
967 *member
; /* Member printer/class */
968 cups_ptype_t dtype
; /* Destination type */
969 ipp_attribute_t
*attr
; /* Printer attribute */
970 int modify
; /* Non-zero if we just modified */
971 char newname
[IPP_MAX_NAME
]; /* New class name */
972 int need_restart_job
; /* Need to restart job? */
975 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
976 con
->http
.fd
, uri
->values
[0].string
.text
);
979 * Do we have a valid URI?
982 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
983 sizeof(scheme
), username
, sizeof(username
), host
,
984 sizeof(host
), &port
, resource
, sizeof(resource
));
987 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
990 * No, return an error...
993 send_ipp_status(con
, IPP_BAD_REQUEST
,
994 _("The printer-uri must be of the form "
995 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
1000 * Do we have a valid printer name?
1003 if (!validate_name(resource
+ 9))
1006 * No, return an error...
1009 send_ipp_status(con
, IPP_BAD_REQUEST
,
1010 _("The printer-uri \"%s\" contains invalid characters."),
1011 uri
->values
[0].string
.text
);
1016 * See if the class already exists; if not, create a new class...
1019 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1022 * Class doesn't exist; see if we have a printer of the same name...
1025 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
1026 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
1029 * Yes, return an error...
1032 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1033 _("A printer named \"%s\" already exists"),
1039 * No, check the default policy and then add the class...
1042 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1044 send_http_error(con
, status
, NULL
);
1048 pclass
= cupsdAddClass(resource
+ 9);
1051 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1054 * Check the default policy, then rename the implicit class to "AnyClass"
1058 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1060 send_http_error(con
, status
, NULL
);
1064 if (ImplicitAnyClasses
)
1066 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1067 cupsdRenamePrinter(pclass
, newname
);
1070 cupsdDeletePrinter(pclass
, 1);
1073 * Add the class as a new local class...
1076 pclass
= cupsdAddClass(resource
+ 9);
1079 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1082 * Check the default policy, then rename the remote class to "Class"...
1085 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1087 send_http_error(con
, status
, NULL
);
1091 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1092 cupsdRenamePrinter(pclass
, newname
);
1095 * Add the class as a new local class...
1098 pclass
= cupsdAddClass(resource
+ 9);
1101 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1104 send_http_error(con
, status
, pclass
);
1111 * Look for attributes and copy them over as needed...
1114 need_restart_job
= 0;
1116 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1117 IPP_TAG_TEXT
)) != NULL
)
1118 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1120 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1121 IPP_TAG_TEXT
)) != NULL
)
1122 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1124 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1125 IPP_TAG_BOOLEAN
)) != NULL
&&
1126 attr
->values
[0].boolean
!= pclass
->accepting
)
1128 cupsdLogMessage(CUPSD_LOG_INFO
,
1129 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1130 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1132 pclass
->accepting
= attr
->values
[0].boolean
;
1133 cupsdAddPrinterHistory(pclass
);
1135 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1136 pclass
->accepting
? "Now" : "No longer");
1139 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1140 IPP_TAG_BOOLEAN
)) != NULL
)
1142 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1143 cupsdDeregisterPrinter(pclass
, 1);
1145 cupsdLogMessage(CUPSD_LOG_INFO
,
1146 "Setting %s printer-is-shared to %d (was %d.)",
1147 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1149 pclass
->shared
= attr
->values
[0].boolean
;
1152 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1153 IPP_TAG_ENUM
)) != NULL
)
1155 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1156 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1158 send_ipp_status(con
, IPP_BAD_REQUEST
,
1159 _("Attempt to set %s printer-state to bad value %d"),
1160 pclass
->name
, attr
->values
[0].integer
);
1164 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1165 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1167 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1168 cupsdStopPrinter(pclass
, 0);
1171 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1172 need_restart_job
= 1;
1175 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1176 IPP_TAG_TEXT
)) != NULL
)
1178 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1179 sizeof(pclass
->state_message
));
1180 cupsdAddPrinterHistory(pclass
);
1182 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1183 pclass
->state_message
);
1185 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1186 IPP_TAG_URI
)) != NULL
)
1189 * Clear the printer array as needed...
1192 need_restart_job
= 1;
1194 if (pclass
->num_printers
> 0)
1196 free(pclass
->printers
);
1197 pclass
->num_printers
= 0;
1201 * Add each printer or class that is listed...
1204 for (i
= 0; i
< attr
->num_values
; i
++)
1207 * Search for the printer or class URI...
1210 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1216 send_ipp_status(con
, IPP_NOT_FOUND
,
1217 _("The printer or class was not found."));
1220 else if (dtype
& CUPS_PRINTER_CLASS
)
1222 send_ipp_status(con
, IPP_BAD_REQUEST
,
1223 _("Nested classes are not allowed"));
1228 * Add it to the class...
1231 cupsdAddPrinterToClass(pclass
, member
);
1235 set_printer_defaults(con
, pclass
);
1237 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1238 IPP_TAG_KEYWORD
)) != NULL
)
1239 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1242 * Update the printer class attributes and return...
1245 cupsdSetPrinterAttrs(pclass
);
1246 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1248 if (need_restart_job
&& pclass
->job
)
1251 * Reset the current job to a "pending" status...
1254 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1255 "Job restarted because the class was modified.");
1258 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1262 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1263 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1264 pclass
->name
, get_username(con
));
1266 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1267 pclass
->name
, get_username(con
));
1271 cupsdAddPrinterHistory(pclass
);
1273 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1274 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1275 pclass
->name
, get_username(con
));
1277 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1278 pclass
->name
, get_username(con
));
1281 con
->response
->request
.status
.status_code
= IPP_OK
;
1286 * 'add_file()' - Add a file to a job.
1289 static int /* O - 0 on success, -1 on error */
1290 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1291 cupsd_job_t
*job
, /* I - Job to add to */
1292 mime_type_t
*filetype
, /* I - Type of file */
1293 int compression
) /* I - Compression */
1295 mime_type_t
**filetypes
; /* New filetypes array... */
1296 int *compressions
; /* New compressions array... */
1299 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1300 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1301 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1302 filetype
->super
, filetype
->type
, compression
);
1305 * Add the file to the job...
1308 if (job
->num_files
== 0)
1310 compressions
= (int *)malloc(sizeof(int));
1311 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1315 compressions
= (int *)realloc(job
->compressions
,
1316 (job
->num_files
+ 1) * sizeof(int));
1317 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1318 (job
->num_files
+ 1) *
1319 sizeof(mime_type_t
*));
1322 if (!compressions
|| !filetypes
)
1324 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1325 "Job aborted because the scheduler ran out of memory.");
1328 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1329 _("Unable to allocate memory for file types"));
1334 job
->compressions
= compressions
;
1335 job
->compressions
[job
->num_files
] = compression
;
1336 job
->filetypes
= filetypes
;
1337 job
->filetypes
[job
->num_files
] = filetype
;
1342 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1349 * 'add_job()' - Add a job to a print queue.
1352 static cupsd_job_t
* /* O - Job object */
1353 add_job(cupsd_client_t
*con
, /* I - Client connection */
1354 cupsd_printer_t
*printer
, /* I - Destination printer */
1355 mime_type_t
*filetype
) /* I - First print file type, if any */
1357 http_status_t status
; /* Policy status */
1358 ipp_attribute_t
*attr
, /* Current attribute */
1359 *auth_info
; /* auth-info attribute */
1360 const char *val
; /* Default option value */
1361 int priority
; /* Job priority */
1362 cupsd_job_t
*job
; /* Current job */
1363 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1364 int kbytes
; /* Size of print file */
1365 int i
; /* Looping var */
1366 int lowerpagerange
; /* Page range bound */
1367 int exact
; /* Did we have an exact match? */
1368 ipp_attribute_t
*media_col
, /* media-col attribute */
1369 *media_margin
; /* media-*-margin attribute */
1370 ipp_t
*unsup_col
; /* media-col in unsupported response */
1373 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1374 con
, con
->http
.fd
, printer
, printer
->name
,
1375 filetype
, filetype
? filetype
->super
: "none",
1376 filetype
? filetype
->type
: "none");
1379 * Check remote printing to non-shared printer...
1382 if (!printer
->shared
&&
1383 strcasecmp(con
->http
.hostname
, "localhost") &&
1384 strcasecmp(con
->http
.hostname
, ServerName
))
1386 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1387 _("The printer or class is not shared"));
1395 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1397 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1399 send_http_error(con
, status
, printer
);
1402 else if (printer
->num_auth_info_required
== 1 &&
1403 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1406 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1410 else if (auth_info
&& !con
->http
.tls
&&
1411 !httpAddrLocalhost(con
->http
.hostaddr
))
1414 * Require encryption of auth-info over non-local connections...
1417 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1420 #endif /* HAVE_SSL */
1423 * See if the printer is accepting jobs...
1426 if (!printer
->accepting
)
1428 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1429 _("Destination \"%s\" is not accepting jobs."),
1435 * Validate job template attributes; for now just document-format,
1436 * copies, number-up, and page-ranges...
1439 if (filetype
&& printer
->filetypes
&&
1440 !cupsArrayFind(printer
->filetypes
, filetype
))
1442 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1443 /* MIME media type string */
1446 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1449 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1450 _("Unsupported format \'%s\'"), mimetype
);
1452 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1453 "document-format", NULL
, mimetype
);
1458 if ((attr
= ippFindAttribute(con
->request
, "copies",
1459 IPP_TAG_INTEGER
)) != NULL
)
1461 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1463 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1464 attr
->values
[0].integer
);
1465 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1466 "copies", attr
->values
[0].integer
);
1471 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1472 IPP_TAG_ZERO
)) != NULL
)
1474 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1475 attr
->value_tag
!= IPP_TAG_NAME
)
1477 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type"));
1481 if (attr
->num_values
> 2)
1483 send_ipp_status(con
, IPP_BAD_REQUEST
,
1484 _("Too many job-sheets values (%d > 2)"),
1489 for (i
= 0; i
< attr
->num_values
; i
++)
1490 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1491 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1493 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\""),
1494 attr
->values
[i
].string
.text
);
1499 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1500 IPP_TAG_INTEGER
)) != NULL
)
1502 if (attr
->values
[0].integer
!= 1 &&
1503 attr
->values
[0].integer
!= 2 &&
1504 attr
->values
[0].integer
!= 4 &&
1505 attr
->values
[0].integer
!= 6 &&
1506 attr
->values
[0].integer
!= 9 &&
1507 attr
->values
[0].integer
!= 16)
1509 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1510 attr
->values
[0].integer
);
1511 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1512 "number-up", attr
->values
[0].integer
);
1517 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1518 IPP_TAG_RANGE
)) != NULL
)
1520 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1522 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1523 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1525 send_ipp_status(con
, IPP_BAD_REQUEST
,
1526 _("Bad page-ranges values %d-%d."),
1527 attr
->values
[i
].range
.lower
,
1528 attr
->values
[i
].range
.upper
);
1532 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1537 * Do media selection as needed...
1540 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1541 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1542 _pwgGetPageSize(printer
->pwg
, con
->request
, NULL
, &exact
))
1545 (media_col
= ippFindAttribute(con
->request
, "media-col",
1546 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1548 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1550 unsup_col
= ippNew();
1551 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1552 "media-bottom-margin",
1553 IPP_TAG_INTEGER
)) != NULL
)
1554 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1555 "media-bottom-margin", media_margin
->values
[0].integer
);
1557 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1558 "media-left-margin",
1559 IPP_TAG_INTEGER
)) != NULL
)
1560 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1561 "media-left-margin", media_margin
->values
[0].integer
);
1563 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1564 "media-right-margin",
1565 IPP_TAG_INTEGER
)) != NULL
)
1566 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1567 "media-right-margin", media_margin
->values
[0].integer
);
1569 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1571 IPP_TAG_INTEGER
)) != NULL
)
1572 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1573 "media-top-margin", media_margin
->values
[0].integer
);
1575 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1577 ippDelete(unsup_col
);
1582 * Make sure we aren't over our limit...
1585 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1588 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1590 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1591 _("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
)
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 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
[1024]; /* job-uuid string */
2336 _cups_md5_state_t md5state
; /* MD5 state */
2337 unsigned char md5sum
[16]; /* MD5 digest/sum */
2341 * First see if the job already has a job-uuid attribute; if so, return...
2344 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2348 * No job-uuid attribute, so build a version 3 UUID with the local job
2349 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2350 * the ServerName, server name and port that the client connected to,
2351 * and local job ID...
2354 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2355 con
->serverport
, job
->id
);
2357 _cupsMD5Init(&md5state
);
2358 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2359 _cupsMD5Finish(&md5state
, md5sum
);
2362 * Format the UUID URI using the MD5 sum and job ID.
2365 snprintf(uuid
, sizeof(uuid
),
2366 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2367 "%02x%02x%02x%02x%02x%02x",
2368 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2369 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2370 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2371 md5sum
[14], md5sum
[15]);
2373 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2378 * 'add_printer()' - Add a printer to the system.
2382 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2383 ipp_attribute_t
*uri
) /* I - URI of printer */
2385 http_status_t status
; /* Policy status */
2386 int i
; /* Looping var */
2387 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2388 username
[HTTP_MAX_URI
], /* Username portion of URI */
2389 host
[HTTP_MAX_URI
], /* Host portion of URI */
2390 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2391 int port
; /* Port portion of URI */
2392 cupsd_printer_t
*printer
; /* Printer/class */
2393 ipp_attribute_t
*attr
; /* Printer attribute */
2394 cups_file_t
*fp
; /* Script/PPD file */
2395 char line
[1024]; /* Line from file... */
2396 char srcfile
[1024], /* Source Script/PPD file */
2397 dstfile
[1024]; /* Destination Script/PPD file */
2398 int modify
; /* Non-zero if we are modifying */
2399 char newname
[IPP_MAX_NAME
]; /* New printer name */
2400 int changed_driver
, /* Changed the PPD/interface script? */
2401 need_restart_job
, /* Need to restart job? */
2402 set_device_uri
, /* Did we set the device URI? */
2403 set_port_monitor
; /* Did we set the port monitor? */
2406 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2407 con
->http
.fd
, uri
->values
[0].string
.text
);
2410 * Do we have a valid URI?
2413 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2414 sizeof(scheme
), username
, sizeof(username
), host
,
2415 sizeof(host
), &port
, resource
, sizeof(resource
));
2417 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2420 * No, return an error...
2423 send_ipp_status(con
, IPP_BAD_REQUEST
,
2424 _("The printer-uri must be of the form "
2425 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2430 * Do we have a valid printer name?
2433 if (!validate_name(resource
+ 10))
2436 * No, return an error...
2439 send_ipp_status(con
, IPP_BAD_REQUEST
,
2440 _("The printer-uri \"%s\" contains invalid characters."),
2441 uri
->values
[0].string
.text
);
2446 * See if the printer already exists; if not, create a new printer...
2449 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2452 * Printer doesn't exist; see if we have a class of the same name...
2455 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2456 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2459 * Yes, return an error...
2462 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2463 _("A class named \"%s\" already exists"),
2469 * No, check the default policy then add the printer...
2472 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2474 send_http_error(con
, status
, NULL
);
2478 printer
= cupsdAddPrinter(resource
+ 10);
2481 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2484 * Check the default policy, then rename the implicit printer to
2485 * "AnyPrinter" or delete it...
2488 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2490 send_http_error(con
, status
, NULL
);
2494 if (ImplicitAnyClasses
)
2496 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2497 cupsdRenamePrinter(printer
, newname
);
2500 cupsdDeletePrinter(printer
, 1);
2503 * Add the printer as a new local printer...
2506 printer
= cupsdAddPrinter(resource
+ 10);
2509 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2512 * Check the default policy, then rename the remote printer to
2513 * "Printer@server"...
2516 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2518 send_http_error(con
, status
, NULL
);
2522 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2524 cupsdRenamePrinter(printer
, newname
);
2527 * Add the printer as a new local printer...
2530 printer
= cupsdAddPrinter(resource
+ 10);
2533 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2536 send_http_error(con
, status
, printer
);
2543 * Look for attributes and copy them over as needed...
2547 need_restart_job
= 0;
2549 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2550 IPP_TAG_TEXT
)) != NULL
)
2551 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2553 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2554 IPP_TAG_TEXT
)) != NULL
)
2555 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2559 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2560 IPP_TAG_URI
)) != NULL
)
2563 * Do we have a valid device URI?
2566 http_uri_status_t uri_status
; /* URI separation status */
2567 char old_device_uri
[1024];
2568 /* Old device URI */
2571 need_restart_job
= 1;
2573 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2574 attr
->values
[0].string
.text
,
2575 scheme
, sizeof(scheme
),
2576 username
, sizeof(username
),
2577 host
, sizeof(host
), &port
,
2578 resource
, sizeof(resource
));
2580 if (uri_status
< HTTP_URI_OK
)
2582 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\""),
2583 attr
->values
[0].string
.text
);
2584 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2585 "add_printer: httpSeparateURI returned %d", uri_status
);
2589 if (!strcmp(scheme
, "file"))
2592 * See if the administrator has enabled file devices...
2595 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2598 * File devices are disabled and the URL is not file:/dev/null...
2601 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2602 _("File device URIs have been disabled! "
2603 "To enable, see the FileDevice directive in "
2604 "\"%s/cupsd.conf\"."),
2612 * See if the backend exists and is executable...
2615 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2616 if (access(srcfile
, X_OK
))
2619 * Could not find device in list!
2622 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\""),
2628 if (printer
->sanitized_device_uri
)
2629 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2630 sizeof(old_device_uri
));
2632 old_device_uri
[0] = '\0';
2634 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2636 cupsdLogMessage(CUPSD_LOG_INFO
,
2637 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2638 printer
->name
, printer
->sanitized_device_uri
,
2644 set_port_monitor
= 0;
2646 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2647 IPP_TAG_NAME
)) != NULL
)
2649 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2652 need_restart_job
= 1;
2654 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2658 for (i
= 0; i
< supported
->num_values
; i
++)
2659 if (!strcmp(supported
->values
[i
].string
.text
,
2660 attr
->values
[0].string
.text
))
2664 if (!supported
|| i
>= supported
->num_values
)
2666 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\""),
2667 attr
->values
[0].string
.text
);
2671 cupsdLogMessage(CUPSD_LOG_INFO
,
2672 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2673 printer
->name
, attr
->values
[0].string
.text
,
2674 printer
->port_monitor
? printer
->port_monitor
: "none");
2676 if (strcmp(attr
->values
[0].string
.text
, "none"))
2677 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2679 cupsdClearString(&printer
->port_monitor
);
2681 set_port_monitor
= 1;
2684 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2685 IPP_TAG_BOOLEAN
)) != NULL
&&
2686 attr
->values
[0].boolean
!= printer
->accepting
)
2688 cupsdLogMessage(CUPSD_LOG_INFO
,
2689 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2690 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2692 printer
->accepting
= attr
->values
[0].boolean
;
2693 cupsdAddPrinterHistory(printer
);
2695 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2696 "%s accepting jobs.",
2697 printer
->accepting
? "Now" : "No longer");
2700 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2701 IPP_TAG_BOOLEAN
)) != NULL
)
2703 if (printer
->shared
&& !attr
->values
[0].boolean
)
2704 cupsdDeregisterPrinter(printer
, 1);
2706 cupsdLogMessage(CUPSD_LOG_INFO
,
2707 "Setting %s printer-is-shared to %d (was %d.)",
2708 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2710 printer
->shared
= attr
->values
[0].boolean
;
2713 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2714 IPP_TAG_ENUM
)) != NULL
)
2716 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2717 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2719 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d"),
2720 attr
->values
[0].integer
);
2724 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2725 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2727 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2728 cupsdStopPrinter(printer
, 0);
2731 need_restart_job
= 1;
2732 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2736 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2737 IPP_TAG_TEXT
)) != NULL
)
2739 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2740 sizeof(printer
->state_message
));
2741 cupsdAddPrinterHistory(printer
);
2743 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2744 printer
->state_message
);
2747 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2748 IPP_TAG_KEYWORD
)) != NULL
)
2750 if (attr
->num_values
>
2751 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2753 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2754 _("Too many printer-state-reasons values (%d > %d)"),
2756 (int)(sizeof(printer
->reasons
) /
2757 sizeof(printer
->reasons
[0])));
2761 for (i
= 0; i
< printer
->num_reasons
; i
++)
2762 _cupsStrFree(printer
->reasons
[i
]);
2764 printer
->num_reasons
= 0;
2765 for (i
= 0; i
< attr
->num_values
; i
++)
2767 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2770 printer
->reasons
[printer
->num_reasons
] =
2771 _cupsStrRetain(attr
->values
[i
].string
.text
);
2772 printer
->num_reasons
++;
2774 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2775 printer
->state
!= IPP_PRINTER_STOPPED
)
2777 cupsdLogMessage(CUPSD_LOG_INFO
,
2778 "Setting %s printer-state to %d (was %d.)",
2779 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2780 cupsdStopPrinter(printer
, 0);
2784 if (PrintcapFormat
== PRINTCAP_PLIST
)
2785 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2787 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2788 "Printer \"%s\" state changed.", printer
->name
);
2791 set_printer_defaults(con
, printer
);
2793 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2794 IPP_TAG_KEYWORD
)) != NULL
)
2795 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2798 * See if we have all required attributes...
2801 if (!printer
->device_uri
)
2802 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2805 * See if we have an interface script or PPD file attached to the request...
2810 need_restart_job
= 1;
2813 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2815 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2818 * Yes; get the first line from it...
2822 cupsFileGets(fp
, line
, sizeof(line
));
2826 * Then see what kind of file it is...
2829 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2832 if (!strncmp(line
, "*PPD-Adobe", 10))
2835 * The new file is a PPD file, so remove any old interface script
2836 * that might be lying around...
2844 * This must be an interface script, so move the file over to the
2845 * interfaces directory and make it executable...
2848 if (copy_file(srcfile
, dstfile
))
2850 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2851 _("Unable to copy interface script - %s"),
2856 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2857 "Copied interface script successfully");
2858 chmod(dstfile
, 0755);
2861 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2864 if (!strncmp(line
, "*PPD-Adobe", 10))
2867 * The new file is a PPD file, so move the file over to the
2868 * ppd directory and make it readable by all...
2871 if (copy_file(srcfile
, dstfile
))
2873 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2874 _("Unable to copy PPD file - %s"),
2879 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2880 "Copied PPD file successfully");
2881 chmod(dstfile
, 0644);
2886 * This must be an interface script, so remove any old PPD file that
2887 * may be lying around...
2894 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2895 IPP_TAG_NAME
)) != NULL
)
2897 need_restart_job
= 1;
2900 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2903 * Raw driver, remove any existing PPD or interface script files.
2906 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2910 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2920 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2924 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2927 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2929 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file"));
2933 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2934 "Copied PPD file successfully");
2935 chmod(dstfile
, 0644);
2942 * If we changed the PPD/interface script, then remove the printer's cache
2943 * file and clear the printer-state-reasons...
2946 char cache_name
[1024]; /* Cache filename for printer attrs */
2948 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp4", CacheDir
,
2952 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.pwg3", CacheDir
,
2956 cupsdSetPrinterReasons(printer
, "none");
2960 * (Re)register color profiles...
2965 apple_unregister_profiles(printer
);
2966 apple_register_profiles(printer
);
2968 #endif /* __APPLE__ */
2972 * If we set the device URI but not the port monitor, check which port
2973 * monitor to use by default...
2976 if (set_device_uri
&& !set_port_monitor
)
2978 ppd_file_t
*ppd
; /* PPD file */
2979 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2982 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2983 sizeof(scheme
), username
, sizeof(username
), host
,
2984 sizeof(host
), &port
, resource
, sizeof(resource
));
2986 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2988 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2990 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2992 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2993 if (!strcmp(scheme
, ppdattr
->spec
))
2995 cupsdLogMessage(CUPSD_LOG_INFO
,
2996 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2997 printer
->name
, ppdattr
->value
,
2998 printer
->port_monitor
? printer
->port_monitor
3001 if (strcmp(ppdattr
->value
, "none"))
3002 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
3004 cupsdClearString(&printer
->port_monitor
);
3014 * Update the printer attributes and return...
3017 cupsdSetPrinterAttrs(printer
);
3018 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3020 if (need_restart_job
&& printer
->job
)
3023 * Restart the current job...
3026 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
3027 "Job restarted because the printer was modified.");
3030 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3034 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
3035 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
3036 printer
->name
, get_username(con
));
3038 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
3039 printer
->name
, get_username(con
));
3043 cupsdAddPrinterHistory(printer
);
3045 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
3046 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
3047 printer
->name
, get_username(con
));
3049 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
3050 printer
->name
, get_username(con
));
3053 con
->response
->request
.status
.status_code
= IPP_OK
;
3058 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
3059 * based upon the printer state...
3063 add_printer_state_reasons(
3064 cupsd_client_t
*con
, /* I - Client connection */
3065 cupsd_printer_t
*p
) /* I - Printer info */
3067 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3068 "add_printer_state_reasons(%p[%d], %p[%s])",
3069 con
, con
->http
.fd
, p
, p
->name
);
3071 if (p
->num_reasons
== 0)
3072 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3073 "printer-state-reasons", NULL
, "none");
3075 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3076 "printer-state-reasons", p
->num_reasons
, NULL
,
3077 (const char * const *)p
->reasons
);
3082 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
3083 * the specified printer or class.
3087 add_queued_job_count(
3088 cupsd_client_t
*con
, /* I - Client connection */
3089 cupsd_printer_t
*p
) /* I - Printer or class */
3091 int count
; /* Number of jobs on destination */
3094 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3095 con
, con
->http
.fd
, p
, p
->name
);
3097 count
= cupsdGetPrinterJobCount(p
->name
);
3099 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3100 "queued-job-count", count
);
3106 * 'apple_init_profile()' - Initialize a color profile.
3111 ppd_file_t
*ppd
, /* I - PPD file */
3112 cups_array_t
*languages
, /* I - Languages in the PPD file */
3113 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3114 unsigned id
, /* I - Profile ID */
3115 const char *name
, /* I - Profile name */
3116 const char *text
, /* I - Profile UI text */
3117 const char *iccfile
) /* I - ICC filename */
3119 char url
[1024]; /* URL for profile filename */
3120 CFMutableDictionaryRef dict
; /* Dictionary for name */
3121 char *language
; /* Current language */
3122 ppd_attr_t
*attr
; /* Profile attribute */
3123 CFStringRef cflang
, /* Language string */
3124 cftext
; /* Localized text */
3128 * Build the profile name dictionary...
3131 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3132 &kCFTypeDictionaryKeyCallBacks
,
3133 &kCFTypeDictionaryValueCallBacks
);
3135 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3136 kCFStringEncodingUTF8
);
3140 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
3147 * Find localized names for the color profiles...
3150 cupsArraySave(ppd
->sorted_attrs
);
3152 for (language
= (char *)cupsArrayFirst(languages
);
3154 language
= (char *)cupsArrayNext(languages
))
3158 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3160 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3163 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3165 if (attr
&& attr
->text
[0])
3167 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3168 kCFStringEncodingUTF8
);
3169 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3170 kCFStringEncodingUTF8
);
3172 if (cflang
&& cftext
)
3173 CFDictionarySetValue(dict
, cflang
, cftext
);
3183 cupsArrayRestore(ppd
->sorted_attrs
);
3187 * Fill in the profile data...
3191 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3194 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3195 profile
->profileID
= id
;
3196 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3197 profile
->profileName
= dict
;
3200 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3201 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3206 * 'apple_register_profiles()' - Register color profiles for a printer.
3210 apple_register_profiles(
3211 cupsd_printer_t
*p
) /* I - Printer */
3213 int i
; /* Looping var */
3214 char ppdfile
[1024], /* PPD filename */
3215 iccfile
[1024], /* ICC filename */
3216 selector
[PPD_MAX_NAME
];
3217 /* Profile selection string */
3218 ppd_file_t
*ppd
; /* PPD file */
3219 ppd_attr_t
*attr
, /* Profile attributes */
3220 *profileid_attr
,/* cupsProfileID attribute */
3221 *q1_attr
, /* ColorModel (or other) qualifier */
3222 *q2_attr
, /* MediaType (or other) qualifier */
3223 *q3_attr
; /* Resolution (or other) qualifier */
3224 char q_keyword
[PPD_MAX_NAME
];
3225 /* Qualifier keyword */
3226 const char *q1_choice
, /* ColorModel (or other) choice */
3227 *q2_choice
, /* MediaType (or other) choice */
3228 *q3_choice
; /* Resolution (or other) choice */
3229 const char *profile_key
; /* Profile keyword */
3230 ppd_option_t
*cm_option
; /* Color model option */
3231 ppd_choice_t
*cm_choice
; /* Color model choice */
3232 int num_profiles
; /* Number of profiles */
3233 CMError error
; /* Last error */
3234 unsigned device_id
, /* Printer device ID */
3235 profile_id
, /* Profile ID */
3236 default_profile_id
= 0;
3237 /* Default profile ID */
3238 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3239 CFStringRef printer_name
; /* Printer name string */
3240 CMDeviceScope scope
= /* Scope of the registration */
3242 kCFPreferencesAnyUser
,
3243 kCFPreferencesCurrentHost
3245 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3246 CMDeviceProfileInfo
*profile
; /* Current profile */
3247 cups_array_t
*languages
; /* Languages array */
3251 * Make sure ColorSync is available...
3254 if (CMRegisterColorDevice
== NULL
)
3258 * Try opening the PPD file for this printer...
3261 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3262 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3266 * See if we have any profiles...
3269 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3270 profile_key
= "APTiogaProfile";
3273 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3274 profile_key
= "cupsICCProfile";
3277 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3278 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3280 if (attr
->value
[0] != '/')
3281 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3284 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3286 if (access(iccfile
, 0))
3294 * If we have profiles, add them...
3297 if (num_profiles
> 0)
3299 if (profile_key
[0] == 'A')
3302 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3306 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3308 default_profile_id
= atoi(attr
->value
);
3310 q1_choice
= q2_choice
= q3_choice
= NULL
;
3315 * For CUPS PPDs, figure out the default profile selector values...
3318 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3319 attr
->value
&& attr
->value
[0])
3321 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3322 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3324 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3325 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3327 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3328 q1_choice
= q1_attr
->value
;
3332 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3333 attr
->value
&& attr
->value
[0])
3335 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3336 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3339 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3341 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3342 q2_choice
= q2_attr
->value
;
3346 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3347 attr
->value
&& attr
->value
[0])
3349 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3350 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3353 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3355 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3356 q3_choice
= q3_attr
->value
;
3362 * Build the array of profiles...
3364 * Note: This calloc actually requests slightly more memory than needed.
3367 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3369 cupsdLogMessage(CUPSD_LOG_ERROR
,
3370 "Unable to allocate memory for %d profiles",
3376 profiles
->profileCount
= num_profiles
;
3377 languages
= _ppdGetLanguages(ppd
);
3379 for (profile
= profiles
->profiles
,
3380 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3382 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3383 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3386 * Add this profile...
3389 if (attr
->value
[0] != '/')
3390 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3393 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3395 if (access(iccfile
, 0))
3398 if (profile_key
[0] == 'c')
3400 cupsArraySave(ppd
->sorted_attrs
);
3402 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3403 attr
->spec
)) != NULL
&&
3404 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3405 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3407 profile_id
= _ppdHashName(attr
->spec
);
3409 cupsArrayRestore(ppd
->sorted_attrs
);
3412 profile_id
= atoi(attr
->spec
);
3414 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3415 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3420 * See if this is the default profile...
3423 if (!default_profile_id
)
3429 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3430 q1_choice
, q2_choice
, q3_choice
);
3431 if (!strcmp(selector
, attr
->spec
))
3432 default_profile_id
= profile_id
;
3435 if (!default_profile_id
)
3437 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3439 if (!strcmp(selector
, attr
->spec
))
3440 default_profile_id
= profile_id
;
3444 if (!default_profile_id
&& q3_choice
)
3446 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3448 if (!strcmp(selector
, attr
->spec
))
3449 default_profile_id
= profile_id
;
3452 if (!default_profile_id
)
3454 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3455 if (!strcmp(selector
, attr
->spec
))
3456 default_profile_id
= profile_id
;
3461 _ppdFreeLanguages(languages
);
3463 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3466 * Extract profiles from ColorModel option...
3469 const char *profile_name
; /* Name of generic profile */
3472 num_profiles
= cm_option
->num_choices
;
3474 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3476 cupsdLogMessage(CUPSD_LOG_ERROR
,
3477 "Unable to allocate memory for %d profiles",
3483 profiles
->profileCount
= num_profiles
;
3485 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3486 cm_choice
= cm_option
->choices
;
3488 i
--, cm_choice
++, profile
++)
3490 if (!strcmp(cm_choice
->choice
, "Gray") ||
3491 !strcmp(cm_choice
->choice
, "Black"))
3492 profile_name
= "Gray";
3493 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3494 !strcmp(cm_choice
->choice
, "CMY"))
3495 profile_name
= "RGB";
3496 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3497 !strcmp(cm_choice
->choice
, "KCMY"))
3498 profile_name
= "CMYK";
3500 profile_name
= "DeviceN";
3502 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3503 profile_id
= _ppdHashName(selector
);
3505 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3506 cm_choice
->text
, NULL
);
3508 if (cm_choice
->marked
)
3509 default_profile_id
= profile_id
;
3515 * Use the default colorspace...
3518 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3520 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3522 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3524 cupsdLogMessage(CUPSD_LOG_ERROR
,
3525 "Unable to allocate memory for %d profiles",
3531 profiles
->profileCount
= num_profiles
;
3533 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3534 "Gray", "Gray", NULL
);
3536 switch (ppd
->colorspace
)
3540 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3541 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3545 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3546 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3554 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3555 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3561 if (num_profiles
> 0)
3564 * Make sure we have a default profile ID...
3567 if (!default_profile_id
)
3568 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3571 * Get the device ID hash and pathelogical name dictionary.
3574 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3577 device_id
= _ppdHashName(p
->name
);
3578 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3579 &kCFTypeDictionaryKeyCallBacks
,
3580 &kCFTypeDictionaryValueCallBacks
);
3581 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3582 p
->name
, kCFStringEncodingUTF8
);
3584 if (device_name
&& printer_name
)
3586 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3589 * Register the device with ColorSync...
3592 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3593 device_name
, &scope
);
3596 * Register the profiles...
3600 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3601 default_profile_id
, profiles
);
3611 cupsdLogMessage(CUPSD_LOG_ERROR
,
3612 "Unable to register ICC color profiles for \"%s\" - %d",
3613 p
->name
, (int)error
);
3615 for (profile
= profiles
->profiles
;
3617 profile
++, num_profiles
--)
3618 CFRelease(profile
->profileName
);
3623 CFRelease(printer_name
);
3626 CFRelease(device_name
);
3634 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3639 apple_unregister_profiles(
3640 cupsd_printer_t
*p
) /* I - Printer */
3643 * Make sure ColorSync is available...
3646 if (CMUnregisterColorDevice
!= NULL
)
3647 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3649 #endif /* __APPLE__ */
3652 * 'apply_printer_defaults()' - Apply printer default options to a job.
3656 apply_printer_defaults(
3657 cupsd_printer_t
*printer
, /* I - Printer */
3658 cupsd_job_t
*job
) /* I - Job */
3660 int i
, /* Looping var */
3661 num_options
; /* Number of default options */
3662 cups_option_t
*options
, /* Default options */
3663 *option
; /* Current option */
3667 * Collect all of the default options and add the missing ones to the
3671 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3672 option
= printer
->options
;
3675 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3677 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3682 * Encode these options as attributes in the job object...
3685 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3686 cupsFreeOptions(num_options
, options
);
3691 * 'authenticate_job()' - Set job authentication info.
3695 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3696 ipp_attribute_t
*uri
) /* I - Job URI */
3698 ipp_attribute_t
*attr
, /* job-id attribute */
3699 *auth_info
; /* auth-info attribute */
3700 int jobid
; /* Job ID */
3701 cupsd_job_t
*job
; /* Current job */
3702 char scheme
[HTTP_MAX_URI
],
3703 /* Method portion of URI */
3704 username
[HTTP_MAX_URI
],
3705 /* Username portion of URI */
3707 /* Host portion of URI */
3708 resource
[HTTP_MAX_URI
];
3709 /* Resource portion of URI */
3710 int port
; /* Port portion of URI */
3713 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3714 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3717 * Start with "everything is OK" status...
3720 con
->response
->request
.status
.status_code
= IPP_OK
;
3723 * See if we have a job URI or a printer URI...
3726 if (!strcmp(uri
->name
, "printer-uri"))
3729 * Got a printer URI; see if we also have a job-id attribute...
3732 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3733 IPP_TAG_INTEGER
)) == NULL
)
3735 send_ipp_status(con
, IPP_BAD_REQUEST
,
3736 _("Got a printer-uri attribute but no job-id"));
3740 jobid
= attr
->values
[0].integer
;
3745 * Got a job URI; parse it to get the job ID...
3748 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3749 sizeof(scheme
), username
, sizeof(username
), host
,
3750 sizeof(host
), &port
, resource
, sizeof(resource
));
3752 if (strncmp(resource
, "/jobs/", 6))
3758 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\""),
3759 uri
->values
[0].string
.text
);
3763 jobid
= atoi(resource
+ 6);
3767 * See if the job exists...
3770 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3773 * Nope - return a "not found" error...
3776 send_ipp_status(con
, IPP_NOT_FOUND
,
3777 _("Job #%d does not exist"), jobid
);
3782 * See if the job has been completed...
3785 if (job
->state_value
!= IPP_JOB_HELD
)
3788 * Return a "not-possible" error...
3791 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3792 _("Job #%d is not held for authentication"),
3798 * See if we have already authenticated...
3801 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3803 if (!con
->username
[0] && !auth_info
)
3805 cupsd_printer_t
*printer
; /* Job destination */
3809 * No auth data. If we need to authenticate via Kerberos, send a
3810 * HTTP auth challenge, otherwise just return an IPP error...
3813 printer
= cupsdFindDest(job
->dest
);
3815 if (printer
&& printer
->num_auth_info_required
> 0 &&
3816 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3817 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3819 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3820 _("No authentication information provided"));
3825 * See if the job is owned by the requesting user...
3828 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3830 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3831 cupsdFindDest(job
->dest
));
3836 * Save the authentication information for this job...
3839 save_auth_info(con
, job
, auth_info
);
3842 * Reset the job-hold-until value to "no-hold"...
3845 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3846 IPP_TAG_KEYWORD
)) == NULL
)
3847 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3851 attr
->value_tag
= IPP_TAG_KEYWORD
;
3852 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3856 * Release the job and return...
3859 cupsdReleaseJob(job
);
3861 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3866 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3870 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3871 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3873 int i
; /* Looping var */
3874 http_status_t status
; /* Policy status */
3875 cups_ptype_t dtype
; /* Destination type */
3876 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3877 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3878 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3879 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3880 int port
; /* Port portion of URI */
3881 ipp_attribute_t
*attr
; /* Attribute in request */
3882 const char *username
= NULL
; /* Username */
3883 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3885 cupsd_printer_t
*printer
; /* Printer */
3886 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3887 cupsd_job_t
*job
; /* Job */
3890 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3891 con
->http
.fd
, uri
->values
[0].string
.text
);
3894 * Get the jobs to cancel/purge...
3897 switch (con
->request
->request
.op
.operation_id
)
3899 case IPP_PURGE_JOBS
:
3901 * Get the username (if any) for the jobs we want to cancel (only if
3902 * "my-jobs" is specified...
3905 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3906 IPP_TAG_BOOLEAN
)) != NULL
&&
3907 attr
->values
[0].boolean
)
3909 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3910 IPP_TAG_NAME
)) != NULL
)
3911 username
= attr
->values
[0].string
.text
;
3914 send_ipp_status(con
, IPP_BAD_REQUEST
,
3915 _("Missing requesting-user-name attribute"));
3921 * Look for the "purge-jobs" attribute...
3924 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3925 IPP_TAG_BOOLEAN
)) != NULL
)
3926 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3928 purge
= CUPSD_JOB_PURGE
;
3931 case IPP_CANCEL_MY_JOBS
:
3932 if (con
->username
[0])
3933 username
= con
->username
;
3934 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3935 IPP_TAG_NAME
)) != NULL
)
3936 username
= attr
->values
[0].string
.text
;
3939 send_ipp_status(con
, IPP_BAD_REQUEST
,
3940 _("Missing requesting-user-name attribute"));
3948 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3951 * See if we have a printer URI...
3954 if (strcmp(uri
->name
, "printer-uri"))
3956 send_ipp_status(con
, IPP_BAD_REQUEST
,
3957 _("The printer-uri attribute is required"));
3962 * And if the destination is valid...
3965 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3971 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3972 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3973 hostname
, sizeof(hostname
), &port
,
3974 resource
, sizeof(resource
));
3976 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3977 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3979 send_ipp_status(con
, IPP_NOT_FOUND
,
3980 _("The printer or class was not found."));
3988 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3990 send_http_error(con
, status
, NULL
);
3996 for (i
= 0; i
< job_ids
->num_values
; i
++)
3998 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
4002 if (i
< job_ids
->num_values
)
4004 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
4005 job_ids
->values
[i
].integer
);
4009 for (i
= 0; i
< job_ids
->num_values
; i
++)
4011 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4013 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4014 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4015 "Job canceled by user.");
4018 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4019 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4025 * Cancel all jobs on all printers...
4028 cupsdCancelJobs(NULL
, username
, purge
);
4030 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
4031 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4041 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4044 send_http_error(con
, status
, printer
);
4050 for (i
= 0; i
< job_ids
->num_values
; i
++)
4052 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
4053 strcasecmp(job
->dest
, printer
->name
))
4057 if (i
< job_ids
->num_values
)
4059 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
4060 job_ids
->values
[i
].integer
);
4064 for (i
= 0; i
< job_ids
->num_values
; i
++)
4066 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4068 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4069 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4070 "Job canceled by user.");
4073 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4074 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4080 * Cancel all of the jobs on the named printer...
4083 cupsdCancelJobs(printer
->name
, username
, purge
);
4085 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
4087 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4092 con
->response
->request
.status
.status_code
= IPP_OK
;
4097 * 'cancel_job()' - Cancel a print job.
4101 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
4102 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4104 ipp_attribute_t
*attr
; /* Current attribute */
4105 int jobid
; /* Job ID */
4106 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4107 username
[HTTP_MAX_URI
], /* Username portion of URI */
4108 host
[HTTP_MAX_URI
], /* Host portion of URI */
4109 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4110 int port
; /* Port portion of URI */
4111 cupsd_job_t
*job
; /* Job information */
4112 cups_ptype_t dtype
; /* Destination type (printer/class) */
4113 cupsd_printer_t
*printer
; /* Printer data */
4114 cupsd_jobaction_t purge
; /* Purge the job? */
4117 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
4118 con
->http
.fd
, uri
->values
[0].string
.text
);
4121 * See if we have a job URI or a printer URI...
4124 if (!strcmp(uri
->name
, "printer-uri"))
4127 * Got a printer URI; see if we also have a job-id attribute...
4130 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4131 IPP_TAG_INTEGER
)) == NULL
)
4133 send_ipp_status(con
, IPP_BAD_REQUEST
,
4134 _("Got a printer-uri attribute but no job-id"));
4138 if ((jobid
= attr
->values
[0].integer
) == 0)
4141 * Find the current job on the specified printer...
4144 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4150 send_ipp_status(con
, IPP_NOT_FOUND
,
4151 _("The printer or class was not found."));
4156 * See if there are any pending jobs...
4159 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4161 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4162 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
4163 !strcasecmp(job
->dest
, printer
->name
))
4171 * No, try stopped jobs...
4174 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4176 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4177 if (job
->state_value
== IPP_JOB_STOPPED
&&
4178 !strcasecmp(job
->dest
, printer
->name
))
4185 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s"),
4195 * Got a job URI; parse it to get the job ID...
4198 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4199 sizeof(scheme
), username
, sizeof(username
), host
,
4200 sizeof(host
), &port
, resource
, sizeof(resource
));
4202 if (strncmp(resource
, "/jobs/", 6))
4208 send_ipp_status(con
, IPP_BAD_REQUEST
,
4209 _("Bad job-uri attribute \"%s\""),
4210 uri
->values
[0].string
.text
);
4214 jobid
= atoi(resource
+ 6);
4218 * Look for the "purge-job" attribute...
4221 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4222 IPP_TAG_BOOLEAN
)) != NULL
)
4223 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4225 purge
= CUPSD_JOB_DEFAULT
;
4228 * See if the job exists...
4231 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4234 * Nope - return a "not found" error...
4237 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
4242 * See if the job is owned by the requesting user...
4245 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4247 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4248 cupsdFindDest(job
->dest
));
4253 * See if the job is already completed, canceled, or aborted; if so,
4254 * we can't cancel...
4257 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4259 switch (job
->state_value
)
4261 case IPP_JOB_CANCELED
:
4262 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4263 _("Job #%d is already canceled - can\'t cancel."),
4267 case IPP_JOB_ABORTED
:
4268 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4269 _("Job #%d is already aborted - can\'t cancel."),
4274 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4275 _("Job #%d is already completed - can\'t cancel."),
4284 * Cancel the job and return...
4287 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4288 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4289 "Job canceled by \"%s\"",
4293 if (purge
== CUPSD_JOB_PURGE
)
4294 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4297 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4300 con
->response
->request
.status
.status_code
= IPP_OK
;
4305 * 'cancel_subscription()' - Cancel a subscription.
4309 cancel_subscription(
4310 cupsd_client_t
*con
, /* I - Client connection */
4311 int sub_id
) /* I - Subscription ID */
4313 http_status_t status
; /* Policy status */
4314 cupsd_subscription_t
*sub
; /* Subscription */
4317 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4318 "cancel_subscription(con=%p[%d], sub_id=%d)",
4319 con
, con
->http
.fd
, sub_id
);
4322 * Is the subscription ID valid?
4325 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4328 * Bad subscription ID...
4331 send_ipp_status(con
, IPP_NOT_FOUND
,
4332 _("notify-subscription-id %d no good"), sub_id
);
4340 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4342 con
, sub
->owner
)) != HTTP_OK
)
4344 send_http_error(con
, status
, sub
->dest
);
4349 * Cancel the subscription...
4352 cupsdDeleteSubscription(sub
, 1);
4354 con
->response
->request
.status
.status_code
= IPP_OK
;
4359 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4362 static int /* O - 1 if OK, 0 if not */
4363 check_rss_recipient(
4364 const char *recipient
) /* I - Recipient URI */
4366 cupsd_subscription_t
*sub
; /* Current subscription */
4369 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4371 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4375 * Compare the URIs up to the first ?...
4378 const char *r1
, *r2
;
4380 for (r1
= recipient
, r2
= sub
->recipient
;
4381 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4393 * 'check_quotas()' - Check quotas for a printer and user.
4396 static int /* O - 1 if OK, 0 if forbidden,
4397 -1 if limit reached */
4398 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4399 cupsd_printer_t
*p
) /* I - Printer or class */
4401 char username
[33], /* Username */
4402 *name
; /* Current user name */
4403 cupsd_quota_t
*q
; /* Quota data */
4404 #ifdef HAVE_MBR_UID_TO_UUID
4406 * Use Apple membership APIs which require that all names represent
4407 * valid user account or group records accessible by the server.
4410 uuid_t usr_uuid
; /* UUID for job requesting user */
4411 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4412 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4413 int mbr_err
; /* Error from membership function */
4414 int is_member
; /* Is this user a member? */
4417 * Use standard POSIX APIs for checking users and groups...
4420 struct passwd
*pw
; /* User password data */
4421 #endif /* HAVE_MBR_UID_TO_UUID */
4424 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4425 con
, con
->http
.fd
, p
, p
->name
);
4428 * Figure out who is printing...
4431 strlcpy(username
, get_username(con
), sizeof(username
));
4434 * Check global active job limits for printers and users...
4437 if (MaxJobsPerPrinter
)
4440 * Check if there are too many pending jobs on this printer...
4443 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4445 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4454 * Check if there are too many pending jobs for this user...
4457 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4459 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4466 * Check against users...
4469 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4472 if (cupsArrayCount(p
->users
))
4474 #ifdef HAVE_MBR_UID_TO_UUID
4476 * Get UUID for job requesting user...
4479 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4485 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4486 "check_quotas: UUID lookup failed for user \"%s\"",
4488 cupsdLogMessage(CUPSD_LOG_INFO
,
4489 "Denying user \"%s\" access to printer \"%s\" "
4490 "(unknown user)...",
4496 * Get UID and GID of requesting user...
4499 pw
= getpwnam(username
);
4501 #endif /* HAVE_MBR_UID_TO_UUID */
4503 for (name
= (char *)cupsArrayFirst(p
->users
);
4505 name
= (char *)cupsArrayNext(p
->users
))
4509 * Check group membership...
4512 #ifdef HAVE_MBR_UID_TO_UUID
4515 if (uuid_parse(name
+ 2, grp_uuid
))
4516 uuid_clear(grp_uuid
);
4518 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
4521 * Invalid ACL entries are ignored for matching; just record a
4522 * warning in the log...
4525 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4526 "check_quotas: UUID lookup failed for ACL entry "
4527 "\"%s\" (err=%d)", name
, mbr_err
);
4528 cupsdLogMessage(CUPSD_LOG_WARN
,
4529 "Access control entry \"%s\" not a valid group name; "
4530 "entry ignored", name
);
4533 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4537 * At this point, there should be no errors, but check anyways...
4540 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4541 "check_quotas: group \"%s\" membership check "
4542 "failed (err=%d)", name
+ 1, mbr_err
);
4547 * Stop if we found a match...
4554 if (cupsdCheckGroup(username
, pw
, name
+ 1))
4556 #endif /* HAVE_MBR_UID_TO_UUID */
4558 #ifdef HAVE_MBR_UID_TO_UUID
4563 if (uuid_parse(name
+ 1, usr2_uuid
))
4564 uuid_clear(usr2_uuid
);
4566 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
4569 * Invalid ACL entries are ignored for matching; just record a
4570 * warning in the log...
4573 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4574 "check_quotas: UUID lookup failed for ACL entry "
4575 "\"%s\" (err=%d)", name
, mbr_err
);
4576 cupsdLogMessage(CUPSD_LOG_WARN
,
4577 "Access control entry \"%s\" not a valid user name; "
4578 "entry ignored", name
);
4581 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4585 else if (!strcasecmp(username
, name
))
4587 #endif /* HAVE_MBR_UID_TO_UUID */
4589 if ((name
!= NULL
) == p
->deny_users
)
4591 cupsdLogMessage(CUPSD_LOG_INFO
,
4592 "Denying user \"%s\" access to printer \"%s\"...",
4602 if (p
->k_limit
|| p
->page_limit
)
4604 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4606 cupsdLogMessage(CUPSD_LOG_ERROR
,
4607 "Unable to allocate quota data for user \"%s\"",
4612 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4613 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4615 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4622 * If we have gotten this far, we're done!
4630 * 'close_job()' - Close a multi-file job.
4634 close_job(cupsd_client_t
*con
, /* I - Client connection */
4635 ipp_attribute_t
*uri
) /* I - Printer URI */
4637 cupsd_job_t
*job
; /* Job */
4638 ipp_attribute_t
*attr
; /* Attribute */
4639 char job_uri
[HTTP_MAX_URI
],
4641 username
[256]; /* User name */
4644 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4645 con
->http
.fd
, uri
->values
[0].string
.text
);
4648 * See if we have a job URI or a printer URI...
4651 if (strcmp(uri
->name
, "printer-uri"))
4654 * job-uri is not supported by Close-Job!
4657 send_ipp_status(con
, IPP_BAD_REQUEST
,
4658 _("Close-Job doesn't support the job-uri attribute."));
4663 * Got a printer URI; see if we also have a job-id attribute...
4666 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4667 IPP_TAG_INTEGER
)) == NULL
)
4669 send_ipp_status(con
, IPP_BAD_REQUEST
,
4670 _("Got a printer-uri attribute but no job-id"));
4674 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4677 * Nope - return a "not found" error...
4680 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
4681 attr
->values
[0].integer
);
4686 * See if the job is owned by the requesting user...
4689 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4691 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4692 cupsdFindDest(job
->dest
));
4697 * Add any ending sheet...
4700 if (cupsdTimeoutJob(job
))
4703 if (job
->state_value
== IPP_JOB_STOPPED
)
4705 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4706 job
->state_value
= IPP_JOB_PENDING
;
4708 else if (job
->state_value
== IPP_JOB_HELD
)
4710 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4711 IPP_TAG_KEYWORD
)) == NULL
)
4712 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4714 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
4716 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4717 job
->state_value
= IPP_JOB_PENDING
;
4722 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
4725 * Fill in the response info...
4728 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
4729 LocalPort
, job
->id
);
4730 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4733 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4735 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4738 add_job_state_reasons(con
, job
);
4740 con
->response
->request
.status
.status_code
= IPP_OK
;
4743 * Start the job if necessary...
4751 * 'copy_attribute()' - Copy a single attribute.
4754 static ipp_attribute_t
* /* O - New attribute */
4756 ipp_t
*to
, /* O - Destination request/response */
4757 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4758 int quickcopy
) /* I - Do a quick copy? */
4760 int i
; /* Looping var */
4761 ipp_attribute_t
*toattr
; /* Destination attribute */
4764 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4765 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4766 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4769 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4772 toattr
= ippAddSeparator(to
);
4775 case IPP_TAG_INTEGER
:
4777 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4778 attr
->name
, attr
->num_values
, NULL
);
4780 for (i
= 0; i
< attr
->num_values
; i
++)
4781 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4784 case IPP_TAG_BOOLEAN
:
4785 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4786 attr
->num_values
, NULL
);
4788 for (i
= 0; i
< attr
->num_values
; i
++)
4789 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4792 case IPP_TAG_STRING
:
4795 case IPP_TAG_KEYWORD
:
4797 case IPP_TAG_URISCHEME
:
4798 case IPP_TAG_CHARSET
:
4799 case IPP_TAG_LANGUAGE
:
4800 case IPP_TAG_MIMETYPE
:
4801 toattr
= ippAddStrings(to
, attr
->group_tag
,
4802 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4803 attr
->name
, attr
->num_values
, NULL
, NULL
);
4807 for (i
= 0; i
< attr
->num_values
; i
++)
4808 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4810 else if (attr
->value_tag
& IPP_TAG_COPY
)
4812 for (i
= 0; i
< attr
->num_values
; i
++)
4813 toattr
->values
[i
].string
.text
=
4814 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4818 for (i
= 0; i
< attr
->num_values
; i
++)
4819 toattr
->values
[i
].string
.text
=
4820 _cupsStrRetain(attr
->values
[i
].string
.text
);
4825 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4826 attr
->values
[0].date
);
4829 case IPP_TAG_RESOLUTION
:
4830 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4831 attr
->num_values
, IPP_RES_PER_INCH
,
4834 for (i
= 0; i
< attr
->num_values
; i
++)
4836 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4837 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4838 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4842 case IPP_TAG_RANGE
:
4843 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4844 attr
->num_values
, NULL
, NULL
);
4846 for (i
= 0; i
< attr
->num_values
; i
++)
4848 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4849 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4853 case IPP_TAG_TEXTLANG
:
4854 case IPP_TAG_NAMELANG
:
4855 toattr
= ippAddStrings(to
, attr
->group_tag
,
4856 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4857 attr
->name
, attr
->num_values
, NULL
, NULL
);
4861 for (i
= 0; i
< attr
->num_values
; i
++)
4863 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4864 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4867 else if (attr
->value_tag
& IPP_TAG_COPY
)
4869 for (i
= 0; i
< attr
->num_values
; i
++)
4872 toattr
->values
[i
].string
.charset
=
4873 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4875 toattr
->values
[i
].string
.charset
=
4876 toattr
->values
[0].string
.charset
;
4878 toattr
->values
[i
].string
.text
=
4879 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4884 for (i
= 0; i
< attr
->num_values
; i
++)
4887 toattr
->values
[i
].string
.charset
=
4888 _cupsStrRetain(attr
->values
[i
].string
.charset
);
4890 toattr
->values
[i
].string
.charset
=
4891 toattr
->values
[0].string
.charset
;
4893 toattr
->values
[i
].string
.text
=
4894 _cupsStrRetain(attr
->values
[i
].string
.text
);
4899 case IPP_TAG_BEGIN_COLLECTION
:
4900 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4901 attr
->num_values
, NULL
);
4903 for (i
= 0; i
< attr
->num_values
; i
++)
4905 toattr
->values
[i
].collection
= attr
->values
[i
].collection
;
4906 attr
->values
[i
].collection
->use
++;
4911 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4912 attr
->name
, attr
->num_values
, NULL
);
4914 for (i
= 0; i
< attr
->num_values
; i
++)
4916 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4918 if (toattr
->values
[i
].unknown
.length
> 0)
4920 if ((toattr
->values
[i
].unknown
.data
=
4921 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4922 toattr
->values
[i
].unknown
.length
= 0;
4924 memcpy(toattr
->values
[i
].unknown
.data
,
4925 attr
->values
[i
].unknown
.data
,
4926 toattr
->values
[i
].unknown
.length
);
4929 break; /* anti-compiler-warning-code */
4937 * 'copy_attrs()' - Copy attributes from one request to another.
4941 copy_attrs(ipp_t
*to
, /* I - Destination request */
4942 ipp_t
*from
, /* I - Source request */
4943 cups_array_t
*ra
, /* I - Requested attributes */
4944 ipp_tag_t group
, /* I - Group to copy */
4945 int quickcopy
, /* I - Do a quick copy? */
4946 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4948 ipp_attribute_t
*fromattr
; /* Source attribute */
4951 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4952 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4953 to
, from
, ra
, group
, quickcopy
);
4958 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4961 * Filter attributes as needed...
4964 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4965 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4969 (cupsArrayFind(exclude
, fromattr
->name
) ||
4970 cupsArrayFind(exclude
, "all")))
4973 * We need to exclude this attribute for security reasons; we require the
4974 * job-id and job-printer-uri attributes regardless of the security
4975 * settings for IPP conformance.
4977 * Subscription attribute security is handled by copy_subscription_attrs().
4980 if (strcmp(fromattr
->name
, "job-id") &&
4981 strcmp(fromattr
->name
, "job-printer-uri"))
4985 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4988 * Don't send collection attributes by default to IPP/1.x clients
4989 * since many do not support collections. Also don't send
4990 * media-col-database unless specifically requested by the client.
4993 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4995 (to
->request
.status
.version
[0] == 1 ||
4996 !strcmp(fromattr
->name
, "media-col-database")))
4999 copy_attribute(to
, fromattr
, quickcopy
);
5006 * 'copy_banner()' - Copy a banner file to the requests directory for the
5010 static int /* O - Size of banner file in kbytes */
5011 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
5012 cupsd_job_t
*job
, /* I - Job information */
5013 const char *name
) /* I - Name of banner */
5015 int i
; /* Looping var */
5016 int kbytes
; /* Size of banner file in kbytes */
5017 char filename
[1024]; /* Job filename */
5018 cupsd_banner_t
*banner
; /* Pointer to banner */
5019 cups_file_t
*in
; /* Input file */
5020 cups_file_t
*out
; /* Output file */
5021 int ch
; /* Character from file */
5022 char attrname
[255], /* Name of attribute */
5023 *s
; /* Pointer into name */
5024 ipp_attribute_t
*attr
; /* Attribute */
5027 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5028 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
5029 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
5030 name
? name
: "(null)");
5033 * Find the banner; return if not found or "none"...
5036 if (!name
|| !strcmp(name
, "none") ||
5037 (banner
= cupsdFindBanner(name
)) == NULL
)
5041 * Open the banner and job files...
5044 if (add_file(con
, job
, banner
->filetype
, 0))
5047 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
5049 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
5051 cupsdLogMessage(CUPSD_LOG_ERROR
,
5052 "Unable to create banner job file %s - %s",
5053 filename
, strerror(errno
));
5058 fchmod(cupsFileNumber(out
), 0640);
5059 fchown(cupsFileNumber(out
), RunUser
, Group
);
5062 * Try the localized banner file under the subdirectory...
5065 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5067 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5070 * Convert ll-cc to ll_CC...
5074 attrname
[3] = toupper(attrname
[3] & 255);
5075 attrname
[4] = toupper(attrname
[4] & 255);
5078 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5081 if (access(filename
, 0) && strlen(attrname
) > 2)
5084 * Wasn't able to find "ll_CC" locale file; try the non-national
5085 * localization banner directory.
5090 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5094 if (access(filename
, 0))
5097 * Use the non-localized banner file.
5100 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5103 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5107 cupsdLogMessage(CUPSD_LOG_ERROR
,
5108 "Unable to open banner template file %s - %s",
5109 filename
, strerror(errno
));
5115 * Parse the file to the end...
5118 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5122 * Get an attribute name...
5125 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5126 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5128 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5138 * Ignore { followed by stuff that is not an attribute name...
5141 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5146 * See if it is defined...
5149 if (attrname
[0] == '?')
5154 if (!strcmp(s
, "printer-name"))
5156 cupsFilePuts(out
, job
->dest
);
5159 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5162 * See if we have a leading question mark...
5165 if (attrname
[0] != '?')
5168 * Nope, write to file as-is; probably a PostScript procedure...
5171 cupsFilePrintf(out
, "{%s}", attrname
);
5178 * Output value(s)...
5181 for (i
= 0; i
< attr
->num_values
; i
++)
5184 cupsFilePutChar(out
, ',');
5186 switch (attr
->value_tag
)
5188 case IPP_TAG_INTEGER
:
5190 if (!strncmp(s
, "time-at-", 8))
5192 struct timeval tv
= { attr
->values
[i
].integer
, 0 };
5193 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5196 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5199 case IPP_TAG_BOOLEAN
:
5200 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5203 case IPP_TAG_NOVALUE
:
5204 cupsFilePuts(out
, "novalue");
5207 case IPP_TAG_RANGE
:
5208 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5209 attr
->values
[i
].range
.upper
);
5212 case IPP_TAG_RESOLUTION
:
5213 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5214 attr
->values
[i
].resolution
.yres
,
5215 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5220 case IPP_TAG_STRING
:
5223 case IPP_TAG_KEYWORD
:
5224 case IPP_TAG_CHARSET
:
5225 case IPP_TAG_LANGUAGE
:
5226 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
5229 * Need to quote strings for PS banners...
5234 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5236 if (*p
== '(' || *p
== ')' || *p
== '\\')
5238 cupsFilePutChar(out
, '\\');
5239 cupsFilePutChar(out
, *p
);
5241 else if (*p
< 32 || *p
> 126)
5242 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5244 cupsFilePutChar(out
, *p
);
5248 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5252 break; /* anti-compiler-warning-code */
5256 else if (ch
== '\\') /* Quoted char */
5258 ch
= cupsFileGetChar(in
);
5260 if (ch
!= '{') /* Only do special handling for \{ */
5261 cupsFilePutChar(out
, '\\');
5263 cupsFilePutChar(out
, ch
);
5266 cupsFilePutChar(out
, ch
);
5270 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5272 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5273 IPP_TAG_INTEGER
)) != NULL
)
5274 attr
->values
[0].integer
+= kbytes
;
5283 * 'copy_file()' - Copy a PPD file or interface script...
5286 static int /* O - 0 = success, -1 = error */
5287 copy_file(const char *from
, /* I - Source file */
5288 const char *to
) /* I - Destination file */
5290 cups_file_t
*src
, /* Source file */
5291 *dst
; /* Destination file */
5292 int bytes
; /* Bytes to read/write */
5293 char buffer
[2048]; /* Copy buffer */
5296 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5299 * Open the source and destination file for a copy...
5302 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5305 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5312 * Copy the source file to the destination...
5315 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5316 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5324 * Close both files and return...
5329 return (cupsFileClose(dst
));
5334 * 'copy_model()' - Copy a PPD model file, substituting default values
5338 static int /* O - 0 = success, -1 = error */
5339 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5340 const char *from
, /* I - Source file */
5341 const char *to
) /* I - Destination file */
5343 fd_set input
; /* select() input set */
5344 struct timeval timeout
; /* select() timeout */
5345 int maxfd
; /* Max file descriptor for select() */
5346 char tempfile
[1024]; /* Temporary PPD file */
5347 int tempfd
; /* Temporary PPD file descriptor */
5348 int temppid
; /* Process ID of cups-driverd */
5349 int temppipe
[2]; /* Temporary pipes */
5350 char *argv
[4], /* Command-line arguments */
5351 *envp
[MAX_ENV
]; /* Environment */
5352 cups_file_t
*src
, /* Source file */
5353 *dst
; /* Destination file */
5354 ppd_file_t
*ppd
; /* PPD file */
5355 int bytes
, /* Bytes from pipe */
5356 total
; /* Total bytes from pipe */
5357 char buffer
[2048]; /* Copy buffer */
5358 int i
; /* Looping var */
5359 char option
[PPD_MAX_NAME
], /* Option name */
5360 choice
[PPD_MAX_NAME
]; /* Choice name */
5361 ppd_size_t
*size
; /* Default size */
5362 int num_defaults
; /* Number of default options */
5363 cups_option_t
*defaults
; /* Default options */
5364 char cups_protocol
[PPD_MAX_LINE
];
5365 /* cupsProtocol attribute */
5368 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5369 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5373 * Run cups-driverd to get the PPD file...
5376 argv
[0] = "cups-driverd";
5378 argv
[2] = (char *)from
;
5381 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5383 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5384 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5385 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5389 cupsdOpenPipe(temppipe
);
5391 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5392 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5394 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5395 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5406 * Wait up to 30 seconds for the PPD file to be copied...
5411 if (temppipe
[0] > CGIPipes
[0])
5412 maxfd
= temppipe
[0] + 1;
5414 maxfd
= CGIPipes
[0] + 1;
5419 * See if we have data ready...
5423 FD_SET(temppipe
[0], &input
);
5424 FD_SET(CGIPipes
[0], &input
);
5426 timeout
.tv_sec
= 30;
5427 timeout
.tv_usec
= 0;
5429 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5439 * We have timed out...
5445 if (FD_ISSET(temppipe
[0], &input
))
5448 * Read the PPD file from the pipe, and write it to the PPD file.
5451 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5453 if (write(tempfd
, buffer
, bytes
) < bytes
)
5462 if (FD_ISSET(CGIPipes
[0], &input
))
5472 * No data from cups-deviced...
5475 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5481 * Read the source file and see what page sizes are supported...
5484 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5491 * Open the destination (if possible) and set the default options...
5496 cups_protocol
[0] = '\0';
5498 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5501 * Read all of the default lines from the old PPD...
5504 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5505 if (!strncmp(buffer
, "*Default", 8))
5508 * Add the default option...
5511 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5512 choice
, sizeof(choice
)))
5514 ppd_option_t
*ppdo
; /* PPD option */
5518 * Only add the default if the default hasn't already been
5519 * set and the choice exists in the new PPD...
5522 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5523 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5524 ppdFindChoice(ppdo
, choice
))
5525 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5529 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5530 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5534 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5537 * Add the default media sizes...
5540 num_defaults
= cupsAddOption("PageSize", size
->name
,
5541 num_defaults
, &defaults
);
5542 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5543 num_defaults
, &defaults
);
5544 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5545 num_defaults
, &defaults
);
5546 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5547 num_defaults
, &defaults
);
5553 * Open the source file for a copy...
5556 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5558 cupsFreeOptions(num_defaults
, defaults
);
5564 * Open the destination file for a copy...
5567 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5569 cupsFreeOptions(num_defaults
, defaults
);
5576 * Copy the source file to the destination...
5579 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5581 if (!strncmp(buffer
, "*Default", 8))
5584 * Check for an previous default option choice...
5587 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5588 choice
, sizeof(choice
)))
5590 const char *val
; /* Default option value */
5593 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5596 * Substitute the previous choice...
5599 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5604 cupsFilePrintf(dst
, "%s\n", buffer
);
5607 if (cups_protocol
[0])
5608 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5610 cupsFreeOptions(num_defaults
, defaults
);
5613 * Close both files and return...
5620 return (cupsFileClose(dst
));
5625 * 'copy_job_attrs()' - Copy job attributes.
5629 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5630 cupsd_job_t
*job
, /* I - Job */
5631 cups_array_t
*ra
, /* I - Requested attributes array */
5632 cups_array_t
*exclude
) /* I - Private attributes array */
5634 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5638 * Send the requested attributes for each job...
5641 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5642 con
->servername
, con
->serverport
, "/jobs/%d",
5645 if (!cupsArrayFind(exclude
, "all"))
5647 if ((!exclude
|| !cupsArrayFind(exclude
, "document-count")) &&
5648 (!ra
|| cupsArrayFind(ra
, "document-count")))
5649 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5650 "document-count", job
->num_files
);
5652 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
5653 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
5654 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5655 "job-media-progress", job
->progress
);
5657 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
5658 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
5659 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5660 "job-more-info", NULL
, job_uri
);
5662 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5663 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
5664 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5665 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5666 job
->num_files
> 0);
5668 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
5669 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
5670 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5671 "job-printer-up-time", time(NULL
));
5674 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5675 add_job_state_reasons(con
, job
);
5677 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5678 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5679 "job-uri", NULL
, job_uri
);
5681 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
5686 * 'copy_printer_attrs()' - Copy printer attributes.
5691 cupsd_client_t
*con
, /* I - Client connection */
5692 cupsd_printer_t
*printer
, /* I - Printer */
5693 cups_array_t
*ra
) /* I - Requested attributes array */
5695 char printer_uri
[HTTP_MAX_URI
];
5697 char printer_icons
[HTTP_MAX_URI
];
5699 time_t curtime
; /* Current time */
5700 int i
; /* Looping var */
5701 ipp_attribute_t
*history
; /* History collection */
5705 * Copy the printer attributes to the response using requested-attributes
5706 * and document-format attributes that may be provided by the client.
5709 curtime
= time(NULL
);
5711 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5712 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5713 "marker-change-time", printer
->marker_time
);
5715 if (printer
->num_printers
> 0 &&
5716 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5718 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5719 cupsd_printer_t
*p2
; /* Printer in class */
5720 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5723 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5724 IPP_TAG_URI
, "member-uris",
5725 printer
->num_printers
, NULL
,
5728 for (i
= 0; i
< printer
->num_printers
; i
++)
5730 p2
= printer
->printers
[i
];
5732 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5733 IPP_TAG_URI
)) != NULL
)
5734 member_uris
->values
[i
].string
.text
=
5735 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5738 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5739 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5741 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5742 "/classes/%s" : "/printers/%s", p2
->name
);
5743 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5749 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5750 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5751 "printer-alert", NULL
, printer
->alert
);
5753 if (printer
->alert_description
&&
5754 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5755 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5756 "printer-alert-description", NULL
,
5757 printer
->alert_description
);
5759 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5760 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5761 ippTimeToDate(curtime
));
5764 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5766 if (printer
->reg_name
)
5767 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5768 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5770 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5771 "printer-dns-sd-name", 0);
5773 #endif /* HAVE_DNSSD */
5775 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5776 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5777 "printer-error-policy", NULL
, printer
->error_policy
);
5779 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
5781 static const char * const errors
[] =/* printer-error-policy-supported values */
5784 "retry-current-job",
5789 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
5790 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5791 "printer-error-policy-supported", NULL
, "retry-current-job");
5793 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5794 "printer-error-policy-supported",
5795 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
5798 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
5800 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
5801 "http", NULL
, con
->servername
, con
->serverport
,
5802 "/icons/%s.png", printer
->name
);
5803 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
5804 NULL
, printer_icons
);
5805 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
5808 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5809 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5810 printer
->accepting
);
5812 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5813 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5816 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5817 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5819 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5820 "http", NULL
, con
->servername
, con
->serverport
,
5821 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5822 "/classes/%s" : "/printers/%s", printer
->name
);
5823 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5824 "printer-more-info", NULL
, printer_uri
);
5827 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5828 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5829 "printer-op-policy", NULL
, printer
->op_policy
);
5831 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5832 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5835 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5836 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5837 "printer-state-change-time", printer
->state_time
);
5839 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5840 cupsArrayFind(ra
, "printer-state-history"))
5843 * Printer history is only sent if specifically requested, so that
5844 * older CUPS/IPP clients won't barf on the collection attributes.
5847 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5848 "printer-state-history",
5849 printer
->num_history
, NULL
);
5851 for (i
= 0; i
< printer
->num_history
; i
++)
5852 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5853 NULL
, IPP_TAG_ZERO
, 0, NULL
);
5856 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5857 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5858 "printer-state-message", NULL
, printer
->state_message
);
5860 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5861 add_printer_state_reasons(con
, printer
);
5863 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5865 int type
; /* printer-type value */
5869 * Add the CUPS-specific printer-type attribute...
5872 type
= printer
->type
;
5874 if (printer
== DefaultPrinter
)
5875 type
|= CUPS_PRINTER_DEFAULT
;
5877 if (!printer
->accepting
)
5878 type
|= CUPS_PRINTER_REJECTING
;
5880 if (!printer
->shared
)
5881 type
|= CUPS_PRINTER_NOT_SHARED
;
5883 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5887 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5888 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5889 "printer-up-time", curtime
);
5891 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5892 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5894 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5895 "ipp", NULL
, con
->servername
, con
->serverport
,
5896 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5897 "/classes/%s" : "/printers/%s", printer
->name
);
5898 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5899 "printer-uri-supported", NULL
, printer_uri
);
5900 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5904 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5905 add_queued_job_count(con
, printer
);
5907 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5908 if (printer
->ppd_attrs
)
5909 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5910 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5915 * 'copy_subscription_attrs()' - Copy subscription attributes.
5919 copy_subscription_attrs(
5920 cupsd_client_t
*con
, /* I - Client connection */
5921 cupsd_subscription_t
*sub
, /* I - Subscription */
5922 cups_array_t
*ra
, /* I - Requested attributes array */
5923 cups_array_t
*exclude
) /* I - Private attributes array */
5925 ipp_attribute_t
*attr
; /* Current attribute */
5926 char printer_uri
[HTTP_MAX_URI
];
5928 int count
; /* Number of events */
5929 unsigned mask
; /* Current event mask */
5930 const char *name
; /* Current event name */
5933 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5934 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5935 con
, sub
, ra
, exclude
);
5938 * Copy the subscription attributes to the response using the
5939 * requested-attributes attribute that may be provided by the client.
5942 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5944 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5945 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5947 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5949 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5952 * Simple event list...
5955 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5956 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5957 "notify-events", NULL
, name
);
5962 * Complex event list...
5965 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5966 if (sub
->mask
& mask
)
5969 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5970 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5971 "notify-events", count
, NULL
, NULL
);
5973 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5974 if (sub
->mask
& mask
)
5976 attr
->values
[count
].string
.text
=
5977 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5984 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5985 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5986 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5987 "notify-lease-duration", sub
->lease
);
5989 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5990 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5991 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5992 "notify-recipient-uri", NULL
, sub
->recipient
);
5993 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5994 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5995 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5996 "notify-pull-method", NULL
, "ippget");
5998 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5999 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
6000 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
6001 "notify-subscriber-user-name", NULL
, sub
->owner
);
6003 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
6004 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
6005 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6006 "notify-time-interval", sub
->interval
);
6008 if (sub
->user_data_len
> 0 &&
6009 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
6010 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
6011 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
6012 sub
->user_data
, sub
->user_data_len
);
6015 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
6016 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6017 "notify-job-id", sub
->job
->id
);
6019 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
6021 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6022 "ipp", NULL
, con
->servername
, con
->serverport
,
6023 "/printers/%s", sub
->dest
->name
);
6024 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6025 "notify-printer-uri", NULL
, printer_uri
);
6028 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
6029 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6030 "notify-subscription-id", sub
->id
);
6035 * 'create_job()' - Print a file to a printer or class.
6039 create_job(cupsd_client_t
*con
, /* I - Client connection */
6040 ipp_attribute_t
*uri
) /* I - Printer URI */
6042 cupsd_printer_t
*printer
; /* Printer */
6043 cupsd_job_t
*job
; /* New job */
6046 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
6047 con
->http
.fd
, uri
->values
[0].string
.text
);
6050 * Is the destination valid?
6053 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6059 send_ipp_status(con
, IPP_NOT_FOUND
,
6060 _("The printer or class was not found."));
6065 * Create the job object...
6068 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6071 job
->pending_timeout
= 1;
6074 * Save and log the job...
6077 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6078 job
->dest
, job
->username
);
6083 * 'create_requested_array()' - Create an array for the requested-attributes.
6086 static cups_array_t
* /* O - Array of attributes or NULL */
6087 create_requested_array(ipp_t
*request
) /* I - IPP request */
6089 int i
; /* Looping var */
6090 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6091 cups_array_t
*ra
; /* Requested attributes array */
6092 char *value
; /* Current value */
6096 * Get the requested-attributes attribute, and return NULL if we don't
6100 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6101 IPP_TAG_KEYWORD
)) == NULL
)
6105 * If the attribute contains a single "all" keyword, return NULL...
6108 if (requested
->num_values
== 1 &&
6109 !strcmp(requested
->values
[0].string
.text
, "all"))
6113 * Create an array using "strcmp" as the comparison function...
6116 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6118 for (i
= 0; i
< requested
->num_values
; i
++)
6120 value
= requested
->values
[i
].string
.text
;
6122 if (!strcmp(value
, "job-template"))
6124 cupsArrayAdd(ra
, "copies");
6125 cupsArrayAdd(ra
, "copies-default");
6126 cupsArrayAdd(ra
, "copies-supported");
6127 cupsArrayAdd(ra
, "finishings");
6128 cupsArrayAdd(ra
, "finishings-default");
6129 cupsArrayAdd(ra
, "finishings-supported");
6130 cupsArrayAdd(ra
, "job-hold-until");
6131 cupsArrayAdd(ra
, "job-hold-until-default");
6132 cupsArrayAdd(ra
, "job-hold-until-supported");
6133 cupsArrayAdd(ra
, "job-priority");
6134 cupsArrayAdd(ra
, "job-priority-default");
6135 cupsArrayAdd(ra
, "job-priority-supported");
6136 cupsArrayAdd(ra
, "job-sheets");
6137 cupsArrayAdd(ra
, "job-sheets-default");
6138 cupsArrayAdd(ra
, "job-sheets-supported");
6139 cupsArrayAdd(ra
, "media");
6140 cupsArrayAdd(ra
, "media-default");
6141 cupsArrayAdd(ra
, "media-supported");
6142 cupsArrayAdd(ra
, "multiple-document-handling");
6143 cupsArrayAdd(ra
, "multiple-document-handling-default");
6144 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6145 cupsArrayAdd(ra
, "number-up");
6146 cupsArrayAdd(ra
, "number-up-default");
6147 cupsArrayAdd(ra
, "number-up-supported");
6148 cupsArrayAdd(ra
, "orientation-requested");
6149 cupsArrayAdd(ra
, "orientation-requested-default");
6150 cupsArrayAdd(ra
, "orientation-requested-supported");
6151 cupsArrayAdd(ra
, "page-ranges");
6152 cupsArrayAdd(ra
, "page-ranges-supported");
6153 cupsArrayAdd(ra
, "printer-resolution");
6154 cupsArrayAdd(ra
, "printer-resolution-default");
6155 cupsArrayAdd(ra
, "printer-resolution-supported");
6156 cupsArrayAdd(ra
, "print-quality");
6157 cupsArrayAdd(ra
, "print-quality-default");
6158 cupsArrayAdd(ra
, "print-quality-supported");
6159 cupsArrayAdd(ra
, "sides");
6160 cupsArrayAdd(ra
, "sides-default");
6161 cupsArrayAdd(ra
, "sides-supported");
6163 else if (!strcmp(value
, "job-description"))
6165 cupsArrayAdd(ra
, "date-time-at-completed");
6166 cupsArrayAdd(ra
, "date-time-at-creation");
6167 cupsArrayAdd(ra
, "date-time-at-processing");
6168 cupsArrayAdd(ra
, "job-detailed-status-message");
6169 cupsArrayAdd(ra
, "job-document-access-errors");
6170 cupsArrayAdd(ra
, "job-id");
6171 cupsArrayAdd(ra
, "job-impressions");
6172 cupsArrayAdd(ra
, "job-impressions-completed");
6173 cupsArrayAdd(ra
, "job-k-octets");
6174 cupsArrayAdd(ra
, "job-k-octets-processed");
6175 cupsArrayAdd(ra
, "job-media-progress");
6176 cupsArrayAdd(ra
, "job-media-sheets");
6177 cupsArrayAdd(ra
, "job-media-sheets-completed");
6178 cupsArrayAdd(ra
, "job-message-from-operator");
6179 cupsArrayAdd(ra
, "job-more-info");
6180 cupsArrayAdd(ra
, "job-name");
6181 cupsArrayAdd(ra
, "job-originating-user-name");
6182 cupsArrayAdd(ra
, "job-printer-up-time");
6183 cupsArrayAdd(ra
, "job-printer-uri");
6184 cupsArrayAdd(ra
, "job-state");
6185 cupsArrayAdd(ra
, "job-state-message");
6186 cupsArrayAdd(ra
, "job-state-reasons");
6187 cupsArrayAdd(ra
, "job-uri");
6188 cupsArrayAdd(ra
, "number-of-documents");
6189 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6190 cupsArrayAdd(ra
, "output-device-assigned");
6191 cupsArrayAdd(ra
, "time-at-completed");
6192 cupsArrayAdd(ra
, "time-at-creation");
6193 cupsArrayAdd(ra
, "time-at-processing");
6195 else if (!strcmp(value
, "printer-description"))
6197 cupsArrayAdd(ra
, "charset-configured");
6198 cupsArrayAdd(ra
, "charset-supported");
6199 cupsArrayAdd(ra
, "color-supported");
6200 cupsArrayAdd(ra
, "compression-supported");
6201 cupsArrayAdd(ra
, "document-format-default");
6202 cupsArrayAdd(ra
, "document-format-supported");
6203 cupsArrayAdd(ra
, "generated-natural-language-supported");
6204 cupsArrayAdd(ra
, "ipp-versions-supported");
6205 cupsArrayAdd(ra
, "job-impressions-supported");
6206 cupsArrayAdd(ra
, "job-k-octets-supported");
6207 cupsArrayAdd(ra
, "job-media-sheets-supported");
6208 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6209 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6210 cupsArrayAdd(ra
, "multiple-operation-time-out");
6211 cupsArrayAdd(ra
, "natural-language-configured");
6212 cupsArrayAdd(ra
, "notify-attributes-supported");
6213 cupsArrayAdd(ra
, "notify-lease-duration-default");
6214 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6215 cupsArrayAdd(ra
, "notify-max-events-supported");
6216 cupsArrayAdd(ra
, "notify-events-default");
6217 cupsArrayAdd(ra
, "notify-events-supported");
6218 cupsArrayAdd(ra
, "notify-pull-method-supported");
6219 cupsArrayAdd(ra
, "notify-schemes-supported");
6220 cupsArrayAdd(ra
, "operations-supported");
6221 cupsArrayAdd(ra
, "pages-per-minute");
6222 cupsArrayAdd(ra
, "pages-per-minute-color");
6223 cupsArrayAdd(ra
, "pdl-override-supported");
6224 cupsArrayAdd(ra
, "printer-alert");
6225 cupsArrayAdd(ra
, "printer-alert-description");
6226 cupsArrayAdd(ra
, "printer-commands");
6227 cupsArrayAdd(ra
, "printer-current-time");
6228 cupsArrayAdd(ra
, "printer-driver-installer");
6229 cupsArrayAdd(ra
, "printer-dns-sd-name");
6230 cupsArrayAdd(ra
, "printer-info");
6231 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6232 cupsArrayAdd(ra
, "printer-location");
6233 cupsArrayAdd(ra
, "printer-make-and-model");
6234 cupsArrayAdd(ra
, "printer-message-from-operator");
6235 cupsArrayAdd(ra
, "printer-more-info");
6236 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6237 cupsArrayAdd(ra
, "printer-name");
6238 cupsArrayAdd(ra
, "printer-state");
6239 cupsArrayAdd(ra
, "printer-state-message");
6240 cupsArrayAdd(ra
, "printer-state-reasons");
6241 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6242 cupsArrayAdd(ra
, "printer-type");
6243 cupsArrayAdd(ra
, "printer-up-time");
6244 cupsArrayAdd(ra
, "printer-uri-supported");
6245 cupsArrayAdd(ra
, "queued-job-count");
6246 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6247 cupsArrayAdd(ra
, "uri-authentication-supported");
6248 cupsArrayAdd(ra
, "uri-security-supported");
6250 else if (!strcmp(value
, "printer-defaults"))
6252 char *name
; /* Option name */
6255 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6257 name
= (char *)cupsArrayNext(CommonDefaults
))
6258 cupsArrayAdd(ra
, name
);
6260 else if (!strcmp(value
, "subscription-template"))
6262 cupsArrayAdd(ra
, "notify-attributes");
6263 cupsArrayAdd(ra
, "notify-charset");
6264 cupsArrayAdd(ra
, "notify-events");
6265 cupsArrayAdd(ra
, "notify-lease-duration");
6266 cupsArrayAdd(ra
, "notify-natural-language");
6267 cupsArrayAdd(ra
, "notify-pull-method");
6268 cupsArrayAdd(ra
, "notify-recipient-uri");
6269 cupsArrayAdd(ra
, "notify-time-interval");
6270 cupsArrayAdd(ra
, "notify-user-data");
6273 cupsArrayAdd(ra
, value
);
6281 * 'create_subscription()' - Create a notification subscription.
6285 create_subscription(
6286 cupsd_client_t
*con
, /* I - Client connection */
6287 ipp_attribute_t
*uri
) /* I - Printer URI */
6289 http_status_t status
; /* Policy status */
6290 int i
; /* Looping var */
6291 ipp_attribute_t
*attr
; /* Current attribute */
6292 cups_ptype_t dtype
; /* Destination type (printer/class) */
6293 char scheme
[HTTP_MAX_URI
],
6294 /* Scheme portion of URI */
6295 userpass
[HTTP_MAX_URI
],
6296 /* Username portion of URI */
6298 /* Host portion of URI */
6299 resource
[HTTP_MAX_URI
];
6300 /* Resource portion of URI */
6301 int port
; /* Port portion of URI */
6302 cupsd_printer_t
*printer
; /* Printer/class */
6303 cupsd_job_t
*job
; /* Job */
6304 int jobid
; /* Job ID */
6305 cupsd_subscription_t
*sub
; /* Subscription object */
6306 const char *username
, /* requesting-user-name or
6307 authenticated username */
6308 *recipient
, /* notify-recipient-uri */
6309 *pullmethod
; /* notify-pull-method */
6310 ipp_attribute_t
*user_data
; /* notify-user-data */
6311 int interval
, /* notify-time-interval */
6312 lease
; /* notify-lease-duration */
6313 unsigned mask
; /* notify-events */
6314 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6315 *notify_lease
; /* notify-lease-duration(-default) */
6319 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6321 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6322 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6323 attr
->value_tag
, attr
->name
);
6325 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6330 * Is the destination valid?
6333 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6334 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6335 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6337 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6338 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6339 sizeof(host
), &port
, resource
, sizeof(resource
));
6341 if (!strcmp(resource
, "/"))
6343 dtype
= (cups_ptype_t
)0;
6346 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6348 dtype
= (cups_ptype_t
)0;
6351 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6353 dtype
= CUPS_PRINTER_CLASS
;
6356 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6362 send_ipp_status(con
, IPP_NOT_FOUND
,
6363 _("The printer or class was not found."));
6373 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6376 send_http_error(con
, status
, printer
);
6380 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6382 send_http_error(con
, status
, NULL
);
6387 * Get the user that is requesting the subscription...
6390 username
= get_username(con
);
6393 * Find the first subscription group attribute; return if we have
6397 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6398 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6403 send_ipp_status(con
, IPP_BAD_REQUEST
,
6404 _("No subscription attributes in request"));
6409 * Process the subscription attributes in the request...
6412 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6420 lease
= DefaultLeaseDuration
;
6422 mask
= CUPSD_EVENT_NONE
;
6426 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6428 notify_lease
= ippFindAttribute(printer
->attrs
,
6429 "notify-lease-duration-default",
6433 lease
= notify_lease
->values
[0].integer
;
6437 notify_events
= NULL
;
6438 notify_lease
= NULL
;
6441 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6443 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6444 attr
->value_tag
== IPP_TAG_URI
)
6447 * Validate the recipient scheme against the ServerBin/notifier
6451 char notifier
[1024]; /* Notifier filename */
6454 recipient
= attr
->values
[0].string
.text
;
6456 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6457 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6458 host
, sizeof(host
), &port
,
6459 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6461 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6462 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
6463 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6464 "notify-status-code", IPP_URI_SCHEME
);
6468 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6470 if (access(notifier
, X_OK
))
6472 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6473 _("notify-recipient-uri URI \"%s\" uses unknown "
6474 "scheme"), recipient
);
6475 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6476 "notify-status-code", IPP_URI_SCHEME
);
6480 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6482 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6483 _("notify-recipient-uri URI \"%s\" is already used"),
6485 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6486 "notify-status-code", IPP_ATTRIBUTES
);
6490 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6491 attr
->value_tag
== IPP_TAG_KEYWORD
)
6493 pullmethod
= attr
->values
[0].string
.text
;
6495 if (strcmp(pullmethod
, "ippget"))
6497 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6498 _("Bad notify-pull-method \"%s\""), pullmethod
);
6499 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6500 "notify-status-code", IPP_ATTRIBUTES
);
6504 else if (!strcmp(attr
->name
, "notify-charset") &&
6505 attr
->value_tag
== IPP_TAG_CHARSET
&&
6506 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6507 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6509 send_ipp_status(con
, IPP_CHARSET
,
6510 _("Character set \"%s\" not supported"),
6511 attr
->values
[0].string
.text
);
6514 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6515 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6516 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6518 send_ipp_status(con
, IPP_CHARSET
,
6519 _("Language \"%s\" not supported"),
6520 attr
->values
[0].string
.text
);
6523 else if (!strcmp(attr
->name
, "notify-user-data") &&
6524 attr
->value_tag
== IPP_TAG_STRING
)
6526 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6528 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6529 _("The notify-user-data value is too large "
6530 "(%d > 63 octets)"),
6531 attr
->values
[0].unknown
.length
);
6537 else if (!strcmp(attr
->name
, "notify-events") &&
6538 attr
->value_tag
== IPP_TAG_KEYWORD
)
6539 notify_events
= attr
;
6540 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6541 attr
->value_tag
== IPP_TAG_INTEGER
)
6542 lease
= attr
->values
[0].integer
;
6543 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6544 attr
->value_tag
== IPP_TAG_INTEGER
)
6545 interval
= attr
->values
[0].integer
;
6546 else if (!strcmp(attr
->name
, "notify-job-id") &&
6547 attr
->value_tag
== IPP_TAG_INTEGER
)
6548 jobid
= attr
->values
[0].integer
;
6555 for (i
= 0; i
< notify_events
->num_values
; i
++)
6556 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6560 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6562 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6563 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6564 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6566 if (!recipient
&& !pullmethod
)
6569 if (mask
== CUPSD_EVENT_NONE
)
6572 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6574 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6577 send_ipp_status(con
, IPP_BAD_REQUEST
,
6578 _("notify-events not specified"));
6583 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6585 cupsdLogMessage(CUPSD_LOG_INFO
,
6586 "create_subscription: Limiting notify-lease-duration to "
6589 lease
= MaxLeaseDuration
;
6594 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6596 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found"), jobid
);
6603 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6605 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6606 _("There are too many subscriptions."));
6611 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6614 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6615 "Added subscription %d for printer \"%s\"",
6616 sub
->id
, printer
->name
);
6618 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6621 sub
->interval
= interval
;
6623 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6625 cupsdSetString(&sub
->owner
, username
);
6629 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6630 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6631 sub
->user_data_len
);
6634 ippAddSeparator(con
->response
);
6635 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6636 "notify-subscription-id", sub
->id
);
6638 con
->response
->request
.status
.status_code
= IPP_OK
;
6644 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6649 * 'delete_printer()' - Remove a printer or class from the system.
6653 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6654 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6656 http_status_t status
; /* Policy status */
6657 cups_ptype_t dtype
; /* Destination type (printer/class) */
6658 cupsd_printer_t
*printer
; /* Printer/class */
6659 char filename
[1024]; /* Script/PPD filename */
6662 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6663 con
->http
.fd
, uri
->values
[0].string
.text
);
6666 * Do we have a valid URI?
6669 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6675 send_ipp_status(con
, IPP_NOT_FOUND
,
6676 _("The printer or class was not found."));
6684 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6686 send_http_error(con
, status
, NULL
);
6691 * Remove old jobs...
6694 cupsdCancelJobs(printer
->name
, NULL
, 1);
6697 * Remove old subscriptions and send a "deleted printer" event...
6700 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6701 "%s \"%s\" deleted by \"%s\".",
6702 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6703 printer
->name
, get_username(con
));
6705 cupsdExpireSubscriptions(printer
, NULL
);
6708 * Remove any old PPD or script files...
6711 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6715 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6719 snprintf(filename
, sizeof(filename
), "%s/%s.ipp4", CacheDir
, printer
->name
);
6722 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
6725 snprintf(filename
, sizeof(filename
), "%s/%s.pwg3", CacheDir
, printer
->name
);
6730 * Unregister color profiles...
6733 apple_unregister_profiles(printer
);
6734 #endif /* __APPLE__ */
6736 if (dtype
& CUPS_PRINTER_CLASS
)
6738 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6739 printer
->name
, get_username(con
));
6741 cupsdDeletePrinter(printer
, 0);
6742 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6746 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6747 printer
->name
, get_username(con
));
6749 if (cupsdDeletePrinter(printer
, 0))
6750 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6752 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6755 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6758 * Return with no errors...
6761 con
->response
->request
.status
.status_code
= IPP_OK
;
6766 * 'get_default()' - Get the default destination.
6770 get_default(cupsd_client_t
*con
) /* I - Client connection */
6772 http_status_t status
; /* Policy status */
6773 cups_array_t
*ra
; /* Requested attributes array */
6776 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6782 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6784 send_http_error(con
, status
, NULL
);
6790 ra
= create_requested_array(con
->request
);
6792 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6794 cupsArrayDelete(ra
);
6796 con
->response
->request
.status
.status_code
= IPP_OK
;
6799 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6804 * 'get_devices()' - Get the list of available devices on the local system.
6808 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6810 http_status_t status
; /* Policy status */
6811 ipp_attribute_t
*limit
, /* limit attribute */
6812 *timeout
, /* timeout attribute */
6813 *requested
, /* requested-attributes attribute */
6814 *exclude
, /* exclude-schemes attribute */
6815 *include
; /* include-schemes attribute */
6816 char command
[1024], /* cups-deviced command */
6817 options
[2048], /* Options to pass to command */
6819 /* String for requested attributes */
6821 /* String for excluded schemes */
6823 /* String for included schemes */
6826 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6832 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6834 send_http_error(con
, status
, NULL
);
6839 * Run cups-deviced command with the given options...
6842 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6843 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6844 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6846 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6847 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6850 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6852 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6855 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6857 exclude_str
[0] = '\0';
6860 url_encode_attr(include
, include_str
, sizeof(include_str
));
6862 include_str
[0] = '\0';
6864 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6865 snprintf(options
, sizeof(options
),
6866 "%d+%d+%d+%d+%s%s%s%s%s",
6867 con
->request
->request
.op
.request_id
,
6868 limit
? limit
->values
[0].integer
: 0,
6869 timeout
? timeout
->values
[0].integer
: 15,
6872 exclude_str
[0] ? "%20" : "", exclude_str
,
6873 include_str
[0] ? "%20" : "", include_str
);
6875 if (cupsdSendCommand(con
, command
, options
, 1))
6878 * Command started successfully, don't send an IPP response here...
6881 ippDelete(con
->response
);
6882 con
->response
= NULL
;
6887 * Command failed, return "internal error" so the user knows something
6891 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6892 _("cups-deviced failed to execute."));
6898 * 'get_document()' - Get a copy of a job file.
6902 get_document(cupsd_client_t
*con
, /* I - Client connection */
6903 ipp_attribute_t
*uri
) /* I - Job URI */
6905 http_status_t status
; /* Policy status */
6906 ipp_attribute_t
*attr
; /* Current attribute */
6907 int jobid
; /* Job ID */
6908 int docnum
; /* Document number */
6909 cupsd_job_t
*job
; /* Current job */
6910 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6911 username
[HTTP_MAX_URI
], /* Username portion of URI */
6912 host
[HTTP_MAX_URI
], /* Host portion of URI */
6913 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6914 int port
; /* Port portion of URI */
6915 char filename
[1024], /* Filename for document */
6916 format
[1024]; /* Format for document */
6919 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6920 con
->http
.fd
, uri
->values
[0].string
.text
);
6923 * See if we have a job URI or a printer URI...
6926 if (!strcmp(uri
->name
, "printer-uri"))
6929 * Got a printer URI; see if we also have a job-id attribute...
6932 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6933 IPP_TAG_INTEGER
)) == NULL
)
6935 send_ipp_status(con
, IPP_BAD_REQUEST
,
6936 _("Got a printer-uri attribute but no job-id"));
6940 jobid
= attr
->values
[0].integer
;
6945 * Got a job URI; parse it to get the job ID...
6948 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6949 sizeof(scheme
), username
, sizeof(username
), host
,
6950 sizeof(host
), &port
, resource
, sizeof(resource
));
6952 if (strncmp(resource
, "/jobs/", 6))
6958 send_ipp_status(con
, IPP_BAD_REQUEST
,
6959 _("Bad job-uri attribute \"%s\""),
6960 uri
->values
[0].string
.text
);
6964 jobid
= atoi(resource
+ 6);
6968 * See if the job exists...
6971 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6974 * Nope - return a "not found" error...
6977 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
6985 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6987 send_http_error(con
, status
, NULL
);
6992 * Get the document number...
6995 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6996 IPP_TAG_INTEGER
)) == NULL
)
6998 send_ipp_status(con
, IPP_BAD_REQUEST
,
6999 _("Missing document-number attribute"));
7003 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
7004 attr
->num_values
> 1)
7006 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
7011 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
7013 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
7015 cupsdLogMessage(CUPSD_LOG_ERROR
,
7016 "Unable to open document %d in job %d - %s", docnum
, jobid
,
7018 send_ipp_status(con
, IPP_NOT_FOUND
,
7019 _("Unable to open document %d in job %d"), docnum
, jobid
);
7023 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7027 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
7028 job
->filetypes
[docnum
- 1]->type
);
7030 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
7032 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
7034 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
7035 IPP_TAG_NAME
)) != NULL
)
7036 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
7037 NULL
, attr
->values
[0].string
.text
);
7042 * 'get_job_attrs()' - Get job attributes.
7046 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
7047 ipp_attribute_t
*uri
) /* I - Job URI */
7049 http_status_t status
; /* Policy status */
7050 ipp_attribute_t
*attr
; /* Current attribute */
7051 int jobid
; /* Job ID */
7052 cupsd_job_t
*job
; /* Current job */
7053 cupsd_printer_t
*printer
; /* Current printer */
7054 cupsd_policy_t
*policy
; /* Current security policy */
7055 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7056 username
[HTTP_MAX_URI
], /* Username portion of URI */
7057 host
[HTTP_MAX_URI
], /* Host portion of URI */
7058 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7059 int port
; /* Port portion of URI */
7060 cups_array_t
*ra
, /* Requested attributes array */
7061 *exclude
; /* Private attributes array */
7064 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7065 con
->http
.fd
, uri
->values
[0].string
.text
);
7068 * See if we have a job URI or a printer URI...
7071 if (!strcmp(uri
->name
, "printer-uri"))
7074 * Got a printer URI; see if we also have a job-id attribute...
7077 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7078 IPP_TAG_INTEGER
)) == NULL
)
7080 send_ipp_status(con
, IPP_BAD_REQUEST
,
7081 _("Got a printer-uri attribute but no job-id"));
7085 jobid
= attr
->values
[0].integer
;
7090 * Got a job URI; parse it to get the job ID...
7093 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7094 sizeof(scheme
), username
, sizeof(username
), host
,
7095 sizeof(host
), &port
, resource
, sizeof(resource
));
7097 if (strncmp(resource
, "/jobs/", 6))
7103 send_ipp_status(con
, IPP_BAD_REQUEST
,
7104 _("Bad job-uri attribute \"%s\""),
7105 uri
->values
[0].string
.text
);
7109 jobid
= atoi(resource
+ 6);
7113 * See if the job exists...
7116 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7119 * Nope - return a "not found" error...
7122 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
7130 if ((printer
= job
->printer
) == NULL
)
7131 printer
= cupsdFindDest(job
->dest
);
7134 policy
= printer
->op_policy_ptr
;
7136 policy
= DefaultPolicyPtr
;
7138 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
7140 send_http_error(con
, status
, NULL
);
7144 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
7147 * Copy attributes...
7152 ra
= create_requested_array(con
->request
);
7153 copy_job_attrs(con
, job
, ra
, exclude
);
7154 cupsArrayDelete(ra
);
7156 con
->response
->request
.status
.status_code
= IPP_OK
;
7161 * 'get_jobs()' - Get a list of jobs for the specified printer.
7165 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7166 ipp_attribute_t
*uri
) /* I - Printer URI */
7168 http_status_t status
; /* Policy status */
7169 ipp_attribute_t
*attr
; /* Current attribute */
7170 const char *dest
; /* Destination */
7171 cups_ptype_t dtype
; /* Destination type (printer/class) */
7172 cups_ptype_t dmask
; /* Destination type mask */
7173 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7174 username
[HTTP_MAX_URI
], /* Username portion of URI */
7175 host
[HTTP_MAX_URI
], /* Host portion of URI */
7176 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7177 int port
; /* Port portion of URI */
7178 int job_comparison
; /* Job comparison */
7179 ipp_jstate_t job_state
; /* job-state value */
7180 int first_job_id
; /* First job ID */
7181 int limit
; /* Maximum number of jobs to return */
7182 int count
; /* Number of jobs that match */
7183 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7184 cupsd_job_t
*job
; /* Current job pointer */
7185 cupsd_printer_t
*printer
; /* Printer */
7186 cups_array_t
*list
; /* Which job list... */
7187 cups_array_t
*ra
, /* Requested attributes array */
7188 *exclude
; /* Private attributes array */
7189 cupsd_policy_t
*policy
; /* Current policy */
7192 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7193 uri
->values
[0].string
.text
);
7196 * Is the destination valid?
7199 if (strcmp(uri
->name
, "printer-uri"))
7201 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request"));
7205 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7206 sizeof(scheme
), username
, sizeof(username
), host
,
7207 sizeof(host
), &port
, resource
, sizeof(resource
));
7209 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7212 dtype
= (cups_ptype_t
)0;
7213 dmask
= (cups_ptype_t
)0;
7216 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7219 dtype
= (cups_ptype_t
)0;
7220 dmask
= CUPS_PRINTER_CLASS
;
7223 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7226 dtype
= CUPS_PRINTER_CLASS
;
7227 dmask
= CUPS_PRINTER_CLASS
;
7230 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7237 send_ipp_status(con
, IPP_NOT_FOUND
,
7238 _("The printer or class was not found."));
7243 dtype
&= CUPS_PRINTER_CLASS
;
7244 dmask
= CUPS_PRINTER_CLASS
;
7252 policy
= printer
->op_policy_ptr
;
7254 policy
= DefaultPolicyPtr
;
7256 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7258 send_http_error(con
, status
, NULL
);
7262 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7265 * See if the "which-jobs" attribute have been specified...
7268 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7269 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7271 send_ipp_status(con
, IPP_CONFLICT
,
7272 _("The %s attribute cannot be provided with job-ids."),
7276 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7278 job_comparison
= -1;
7279 job_state
= IPP_JOB_STOPPED
;
7282 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7285 job_state
= IPP_JOB_CANCELED
;
7288 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7291 job_state
= IPP_JOB_ABORTED
;
7294 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7297 job_state
= IPP_JOB_PENDING
;
7300 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7303 job_state
= IPP_JOB_CANCELED
;
7306 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7309 job_state
= IPP_JOB_PENDING
;
7312 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7315 job_state
= IPP_JOB_HELD
;
7318 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7321 job_state
= IPP_JOB_PROCESSING
;
7322 list
= PrintingJobs
;
7324 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7327 job_state
= IPP_JOB_STOPPED
;
7332 send_ipp_status(con
, IPP_ATTRIBUTES
,
7333 _("The which-jobs value \"%s\" is not supported."),
7334 attr
->values
[0].string
.text
);
7335 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7336 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7341 * See if they want to limit the number of jobs reported...
7344 if ((attr
= ippFindAttribute(con
->request
, "limit",
7345 IPP_TAG_INTEGER
)) != NULL
)
7349 send_ipp_status(con
, IPP_CONFLICT
,
7350 _("The %s attribute cannot be provided with job-ids."),
7355 limit
= attr
->values
[0].integer
;
7360 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7361 IPP_TAG_INTEGER
)) != NULL
)
7365 send_ipp_status(con
, IPP_CONFLICT
,
7366 _("The %s attribute cannot be provided with job-ids."),
7371 first_job_id
= attr
->values
[0].integer
;
7377 * See if we only want to see jobs for a specific user...
7380 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7381 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7383 send_ipp_status(con
, IPP_CONFLICT
,
7384 _("The %s attribute cannot be provided with job-ids."),
7388 else if (attr
&& attr
->values
[0].boolean
)
7389 strlcpy(username
, get_username(con
), sizeof(username
));
7393 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7394 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7397 * IPP conformance - Get-Jobs has a default requested-attributes value of
7398 * "job-id" and "job-uri".
7401 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7402 cupsArrayAdd(ra
, "job-id");
7403 cupsArrayAdd(ra
, "job-uri");
7407 * OK, build a list of jobs for this printer...
7412 int i
; /* Looping var */
7414 for (i
= 0; i
< job_ids
->num_values
; i
++)
7416 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
7420 if (i
< job_ids
->num_values
)
7422 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
7423 job_ids
->values
[i
].integer
);
7427 for (i
= 0; i
< job_ids
->num_values
; i
++)
7429 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7435 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7441 ippAddSeparator(con
->response
);
7443 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7444 job
->printer
->op_policy_ptr
:
7445 policy
, con
, job
->printer
,
7448 copy_job_attrs(con
, job
, ra
, exclude
);
7453 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7454 (limit
<= 0 || count
< limit
) && job
;
7455 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7458 * Filter out jobs that don't match...
7461 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7462 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7463 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7464 job
->username
, job
->state_value
, job
->attrs
);
7466 if (!job
->dest
|| !job
->username
)
7469 if (!job
->dest
|| !job
->username
)
7472 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7473 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7475 if ((job
->dtype
& dmask
) != dtype
&&
7476 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7479 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7480 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7481 (job_comparison
> 0 && job
->state_value
< job_state
))
7484 if (job
->id
< first_job_id
)
7491 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7496 if (username
[0] && strcasecmp(username
, job
->username
))
7500 ippAddSeparator(con
->response
);
7504 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7505 job
->printer
->op_policy_ptr
:
7506 policy
, con
, job
->printer
,
7509 copy_job_attrs(con
, job
, ra
, exclude
);
7512 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7515 cupsArrayDelete(ra
);
7517 con
->response
->request
.status
.status_code
= IPP_OK
;
7522 * 'get_notifications()' - Get events for a subscription.
7526 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7528 int i
, j
; /* Looping vars */
7529 http_status_t status
; /* Policy status */
7530 cupsd_subscription_t
*sub
; /* Subscription */
7531 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7532 *sequences
; /* notify-sequence-numbers */
7533 int min_seq
; /* Minimum sequence number */
7534 int interval
; /* Poll interval */
7537 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7541 * Get subscription attributes...
7544 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7546 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7551 send_ipp_status(con
, IPP_BAD_REQUEST
,
7552 _("Missing notify-subscription-ids attribute"));
7557 * Are the subscription IDs valid?
7560 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7562 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7565 * Bad subscription ID...
7568 send_ipp_status(con
, IPP_NOT_FOUND
,
7569 _("notify-subscription-id %d no good"),
7570 ids
->values
[i
].integer
);
7578 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7580 con
, sub
->owner
)) != HTTP_OK
)
7582 send_http_error(con
, status
, sub
->dest
);
7587 * Check the subscription type and update the interval accordingly.
7590 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7593 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7595 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7601 * Tell the client to poll again in N seconds...
7605 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7606 "notify-get-interval", interval
);
7608 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7609 "printer-up-time", time(NULL
));
7612 * Copy the subscription event attributes to the response.
7615 con
->response
->request
.status
.status_code
=
7616 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7618 for (i
= 0; i
< ids
->num_values
; i
++)
7621 * Get the subscription and sequence number...
7624 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7626 if (sequences
&& i
< sequences
->num_values
)
7627 min_seq
= sequences
->values
[i
].integer
;
7632 * If we don't have any new events, nothing to do here...
7635 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
7639 * Otherwise copy all of the new events...
7642 if (sub
->first_event_id
> min_seq
)
7645 j
= min_seq
- sub
->first_event_id
;
7647 for (; j
< cupsArrayCount(sub
->events
); j
++)
7649 ippAddSeparator(con
->response
);
7651 copy_attrs(con
->response
,
7652 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7653 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7660 * 'get_ppd()' - Get a named PPD from the local system.
7664 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7665 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7667 http_status_t status
; /* Policy status */
7668 cupsd_printer_t
*dest
; /* Destination */
7669 cups_ptype_t dtype
; /* Destination type */
7672 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7673 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7675 if (!strcmp(uri
->name
, "ppd-name"))
7678 * Return a PPD file from cups-driverd...
7681 char command
[1024], /* cups-driverd command */
7682 options
[1024], /* Options to pass to command */
7683 ppd_name
[1024]; /* ppd-name */
7690 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7692 send_http_error(con
, status
, NULL
);
7697 * Run cups-driverd command with the given options...
7700 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7701 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7702 snprintf(options
, sizeof(options
), "get+%d+%s",
7703 con
->request
->request
.op
.request_id
, ppd_name
);
7705 if (cupsdSendCommand(con
, command
, options
, 0))
7708 * Command started successfully, don't send an IPP response here...
7711 ippDelete(con
->response
);
7712 con
->response
= NULL
;
7717 * Command failed, return "internal error" so the user knows something
7721 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7722 _("cups-driverd failed to execute."));
7725 else if (!strcmp(uri
->name
, "printer-uri") &&
7726 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7728 int i
; /* Looping var */
7729 char filename
[1024]; /* PPD filename */
7736 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7738 send_http_error(con
, status
, dest
);
7743 * See if we need the PPD for a class or remote printer...
7746 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7749 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7751 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7752 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7753 "printer-uri", NULL
, dest
->uri
);
7756 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7758 for (i
= 0; i
< dest
->num_printers
; i
++)
7759 if (!(dest
->printers
[i
]->type
&
7760 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7762 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7763 dest
->printers
[i
]->name
);
7765 if (!access(filename
, 0))
7769 if (i
< dest
->num_printers
)
7770 dest
= dest
->printers
[i
];
7773 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7774 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7775 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7781 * Found the printer with the PPD file, now see if there is one...
7784 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7786 send_ipp_status(con
, IPP_NOT_FOUND
,
7787 _("The PPD file \"%s\" could not be opened: %s"),
7788 uri
->values
[0].string
.text
, strerror(errno
));
7792 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7796 con
->response
->request
.status
.status_code
= IPP_OK
;
7799 send_ipp_status(con
, IPP_NOT_FOUND
,
7800 _("The PPD file \"%s\" could not be found."),
7801 uri
->values
[0].string
.text
);
7806 * 'get_ppds()' - Get the list of PPD files on the local system.
7810 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7812 http_status_t status
; /* Policy status */
7813 ipp_attribute_t
*limit
, /* Limit attribute */
7814 *device
, /* ppd-device-id attribute */
7815 *language
, /* ppd-natural-language attribute */
7816 *make
, /* ppd-make attribute */
7817 *model
, /* ppd-make-and-model attribute */
7818 *model_number
, /* ppd-model-number attribute */
7819 *product
, /* ppd-product attribute */
7820 *psversion
, /* ppd-psverion attribute */
7821 *type
, /* ppd-type attribute */
7822 *requested
, /* requested-attributes attribute */
7823 *exclude
, /* exclude-schemes attribute */
7824 *include
; /* include-schemes attribute */
7825 char command
[1024], /* cups-driverd command */
7826 options
[4096], /* Options to pass to command */
7827 device_str
[256],/* Escaped ppd-device-id string */
7829 /* Escaped ppd-natural-language */
7830 make_str
[256], /* Escaped ppd-make string */
7831 model_str
[256], /* Escaped ppd-make-and-model string */
7832 model_number_str
[256],
7833 /* ppd-model-number string */
7835 /* Escaped ppd-product string */
7837 /* Escaped ppd-psversion string */
7838 type_str
[256], /* Escaped ppd-type string */
7840 /* String for requested attributes */
7842 /* String for excluded schemes */
7844 /* String for included schemes */
7847 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7853 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7855 send_http_error(con
, status
, NULL
);
7860 * Run cups-driverd command with the given options...
7863 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7864 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7865 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7867 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7868 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7870 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7872 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7873 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7874 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7875 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7877 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7879 include
= ippFindAttribute(con
->request
, "include-schemes",
7883 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7885 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7888 url_encode_attr(device
, device_str
, sizeof(device_str
));
7890 device_str
[0] = '\0';
7893 url_encode_attr(language
, language_str
, sizeof(language_str
));
7895 language_str
[0] = '\0';
7898 url_encode_attr(make
, make_str
, sizeof(make_str
));
7903 url_encode_attr(model
, model_str
, sizeof(model_str
));
7905 model_str
[0] = '\0';
7908 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7909 model_number
->values
[0].integer
);
7911 model_number_str
[0] = '\0';
7914 url_encode_attr(product
, product_str
, sizeof(product_str
));
7916 product_str
[0] = '\0';
7919 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7921 psversion_str
[0] = '\0';
7924 url_encode_attr(type
, type_str
, sizeof(type_str
));
7929 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7931 exclude_str
[0] = '\0';
7934 url_encode_attr(include
, include_str
, sizeof(include_str
));
7936 include_str
[0] = '\0';
7938 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7939 snprintf(options
, sizeof(options
),
7940 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7941 con
->request
->request
.op
.request_id
,
7942 limit
? limit
->values
[0].integer
: 0,
7944 device
? "%20" : "", device_str
,
7945 language
? "%20" : "", language_str
,
7946 make
? "%20" : "", make_str
,
7947 model
? "%20" : "", model_str
,
7948 model_number
? "%20" : "", model_number_str
,
7949 product
? "%20" : "", product_str
,
7950 psversion
? "%20" : "", psversion_str
,
7951 type
? "%20" : "", type_str
,
7952 exclude_str
[0] ? "%20" : "", exclude_str
,
7953 include_str
[0] ? "%20" : "", include_str
);
7955 if (cupsdSendCommand(con
, command
, options
, 0))
7958 * Command started successfully, don't send an IPP response here...
7961 ippDelete(con
->response
);
7962 con
->response
= NULL
;
7967 * Command failed, return "internal error" so the user knows something
7971 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7972 _("cups-driverd failed to execute."));
7978 * 'get_printer_attrs()' - Get printer attributes.
7982 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7983 ipp_attribute_t
*uri
) /* I - Printer URI */
7985 http_status_t status
; /* Policy status */
7986 cups_ptype_t dtype
; /* Destination type (printer/class) */
7987 cupsd_printer_t
*printer
; /* Printer/class */
7988 cups_array_t
*ra
; /* Requested attributes array */
7991 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7992 con
->http
.fd
, uri
->values
[0].string
.text
);
7995 * Is the destination valid?
7998 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8004 send_ipp_status(con
, IPP_NOT_FOUND
,
8005 _("The printer or class was not found."));
8013 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8015 send_http_error(con
, status
, printer
);
8020 * Send the attributes...
8023 ra
= create_requested_array(con
->request
);
8025 copy_printer_attrs(con
, printer
, ra
);
8027 cupsArrayDelete(ra
);
8029 con
->response
->request
.status
.status_code
= IPP_OK
;
8034 * 'get_printer_supported()' - Get printer supported values.
8038 get_printer_supported(
8039 cupsd_client_t
*con
, /* I - Client connection */
8040 ipp_attribute_t
*uri
) /* I - Printer URI */
8042 http_status_t status
; /* Policy status */
8043 cups_ptype_t dtype
; /* Destination type (printer/class) */
8044 cupsd_printer_t
*printer
; /* Printer/class */
8047 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
8048 con
->http
.fd
, uri
->values
[0].string
.text
);
8051 * Is the destination valid?
8054 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8060 send_ipp_status(con
, IPP_NOT_FOUND
,
8061 _("The printer or class was not found."));
8069 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8071 send_http_error(con
, status
, printer
);
8076 * Return a list of attributes that can be set via Set-Printer-Attributes.
8079 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8081 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8082 "printer-location", 0);
8084 con
->response
->request
.status
.status_code
= IPP_OK
;
8089 * 'get_printers()' - Get a list of printers or classes.
8093 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8094 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8096 http_status_t status
; /* Policy status */
8097 ipp_attribute_t
*attr
; /* Current attribute */
8098 int limit
; /* Max number of printers to return */
8099 int count
; /* Number of printers that match */
8100 cupsd_printer_t
*printer
; /* Current printer pointer */
8101 int printer_type
, /* printer-type attribute */
8102 printer_mask
; /* printer-type-mask attribute */
8103 char *location
; /* Location string */
8104 const char *username
; /* Current user */
8105 char *first_printer_name
; /* first-printer-name attribute */
8106 cups_array_t
*ra
; /* Requested attributes array */
8107 int local
; /* Local connection? */
8110 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8111 con
->http
.fd
, type
);
8117 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8119 send_http_error(con
, status
, NULL
);
8124 * Check for printers...
8127 if (!Printers
|| !cupsArrayCount(Printers
))
8129 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8134 * See if they want to limit the number of printers reported...
8137 if ((attr
= ippFindAttribute(con
->request
, "limit",
8138 IPP_TAG_INTEGER
)) != NULL
)
8139 limit
= attr
->values
[0].integer
;
8143 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8144 IPP_TAG_NAME
)) != NULL
)
8145 first_printer_name
= attr
->values
[0].string
.text
;
8147 first_printer_name
= NULL
;
8150 * Support filtering...
8153 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8154 IPP_TAG_ENUM
)) != NULL
)
8155 printer_type
= attr
->values
[0].integer
;
8159 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8160 IPP_TAG_ENUM
)) != NULL
)
8161 printer_mask
= attr
->values
[0].integer
;
8165 local
= httpAddrLocalhost(&(con
->clientaddr
));
8167 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8168 IPP_TAG_TEXT
)) != NULL
)
8169 location
= attr
->values
[0].string
.text
;
8173 if (con
->username
[0])
8174 username
= con
->username
;
8175 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8176 IPP_TAG_NAME
)) != NULL
)
8177 username
= attr
->values
[0].string
.text
;
8181 ra
= create_requested_array(con
->request
);
8184 * OK, build a list of printers for this printer...
8187 if (first_printer_name
)
8189 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8190 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8193 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8196 count
< limit
&& printer
;
8197 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8199 if (!local
&& !printer
->shared
)
8202 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8203 (printer
->type
& printer_mask
) == printer_type
&&
8205 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
8208 * If HideImplicitMembers is enabled, see if this printer or class
8209 * is a member of an implicit class...
8212 if (ImplicitClasses
&& HideImplicitMembers
&&
8213 printer
->in_implicit_class
)
8217 * If a username is specified, see if it is allowed or denied
8221 if (cupsArrayCount(printer
->users
) && username
&&
8222 !user_allowed(printer
, username
))
8226 * Add the group separator as needed...
8230 ippAddSeparator(con
->response
);
8235 * Send the attributes...
8238 copy_printer_attrs(con
, printer
, ra
);
8242 cupsArrayDelete(ra
);
8244 con
->response
->request
.status
.status_code
= IPP_OK
;
8249 * 'get_subscription_attrs()' - Get subscription attributes.
8253 get_subscription_attrs(
8254 cupsd_client_t
*con
, /* I - Client connection */
8255 int sub_id
) /* I - Subscription ID */
8257 http_status_t status
; /* Policy status */
8258 cupsd_subscription_t
*sub
; /* Subscription */
8259 cupsd_policy_t
*policy
; /* Current security policy */
8260 cups_array_t
*ra
, /* Requested attributes array */
8261 *exclude
; /* Private attributes array */
8264 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8265 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8266 con
, con
->http
.fd
, sub_id
);
8269 * Is the subscription ID valid?
8272 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8275 * Bad subscription ID...
8278 send_ipp_status(con
, IPP_NOT_FOUND
,
8279 _("notify-subscription-id %d no good"), sub_id
);
8288 policy
= sub
->dest
->op_policy_ptr
;
8290 policy
= DefaultPolicyPtr
;
8292 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
8294 send_http_error(con
, status
, sub
->dest
);
8298 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
8301 * Copy the subscription attributes to the response using the
8302 * requested-attributes attribute that may be provided by the client.
8305 ra
= create_requested_array(con
->request
);
8307 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8309 cupsArrayDelete(ra
);
8311 con
->response
->request
.status
.status_code
= IPP_OK
;
8316 * 'get_subscriptions()' - Get subscriptions.
8320 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8321 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8323 http_status_t status
; /* Policy status */
8324 int count
; /* Number of subscriptions */
8325 int limit
; /* Limit */
8326 cupsd_subscription_t
*sub
; /* Subscription */
8327 cups_array_t
*ra
; /* Requested attributes array */
8328 ipp_attribute_t
*attr
; /* Attribute */
8329 cups_ptype_t dtype
; /* Destination type (printer/class) */
8330 char scheme
[HTTP_MAX_URI
],
8331 /* Scheme portion of URI */
8332 username
[HTTP_MAX_URI
],
8333 /* Username portion of URI */
8335 /* Host portion of URI */
8336 resource
[HTTP_MAX_URI
];
8337 /* Resource portion of URI */
8338 int port
; /* Port portion of URI */
8339 cupsd_job_t
*job
; /* Job pointer */
8340 cupsd_printer_t
*printer
; /* Printer */
8341 cupsd_policy_t
*policy
; /* Policy */
8342 cups_array_t
*exclude
; /* Private attributes array */
8345 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8346 "get_subscriptions(con=%p[%d], uri=%s)",
8347 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8350 * Is the destination valid?
8353 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8354 sizeof(scheme
), username
, sizeof(username
), host
,
8355 sizeof(host
), &port
, resource
, sizeof(resource
));
8357 if (!strcmp(resource
, "/") ||
8358 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8359 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8360 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8365 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8368 job
= cupsdFindJob(atoi(resource
+ 6));
8372 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist"),
8377 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8383 send_ipp_status(con
, IPP_NOT_FOUND
,
8384 _("The printer or class was not found."));
8387 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8388 IPP_TAG_INTEGER
)) != NULL
)
8390 job
= cupsdFindJob(attr
->values
[0].integer
);
8394 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
8395 attr
->values
[0].integer
);
8407 policy
= printer
->op_policy_ptr
;
8409 policy
= DefaultPolicyPtr
;
8411 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
8413 send_http_error(con
, status
, printer
);
8418 * Copy the subscription attributes to the response using the
8419 * requested-attributes attribute that may be provided by the client.
8422 ra
= create_requested_array(con
->request
);
8424 if ((attr
= ippFindAttribute(con
->request
, "limit",
8425 IPP_TAG_INTEGER
)) != NULL
)
8426 limit
= attr
->values
[0].integer
;
8431 * See if we only want to see subscriptions for a specific user...
8434 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8435 IPP_TAG_BOOLEAN
)) != NULL
&&
8436 attr
->values
[0].boolean
)
8437 strlcpy(username
, get_username(con
), sizeof(username
));
8441 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8443 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8444 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8445 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
8447 ippAddSeparator(con
->response
);
8449 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
8450 policy
, con
, sub
->dest
,
8453 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8456 if (limit
&& count
>= limit
)
8460 cupsArrayDelete(ra
);
8463 con
->response
->request
.status
.status_code
= IPP_OK
;
8465 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8470 * 'get_username()' - Get the username associated with a request.
8473 static const char * /* O - Username */
8474 get_username(cupsd_client_t
*con
) /* I - Connection */
8476 ipp_attribute_t
*attr
; /* Attribute */
8479 if (con
->username
[0])
8480 return (con
->username
);
8481 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8482 IPP_TAG_NAME
)) != NULL
)
8483 return (attr
->values
[0].string
.text
);
8485 return ("anonymous");
8490 * 'hold_job()' - Hold a print job.
8494 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8495 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8497 ipp_attribute_t
*attr
; /* Current job-hold-until */
8498 const char *when
; /* New value */
8499 int jobid
; /* Job ID */
8500 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8501 username
[HTTP_MAX_URI
], /* Username portion of URI */
8502 host
[HTTP_MAX_URI
], /* Host portion of URI */
8503 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8504 int port
; /* Port portion of URI */
8505 cupsd_job_t
*job
; /* Job information */
8508 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8509 uri
->values
[0].string
.text
);
8512 * See if we have a job URI or a printer URI...
8515 if (!strcmp(uri
->name
, "printer-uri"))
8518 * Got a printer URI; see if we also have a job-id attribute...
8521 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8522 IPP_TAG_INTEGER
)) == NULL
)
8524 send_ipp_status(con
, IPP_BAD_REQUEST
,
8525 _("Got a printer-uri attribute but no job-id"));
8529 jobid
= attr
->values
[0].integer
;
8534 * Got a job URI; parse it to get the job ID...
8537 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8538 sizeof(scheme
), username
, sizeof(username
), host
,
8539 sizeof(host
), &port
, resource
, sizeof(resource
));
8541 if (strncmp(resource
, "/jobs/", 6))
8547 send_ipp_status(con
, IPP_BAD_REQUEST
,
8548 _("Bad job-uri attribute \"%s\""),
8549 uri
->values
[0].string
.text
);
8553 jobid
= atoi(resource
+ 6);
8557 * See if the job exists...
8560 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8563 * Nope - return a "not found" error...
8566 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
8571 * See if the job is owned by the requesting user...
8574 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8576 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8577 cupsdFindDest(job
->dest
));
8582 * Hold the job and return...
8585 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8586 IPP_TAG_KEYWORD
)) == NULL
)
8587 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8591 when
= attr
->values
[0].string
.text
;
8593 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8594 "Job job-hold-until value changed by user.");
8597 when
= "indefinite";
8599 cupsdSetJobHoldUntil(job
, when
, 1);
8600 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8603 con
->response
->request
.status
.status_code
= IPP_OK
;
8608 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8612 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8613 ipp_attribute_t
*uri
) /* I - Printer URI */
8615 http_status_t status
; /* Policy status */
8616 cups_ptype_t dtype
; /* Destination type (printer/class) */
8617 cupsd_printer_t
*printer
; /* Printer data */
8620 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8621 con
->http
.fd
, uri
->values
[0].string
.text
);
8624 * Is the destination valid?
8627 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8633 send_ipp_status(con
, IPP_NOT_FOUND
,
8634 _("The printer or class was not found."));
8642 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8644 send_http_error(con
, status
, printer
);
8649 * Hold pending/new jobs sent to the printer...
8652 printer
->holding_new_jobs
= 1;
8654 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8655 cupsdAddPrinterHistory(printer
);
8657 if (dtype
& CUPS_PRINTER_CLASS
)
8658 cupsdLogMessage(CUPSD_LOG_INFO
,
8659 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8660 printer
->name
, get_username(con
));
8662 cupsdLogMessage(CUPSD_LOG_INFO
,
8663 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8664 printer
->name
, get_username(con
));
8667 * Everything was ok, so return OK status...
8670 con
->response
->request
.status
.status_code
= IPP_OK
;
8675 * 'move_job()' - Move a job to a new destination.
8679 move_job(cupsd_client_t
*con
, /* I - Client connection */
8680 ipp_attribute_t
*uri
) /* I - Job URI */
8682 http_status_t status
; /* Policy status */
8683 ipp_attribute_t
*attr
; /* Current attribute */
8684 int jobid
; /* Job ID */
8685 cupsd_job_t
*job
; /* Current job */
8686 const char *src
; /* Source printer/class */
8687 cups_ptype_t stype
, /* Source type (printer or class) */
8688 dtype
; /* Destination type (printer/class) */
8689 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8690 username
[HTTP_MAX_URI
], /* Username portion of URI */
8691 host
[HTTP_MAX_URI
], /* Host portion of URI */
8692 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8693 int port
; /* Port portion of URI */
8694 cupsd_printer_t
*sprinter
, /* Source printer */
8695 *dprinter
; /* Destination printer */
8698 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8699 uri
->values
[0].string
.text
);
8702 * Get the new printer or class...
8705 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8706 IPP_TAG_URI
)) == NULL
)
8709 * Need job-printer-uri...
8712 send_ipp_status(con
, IPP_BAD_REQUEST
,
8713 _("job-printer-uri attribute missing"));
8717 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8723 send_ipp_status(con
, IPP_NOT_FOUND
,
8724 _("The printer or class was not found."));
8729 * See if we have a job URI or a printer URI...
8732 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8733 sizeof(scheme
), username
, sizeof(username
), host
,
8734 sizeof(host
), &port
, resource
, sizeof(resource
));
8736 if (!strcmp(uri
->name
, "printer-uri"))
8739 * Got a printer URI; see if we also have a job-id attribute...
8742 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8743 IPP_TAG_INTEGER
)) == NULL
)
8749 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8750 &sprinter
)) == NULL
)
8756 send_ipp_status(con
, IPP_NOT_FOUND
,
8757 _("The printer or class was not found."));
8766 * Otherwise, just move a single job...
8769 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8772 * Nope - return a "not found" error...
8775 send_ipp_status(con
, IPP_NOT_FOUND
,
8776 _("Job #%d does not exist"), attr
->values
[0].integer
);
8782 * Job found, initialize source pointers...
8793 * Got a job URI; parse it to get the job ID...
8796 if (strncmp(resource
, "/jobs/", 6))
8802 send_ipp_status(con
, IPP_BAD_REQUEST
,
8803 _("Bad job-uri attribute \"%s\""),
8804 uri
->values
[0].string
.text
);
8809 * See if the job exists...
8812 jobid
= atoi(resource
+ 6);
8814 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8817 * Nope - return a "not found" error...
8820 send_ipp_status(con
, IPP_NOT_FOUND
,
8821 _("Job #%d does not exist"), jobid
);
8827 * Job found, initialize source pointers...
8836 * Check the policy of the destination printer...
8839 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8840 job
? job
->username
: NULL
)) != HTTP_OK
)
8842 send_http_error(con
, status
, dprinter
);
8847 * Now move the job or jobs...
8853 * See if the job has been completed...
8856 if (job
->state_value
> IPP_JOB_STOPPED
)
8859 * Return a "not-possible" error...
8862 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8863 _("Job #%d is finished and cannot be altered"),
8869 * See if the job is owned by the requesting user...
8872 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8874 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8875 cupsdFindDest(job
->dest
));
8880 * Move the job to a different printer or class...
8883 cupsdMoveJob(job
, dprinter
);
8888 * Got the source printer, now look through the jobs...
8891 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8893 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8896 * See if the job is pointing at the source printer or has not been
8900 if (strcasecmp(job
->dest
, src
) ||
8901 job
->state_value
> IPP_JOB_STOPPED
)
8905 * See if the job can be moved by the requesting user...
8908 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8912 * Move the job to a different printer or class...
8915 cupsdMoveJob(job
, dprinter
);
8920 * Start jobs if possible...
8926 * Return with "everything is OK" status...
8929 con
->response
->request
.status
.status_code
= IPP_OK
;
8934 * 'ppd_parse_line()' - Parse a PPD default line.
8937 static int /* O - 0 on success, -1 on failure */
8938 ppd_parse_line(const char *line
, /* I - Line */
8939 char *option
, /* O - Option name */
8940 int olen
, /* I - Size of option name */
8941 char *choice
, /* O - Choice name */
8942 int clen
) /* I - Size of choice name */
8945 * Verify this is a default option line...
8948 if (strncmp(line
, "*Default", 8))
8952 * Read the option name...
8955 for (line
+= 8, olen
--;
8956 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8967 * Skip everything else up to the colon (:)...
8970 while (*line
&& *line
!= ':')
8979 * Now grab the option choice, skipping leading whitespace...
8982 while (isspace(*line
& 255))
8986 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8997 * Return with no errors...
9005 * 'print_job()' - Print a file to a printer or class.
9009 print_job(cupsd_client_t
*con
, /* I - Client connection */
9010 ipp_attribute_t
*uri
) /* I - Printer URI */
9012 ipp_attribute_t
*attr
; /* Current attribute */
9013 ipp_attribute_t
*format
; /* Document-format attribute */
9014 const char *default_format
; /* document-format-default value */
9015 cupsd_job_t
*job
; /* New job */
9016 char filename
[1024]; /* Job filename */
9017 mime_type_t
*filetype
; /* Type of file */
9018 char super
[MIME_MAX_SUPER
], /* Supertype of file */
9019 type
[MIME_MAX_TYPE
], /* Subtype of file */
9020 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9021 /* Textual name of mime type */
9022 cupsd_printer_t
*printer
; /* Printer data */
9023 struct stat fileinfo
; /* File information */
9024 int kbytes
; /* Size of file */
9025 int compression
; /* Document compression */
9028 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
9029 uri
->values
[0].string
.text
);
9032 * Validate print file attributes, for now just document-format and
9033 * compression (CUPS only supports "none" and "gzip")...
9036 compression
= CUPS_FILE_NONE
;
9038 if ((attr
= ippFindAttribute(con
->request
, "compression",
9039 IPP_TAG_KEYWORD
)) != NULL
)
9041 if (strcmp(attr
->values
[0].string
.text
, "none")
9043 && strcmp(attr
->values
[0].string
.text
, "gzip")
9044 #endif /* HAVE_LIBZ */
9047 send_ipp_status(con
, IPP_ATTRIBUTES
,
9048 _("Unsupported compression \"%s\""),
9049 attr
->values
[0].string
.text
);
9050 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9051 "compression", NULL
, attr
->values
[0].string
.text
);
9056 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9057 compression
= CUPS_FILE_GZIP
;
9058 #endif /* HAVE_LIBZ */
9062 * Do we have a file to print?
9067 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
9072 * Is the destination valid?
9075 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
9081 send_ipp_status(con
, IPP_NOT_FOUND
,
9082 _("The printer or class was not found."));
9087 * Is it a format we support?
9090 if ((format
= ippFindAttribute(con
->request
, "document-format",
9091 IPP_TAG_MIMETYPE
)) != NULL
)
9094 * Grab format from client...
9097 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9100 send_ipp_status(con
, IPP_BAD_REQUEST
,
9101 _("Bad document-format \"%s\""),
9102 format
->values
[0].string
.text
);
9106 else if ((default_format
= cupsGetOption("document-format",
9107 printer
->num_options
,
9108 printer
->options
)) != NULL
)
9111 * Use default document format...
9114 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9116 send_ipp_status(con
, IPP_BAD_REQUEST
,
9117 _("Bad document-format \"%s\""),
9128 strcpy(super
, "application");
9129 strcpy(type
, "octet-stream");
9132 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9135 * Auto-type the file...
9138 ipp_attribute_t
*doc_name
; /* document-name attribute */
9141 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9143 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9144 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9145 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9149 filetype
= mimeType(MimeDatabase
, super
, type
);
9151 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9152 filetype
->super
, filetype
->type
);
9155 filetype
= mimeType(MimeDatabase
, super
, type
);
9159 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9162 * Replace the document-format attribute value with the auto-typed or
9166 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9171 _cupsStrFree(format
->values
[0].string
.text
);
9173 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9176 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9177 "document-format", NULL
, mimetype
);
9181 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9182 _("Unsupported document-format \"%s\""),
9183 format
? format
->values
[0].string
.text
:
9184 "application/octet-stream");
9185 cupsdLogMessage(CUPSD_LOG_INFO
,
9186 "Hint: Do you have the raw file printing rules enabled?");
9189 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9190 "document-format", NULL
, format
->values
[0].string
.text
);
9196 * Read any embedded job ticket info from PS files...
9199 if (!strcasecmp(filetype
->super
, "application") &&
9200 (!strcasecmp(filetype
->type
, "postscript") ||
9201 !strcasecmp(filetype
->type
, "pdf")))
9202 read_job_ticket(con
);
9205 * Create the job object...
9208 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9212 * Update quota data...
9215 if (stat(con
->filename
, &fileinfo
))
9218 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9220 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9222 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9223 IPP_TAG_INTEGER
)) != NULL
)
9224 attr
->values
[0].integer
+= kbytes
;
9227 * Add the job file...
9230 if (add_file(con
, job
, filetype
, compression
))
9233 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9235 rename(con
->filename
, filename
);
9236 cupsdClearString(&con
->filename
);
9239 * See if we need to add the ending sheet...
9242 if (cupsdTimeoutJob(job
))
9246 * Log and save the job...
9249 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9250 "File of type %s/%s queued by \"%s\".",
9251 filetype
->super
, filetype
->type
, job
->username
);
9252 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9253 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9254 job
->dest
, job
->username
);
9257 * Start the job if possible...
9265 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9267 * This function only gets called when printing a single PDF or PostScript
9268 * file using the Print-Job operation. It doesn't work for Create-Job +
9269 * Send-File, since the job attributes need to be set at job creation
9270 * time for banners to work. The embedded job ticket stuff is here
9271 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9272 * options and IPP attributes which otherwise would be lost.
9274 * The format of a job ticket is simple:
9276 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9278 * %cupsJobTicket: attr1=value1
9279 * %cupsJobTicket: attr2=value2
9281 * %cupsJobTicket: attrN=valueN
9283 * Job ticket lines must appear immediately after the first line that
9284 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9285 * stops looking for job ticket info when it finds a line that does not begin
9286 * with "%cupsJobTicket:".
9288 * The maximum length of a job ticket line, including the prefix, is
9289 * 255 characters to conform with the Adobe DSC.
9291 * Read-only attributes are rejected with a notice to the error log in
9292 * case a malicious user tries anything. Since the job ticket is read
9293 * prior to attribute validation in print_job(), job ticket attributes
9294 * will go through the same validation as IPP attributes...
9298 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9300 cups_file_t
*fp
; /* File to read from */
9301 char line
[256]; /* Line data */
9302 int num_options
; /* Number of options */
9303 cups_option_t
*options
; /* Options */
9304 ipp_t
*ticket
; /* New attributes */
9305 ipp_attribute_t
*attr
, /* Current attribute */
9306 *attr2
, /* Job attribute */
9307 *prev2
; /* Previous job attribute */
9311 * First open the print file...
9314 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9316 cupsdLogMessage(CUPSD_LOG_ERROR
,
9317 "Unable to open print file for job ticket - %s",
9323 * Skip the first line...
9326 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9328 cupsdLogMessage(CUPSD_LOG_ERROR
,
9329 "Unable to read from print file for job ticket - %s",
9335 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9338 * Not a DSC-compliant file, so no job ticket info will be available...
9346 * Read job ticket info from the file...
9352 while (cupsFileGets(fp
, line
, sizeof(line
)))
9355 * Stop at the first non-ticket line...
9358 if (strncmp(line
, "%cupsJobTicket:", 15))
9362 * Add the options to the option array...
9365 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9369 * Done with the file; see if we have any options...
9374 if (num_options
== 0)
9378 * OK, convert the options to an attribute list, and apply them to
9383 cupsEncodeOptions(ticket
, num_options
, options
);
9386 * See what the user wants to change.
9389 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9391 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9394 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9395 !strcmp(attr
->name
, "job-originating-user-name") ||
9396 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9397 !strcmp(attr
->name
, "job-k-octets") ||
9398 !strcmp(attr
->name
, "job-id") ||
9399 !strncmp(attr
->name
, "job-state", 9) ||
9400 !strncmp(attr
->name
, "time-at-", 8))
9401 continue; /* Read-only attrs */
9403 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9404 IPP_TAG_ZERO
)) != NULL
)
9407 * Some other value; first free the old value...
9410 if (con
->request
->attrs
== attr2
)
9412 con
->request
->attrs
= attr2
->next
;
9417 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9418 if (prev2
->next
== attr2
)
9420 prev2
->next
= attr2
->next
;
9425 if (con
->request
->last
== attr2
)
9426 con
->request
->last
= prev2
;
9428 _ippFreeAttr(attr2
);
9432 * Add new option by copying it...
9435 copy_attribute(con
->request
, attr
, 0);
9439 * Then free the attribute list and option array...
9443 cupsFreeOptions(num_options
, options
);
9448 * 'reject_jobs()' - Reject print jobs to a printer.
9452 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9453 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9455 http_status_t status
; /* Policy status */
9456 cups_ptype_t dtype
; /* Destination type (printer/class) */
9457 cupsd_printer_t
*printer
; /* Printer data */
9458 ipp_attribute_t
*attr
; /* printer-state-message text */
9461 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9462 con
->http
.fd
, uri
->values
[0].string
.text
);
9465 * Is the destination valid?
9468 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9474 send_ipp_status(con
, IPP_NOT_FOUND
,
9475 _("The printer or class was not found."));
9483 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9485 send_http_error(con
, status
, printer
);
9490 * Reject jobs sent to the printer...
9493 printer
->accepting
= 0;
9495 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9496 IPP_TAG_TEXT
)) == NULL
)
9497 strcpy(printer
->state_message
, "Rejecting Jobs");
9499 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9500 sizeof(printer
->state_message
));
9502 cupsdAddPrinterHistory(printer
);
9504 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9505 "No longer accepting jobs.");
9507 if (dtype
& CUPS_PRINTER_CLASS
)
9509 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9511 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9512 printer
->name
, get_username(con
));
9516 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9518 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9519 printer
->name
, get_username(con
));
9523 * Everything was ok, so return OK status...
9526 con
->response
->request
.status
.status_code
= IPP_OK
;
9531 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9535 release_held_new_jobs(
9536 cupsd_client_t
*con
, /* I - Connection */
9537 ipp_attribute_t
*uri
) /* I - Printer URI */
9539 http_status_t status
; /* Policy status */
9540 cups_ptype_t dtype
; /* Destination type (printer/class) */
9541 cupsd_printer_t
*printer
; /* Printer data */
9544 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9545 con
->http
.fd
, uri
->values
[0].string
.text
);
9548 * Is the destination valid?
9551 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9557 send_ipp_status(con
, IPP_NOT_FOUND
,
9558 _("The printer or class was not found."));
9566 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9568 send_http_error(con
, status
, printer
);
9573 * Hold pending/new jobs sent to the printer...
9576 printer
->holding_new_jobs
= 0;
9578 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9579 cupsdAddPrinterHistory(printer
);
9581 if (dtype
& CUPS_PRINTER_CLASS
)
9582 cupsdLogMessage(CUPSD_LOG_INFO
,
9583 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9584 printer
->name
, get_username(con
));
9586 cupsdLogMessage(CUPSD_LOG_INFO
,
9587 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9588 printer
->name
, get_username(con
));
9591 * Everything was ok, so return OK status...
9594 con
->response
->request
.status
.status_code
= IPP_OK
;
9599 * 'release_job()' - Release a held print job.
9603 release_job(cupsd_client_t
*con
, /* I - Client connection */
9604 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9606 ipp_attribute_t
*attr
; /* Current attribute */
9607 int jobid
; /* Job ID */
9608 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9609 username
[HTTP_MAX_URI
], /* Username portion of URI */
9610 host
[HTTP_MAX_URI
], /* Host portion of URI */
9611 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9612 int port
; /* Port portion of URI */
9613 cupsd_job_t
*job
; /* Job information */
9616 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9617 con
->http
.fd
, uri
->values
[0].string
.text
);
9620 * See if we have a job URI or a printer URI...
9623 if (!strcmp(uri
->name
, "printer-uri"))
9626 * Got a printer URI; see if we also have a job-id attribute...
9629 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9630 IPP_TAG_INTEGER
)) == NULL
)
9632 send_ipp_status(con
, IPP_BAD_REQUEST
,
9633 _("Got a printer-uri attribute but no job-id"));
9637 jobid
= attr
->values
[0].integer
;
9642 * Got a job URI; parse it to get the job ID...
9645 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9646 sizeof(scheme
), username
, sizeof(username
), host
,
9647 sizeof(host
), &port
, resource
, sizeof(resource
));
9649 if (strncmp(resource
, "/jobs/", 6))
9655 send_ipp_status(con
, IPP_BAD_REQUEST
,
9656 _("Bad job-uri attribute \"%s\""),
9657 uri
->values
[0].string
.text
);
9661 jobid
= atoi(resource
+ 6);
9665 * See if the job exists...
9668 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9671 * Nope - return a "not found" error...
9674 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9679 * See if job is "held"...
9682 if (job
->state_value
!= IPP_JOB_HELD
)
9685 * Nope - return a "not possible" error...
9688 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held"), jobid
);
9693 * See if the job is owned by the requesting user...
9696 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9698 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9699 cupsdFindDest(job
->dest
));
9704 * Reset the job-hold-until value to "no-hold"...
9707 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9708 IPP_TAG_KEYWORD
)) == NULL
)
9709 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9713 _cupsStrFree(attr
->values
[0].string
.text
);
9715 attr
->value_tag
= IPP_TAG_KEYWORD
;
9716 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9718 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9719 "Job job-hold-until value changed by user.");
9723 * Release the job and return...
9726 cupsdReleaseJob(job
);
9728 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9729 "Job released by user.");
9731 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9733 con
->response
->request
.status
.status_code
= IPP_OK
;
9740 * 'renew_subscription()' - Renew an existing subscription...
9745 cupsd_client_t
*con
, /* I - Client connection */
9746 int sub_id
) /* I - Subscription ID */
9748 http_status_t status
; /* Policy status */
9749 cupsd_subscription_t
*sub
; /* Subscription */
9750 ipp_attribute_t
*lease
; /* notify-lease-duration */
9753 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9754 "renew_subscription(con=%p[%d], sub_id=%d)",
9755 con
, con
->http
.fd
, sub_id
);
9758 * Is the subscription ID valid?
9761 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9764 * Bad subscription ID...
9767 send_ipp_status(con
, IPP_NOT_FOUND
,
9768 _("notify-subscription-id %d no good"), sub_id
);
9775 * Job subscriptions cannot be renewed...
9778 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9779 _("Job subscriptions cannot be renewed"));
9787 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9789 con
, sub
->owner
)) != HTTP_OK
)
9791 send_http_error(con
, status
, sub
->dest
);
9796 * Renew the subscription...
9799 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9802 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9804 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9806 cupsdLogMessage(CUPSD_LOG_INFO
,
9807 "renew_subscription: Limiting notify-lease-duration to "
9810 sub
->lease
= MaxLeaseDuration
;
9813 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9815 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9817 con
->response
->request
.status
.status_code
= IPP_OK
;
9819 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9820 "notify-lease-duration", sub
->lease
);
9825 * 'restart_job()' - Restart an old print job.
9829 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9830 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9832 ipp_attribute_t
*attr
; /* Current attribute */
9833 int jobid
; /* Job ID */
9834 cupsd_job_t
*job
; /* Job information */
9835 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9836 username
[HTTP_MAX_URI
], /* Username portion of URI */
9837 host
[HTTP_MAX_URI
], /* Host portion of URI */
9838 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9839 int port
; /* Port portion of URI */
9842 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9843 con
->http
.fd
, uri
->values
[0].string
.text
);
9846 * See if we have a job URI or a printer URI...
9849 if (!strcmp(uri
->name
, "printer-uri"))
9852 * Got a printer URI; see if we also have a job-id attribute...
9855 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9856 IPP_TAG_INTEGER
)) == NULL
)
9858 send_ipp_status(con
, IPP_BAD_REQUEST
,
9859 _("Got a printer-uri attribute but no job-id"));
9863 jobid
= attr
->values
[0].integer
;
9868 * Got a job URI; parse it to get the job ID...
9871 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9872 sizeof(scheme
), username
, sizeof(username
), host
,
9873 sizeof(host
), &port
, resource
, sizeof(resource
));
9875 if (strncmp(resource
, "/jobs/", 6))
9881 send_ipp_status(con
, IPP_BAD_REQUEST
,
9882 _("Bad job-uri attribute \"%s\""),
9883 uri
->values
[0].string
.text
);
9887 jobid
= atoi(resource
+ 6);
9891 * See if the job exists...
9894 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9897 * Nope - return a "not found" error...
9900 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9905 * See if job is in any of the "completed" states...
9908 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9911 * Nope - return a "not possible" error...
9914 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete"),
9920 * See if we have retained the job files...
9925 if (!job
->attrs
|| job
->num_files
== 0)
9928 * Nope - return a "not possible" error...
9931 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9932 _("Job #%d cannot be restarted - no files"), jobid
);
9937 * See if the job is owned by the requesting user...
9940 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9942 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9943 cupsdFindDest(job
->dest
));
9948 * See if the job-hold-until attribute is specified...
9951 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9952 IPP_TAG_KEYWORD
)) == NULL
)
9953 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9955 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9958 * Return the job to a held state...
9961 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9962 "Restarted by \"%s\" with job-hold-until=%s.",
9963 username
, attr
->values
[0].string
.text
);
9964 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9966 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9967 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9968 attr
->values
[0].string
.text
);
9973 * Restart the job...
9976 cupsdRestartJob(job
);
9980 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9982 con
->response
->request
.status
.status_code
= IPP_OK
;
9987 * 'save_auth_info()' - Save authentication information for a job.
9992 cupsd_client_t
*con
, /* I - Client connection */
9993 cupsd_job_t
*job
, /* I - Job */
9994 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9996 int i
; /* Looping var */
9997 char filename
[1024]; /* Job authentication filename */
9998 cups_file_t
*fp
; /* Job authentication file */
9999 char line
[2048]; /* Line for file */
10000 cupsd_printer_t
*dest
; /* Destination printer/class */
10004 * This function saves the in-memory authentication information for
10005 * a job so that it can be used to authenticate with a remote host.
10006 * The information is stored in a file that is readable only by the
10007 * root user. The fields are Base-64 encoded, each on a separate line,
10008 * followed by random number (up to 1024) of newlines to limit the
10009 * amount of information that is exposed.
10011 * Because of the potential for exposing of authentication information,
10012 * this functionality is only enabled when running cupsd as root.
10014 * This caching only works for the Basic and BasicDigest authentication
10015 * types. Digest authentication cannot be cached this way, and in
10016 * the future Kerberos authentication may make all of this obsolete.
10018 * Authentication information is saved whenever an authenticated
10019 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
10022 * This information is deleted after a job is completed or canceled,
10023 * so reprints may require subsequent re-authentication.
10029 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
10033 * Create the authentication file and change permissions...
10036 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
10037 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
10039 cupsdLogMessage(CUPSD_LOG_ERROR
,
10040 "Unable to save authentication info to \"%s\" - %s",
10041 filename
, strerror(errno
));
10045 fchown(cupsFileNumber(fp
), 0, 0);
10046 fchmod(cupsFileNumber(fp
), 0400);
10048 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
10051 * Write 1 to 3 auth values...
10054 cupsdClearString(&job
->auth_username
);
10055 cupsdClearString(&job
->auth_domain
);
10056 cupsdClearString(&job
->auth_password
);
10058 for (i
= 0; i
< auth_info
->num_values
; i
++)
10060 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
10061 strlen(auth_info
->values
[i
].string
.text
));
10062 cupsFilePrintf(fp
, "%s\n", line
);
10064 if (!strcmp(dest
->auth_info_required
[i
], "username"))
10065 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
10066 auth_info
->values
[i
].string
.text
);
10067 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
10068 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
10069 auth_info
->values
[i
].string
.text
);
10070 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
10071 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
10072 auth_info
->values
[i
].string
.text
);
10075 else if (con
->username
[0])
10078 * Write the authenticated username...
10081 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
10082 cupsFilePrintf(fp
, "%s\n", line
);
10084 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
10085 cupsdClearString(&job
->auth_domain
);
10088 * Write the authenticated password...
10091 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10092 cupsFilePrintf(fp
, "%s\n", line
);
10094 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
10098 * Write a random number of newlines to the end of the file...
10101 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10102 cupsFilePutChar(fp
, '\n');
10105 * Close the file and return...
10110 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10111 # ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
10112 if (con
->have_gss
&&
10113 (con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
|| con
->gss_creds
))
10115 if (con
->have_gss
&& con
->gss_creds
)
10116 # endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
10117 save_krb5_creds(con
, job
);
10118 else if (job
->ccname
)
10119 cupsdClearString(&(job
->ccname
));
10120 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10124 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10126 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
10130 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
10131 cupsd_job_t
*job
) /* I - Job */
10134 * Get the credentials...
10137 job
->ccache
= cupsdCopyKrb5Creds(con
);
10140 * Add the KRB5CCNAME environment variable to the job so that the
10141 * backend can use the credentials when printing.
10146 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
10147 krb5_cc_get_name(KerberosContext
, job
->ccache
));
10149 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
10152 cupsdClearString(&(job
->ccname
));
10154 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10158 * 'send_document()' - Send a file to a printer or class.
10162 send_document(cupsd_client_t
*con
, /* I - Client connection */
10163 ipp_attribute_t
*uri
) /* I - Printer URI */
10165 ipp_attribute_t
*attr
; /* Current attribute */
10166 ipp_attribute_t
*format
; /* Request's document-format attribute */
10167 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10168 const char *default_format
;/* document-format-default value */
10169 int jobid
; /* Job ID number */
10170 cupsd_job_t
*job
; /* Current job */
10171 char job_uri
[HTTP_MAX_URI
],
10173 scheme
[HTTP_MAX_URI
],
10174 /* Method portion of URI */
10175 username
[HTTP_MAX_URI
],
10176 /* Username portion of URI */
10177 host
[HTTP_MAX_URI
],
10178 /* Host portion of URI */
10179 resource
[HTTP_MAX_URI
];
10180 /* Resource portion of URI */
10181 int port
; /* Port portion of URI */
10182 mime_type_t
*filetype
; /* Type of file */
10183 char super
[MIME_MAX_SUPER
],
10184 /* Supertype of file */
10185 type
[MIME_MAX_TYPE
],
10186 /* Subtype of file */
10187 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10188 /* Textual name of mime type */
10189 char filename
[1024]; /* Job filename */
10190 cupsd_printer_t
*printer
; /* Current printer */
10191 struct stat fileinfo
; /* File information */
10192 int kbytes
; /* Size of file */
10193 int compression
; /* Type of compression */
10194 int start_job
; /* Start the job? */
10197 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10198 con
->http
.fd
, uri
->values
[0].string
.text
);
10201 * See if we have a job URI or a printer URI...
10204 if (!strcmp(uri
->name
, "printer-uri"))
10207 * Got a printer URI; see if we also have a job-id attribute...
10210 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10211 IPP_TAG_INTEGER
)) == NULL
)
10213 send_ipp_status(con
, IPP_BAD_REQUEST
,
10214 _("Got a printer-uri attribute but no job-id"));
10218 jobid
= attr
->values
[0].integer
;
10223 * Got a job URI; parse it to get the job ID...
10226 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10227 sizeof(scheme
), username
, sizeof(username
), host
,
10228 sizeof(host
), &port
, resource
, sizeof(resource
));
10230 if (strncmp(resource
, "/jobs/", 6))
10236 send_ipp_status(con
, IPP_BAD_REQUEST
,
10237 _("Bad job-uri attribute \"%s\""),
10238 uri
->values
[0].string
.text
);
10242 jobid
= atoi(resource
+ 6);
10246 * See if the job exists...
10249 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10252 * Nope - return a "not found" error...
10255 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10259 printer
= cupsdFindDest(job
->dest
);
10262 * See if the job is owned by the requesting user...
10265 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10267 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10268 cupsdFindDest(job
->dest
));
10273 * OK, see if the client is sending the document compressed - CUPS
10274 * only supports "none" and "gzip".
10277 compression
= CUPS_FILE_NONE
;
10279 if ((attr
= ippFindAttribute(con
->request
, "compression",
10280 IPP_TAG_KEYWORD
)) != NULL
)
10282 if (strcmp(attr
->values
[0].string
.text
, "none")
10284 && strcmp(attr
->values
[0].string
.text
, "gzip")
10285 #endif /* HAVE_LIBZ */
10288 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\""),
10289 attr
->values
[0].string
.text
);
10290 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10291 "compression", NULL
, attr
->values
[0].string
.text
);
10296 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10297 compression
= CUPS_FILE_GZIP
;
10298 #endif /* HAVE_LIBZ */
10302 * Do we have a file to print?
10305 if (!con
->filename
)
10308 * Check for an empty request with "last-document" set to true, which is
10309 * used to close an "open" job by RFC 2911, section 3.3.2.
10312 if (job
->num_files
> 0 &&
10313 (attr
= ippFindAttribute(con
->request
, "last-document",
10314 IPP_TAG_BOOLEAN
)) != NULL
&&
10315 attr
->values
[0].boolean
)
10316 goto last_document
;
10318 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
10323 * Is it a format we support?
10326 if ((format
= ippFindAttribute(con
->request
, "document-format",
10327 IPP_TAG_MIMETYPE
)) != NULL
)
10330 * Grab format from client...
10333 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10336 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
10337 format
->values
[0].string
.text
);
10341 else if ((default_format
= cupsGetOption("document-format",
10342 printer
->num_options
,
10343 printer
->options
)) != NULL
)
10346 * Use default document format...
10349 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10351 send_ipp_status(con
, IPP_BAD_REQUEST
,
10352 _("Could not scan type \"%s\""),
10360 * No document format attribute? Auto-type it!
10363 strcpy(super
, "application");
10364 strcpy(type
, "octet-stream");
10367 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10370 * Auto-type the file...
10373 ipp_attribute_t
*doc_name
; /* document-name attribute */
10376 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10378 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10379 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10380 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10384 filetype
= mimeType(MimeDatabase
, super
, type
);
10386 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10387 filetype
->super
, filetype
->type
);
10390 filetype
= mimeType(MimeDatabase
, super
, type
);
10395 * Replace the document-format attribute value with the auto-typed or
10399 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10402 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10403 IPP_TAG_MIMETYPE
)) != NULL
)
10405 _cupsStrFree(jformat
->values
[0].string
.text
);
10407 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10410 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10411 "document-format", NULL
, mimetype
);
10413 else if (!filetype
)
10415 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10416 _("Unsupported format \'%s/%s\'"), super
, type
);
10417 cupsdLogMessage(CUPSD_LOG_INFO
,
10418 "Hint: Do you have the raw file printing rules enabled?");
10421 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10422 "document-format", NULL
, format
->values
[0].string
.text
);
10427 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10429 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10432 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10433 _("Unsupported format \'%s\'"), mimetype
);
10435 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10436 "document-format", NULL
, mimetype
);
10442 * Add the file to the job...
10447 if (add_file(con
, job
, filetype
, compression
))
10450 if (stat(con
->filename
, &fileinfo
))
10453 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10455 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10457 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10458 IPP_TAG_INTEGER
)) != NULL
)
10459 attr
->values
[0].integer
+= kbytes
;
10461 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10463 rename(con
->filename
, filename
);
10465 cupsdClearString(&con
->filename
);
10467 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10468 filetype
->super
, filetype
->type
, job
->username
);
10471 * Start the job if this is the last document...
10476 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10477 IPP_TAG_BOOLEAN
)) != NULL
&&
10478 attr
->values
[0].boolean
)
10481 * See if we need to add the ending sheet...
10484 if (cupsdTimeoutJob(job
))
10487 if (job
->state_value
== IPP_JOB_STOPPED
)
10489 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10490 job
->state_value
= IPP_JOB_PENDING
;
10492 else if (job
->state_value
== IPP_JOB_HELD
)
10494 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10495 IPP_TAG_KEYWORD
)) == NULL
)
10496 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10498 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10500 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10501 job
->state_value
= IPP_JOB_PENDING
;
10506 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10512 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10513 IPP_TAG_KEYWORD
)) == NULL
)
10514 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10516 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10518 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10519 job
->state_value
= IPP_JOB_HELD
;
10520 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10523 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10530 * Fill in the response info...
10533 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10536 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10539 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10541 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10543 add_job_state_reasons(con
, job
);
10545 con
->response
->request
.status
.status_code
= IPP_OK
;
10548 * Start the job if necessary...
10557 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10562 cupsd_client_t
*con
, /* I - Client connection */
10563 http_status_t status
, /* I - HTTP status code */
10564 cupsd_printer_t
*printer
) /* I - Printer, if any */
10566 ipp_attribute_t
*uri
; /* Request URI, if any */
10569 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10570 IPP_TAG_URI
)) == NULL
)
10571 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10573 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10574 "Returning HTTP %s for %s (%s) from %s",
10575 httpStatus(status
),
10576 ippOpString(con
->request
->request
.op
.operation_id
),
10577 uri
? uri
->values
[0].string
.text
: "no URI",
10578 con
->http
.hostname
);
10582 int auth_type
; /* Type of authentication required */
10585 auth_type
= CUPSD_AUTH_NONE
;
10587 if (status
== HTTP_UNAUTHORIZED
&&
10588 printer
->num_auth_info_required
> 0 &&
10589 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10591 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10592 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10593 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10596 * Creating and authenticating jobs requires Kerberos...
10599 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10604 * Use policy/location-defined authentication requirements...
10607 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10608 cupsd_location_t
*auth
; /* Pointer to authentication element */
10611 if (printer
->type
& CUPS_PRINTER_CLASS
)
10612 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10614 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10616 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10617 auth
->type
== CUPSD_AUTH_NONE
)
10618 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10620 con
->request
->request
.op
.operation_id
:
10625 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10626 auth_type
= DefaultAuthType
;
10628 auth_type
= auth
->type
;
10632 cupsdSendError(con
, status
, auth_type
);
10635 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10637 ippDelete(con
->response
);
10638 con
->response
= NULL
;
10645 * 'send_ipp_status()' - Send a status back to the IPP client.
10649 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10650 ipp_status_t status
, /* I - IPP status code */
10651 const char *message
,/* I - Status message */
10652 ...) /* I - Additional args as needed */
10654 va_list ap
; /* Pointer to additional args */
10655 char formatted
[1024]; /* Formatted errror message */
10658 va_start(ap
, message
);
10659 vsnprintf(formatted
, sizeof(formatted
),
10660 _cupsLangString(con
->language
, message
), ap
);
10663 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10664 ippOpString(con
->request
->request
.op
.operation_id
),
10665 ippErrorString(status
), formatted
);
10667 con
->response
->request
.status
.status_code
= status
;
10669 if (ippFindAttribute(con
->response
, "attributes-charset",
10670 IPP_TAG_ZERO
) == NULL
)
10671 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10672 "attributes-charset", NULL
, "utf-8");
10674 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10675 IPP_TAG_ZERO
) == NULL
)
10676 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10677 "attributes-natural-language", NULL
, DefaultLanguage
);
10679 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10680 "status-message", NULL
, formatted
);
10685 * 'set_default()' - Set the default destination...
10689 set_default(cupsd_client_t
*con
, /* I - Client connection */
10690 ipp_attribute_t
*uri
) /* I - Printer URI */
10692 http_status_t status
; /* Policy status */
10693 cups_ptype_t dtype
; /* Destination type (printer/class) */
10694 cupsd_printer_t
*printer
, /* Printer */
10695 *oldprinter
; /* Old default printer */
10698 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10699 con
->http
.fd
, uri
->values
[0].string
.text
);
10702 * Is the destination valid?
10705 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10711 send_ipp_status(con
, IPP_NOT_FOUND
,
10712 _("The printer or class was not found."));
10720 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10722 send_http_error(con
, status
, NULL
);
10727 * Set it as the default...
10730 oldprinter
= DefaultPrinter
;
10731 DefaultPrinter
= printer
;
10734 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10735 "%s is no longer the default printer.", oldprinter
->name
);
10737 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10738 "%s is now the default printer.", printer
->name
);
10740 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10741 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10743 cupsdLogMessage(CUPSD_LOG_INFO
,
10744 "Default destination set to \"%s\" by \"%s\".",
10745 printer
->name
, get_username(con
));
10748 * Everything was ok, so return OK status...
10751 con
->response
->request
.status
.status_code
= IPP_OK
;
10756 * 'set_job_attrs()' - Set job attributes.
10760 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10761 ipp_attribute_t
*uri
) /* I - Job URI */
10763 ipp_attribute_t
*attr
, /* Current attribute */
10764 *attr2
; /* Job attribute */
10765 int jobid
; /* Job ID */
10766 cupsd_job_t
*job
; /* Current job */
10767 char scheme
[HTTP_MAX_URI
],
10768 /* Method portion of URI */
10769 username
[HTTP_MAX_URI
],
10770 /* Username portion of URI */
10771 host
[HTTP_MAX_URI
],
10772 /* Host portion of URI */
10773 resource
[HTTP_MAX_URI
];
10774 /* Resource portion of URI */
10775 int port
; /* Port portion of URI */
10776 int event
; /* Events? */
10777 int check_jobs
; /* Check jobs? */
10780 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10781 con
->http
.fd
, uri
->values
[0].string
.text
);
10784 * Start with "everything is OK" status...
10787 con
->response
->request
.status
.status_code
= IPP_OK
;
10790 * See if we have a job URI or a printer URI...
10793 if (!strcmp(uri
->name
, "printer-uri"))
10796 * Got a printer URI; see if we also have a job-id attribute...
10799 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10800 IPP_TAG_INTEGER
)) == NULL
)
10802 send_ipp_status(con
, IPP_BAD_REQUEST
,
10803 _("Got a printer-uri attribute but no job-id"));
10807 jobid
= attr
->values
[0].integer
;
10812 * Got a job URI; parse it to get the job ID...
10815 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10816 sizeof(scheme
), username
, sizeof(username
), host
,
10817 sizeof(host
), &port
, resource
, sizeof(resource
));
10819 if (strncmp(resource
, "/jobs/", 6))
10825 send_ipp_status(con
, IPP_BAD_REQUEST
,
10826 _("Bad job-uri attribute \"%s\""),
10827 uri
->values
[0].string
.text
);
10831 jobid
= atoi(resource
+ 6);
10835 * See if the job exists...
10838 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10841 * Nope - return a "not found" error...
10844 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10849 * See if the job has been completed...
10852 if (job
->state_value
> IPP_JOB_STOPPED
)
10855 * Return a "not-possible" error...
10858 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10859 _("Job #%d is finished and cannot be altered"), jobid
);
10864 * See if the job is owned by the requesting user...
10867 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10869 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10870 cupsdFindDest(job
->dest
));
10875 * See what the user wants to change.
10883 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10885 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10888 if (!strcmp(attr
->name
, "attributes-charset") ||
10889 !strcmp(attr
->name
, "attributes-natural-language") ||
10890 !strcmp(attr
->name
, "document-compression") ||
10891 !strcmp(attr
->name
, "document-format") ||
10892 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10893 !strcmp(attr
->name
, "job-document-access-errors") ||
10894 !strcmp(attr
->name
, "job-id") ||
10895 !strcmp(attr
->name
, "job-impressions-completed") ||
10896 !strcmp(attr
->name
, "job-k-octets") ||
10897 !strcmp(attr
->name
, "job-originating-host-name") ||
10898 !strcmp(attr
->name
, "job-originating-user-name") ||
10899 !strcmp(attr
->name
, "job-printer-up-time") ||
10900 !strcmp(attr
->name
, "job-printer-uri") ||
10901 !strcmp(attr
->name
, "job-sheets") ||
10902 !strcmp(attr
->name
, "job-state-message") ||
10903 !strcmp(attr
->name
, "job-state-reasons") ||
10904 !strcmp(attr
->name
, "job-uri") ||
10905 !strcmp(attr
->name
, "number-of-documents") ||
10906 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10907 !strcmp(attr
->name
, "output-device-assigned") ||
10908 !strncmp(attr
->name
, "date-time-at-", 13) ||
10909 !strncmp(attr
->name
, "job-k-octets", 12) ||
10910 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10911 !strncmp(attr
->name
, "time-at-", 8))
10917 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10918 _("%s cannot be changed."), attr
->name
);
10920 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10921 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10926 if (!strcmp(attr
->name
, "job-priority"))
10929 * Change the job priority...
10932 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10934 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value"));
10936 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10937 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10939 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10941 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10942 _("Job is completed and cannot be changed."));
10945 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10947 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10948 attr
->values
[0].integer
);
10949 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10952 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10953 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10956 else if (!strcmp(attr
->name
, "job-state"))
10959 * Change the job state...
10962 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10964 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value"));
10966 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10967 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10971 switch (attr
->values
[0].integer
)
10973 case IPP_JOB_PENDING
:
10974 case IPP_JOB_HELD
:
10975 if (job
->state_value
> IPP_JOB_HELD
)
10977 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10978 _("Job state cannot be changed."));
10981 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10983 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10984 attr
->values
[0].integer
);
10985 cupsdSetJobState(job
, attr
->values
[0].integer
,
10987 "Job state changed by \"%s\"", username
);
10992 case IPP_JOB_PROCESSING
:
10993 case IPP_JOB_STOPPED
:
10994 if (job
->state_value
!= attr
->values
[0].integer
)
10996 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10997 _("Job state cannot be changed."));
11002 case IPP_JOB_CANCELED
:
11003 case IPP_JOB_ABORTED
:
11004 case IPP_JOB_COMPLETED
:
11005 if (job
->state_value
> IPP_JOB_PROCESSING
)
11007 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11008 _("Job state cannot be changed."));
11011 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11013 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11014 attr
->values
[0].integer
);
11015 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
11017 "Job state changed by \"%s\"", username
);
11024 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
11026 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11027 IPP_TAG_ZERO
)) != NULL
)
11030 * Some other value; first free the old value...
11033 if (job
->attrs
->prev
)
11034 job
->attrs
->prev
->next
= attr2
->next
;
11036 job
->attrs
->attrs
= attr2
->next
;
11038 if (job
->attrs
->last
== attr2
)
11039 job
->attrs
->last
= job
->attrs
->prev
;
11041 _ippFreeAttr(attr2
);
11044 * Then copy the attribute...
11047 copy_attribute(job
->attrs
, attr
, 0);
11050 * See if the job-name or job-hold-until is being changed.
11053 if (!strcmp(attr
->name
, "job-hold-until"))
11055 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
11056 attr
->values
[0].string
.text
);
11057 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
11059 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
11061 cupsdReleaseJob(job
);
11065 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
11066 "Job held by \"%s\".", username
);
11068 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
11071 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
11074 * Delete the attribute...
11077 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11078 IPP_TAG_ZERO
)) != NULL
)
11080 if (job
->attrs
->prev
)
11081 job
->attrs
->prev
->next
= attr2
->next
;
11083 job
->attrs
->attrs
= attr2
->next
;
11085 if (attr2
== job
->attrs
->last
)
11086 job
->attrs
->last
= job
->attrs
->prev
;
11088 _ippFreeAttr(attr2
);
11090 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11096 * Add new option by copying it...
11099 copy_attribute(job
->attrs
, attr
, 0);
11101 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11110 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11113 * Send events as needed...
11116 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11117 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11118 cupsdFindDest(job
->dest
), job
,
11119 "Job priority changed by user.");
11121 if (event
& CUPSD_EVENT_JOB_STATE
)
11122 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11123 job
->state_value
== IPP_JOB_HELD
?
11124 "Job held by user." : "Job restarted by user.");
11126 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11127 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11128 "Job options changed by user.");
11131 * Start jobs if possible...
11140 * 'set_printer_attrs()' - Set printer attributes.
11144 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11145 ipp_attribute_t
*uri
) /* I - Printer */
11147 http_status_t status
; /* Policy status */
11148 cups_ptype_t dtype
; /* Destination type (printer/class) */
11149 cupsd_printer_t
*printer
; /* Printer/class */
11150 ipp_attribute_t
*attr
; /* Printer attribute */
11151 int changed
= 0; /* Was anything changed? */
11154 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11155 con
->http
.fd
, uri
->values
[0].string
.text
);
11158 * Is the destination valid?
11161 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11167 send_ipp_status(con
, IPP_NOT_FOUND
,
11168 _("The printer or class was not found."));
11176 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11178 send_http_error(con
, status
, printer
);
11183 * Return a list of attributes that can be set via Set-Printer-Attributes.
11186 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11187 IPP_TAG_TEXT
)) != NULL
)
11189 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11193 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11194 IPP_TAG_TEXT
)) != NULL
)
11196 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11201 * Update the printer attributes and return...
11206 cupsdSetPrinterAttrs(printer
);
11207 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11209 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11210 "Printer \"%s\" description or location changed by \"%s\".",
11211 printer
->name
, get_username(con
));
11213 cupsdLogMessage(CUPSD_LOG_INFO
,
11214 "Printer \"%s\" description or location changed by \"%s\".",
11215 printer
->name
, get_username(con
));
11218 con
->response
->request
.status
.status_code
= IPP_OK
;
11223 * 'set_printer_defaults()' - Set printer default options from a request.
11227 set_printer_defaults(
11228 cupsd_client_t
*con
, /* I - Client connection */
11229 cupsd_printer_t
*printer
) /* I - Printer */
11231 int i
; /* Looping var */
11232 ipp_attribute_t
*attr
; /* Current attribute */
11233 int namelen
; /* Length of attribute name */
11234 char name
[256], /* New attribute name */
11235 value
[256]; /* String version of integer attrs */
11238 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11241 * Skip non-printer attributes...
11244 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11247 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11249 if (!strcmp(attr
->name
, "job-sheets-default"))
11252 * Only allow keywords and names...
11255 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11259 * Only allow job-sheets-default to be set when running without a
11260 * system high classification level...
11263 if (Classification
)
11266 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11268 if (attr
->num_values
> 1)
11269 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11271 cupsdSetString(&printer
->job_sheets
[1], "none");
11273 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11275 cupsdFreeStrings(&(printer
->users
));
11277 printer
->deny_users
= 0;
11279 if (attr
->value_tag
== IPP_TAG_NAME
&&
11280 (attr
->num_values
> 1 ||
11281 strcmp(attr
->values
[0].string
.text
, "all")))
11283 for (i
= 0; i
< attr
->num_values
; i
++)
11284 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11287 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11289 cupsdFreeStrings(&(printer
->users
));
11291 printer
->deny_users
= 1;
11293 if (attr
->value_tag
== IPP_TAG_NAME
&&
11294 (attr
->num_values
> 1 ||
11295 strcmp(attr
->values
[0].string
.text
, "none")))
11297 for (i
= 0; i
< attr
->num_values
; i
++)
11298 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11301 else if (!strcmp(attr
->name
, "job-quota-period"))
11303 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11306 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11307 attr
->values
[0].integer
);
11308 cupsdFreeQuotas(printer
);
11310 printer
->quota_period
= attr
->values
[0].integer
;
11312 else if (!strcmp(attr
->name
, "job-k-limit"))
11314 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11317 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11318 attr
->values
[0].integer
);
11319 cupsdFreeQuotas(printer
);
11321 printer
->k_limit
= attr
->values
[0].integer
;
11323 else if (!strcmp(attr
->name
, "job-page-limit"))
11325 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11328 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11329 attr
->values
[0].integer
);
11330 cupsdFreeQuotas(printer
);
11332 printer
->page_limit
= attr
->values
[0].integer
;
11334 else if (!strcmp(attr
->name
, "printer-op-policy"))
11336 cupsd_policy_t
*p
; /* Policy */
11339 if (attr
->value_tag
!= IPP_TAG_NAME
)
11342 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11344 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11345 "Setting printer-op-policy to \"%s\"...",
11346 attr
->values
[0].string
.text
);
11347 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11348 printer
->op_policy_ptr
= p
;
11352 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11353 _("Unknown printer-op-policy \"%s\"."),
11354 attr
->values
[0].string
.text
);
11358 else if (!strcmp(attr
->name
, "printer-error-policy"))
11360 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11363 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11364 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
11365 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11366 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11367 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11369 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11370 _("Unknown printer-error-policy \"%s\"."),
11371 attr
->values
[0].string
.text
);
11375 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11376 "Setting printer-error-policy to \"%s\"...",
11377 attr
->values
[0].string
.text
);
11378 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11382 * Skip any other non-default attributes...
11385 namelen
= strlen(attr
->name
);
11386 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11387 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11391 * OK, anything else must be a user-defined default...
11394 strlcpy(name
, attr
->name
, sizeof(name
));
11395 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11397 switch (attr
->value_tag
)
11399 case IPP_TAG_DELETEATTR
:
11400 printer
->num_options
= cupsRemoveOption(name
,
11401 printer
->num_options
,
11402 &(printer
->options
));
11403 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11404 "Deleting %s", attr
->name
);
11407 case IPP_TAG_NAME
:
11408 case IPP_TAG_KEYWORD
:
11410 printer
->num_options
= cupsAddOption(name
,
11411 attr
->values
[0].string
.text
,
11412 printer
->num_options
,
11413 &(printer
->options
));
11414 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11415 "Setting %s to \"%s\"...", attr
->name
,
11416 attr
->values
[0].string
.text
);
11419 case IPP_TAG_BOOLEAN
:
11420 printer
->num_options
= cupsAddOption(name
,
11421 attr
->values
[0].boolean
?
11423 printer
->num_options
,
11424 &(printer
->options
));
11425 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11426 "Setting %s to %s...", attr
->name
,
11427 attr
->values
[0].boolean
? "true" : "false");
11430 case IPP_TAG_INTEGER
:
11431 case IPP_TAG_ENUM
:
11432 sprintf(value
, "%d", attr
->values
[0].integer
);
11433 printer
->num_options
= cupsAddOption(name
, value
,
11434 printer
->num_options
,
11435 &(printer
->options
));
11436 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11437 "Setting %s to %s...", attr
->name
, value
);
11440 case IPP_TAG_RANGE
:
11441 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11442 attr
->values
[0].range
.upper
);
11443 printer
->num_options
= cupsAddOption(name
, value
,
11444 printer
->num_options
,
11445 &(printer
->options
));
11446 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11447 "Setting %s to %s...", attr
->name
, value
);
11450 case IPP_TAG_RESOLUTION
:
11451 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11452 attr
->values
[0].resolution
.yres
,
11453 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11455 printer
->num_options
= cupsAddOption(name
, value
,
11456 printer
->num_options
,
11457 &(printer
->options
));
11458 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11459 "Setting %s to %s...", attr
->name
, value
);
11463 /* Do nothing for other values */
11471 * 'start_printer()' - Start a printer.
11475 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11476 ipp_attribute_t
*uri
) /* I - Printer URI */
11478 int i
; /* Temporary variable */
11479 http_status_t status
; /* Policy status */
11480 cups_ptype_t dtype
; /* Destination type (printer/class) */
11481 cupsd_printer_t
*printer
; /* Printer data */
11484 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11485 con
->http
.fd
, uri
->values
[0].string
.text
);
11488 * Is the destination valid?
11491 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11497 send_ipp_status(con
, IPP_NOT_FOUND
,
11498 _("The printer or class was not found."));
11506 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11508 send_http_error(con
, status
, printer
);
11513 * Start the printer...
11516 printer
->state_message
[0] = '\0';
11518 cupsdStartPrinter(printer
, 1);
11520 if (dtype
& CUPS_PRINTER_CLASS
)
11521 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11522 printer
->name
, get_username(con
));
11524 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11525 printer
->name
, get_username(con
));
11533 if ((i
= check_quotas(con
, printer
)) < 0)
11535 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
11540 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
11545 * Everything was ok, so return OK status...
11548 con
->response
->request
.status
.status_code
= IPP_OK
;
11553 * 'stop_printer()' - Stop a printer.
11557 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11558 ipp_attribute_t
*uri
) /* I - Printer URI */
11560 http_status_t status
; /* Policy status */
11561 cups_ptype_t dtype
; /* Destination type (printer/class) */
11562 cupsd_printer_t
*printer
; /* Printer data */
11563 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11566 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11567 con
->http
.fd
, uri
->values
[0].string
.text
);
11570 * Is the destination valid?
11573 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11579 send_ipp_status(con
, IPP_NOT_FOUND
,
11580 _("The printer or class was not found."));
11588 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11590 send_http_error(con
, status
, printer
);
11595 * Stop the printer...
11598 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11599 IPP_TAG_TEXT
)) == NULL
)
11600 strcpy(printer
->state_message
, "Paused");
11603 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11604 sizeof(printer
->state_message
));
11607 cupsdStopPrinter(printer
, 1);
11609 if (dtype
& CUPS_PRINTER_CLASS
)
11610 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11611 printer
->name
, get_username(con
));
11613 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11614 printer
->name
, get_username(con
));
11617 * Everything was ok, so return OK status...
11620 con
->response
->request
.status
.status_code
= IPP_OK
;
11625 * 'url_encode_attr()' - URL-encode a string attribute.
11629 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11630 char *buffer
,/* I - String buffer */
11631 int bufsize
)/* I - Size of buffer */
11633 int i
; /* Looping var */
11634 char *bufptr
, /* Pointer into buffer */
11635 *bufend
; /* End of buffer */
11638 strlcpy(buffer
, attr
->name
, bufsize
);
11639 bufptr
= buffer
+ strlen(buffer
);
11640 bufend
= buffer
+ bufsize
- 1;
11642 for (i
= 0; i
< attr
->num_values
; i
++)
11644 if (bufptr
>= bufend
)
11652 if (bufptr
>= bufend
)
11657 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11658 bufptr
, bufend
- bufptr
+ 1);
11660 if (bufptr
>= bufend
)
11671 * 'url_encode_string()' - URL-encode a string.
11674 static char * /* O - End of string */
11675 url_encode_string(const char *s
, /* I - String */
11676 char *buffer
, /* I - String buffer */
11677 int bufsize
) /* I - Size of buffer */
11679 char *bufptr
, /* Pointer into buffer */
11680 *bufend
; /* End of buffer */
11681 static const char *hex
= "0123456789ABCDEF";
11686 bufend
= buffer
+ bufsize
- 1;
11688 while (*s
&& bufptr
< bufend
)
11690 if (*s
== ' ' || *s
== '%' || *s
== '+')
11692 if (bufptr
>= (bufend
- 2))
11696 *bufptr
++ = hex
[(*s
>> 4) & 15];
11697 *bufptr
++ = hex
[*s
& 15];
11701 else if (*s
== '\'' || *s
== '\\')
11703 if (bufptr
>= (bufend
- 1))
11720 * 'user_allowed()' - See if a user is allowed to print to a queue.
11723 static int /* O - 0 if not allowed, 1 if allowed */
11724 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11725 const char *username
) /* I - Username */
11727 struct passwd
*pw
; /* User password data */
11728 char baseuser
[256], /* Base username */
11729 *baseptr
, /* Pointer to "@" in base username */
11730 *name
; /* Current user name */
11733 if (cupsArrayCount(p
->users
) == 0)
11736 if (!strcmp(username
, "root"))
11739 if (strchr(username
, '@'))
11742 * Strip @REALM for username check...
11745 strlcpy(baseuser
, username
, sizeof(baseuser
));
11747 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11750 username
= baseuser
;
11753 pw
= getpwnam(username
);
11756 for (name
= (char *)cupsArrayFirst(p
->users
);
11758 name
= (char *)cupsArrayNext(p
->users
))
11760 if (name
[0] == '@')
11763 * Check group membership...
11766 if (cupsdCheckGroup(username
, pw
, name
+ 1))
11769 else if (name
[0] == '#')
11775 if (cupsdCheckGroup(username
, pw
, name
))
11778 else if (!strcasecmp(username
, name
))
11782 return ((name
!= NULL
) != p
->deny_users
);
11787 * 'validate_job()' - Validate printer options and destination.
11791 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11792 ipp_attribute_t
*uri
) /* I - Printer URI */
11794 http_status_t status
; /* Policy status */
11795 ipp_attribute_t
*attr
, /* Current attribute */
11796 *auth_info
; /* auth-info attribute */
11797 ipp_attribute_t
*format
; /* Document-format attribute */
11798 cups_ptype_t dtype
; /* Destination type (printer/class) */
11799 char super
[MIME_MAX_SUPER
],
11800 /* Supertype of file */
11801 type
[MIME_MAX_TYPE
];
11802 /* Subtype of file */
11803 cupsd_printer_t
*printer
; /* Printer */
11806 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11807 con
->http
.fd
, uri
->values
[0].string
.text
);
11810 * OK, see if the client is sending the document compressed - CUPS
11811 * doesn't support compression yet...
11814 if ((attr
= ippFindAttribute(con
->request
, "compression",
11815 IPP_TAG_KEYWORD
)) != NULL
)
11817 if (strcmp(attr
->values
[0].string
.text
, "none")
11819 && strcmp(attr
->values
[0].string
.text
, "gzip")
11820 #endif /* HAVE_LIBZ */
11823 send_ipp_status(con
, IPP_ATTRIBUTES
,
11824 _("Unsupported compression \"%s\""),
11825 attr
->values
[0].string
.text
);
11826 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11827 "compression", NULL
, attr
->values
[0].string
.text
);
11833 * Is it a format we support?
11836 if ((format
= ippFindAttribute(con
->request
, "document-format",
11837 IPP_TAG_MIMETYPE
)) != NULL
)
11839 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11842 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
11843 format
->values
[0].string
.text
);
11847 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11848 !mimeType(MimeDatabase
, super
, type
))
11850 cupsdLogMessage(CUPSD_LOG_INFO
,
11851 "Hint: Do you have the raw file printing rules enabled?");
11852 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11853 _("Unsupported document-format \"%s\""),
11854 format
->values
[0].string
.text
);
11855 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11856 "document-format", NULL
, format
->values
[0].string
.text
);
11862 * Is the destination valid?
11865 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11871 send_ipp_status(con
, IPP_NOT_FOUND
,
11872 _("The printer or class was not found."));
11880 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11882 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11884 send_http_error(con
, status
, printer
);
11887 else if (printer
->num_auth_info_required
== 1 &&
11888 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11891 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11895 else if (auth_info
&& !con
->http
.tls
&&
11896 !httpAddrLocalhost(con
->http
.hostaddr
))
11899 * Require encryption of auth-info over non-local connections...
11902 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11905 #endif /* HAVE_SSL */
11908 * Everything was ok, so return OK status...
11911 con
->response
->request
.status
.status_code
= IPP_OK
;
11916 * 'validate_name()' - Make sure the printer name only contains valid chars.
11919 static int /* O - 0 if name is no good, 1 if good */
11920 validate_name(const char *name
) /* I - Name to check */
11922 const char *ptr
; /* Pointer into name */
11926 * Scan the whole name...
11929 for (ptr
= name
; *ptr
; ptr
++)
11930 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11934 * All the characters are good; validate the length, too...
11937 return ((ptr
- name
) < 128);
11942 * 'validate_user()' - Validate the user for the request.
11945 static int /* O - 1 if permitted, 0 otherwise */
11946 validate_user(cupsd_job_t
*job
, /* I - Job */
11947 cupsd_client_t
*con
, /* I - Client connection */
11948 const char *owner
, /* I - Owner of job/resource */
11949 char *username
, /* O - Authenticated username */
11950 int userlen
) /* I - Length of username */
11952 cupsd_printer_t
*printer
; /* Printer for job */
11955 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11956 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11958 job
->id
, con
? con
->http
.fd
: 0,
11959 owner
? owner
: "(null)", username
, userlen
);
11962 * Validate input...
11965 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11969 * Get the best authenticated username that is available.
11972 strlcpy(username
, get_username(con
), userlen
);
11975 * Check the username against the owner...
11978 printer
= cupsdFindDest(job
->dest
);
11980 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11981 con
, owner
) == HTTP_OK
);
11986 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".