2 * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
4 * IPP routines for the Common UNIX Printing System (CUPS) scheduler.
6 * Copyright 2007-2009 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 print jobs.
42 * cancel_job() - Cancel a print job.
43 * cancel_subscription() - Cancel a subscription.
44 * check_quotas() - Check quotas for a printer and user.
45 * check_rss_recipient() - Check that we do not have a duplicate RSS
47 * copy_attribute() - Copy a single attribute.
48 * copy_attrs() - Copy attributes from one request to another.
49 * copy_banner() - Copy a banner file to the requests directory
50 * for the specified job.
51 * copy_file() - Copy a PPD file or interface script...
52 * copy_model() - Copy a PPD model file, substituting default
54 * copy_job_attrs() - Copy job attributes.
55 * copy_printer_attrs() - Copy printer attributes.
56 * copy_subscription_attrs() - Copy subscription attributes.
57 * create_job() - Print a file to a printer or class.
58 * create_requested_array() - Create an array for the requested-attributes.
59 * create_subscription() - Create a notification subscription.
60 * delete_printer() - Remove a printer or class from the system.
61 * get_default() - Get the default destination.
62 * get_devices() - Get the list of available devices on the
64 * get_document() - Get a copy of a job file.
65 * get_job_attrs() - Get job attributes.
66 * get_jobs() - Get a list of jobs for the specified printer.
67 * get_notifications() - Get events for a subscription.
68 * get_ppd() - Get a named PPD from the local system.
69 * get_ppds() - Get the list of PPD files on the local
71 * get_printer_attrs() - Get printer attributes.
72 * get_printers() - Get a list of printers or classes.
73 * get_subscription_attrs() - Get subscription attributes.
74 * get_subscriptions() - Get subscriptions.
75 * get_username() - Get the username associated with a request.
76 * hold_job() - Hold a print job.
77 * move_job() - Move a job to a new destination.
78 * ppd_parse_line() - Parse a PPD default line.
79 * print_job() - Print a file to a printer or class.
80 * read_job_ticket() - Read a job ticket embedded in a print file.
81 * reject_jobs() - Reject print jobs to a printer.
82 * release_job() - Release a held print job.
83 * renew_subscription() - Renew an existing subscription...
84 * restart_job() - Restart an old print job.
85 * save_auth_info() - Save authentication information for a job.
86 * save_krb5_creds() - Save Kerberos credentials for the job.
87 * send_document() - Send a file to a printer or class.
88 * send_http_error() - Send a HTTP error back to the IPP client.
89 * send_ipp_status() - Send a status back to the IPP client.
90 * set_default() - Set the default destination...
91 * set_job_attrs() - Set job attributes.
92 * set_printer_attrs() - Set printer attributes.
93 * set_printer_defaults() - Set printer default options from a request.
94 * start_printer() - Start a printer.
95 * stop_printer() - Stop a printer.
96 * url_encode_attr() - URL-encode a string attribute.
97 * url_encode_string() - URL-encode a string.
98 * user_allowed() - See if a user is allowed to print to a queue.
99 * validate_job() - Validate printer options and destination.
100 * validate_name() - Make sure the printer name only contains
102 * validate_user() - Validate the user for the request.
106 * Include necessary headers...
110 #include <cups/ppd-private.h>
113 # include <ApplicationServices/ApplicationServices.h>
114 # include <CoreFoundation/CoreFoundation.h>
115 # ifdef HAVE_MEMBERSHIP_H
116 # include <membership.h>
117 # endif /* HAVE_MEMBERSHIP_H */
118 # ifdef HAVE_MEMBERSHIPPRIV_H
119 # include <membershipPriv.h>
121 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
122 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
123 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
124 # endif /* HAVE_MEMBERSHIPPRIV_H */
125 #endif /* __APPLE__ */
132 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
133 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
134 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
135 mime_type_t
*filetype
, int compression
);
136 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
137 mime_type_t
*filetype
);
138 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
139 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
140 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
141 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
142 static void add_printer_state_reasons(cupsd_client_t
*con
,
144 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
146 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
147 CMDeviceProfileInfo
*profile
, unsigned id
,
148 const char *name
, const char *text
,
149 const char *iccfile
);
150 static void apple_register_profiles(cupsd_printer_t
*p
);
151 static void apple_unregister_profiles(cupsd_printer_t
*p
);
152 #endif /* __APPLE__ */
153 static void apply_printer_defaults(cupsd_printer_t
*printer
,
155 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
156 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
157 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
158 static void cancel_subscription(cupsd_client_t
*con
, int id
);
159 static int check_rss_recipient(const char *recipient
);
160 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
161 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
163 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
164 ipp_tag_t group
, int quickcopy
);
165 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
167 static int copy_file(const char *from
, const char *to
);
168 static int copy_model(cupsd_client_t
*con
, const char *from
,
170 static void copy_job_attrs(cupsd_client_t
*con
,
173 static void copy_printer_attrs(cupsd_client_t
*con
,
174 cupsd_printer_t
*printer
,
176 static void copy_subscription_attrs(cupsd_client_t
*con
,
177 cupsd_subscription_t
*sub
,
179 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
180 static cups_array_t
*create_requested_array(ipp_t
*request
);
181 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
182 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
183 static void get_default(cupsd_client_t
*con
);
184 static void get_devices(cupsd_client_t
*con
);
185 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
187 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
188 static void get_notifications(cupsd_client_t
*con
);
189 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static void get_ppds(cupsd_client_t
*con
);
191 static void get_printers(cupsd_client_t
*con
, int type
);
192 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
193 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
194 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
195 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
196 static const char *get_username(cupsd_client_t
*con
);
197 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
199 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
200 static int ppd_parse_line(const char *line
, char *option
, int olen
,
201 char *choice
, int clen
);
202 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
203 static void read_job_ticket(cupsd_client_t
*con
);
204 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
205 static void release_held_new_jobs(cupsd_client_t
*con
,
206 ipp_attribute_t
*uri
);
207 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
208 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
209 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
210 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
211 ipp_attribute_t
*auth_info
);
212 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
213 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
214 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
215 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
216 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
217 cupsd_printer_t
*printer
);
218 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
219 const char *message
, ...)
221 __attribute__ ((__format__ (__printf__
, 3, 4)))
222 # endif /* __GNUC__ */
224 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
225 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
226 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
227 static void set_printer_defaults(cupsd_client_t
*con
,
228 cupsd_printer_t
*printer
);
229 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
230 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
231 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
233 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
234 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
235 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
236 static int validate_name(const char *name
);
237 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
238 const char *owner
, char *username
,
243 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
246 int /* O - 1 on success, 0 on failure */
247 cupsdProcessIPPRequest(
248 cupsd_client_t
*con
) /* I - Client connection */
250 ipp_tag_t group
; /* Current group tag */
251 ipp_attribute_t
*attr
; /* Current attribute */
252 ipp_attribute_t
*charset
; /* Character set attribute */
253 ipp_attribute_t
*language
; /* Language attribute */
254 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
255 ipp_attribute_t
*username
; /* requesting-user-name attr */
256 int sub_id
; /* Subscription ID */
259 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
260 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
261 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
264 * First build an empty response message for this request...
267 con
->response
= ippNew();
269 con
->response
->request
.status
.version
[0] =
270 con
->request
->request
.op
.version
[0];
271 con
->response
->request
.status
.version
[1] =
272 con
->request
->request
.op
.version
[1];
273 con
->response
->request
.status
.request_id
=
274 con
->request
->request
.op
.request_id
;
277 * Then validate the request header and required attributes...
280 if (con
->request
->request
.any
.version
[0] != 1 &&
281 con
->request
->request
.any
.version
[0] != 2)
284 * Return an error, since we only support IPP 1.x and 2.x.
287 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
288 "%04X %s Bad request version number %d.%d",
289 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
290 con
->request
->request
.any
.version
[0],
291 con
->request
->request
.any
.version
[1]);
293 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
294 _("Bad request version number %d.%d"),
295 con
->request
->request
.any
.version
[0],
296 con
->request
->request
.any
.version
[1]);
298 else if (con
->request
->request
.any
.request_id
< 1)
301 * Return an error, since request IDs must be between 1 and 2^31-1
304 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
305 "%04X %s Bad request ID %d",
306 IPP_BAD_REQUEST
, con
->http
.hostname
,
307 con
->request
->request
.any
.request_id
);
309 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d"),
310 con
->request
->request
.any
.request_id
);
312 else if (!con
->request
->attrs
)
314 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
315 "%04X %s No attributes in request",
316 IPP_BAD_REQUEST
, con
->http
.hostname
);
318 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request"));
323 * Make sure that the attributes are provided in the correct order and
324 * don't repeat groups...
327 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
330 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
333 * Out of order; return an error...
336 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
337 "%04X %s Attribute groups are out of order",
338 IPP_BAD_REQUEST
, con
->http
.hostname
);
340 send_ipp_status(con
, IPP_BAD_REQUEST
,
341 _("Attribute groups are out of order (%x < %x)"),
342 attr
->group_tag
, group
);
346 group
= attr
->group_tag
;
351 * Then make sure that the first three attributes are:
354 * attributes-natural-language
355 * printer-uri/job-uri
358 attr
= con
->request
->attrs
;
359 if (attr
&& attr
->name
&&
360 !strcmp(attr
->name
, "attributes-charset") &&
361 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
369 if (attr
&& attr
->name
&&
370 !strcmp(attr
->name
, "attributes-natural-language") &&
371 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
376 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
377 IPP_TAG_URI
)) != NULL
)
379 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
380 IPP_TAG_URI
)) != NULL
)
382 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
383 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
388 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
389 "attributes-charset", NULL
,
390 charset
->values
[0].string
.text
);
392 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
393 "attributes-charset", NULL
, DefaultCharset
);
396 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
397 "attributes-natural-language", NULL
,
398 language
->values
[0].string
.text
);
400 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
401 "attributes-natural-language", NULL
, DefaultLanguage
);
404 strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
405 strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
408 * Bad character set...
411 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
412 charset
->values
[0].string
.text
);
413 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
414 "%04X %s Unsupported attributes-charset value \"%s\"",
415 IPP_CHARSET
, con
->http
.hostname
,
416 charset
->values
[0].string
.text
);
417 send_ipp_status(con
, IPP_BAD_REQUEST
,
418 _("Unsupported character set \"%s\""),
419 charset
->values
[0].string
.text
);
421 else if (!charset
|| !language
||
423 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
424 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
425 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
426 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
427 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
430 * Return an error, since attributes-charset,
431 * attributes-natural-language, and printer-uri/job-uri are required
432 * for all operations.
437 cupsdLogMessage(CUPSD_LOG_ERROR
,
438 "Missing attributes-charset attribute");
440 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
441 "%04X %s Missing attributes-charset attribute",
442 IPP_BAD_REQUEST
, con
->http
.hostname
);
447 cupsdLogMessage(CUPSD_LOG_ERROR
,
448 "Missing attributes-natural-language attribute");
450 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
451 "%04X %s Missing attributes-natural-language attribute",
452 IPP_BAD_REQUEST
, con
->http
.hostname
);
457 cupsdLogMessage(CUPSD_LOG_ERROR
,
458 "Missing printer-uri, job-uri, or ppd-name "
461 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
462 "%04X %s Missing printer-uri, job-uri, or ppd-name "
463 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
466 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
468 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
469 cupsdLogMessage(CUPSD_LOG_DEBUG
,
470 "attr \"%s\": group_tag = %x, value_tag = %x",
471 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
474 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
476 send_ipp_status(con
, IPP_BAD_REQUEST
,
477 _("Missing required attributes"));
482 * OK, all the checks pass so far; make sure requesting-user-name is
483 * not "root" from a remote host...
486 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
487 IPP_TAG_NAME
)) != NULL
)
490 * Check for root user...
493 if (!strcmp(username
->values
[0].string
.text
, "root") &&
494 strcasecmp(con
->http
.hostname
, "localhost") &&
495 strcmp(con
->username
, "root"))
498 * Remote unauthenticated user masquerading as local root...
501 _cupsStrFree(username
->values
[0].string
.text
);
502 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
506 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
507 IPP_TAG_INTEGER
)) != NULL
)
508 sub_id
= attr
->values
[0].integer
;
513 * Then try processing the operation...
517 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
518 ippOpString(con
->request
->request
.op
.operation_id
),
519 uri
->values
[0].string
.text
);
521 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
522 ippOpString(con
->request
->request
.op
.operation_id
));
524 switch (con
->request
->request
.op
.operation_id
)
530 case IPP_VALIDATE_JOB
:
531 validate_job(con
, uri
);
534 case IPP_CREATE_JOB
:
535 create_job(con
, uri
);
538 case IPP_SEND_DOCUMENT
:
539 send_document(con
, uri
);
542 case IPP_CANCEL_JOB
:
543 cancel_job(con
, uri
);
546 case IPP_GET_JOB_ATTRIBUTES
:
547 get_job_attrs(con
, uri
);
554 case IPP_GET_PRINTER_ATTRIBUTES
:
555 get_printer_attrs(con
, uri
);
558 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
559 get_printer_supported(con
, uri
);
566 case IPP_RELEASE_JOB
:
567 release_job(con
, uri
);
570 case IPP_RESTART_JOB
:
571 restart_job(con
, uri
);
574 case IPP_PAUSE_PRINTER
:
575 stop_printer(con
, uri
);
578 case IPP_RESUME_PRINTER
:
579 start_printer(con
, uri
);
582 case IPP_PURGE_JOBS
:
583 cancel_all_jobs(con
, uri
);
586 case IPP_SET_JOB_ATTRIBUTES
:
587 set_job_attrs(con
, uri
);
590 case IPP_SET_PRINTER_ATTRIBUTES
:
591 set_printer_attrs(con
, uri
);
594 case IPP_HOLD_NEW_JOBS
:
595 hold_new_jobs(con
, uri
);
598 case IPP_RELEASE_HELD_NEW_JOBS
:
599 release_held_new_jobs(con
, uri
);
602 case CUPS_GET_DEFAULT
:
606 case CUPS_GET_PRINTERS
:
607 get_printers(con
, 0);
610 case CUPS_GET_CLASSES
:
611 get_printers(con
, CUPS_PRINTER_CLASS
);
614 case CUPS_ADD_PRINTER
:
615 add_printer(con
, uri
);
618 case CUPS_DELETE_PRINTER
:
619 delete_printer(con
, uri
);
622 case CUPS_ADD_CLASS
:
626 case CUPS_DELETE_CLASS
:
627 delete_printer(con
, uri
);
630 case CUPS_ACCEPT_JOBS
:
631 case IPP_ENABLE_PRINTER
:
632 accept_jobs(con
, uri
);
635 case CUPS_REJECT_JOBS
:
636 case IPP_DISABLE_PRINTER
:
637 reject_jobs(con
, uri
);
640 case CUPS_SET_DEFAULT
:
641 set_default(con
, uri
);
644 case CUPS_GET_DEVICES
:
648 case CUPS_GET_DOCUMENT
:
649 get_document(con
, uri
);
664 case CUPS_AUTHENTICATE_JOB
:
665 authenticate_job(con
, uri
);
668 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
669 case IPP_CREATE_JOB_SUBSCRIPTION
:
670 create_subscription(con
, uri
);
673 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
674 get_subscription_attrs(con
, sub_id
);
677 case IPP_GET_SUBSCRIPTIONS
:
678 get_subscriptions(con
, uri
);
681 case IPP_RENEW_SUBSCRIPTION
:
682 renew_subscription(con
, sub_id
);
685 case IPP_CANCEL_SUBSCRIPTION
:
686 cancel_subscription(con
, sub_id
);
689 case IPP_GET_NOTIFICATIONS
:
690 get_notifications(con
);
694 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
695 "%04X %s Operation %04X (%s) not supported",
696 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
697 con
->request
->request
.op
.operation_id
,
698 ippOpString(con
->request
->request
.op
.operation_id
));
700 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
701 _("%s not supported"),
703 con
->request
->request
.op
.operation_id
));
713 * Sending data from the scheduler...
716 cupsdLogMessage(con
->response
->request
.status
.status_code
717 >= IPP_BAD_REQUEST
&&
718 con
->response
->request
.status
.status_code
719 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
720 "Returning IPP %s for %s (%s) from %s",
721 ippErrorString(con
->response
->request
.status
.status_code
),
722 ippOpString(con
->request
->request
.op
.operation_id
),
723 uri
? uri
->values
[0].string
.text
: "no URI",
726 if (LogLevel
== CUPSD_LOG_DEBUG2
)
727 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
728 "cupsdProcessIPPRequest: ippLength(response)=%ld",
729 (long)ippLength(con
->response
));
731 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
733 #ifdef CUPSD_USE_CHUNKING
735 * Because older versions of CUPS (1.1.17 and older) and some IPP
736 * clients do not implement chunking properly, we cannot use
737 * chunking by default. This may become the default in future
738 * CUPS releases, or we might add a configuration directive for
742 if (con
->http
.version
== HTTP_1_1
)
744 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
747 if (cupsdFlushHeader(con
) < 0)
750 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
753 #endif /* CUPSD_USE_CHUNKING */
755 size_t length
; /* Length of response */
758 length
= ippLength(con
->response
);
760 if (con
->file
>= 0 && !con
->pipe_pid
)
762 struct stat fileinfo
; /* File information */
765 if (!fstat(con
->file
, &fileinfo
))
766 length
+= fileinfo
.st_size
;
769 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
770 CUPS_LLCAST length
) < 0)
773 if (cupsdFlushHeader(con
) < 0)
776 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
777 con
->http
.data_remaining
= length
;
779 if (con
->http
.data_remaining
<= INT_MAX
)
780 con
->http
._data_remaining
= con
->http
.data_remaining
;
782 con
->http
._data_remaining
= INT_MAX
;
785 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
786 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
789 * Tell the caller the response header was sent successfully...
797 * Tell the caller the response header could not be sent...
806 * Sending data from a subprocess like cups-deviced; tell the caller
807 * everything is A-OK so far...
816 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
819 int /* O - 0 on success, -1 on error */
820 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
822 cupsd_printer_t
*printer
; /* Destination printer or class */
823 ipp_attribute_t
*attr
; /* job-sheets attribute */
824 int kbytes
; /* Kilobytes in banner */
827 job
->pending_timeout
= 0;
830 * See if we need to add the ending sheet...
833 printer
= cupsdFindDest(job
->dest
);
834 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
837 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
838 attr
&& attr
->num_values
> 1)
844 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
845 attr
->values
[1].string
.text
);
847 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
850 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
858 * 'accept_jobs()' - Accept print jobs to a printer.
862 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
863 ipp_attribute_t
*uri
) /* I - Printer or class URI */
865 http_status_t status
; /* Policy status */
866 cups_ptype_t dtype
; /* Destination type (printer/class) */
867 cupsd_printer_t
*printer
; /* Printer data */
870 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
871 con
->http
.fd
, uri
->values
[0].string
.text
);
874 * Is the destination valid?
877 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
883 send_ipp_status(con
, IPP_NOT_FOUND
,
884 _("The printer or class was not found."));
892 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
894 send_http_error(con
, status
, printer
);
899 * Accept jobs sent to the printer...
902 printer
->accepting
= 1;
903 printer
->state_message
[0] = '\0';
905 cupsdAddPrinterHistory(printer
);
907 if (dtype
& CUPS_PRINTER_CLASS
)
909 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
911 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
912 printer
->name
, get_username(con
));
916 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
918 cupsdLogMessage(CUPSD_LOG_INFO
,
919 "Printer \"%s\" now accepting jobs (\"%s\").",
920 printer
->name
, get_username(con
));
924 * Everything was ok, so return OK status...
927 con
->response
->request
.status
.status_code
= IPP_OK
;
932 * 'add_class()' - Add a class to the system.
936 add_class(cupsd_client_t
*con
, /* I - Client connection */
937 ipp_attribute_t
*uri
) /* I - URI of class */
939 http_status_t status
; /* Policy status */
940 int i
; /* Looping var */
941 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
942 username
[HTTP_MAX_URI
], /* Username portion of URI */
943 host
[HTTP_MAX_URI
], /* Host portion of URI */
944 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
945 int port
; /* Port portion of URI */
946 cupsd_printer_t
*pclass
, /* Class */
947 *member
; /* Member printer/class */
948 cups_ptype_t dtype
; /* Destination type */
949 ipp_attribute_t
*attr
; /* Printer attribute */
950 int modify
; /* Non-zero if we just modified */
951 char newname
[IPP_MAX_NAME
]; /* New class name */
952 int need_restart_job
; /* Need to restart job? */
955 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
956 con
->http
.fd
, uri
->values
[0].string
.text
);
959 * Do we have a valid URI?
962 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
963 sizeof(scheme
), username
, sizeof(username
), host
,
964 sizeof(host
), &port
, resource
, sizeof(resource
));
967 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
970 * No, return an error...
973 send_ipp_status(con
, IPP_BAD_REQUEST
,
974 _("The printer-uri must be of the form "
975 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
980 * Do we have a valid printer name?
983 if (!validate_name(resource
+ 9))
986 * No, return an error...
989 send_ipp_status(con
, IPP_BAD_REQUEST
,
990 _("The printer-uri \"%s\" contains invalid characters."),
991 uri
->values
[0].string
.text
);
996 * See if the class already exists; if not, create a new class...
999 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1002 * Class doesn't exist; see if we have a printer of the same name...
1005 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
1006 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
1009 * Yes, return an error...
1012 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1013 _("A printer named \"%s\" already exists"),
1019 * No, check the default policy and then add the class...
1022 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1024 send_http_error(con
, status
, NULL
);
1028 pclass
= cupsdAddClass(resource
+ 9);
1031 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1034 * Check the default policy, then rename the implicit class to "AnyClass"
1038 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1040 send_http_error(con
, status
, NULL
);
1044 if (ImplicitAnyClasses
)
1046 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1047 cupsdRenamePrinter(pclass
, newname
);
1050 cupsdDeletePrinter(pclass
, 1);
1053 * Add the class as a new local class...
1056 pclass
= cupsdAddClass(resource
+ 9);
1059 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1062 * Check the default policy, then rename the remote class to "Class"...
1065 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1067 send_http_error(con
, status
, NULL
);
1071 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1072 cupsdRenamePrinter(pclass
, newname
);
1075 * Add the class as a new local class...
1078 pclass
= cupsdAddClass(resource
+ 9);
1081 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1084 send_http_error(con
, status
, pclass
);
1091 * Look for attributes and copy them over as needed...
1094 need_restart_job
= 0;
1096 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1097 IPP_TAG_TEXT
)) != NULL
)
1098 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1100 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1101 IPP_TAG_TEXT
)) != NULL
)
1102 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1104 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1105 IPP_TAG_BOOLEAN
)) != NULL
)
1107 cupsdLogMessage(CUPSD_LOG_INFO
,
1108 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1109 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1111 pclass
->accepting
= attr
->values
[0].boolean
;
1112 cupsdAddPrinterHistory(pclass
);
1115 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1116 IPP_TAG_BOOLEAN
)) != NULL
)
1118 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1119 cupsdDeregisterPrinter(pclass
, 1);
1121 cupsdLogMessage(CUPSD_LOG_INFO
,
1122 "Setting %s printer-is-shared to %d (was %d.)",
1123 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1125 pclass
->shared
= attr
->values
[0].boolean
;
1128 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1129 IPP_TAG_ENUM
)) != NULL
)
1131 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1132 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1134 send_ipp_status(con
, IPP_BAD_REQUEST
,
1135 _("Attempt to set %s printer-state to bad value %d"),
1136 pclass
->name
, attr
->values
[0].integer
);
1140 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1141 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1143 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1144 cupsdStopPrinter(pclass
, 0);
1147 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1148 need_restart_job
= 1;
1151 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1152 IPP_TAG_TEXT
)) != NULL
)
1154 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1155 sizeof(pclass
->state_message
));
1156 cupsdAddPrinterHistory(pclass
);
1158 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1159 IPP_TAG_URI
)) != NULL
)
1162 * Clear the printer array as needed...
1165 need_restart_job
= 1;
1167 if (pclass
->num_printers
> 0)
1169 free(pclass
->printers
);
1170 pclass
->num_printers
= 0;
1174 * Add each printer or class that is listed...
1177 for (i
= 0; i
< attr
->num_values
; i
++)
1180 * Search for the printer or class URI...
1183 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1189 send_ipp_status(con
, IPP_NOT_FOUND
,
1190 _("The printer or class was not found."));
1193 else if (dtype
& CUPS_PRINTER_CLASS
)
1195 send_ipp_status(con
, IPP_BAD_REQUEST
,
1196 _("Nested classes are not allowed"));
1201 * Add it to the class...
1204 cupsdAddPrinterToClass(pclass
, member
);
1208 set_printer_defaults(con
, pclass
);
1210 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1211 IPP_TAG_KEYWORD
)) != NULL
)
1212 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1215 * Update the printer class attributes and return...
1218 cupsdSetPrinterAttrs(pclass
);
1219 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1221 if (need_restart_job
&& pclass
->job
)
1224 * Reset the current job to a "pending" status...
1227 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1228 "Job restarted because the class was modified.");
1231 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1235 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, pclass
, NULL
,
1236 "Class \"%s\" modified by \"%s\".", pclass
->name
,
1239 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1240 pclass
->name
, get_username(con
));
1244 cupsdAddPrinterHistory(pclass
);
1246 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, pclass
, NULL
,
1247 "New class \"%s\" added by \"%s\".", pclass
->name
,
1250 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1251 pclass
->name
, get_username(con
));
1254 con
->response
->request
.status
.status_code
= IPP_OK
;
1259 * 'add_file()' - Add a file to a job.
1262 static int /* O - 0 on success, -1 on error */
1263 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1264 cupsd_job_t
*job
, /* I - Job to add to */
1265 mime_type_t
*filetype
, /* I - Type of file */
1266 int compression
) /* I - Compression */
1268 mime_type_t
**filetypes
; /* New filetypes array... */
1269 int *compressions
; /* New compressions array... */
1272 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1273 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1274 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1275 filetype
->super
, filetype
->type
, compression
);
1278 * Add the file to the job...
1281 if (job
->num_files
== 0)
1283 compressions
= (int *)malloc(sizeof(int));
1284 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1288 compressions
= (int *)realloc(job
->compressions
,
1289 (job
->num_files
+ 1) * sizeof(int));
1290 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1291 (job
->num_files
+ 1) *
1292 sizeof(mime_type_t
*));
1295 if (!compressions
|| !filetypes
)
1297 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1298 "Job aborted because the scheduler ran out of memory.");
1301 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1302 _("Unable to allocate memory for file types"));
1307 job
->compressions
= compressions
;
1308 job
->compressions
[job
->num_files
] = compression
;
1309 job
->filetypes
= filetypes
;
1310 job
->filetypes
[job
->num_files
] = filetype
;
1315 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1322 * 'add_job()' - Add a job to a print queue.
1325 static cupsd_job_t
* /* O - Job object */
1326 add_job(cupsd_client_t
*con
, /* I - Client connection */
1327 cupsd_printer_t
*printer
, /* I - Destination printer */
1328 mime_type_t
*filetype
) /* I - First print file type, if any */
1330 http_status_t status
; /* Policy status */
1331 ipp_attribute_t
*attr
, /* Current attribute */
1332 *auth_info
; /* auth-info attribute */
1333 const char *val
; /* Default option value */
1334 int priority
; /* Job priority */
1335 char *title
; /* Job name/title */
1336 cupsd_job_t
*job
; /* Current job */
1337 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1338 int kbytes
; /* Size of print file */
1339 int i
; /* Looping var */
1340 int lowerpagerange
; /* Page range bound */
1343 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1344 con
, con
->http
.fd
, printer
, printer
->name
,
1345 filetype
, filetype
? filetype
->super
: "none",
1346 filetype
? filetype
->type
: "none");
1349 * Check remote printing to non-shared printer...
1352 if (!printer
->shared
&&
1353 strcasecmp(con
->http
.hostname
, "localhost") &&
1354 strcasecmp(con
->http
.hostname
, ServerName
))
1356 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1357 _("The printer or class is not shared"));
1365 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1367 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1369 send_http_error(con
, status
, printer
);
1372 else if (printer
->num_auth_info_required
== 1 &&
1373 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1376 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1380 else if (auth_info
&& !con
->http
.tls
&&
1381 !httpAddrLocalhost(con
->http
.hostaddr
))
1384 * Require encryption of auth-info over non-local connections...
1387 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1390 #endif /* HAVE_SSL */
1393 * See if the printer is accepting jobs...
1396 if (!printer
->accepting
)
1398 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1399 _("Destination \"%s\" is not accepting jobs."),
1405 * Validate job template attributes; for now just document-format,
1406 * copies, number-up, and page-ranges...
1409 if (filetype
&& printer
->filetypes
&&
1410 !cupsArrayFind(printer
->filetypes
, filetype
))
1412 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1413 /* MIME media type string */
1416 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1419 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1420 _("Unsupported format \'%s\'"), mimetype
);
1422 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1423 "document-format", NULL
, mimetype
);
1428 if ((attr
= ippFindAttribute(con
->request
, "copies",
1429 IPP_TAG_INTEGER
)) != NULL
)
1431 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1433 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1434 attr
->values
[0].integer
);
1435 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1436 "copies", attr
->values
[0].integer
);
1441 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1442 IPP_TAG_ZERO
)) != NULL
)
1444 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1445 attr
->value_tag
!= IPP_TAG_NAME
)
1447 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type"));
1451 if (attr
->num_values
> 2)
1453 send_ipp_status(con
, IPP_BAD_REQUEST
,
1454 _("Too many job-sheets values (%d > 2)"),
1459 for (i
= 0; i
< attr
->num_values
; i
++)
1460 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1461 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1463 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\""),
1464 attr
->values
[i
].string
.text
);
1469 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1470 IPP_TAG_INTEGER
)) != NULL
)
1472 if (attr
->values
[0].integer
!= 1 &&
1473 attr
->values
[0].integer
!= 2 &&
1474 attr
->values
[0].integer
!= 4 &&
1475 attr
->values
[0].integer
!= 6 &&
1476 attr
->values
[0].integer
!= 9 &&
1477 attr
->values
[0].integer
!= 16)
1479 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1480 attr
->values
[0].integer
);
1481 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1482 "number-up", attr
->values
[0].integer
);
1487 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1488 IPP_TAG_RANGE
)) != NULL
)
1490 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1492 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1493 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1495 send_ipp_status(con
, IPP_BAD_REQUEST
,
1496 _("Bad page-ranges values %d-%d."),
1497 attr
->values
[i
].range
.lower
,
1498 attr
->values
[i
].range
.upper
);
1502 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1507 * Make sure we aren't over our limit...
1510 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1513 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1515 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1516 _("Too many active jobs."));
1520 if ((i
= check_quotas(con
, printer
)) < 0)
1522 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1527 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1532 * Create the job and set things up...
1535 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1536 IPP_TAG_INTEGER
)) != NULL
)
1537 priority
= attr
->values
[0].integer
;
1540 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1541 printer
->options
)) != NULL
)
1542 priority
= atoi(val
);
1546 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1550 if ((attr
= ippFindAttribute(con
->request
, "job-name",
1551 IPP_TAG_NAME
)) != NULL
)
1552 title
= attr
->values
[0].string
.text
;
1554 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1555 title
= "Untitled");
1557 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1559 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1560 _("Unable to add job for destination \"%s\""),
1565 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1566 CUPS_PRINTER_REMOTE
);
1567 job
->attrs
= con
->request
;
1569 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1571 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1573 add_job_uuid(con
, job
);
1574 apply_printer_defaults(printer
, job
);
1576 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1578 if (con
->username
[0])
1580 cupsdSetString(&job
->username
, con
->username
);
1583 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1587 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1588 "add_job: requesting-user-name=\"%s\"",
1589 attr
->values
[0].string
.text
);
1591 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1594 cupsdSetString(&job
->username
, "anonymous");
1597 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1598 "job-originating-user-name", NULL
, job
->username
);
1601 attr
->group_tag
= IPP_TAG_JOB
;
1602 _cupsStrFree(attr
->name
);
1603 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1606 if (con
->username
[0] || auth_info
)
1608 save_auth_info(con
, job
, auth_info
);
1611 * Remove the auth-info attribute from the attribute data...
1615 ippDeleteAttribute(job
->attrs
, auth_info
);
1618 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1619 IPP_TAG_ZERO
)) != NULL
)
1622 * Request contains a job-originating-host-name attribute; validate it...
1625 if (attr
->value_tag
!= IPP_TAG_NAME
||
1626 attr
->num_values
!= 1 ||
1627 strcmp(con
->http
.hostname
, "localhost"))
1630 * Can't override the value if we aren't connected via localhost.
1631 * Also, we can only have 1 value and it must be a name value.
1634 switch (attr
->value_tag
)
1636 case IPP_TAG_STRING
:
1637 case IPP_TAG_TEXTLANG
:
1638 case IPP_TAG_NAMELANG
:
1641 case IPP_TAG_KEYWORD
:
1643 case IPP_TAG_URISCHEME
:
1644 case IPP_TAG_CHARSET
:
1645 case IPP_TAG_LANGUAGE
:
1646 case IPP_TAG_MIMETYPE
:
1648 * Free old strings...
1651 for (i
= 0; i
< attr
->num_values
; i
++)
1653 _cupsStrFree(attr
->values
[i
].string
.text
);
1654 attr
->values
[i
].string
.text
= NULL
;
1655 if (attr
->values
[i
].string
.charset
)
1657 _cupsStrFree(attr
->values
[i
].string
.charset
);
1658 attr
->values
[i
].string
.charset
= NULL
;
1667 * Use the default connection hostname instead...
1670 attr
->value_tag
= IPP_TAG_NAME
;
1671 attr
->num_values
= 1;
1672 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1675 attr
->group_tag
= IPP_TAG_JOB
;
1680 * No job-originating-host-name attribute, so use the hostname from
1684 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1685 "job-originating-host-name", NULL
, con
->http
.hostname
);
1688 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1690 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1691 "time-at-processing", 0);
1692 attr
->value_tag
= IPP_TAG_NOVALUE
;
1693 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1694 "time-at-completed", 0);
1695 attr
->value_tag
= IPP_TAG_NOVALUE
;
1698 * Add remaining job attributes...
1701 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1702 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1703 "job-state", IPP_JOB_STOPPED
);
1704 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1705 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1706 "job-media-sheets-completed", 0);
1707 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1710 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1711 IPP_TAG_INTEGER
)) != NULL
)
1712 attr
->values
[0].integer
= 0;
1714 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1716 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1717 IPP_TAG_KEYWORD
)) == NULL
)
1718 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1721 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1722 printer
->options
)) == NULL
)
1725 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1726 "job-hold-until", NULL
, val
);
1728 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1731 * Hold job until specified time...
1734 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1736 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1737 job
->state_value
= IPP_JOB_HELD
;
1739 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1741 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1742 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1743 job
->state_value
= IPP_JOB_HELD
;
1747 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1748 job
->state_value
= IPP_JOB_PENDING
;
1751 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1755 * Add job sheets options...
1758 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1759 IPP_TAG_ZERO
)) == NULL
)
1761 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1762 "Adding default job-sheets values \"%s,%s\"...",
1763 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1765 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1767 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1768 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1771 job
->job_sheets
= attr
;
1774 * Enforce classification level if set...
1779 cupsdLogMessage(CUPSD_LOG_INFO
,
1780 "Classification=\"%s\", ClassifyOverride=%d",
1781 Classification
? Classification
: "(null)",
1784 if (ClassifyOverride
)
1786 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1787 (attr
->num_values
== 1 ||
1788 !strcmp(attr
->values
[1].string
.text
, "none")))
1791 * Force the leading banner to have the classification on it...
1794 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1796 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1797 "job-sheets=\"%s,none\", "
1798 "job-originating-user-name=\"%s\"",
1799 Classification
, job
->username
);
1801 else if (attr
->num_values
== 2 &&
1802 strcmp(attr
->values
[0].string
.text
,
1803 attr
->values
[1].string
.text
) &&
1804 strcmp(attr
->values
[0].string
.text
, "none") &&
1805 strcmp(attr
->values
[1].string
.text
, "none"))
1808 * Can't put two different security markings on the same document!
1811 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1813 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1814 "job-sheets=\"%s,%s\", "
1815 "job-originating-user-name=\"%s\"",
1816 attr
->values
[0].string
.text
,
1817 attr
->values
[1].string
.text
, job
->username
);
1819 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1820 strcmp(attr
->values
[0].string
.text
, "none") &&
1821 (attr
->num_values
== 1 ||
1822 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1823 strcmp(attr
->values
[1].string
.text
, "none"))))
1825 if (attr
->num_values
== 1)
1826 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1827 "CLASSIFICATION OVERRIDDEN "
1828 "job-sheets=\"%s\", "
1829 "job-originating-user-name=\"%s\"",
1830 attr
->values
[0].string
.text
, job
->username
);
1832 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1833 "CLASSIFICATION OVERRIDDEN "
1834 "job-sheets=\"%s,%s\",fffff "
1835 "job-originating-user-name=\"%s\"",
1836 attr
->values
[0].string
.text
,
1837 attr
->values
[1].string
.text
, job
->username
);
1840 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1841 (attr
->num_values
== 1 ||
1842 strcmp(attr
->values
[1].string
.text
, Classification
)))
1845 * Force the banner to have the classification on it...
1848 if (attr
->num_values
> 1 &&
1849 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1851 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1852 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1856 if (attr
->num_values
== 1 ||
1857 strcmp(attr
->values
[0].string
.text
, "none"))
1858 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1860 if (attr
->num_values
> 1 &&
1861 strcmp(attr
->values
[1].string
.text
, "none"))
1862 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1865 if (attr
->num_values
> 1)
1866 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1867 "CLASSIFICATION FORCED "
1868 "job-sheets=\"%s,%s\", "
1869 "job-originating-user-name=\"%s\"",
1870 attr
->values
[0].string
.text
,
1871 attr
->values
[1].string
.text
, job
->username
);
1873 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1874 "CLASSIFICATION FORCED "
1875 "job-sheets=\"%s\", "
1876 "job-originating-user-name=\"%s\"",
1877 Classification
, job
->username
);
1882 * See if we need to add the starting sheet...
1885 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1887 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1888 attr
->values
[0].string
.text
);
1890 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1892 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1893 "Aborting job because the start banner could not be "
1898 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1901 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1902 IPP_TAG_ZERO
)) != NULL
)
1906 * Fill in the response info...
1909 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1910 LocalPort
, job
->id
);
1912 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1915 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1917 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1919 add_job_state_reasons(con
, job
);
1921 con
->response
->request
.status
.status_code
= IPP_OK
;
1924 * Add any job subscriptions...
1927 add_job_subscriptions(con
, job
);
1930 * Set all but the first two attributes to the job attributes group...
1933 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1934 attr
->group_tag
= IPP_TAG_JOB
;
1937 * Fire the "job created" event...
1940 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1943 * Return the new job...
1951 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1952 * upon the job and printer state...
1956 add_job_state_reasons(
1957 cupsd_client_t
*con
, /* I - Client connection */
1958 cupsd_job_t
*job
) /* I - Job info */
1960 cupsd_printer_t
*dest
; /* Destination printer */
1963 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1964 con
, con
->http
.fd
, job
? job
->id
: 0);
1966 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1968 case IPP_JOB_PENDING
:
1969 dest
= cupsdFindDest(job
->dest
);
1971 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1972 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1973 "job-state-reasons", NULL
, "printer-stopped");
1975 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1976 "job-state-reasons", NULL
, "none");
1980 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1981 IPP_TAG_KEYWORD
) != NULL
||
1982 ippFindAttribute(job
->attrs
, "job-hold-until",
1983 IPP_TAG_NAME
) != NULL
)
1984 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1985 "job-state-reasons", NULL
, "job-hold-until-specified");
1987 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1988 "job-state-reasons", NULL
, "job-incoming");
1991 case IPP_JOB_PROCESSING
:
1992 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1993 "job-state-reasons", NULL
, "job-printing");
1996 case IPP_JOB_STOPPED
:
1997 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1998 "job-state-reasons", NULL
, "job-stopped");
2001 case IPP_JOB_CANCELED
:
2002 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2003 "job-state-reasons", NULL
, "job-canceled-by-user");
2006 case IPP_JOB_ABORTED
:
2007 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2008 "job-state-reasons", NULL
, "aborted-by-system");
2011 case IPP_JOB_COMPLETED
:
2012 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2013 "job-state-reasons", NULL
, "job-completed-successfully");
2020 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2024 add_job_subscriptions(
2025 cupsd_client_t
*con
, /* I - Client connection */
2026 cupsd_job_t
*job
) /* I - Newly created job */
2028 int i
; /* Looping var */
2029 ipp_attribute_t
*prev
, /* Previous attribute */
2030 *next
, /* Next attribute */
2031 *attr
; /* Current attribute */
2032 cupsd_subscription_t
*sub
; /* Subscription object */
2033 const char *recipient
, /* notify-recipient-uri */
2034 *pullmethod
; /* notify-pull-method */
2035 ipp_attribute_t
*user_data
; /* notify-user-data */
2036 int interval
; /* notify-time-interval */
2037 unsigned mask
; /* notify-events */
2041 * Find the first subscription group attribute; return if we have
2045 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2046 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2053 * Process the subscription attributes in the request...
2062 mask
= CUPSD_EVENT_NONE
;
2064 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2066 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2067 attr
->value_tag
== IPP_TAG_URI
)
2070 * Validate the recipient scheme against the ServerBin/notifier
2074 char notifier
[1024], /* Notifier filename */
2075 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2076 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2077 host
[HTTP_MAX_URI
], /* Host portion of URI */
2078 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2079 int port
; /* Port portion of URI */
2082 recipient
= attr
->values
[0].string
.text
;
2084 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2085 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2086 host
, sizeof(host
), &port
,
2087 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2089 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2090 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
2091 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2092 "notify-status-code", IPP_URI_SCHEME
);
2096 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2098 if (access(notifier
, X_OK
))
2100 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2101 _("notify-recipient-uri URI \"%s\" uses unknown "
2102 "scheme"), recipient
);
2103 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2104 "notify-status-code", IPP_URI_SCHEME
);
2108 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2110 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2111 _("notify-recipient-uri URI \"%s\" is already used"),
2113 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2114 "notify-status-code", IPP_ATTRIBUTES
);
2118 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2119 attr
->value_tag
== IPP_TAG_KEYWORD
)
2121 pullmethod
= attr
->values
[0].string
.text
;
2123 if (strcmp(pullmethod
, "ippget"))
2125 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2126 _("Bad notify-pull-method \"%s\""), pullmethod
);
2127 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2128 "notify-status-code", IPP_ATTRIBUTES
);
2132 else if (!strcmp(attr
->name
, "notify-charset") &&
2133 attr
->value_tag
== IPP_TAG_CHARSET
&&
2134 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2135 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2137 send_ipp_status(con
, IPP_CHARSET
,
2138 _("Character set \"%s\" not supported"),
2139 attr
->values
[0].string
.text
);
2142 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2143 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2144 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2146 send_ipp_status(con
, IPP_CHARSET
,
2147 _("Language \"%s\" not supported"),
2148 attr
->values
[0].string
.text
);
2151 else if (!strcmp(attr
->name
, "notify-user-data") &&
2152 attr
->value_tag
== IPP_TAG_STRING
)
2154 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2156 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2157 _("The notify-user-data value is too large "
2158 "(%d > 63 octets)"),
2159 attr
->values
[0].unknown
.length
);
2165 else if (!strcmp(attr
->name
, "notify-events") &&
2166 attr
->value_tag
== IPP_TAG_KEYWORD
)
2168 for (i
= 0; i
< attr
->num_values
; i
++)
2169 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2171 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2173 send_ipp_status(con
, IPP_BAD_REQUEST
,
2174 _("The notify-lease-duration attribute cannot be "
2175 "used with job subscriptions."));
2178 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2179 attr
->value_tag
== IPP_TAG_INTEGER
)
2180 interval
= attr
->values
[0].integer
;
2185 if (!recipient
&& !pullmethod
)
2188 if (mask
== CUPSD_EVENT_NONE
)
2189 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2191 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2192 recipient
, 0)) != NULL
)
2194 sub
->interval
= interval
;
2196 cupsdSetString(&sub
->owner
, job
->username
);
2200 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2201 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2202 sub
->user_data_len
);
2205 ippAddSeparator(con
->response
);
2206 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2207 "notify-subscription-id", sub
->id
);
2214 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2217 * Remove all of the subscription attributes from the job request...
2219 * TODO: Optimize this since subscription groups have to come at the
2220 * end of the request...
2223 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2227 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2228 attr
->group_tag
== IPP_TAG_ZERO
)
2231 * Free and remove this attribute...
2239 job
->attrs
->attrs
= next
;
2245 job
->attrs
->last
= prev
;
2246 job
->attrs
->current
= prev
;
2251 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2253 * See RFC 4122 for the definition of UUIDs and the format.
2257 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2258 cupsd_job_t
*job
) /* I - Job */
2260 char uuid
[1024]; /* job-uuid string */
2261 _cups_md5_state_t md5state
; /* MD5 state */
2262 unsigned char md5sum
[16]; /* MD5 digest/sum */
2266 * First see if the job already has a job-uuid attribute; if so, return...
2269 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2273 * No job-uuid attribute, so build a version 3 UUID with the local job
2274 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2275 * the ServerName, server name and port that the client connected to,
2276 * and local job ID...
2279 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2280 con
->serverport
, job
->id
);
2282 _cupsMD5Init(&md5state
);
2283 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2284 _cupsMD5Finish(&md5state
, md5sum
);
2287 * Format the UUID URI using the MD5 sum and job ID.
2290 snprintf(uuid
, sizeof(uuid
),
2291 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2292 "%02x%02x%02x%02x%02x%02x",
2293 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2294 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2295 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2296 md5sum
[14], md5sum
[15]);
2298 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2303 * 'add_printer()' - Add a printer to the system.
2307 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2308 ipp_attribute_t
*uri
) /* I - URI of printer */
2310 http_status_t status
; /* Policy status */
2311 int i
; /* Looping var */
2312 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2313 username
[HTTP_MAX_URI
], /* Username portion of URI */
2314 host
[HTTP_MAX_URI
], /* Host portion of URI */
2315 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2316 int port
; /* Port portion of URI */
2317 cupsd_printer_t
*printer
; /* Printer/class */
2318 ipp_attribute_t
*attr
; /* Printer attribute */
2319 cups_file_t
*fp
; /* Script/PPD file */
2320 char line
[1024]; /* Line from file... */
2321 char srcfile
[1024], /* Source Script/PPD file */
2322 dstfile
[1024]; /* Destination Script/PPD file */
2323 int modify
; /* Non-zero if we are modifying */
2324 char newname
[IPP_MAX_NAME
]; /* New printer name */
2325 int changed_driver
, /* Changed the PPD/interface script? */
2326 need_restart_job
, /* Need to restart job? */
2327 set_device_uri
, /* Did we set the device URI? */
2328 set_port_monitor
; /* Did we set the port monitor? */
2331 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2332 con
->http
.fd
, uri
->values
[0].string
.text
);
2335 * Do we have a valid URI?
2338 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2339 sizeof(scheme
), username
, sizeof(username
), host
,
2340 sizeof(host
), &port
, resource
, sizeof(resource
));
2342 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2345 * No, return an error...
2348 send_ipp_status(con
, IPP_BAD_REQUEST
,
2349 _("The printer-uri must be of the form "
2350 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2355 * Do we have a valid printer name?
2358 if (!validate_name(resource
+ 10))
2361 * No, return an error...
2364 send_ipp_status(con
, IPP_BAD_REQUEST
,
2365 _("The printer-uri \"%s\" contains invalid characters."),
2366 uri
->values
[0].string
.text
);
2371 * See if the printer already exists; if not, create a new printer...
2374 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2377 * Printer doesn't exist; see if we have a class of the same name...
2380 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2381 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2384 * Yes, return an error...
2387 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2388 _("A class named \"%s\" already exists"),
2394 * No, check the default policy then add the printer...
2397 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2399 send_http_error(con
, status
, NULL
);
2403 printer
= cupsdAddPrinter(resource
+ 10);
2406 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2409 * Check the default policy, then rename the implicit printer to
2410 * "AnyPrinter" or delete it...
2413 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2415 send_http_error(con
, status
, NULL
);
2419 if (ImplicitAnyClasses
)
2421 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2422 cupsdRenamePrinter(printer
, newname
);
2425 cupsdDeletePrinter(printer
, 1);
2428 * Add the printer as a new local printer...
2431 printer
= cupsdAddPrinter(resource
+ 10);
2434 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2437 * Check the default policy, then rename the remote printer to
2438 * "Printer@server"...
2441 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2443 send_http_error(con
, status
, NULL
);
2447 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2449 cupsdRenamePrinter(printer
, newname
);
2452 * Add the printer as a new local printer...
2455 printer
= cupsdAddPrinter(resource
+ 10);
2458 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2461 send_http_error(con
, status
, printer
);
2468 * Look for attributes and copy them over as needed...
2472 need_restart_job
= 0;
2474 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2475 IPP_TAG_TEXT
)) != NULL
)
2476 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2478 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2479 IPP_TAG_TEXT
)) != NULL
)
2480 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2484 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2485 IPP_TAG_URI
)) != NULL
)
2488 * Do we have a valid device URI?
2491 http_uri_status_t uri_status
; /* URI separation status */
2492 char old_device_uri
[1024];
2493 /* Old device URI */
2496 need_restart_job
= 1;
2498 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2499 attr
->values
[0].string
.text
,
2500 scheme
, sizeof(scheme
),
2501 username
, sizeof(username
),
2502 host
, sizeof(host
), &port
,
2503 resource
, sizeof(resource
));
2505 if (uri_status
< HTTP_URI_OK
)
2507 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\""),
2508 attr
->values
[0].string
.text
);
2509 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2510 "add_printer: httpSeparateURI returned %d", uri_status
);
2514 if (!strcmp(scheme
, "file"))
2517 * See if the administrator has enabled file devices...
2520 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2523 * File devices are disabled and the URL is not file:/dev/null...
2526 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2527 _("File device URIs have been disabled! "
2528 "To enable, see the FileDevice directive in "
2529 "\"%s/cupsd.conf\"."),
2537 * See if the backend exists and is executable...
2540 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2541 if (access(srcfile
, X_OK
))
2544 * Could not find device in list!
2547 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\""),
2553 if (printer
->sanitized_device_uri
)
2554 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2555 sizeof(old_device_uri
));
2557 old_device_uri
[0] = '\0';
2559 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2561 cupsdLogMessage(CUPSD_LOG_INFO
,
2562 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2563 printer
->name
, printer
->sanitized_device_uri
,
2569 set_port_monitor
= 0;
2571 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2572 IPP_TAG_NAME
)) != NULL
)
2574 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2577 need_restart_job
= 1;
2579 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2583 for (i
= 0; i
< supported
->num_values
; i
++)
2584 if (!strcmp(supported
->values
[i
].string
.text
,
2585 attr
->values
[0].string
.text
))
2589 if (!supported
|| i
>= supported
->num_values
)
2591 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\""),
2592 attr
->values
[0].string
.text
);
2596 cupsdLogMessage(CUPSD_LOG_INFO
,
2597 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2598 printer
->name
, attr
->values
[0].string
.text
,
2599 printer
->port_monitor
? printer
->port_monitor
: "none");
2601 if (strcmp(attr
->values
[0].string
.text
, "none"))
2602 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2604 cupsdClearString(&printer
->port_monitor
);
2606 set_port_monitor
= 1;
2609 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2610 IPP_TAG_BOOLEAN
)) != NULL
)
2612 cupsdLogMessage(CUPSD_LOG_INFO
,
2613 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2614 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2616 printer
->accepting
= attr
->values
[0].boolean
;
2617 cupsdAddPrinterHistory(printer
);
2620 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2621 IPP_TAG_BOOLEAN
)) != NULL
)
2623 if (printer
->shared
&& !attr
->values
[0].boolean
)
2624 cupsdDeregisterPrinter(printer
, 1);
2626 cupsdLogMessage(CUPSD_LOG_INFO
,
2627 "Setting %s printer-is-shared to %d (was %d.)",
2628 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2630 printer
->shared
= attr
->values
[0].boolean
;
2633 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2634 IPP_TAG_ENUM
)) != NULL
)
2636 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2637 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2639 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d"),
2640 attr
->values
[0].integer
);
2644 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2645 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2647 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2648 cupsdStopPrinter(printer
, 0);
2651 need_restart_job
= 1;
2652 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2656 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2657 IPP_TAG_TEXT
)) != NULL
)
2659 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2660 sizeof(printer
->state_message
));
2661 cupsdAddPrinterHistory(printer
);
2664 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2665 IPP_TAG_KEYWORD
)) != NULL
)
2667 if (attr
->num_values
>
2668 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2670 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2671 _("Too many printer-state-reasons values (%d > %d)"),
2673 (int)(sizeof(printer
->reasons
) /
2674 sizeof(printer
->reasons
[0])));
2678 for (i
= 0; i
< printer
->num_reasons
; i
++)
2679 _cupsStrFree(printer
->reasons
[i
]);
2681 printer
->num_reasons
= 0;
2682 for (i
= 0; i
< attr
->num_values
; i
++)
2684 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2687 printer
->reasons
[printer
->num_reasons
] =
2688 _cupsStrRetain(attr
->values
[i
].string
.text
);
2689 printer
->num_reasons
++;
2691 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2692 printer
->state
!= IPP_PRINTER_STOPPED
)
2694 cupsdLogMessage(CUPSD_LOG_INFO
,
2695 "Setting %s printer-state to %d (was %d.)",
2696 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2697 cupsdStopPrinter(printer
, 0);
2701 if (PrintcapFormat
== PRINTCAP_PLIST
)
2702 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2705 set_printer_defaults(con
, printer
);
2707 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2708 IPP_TAG_KEYWORD
)) != NULL
)
2709 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2712 * See if we have all required attributes...
2715 if (!printer
->device_uri
)
2716 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2719 * See if we have an interface script or PPD file attached to the request...
2724 need_restart_job
= 1;
2727 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2729 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2732 * Yes; get the first line from it...
2736 cupsFileGets(fp
, line
, sizeof(line
));
2740 * Then see what kind of file it is...
2743 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2746 if (!strncmp(line
, "*PPD-Adobe", 10))
2749 * The new file is a PPD file, so remove any old interface script
2750 * that might be lying around...
2758 * This must be an interface script, so move the file over to the
2759 * interfaces directory and make it executable...
2762 if (copy_file(srcfile
, dstfile
))
2764 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2765 _("Unable to copy interface script - %s"),
2770 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2771 "Copied interface script successfully");
2772 chmod(dstfile
, 0755);
2775 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2778 if (!strncmp(line
, "*PPD-Adobe", 10))
2781 * The new file is a PPD file, so move the file over to the
2782 * ppd directory and make it readable by all...
2785 if (copy_file(srcfile
, dstfile
))
2787 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2788 _("Unable to copy PPD file - %s"),
2793 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2794 "Copied PPD file successfully");
2795 chmod(dstfile
, 0644);
2800 * This must be an interface script, so remove any old PPD file that
2801 * may be lying around...
2808 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2809 IPP_TAG_NAME
)) != NULL
)
2811 need_restart_job
= 1;
2814 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2817 * Raw driver, remove any existing PPD or interface script files.
2820 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2824 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2834 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2838 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2841 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2843 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file"));
2847 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2848 "Copied PPD file successfully");
2849 chmod(dstfile
, 0644);
2856 * If we changed the PPD/interface script, then remove the printer's cache
2860 char cache_name
[1024]; /* Cache filename for printer attrs */
2862 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp", CacheDir
,
2868 * (Re)register color profiles...
2873 apple_unregister_profiles(printer
);
2874 apple_register_profiles(printer
);
2876 #endif /* __APPLE__ */
2880 * If we set the device URI but not the port monitor, check which port
2881 * monitor to use by default...
2884 if (set_device_uri
&& !set_port_monitor
)
2886 ppd_file_t
*ppd
; /* PPD file */
2887 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2890 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2891 sizeof(scheme
), username
, sizeof(username
), host
,
2892 sizeof(host
), &port
, resource
, sizeof(resource
));
2894 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2896 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2898 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2900 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2901 if (!strcmp(scheme
, ppdattr
->spec
))
2903 cupsdLogMessage(CUPSD_LOG_INFO
,
2904 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2905 printer
->name
, ppdattr
->value
,
2906 printer
->port_monitor
? printer
->port_monitor
2909 if (strcmp(ppdattr
->value
, "none"))
2910 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2912 cupsdClearString(&printer
->port_monitor
);
2922 * Update the printer attributes and return...
2925 cupsdSetPrinterAttrs(printer
);
2926 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2928 if (need_restart_job
&& printer
->job
)
2931 * Restart the current job...
2934 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2935 "Job restarted because the printer was modified.");
2938 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2942 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2943 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2946 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2947 printer
->name
, get_username(con
));
2951 cupsdAddPrinterHistory(printer
);
2953 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2954 "New printer \"%s\" added by \"%s\".", printer
->name
,
2957 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2958 printer
->name
, get_username(con
));
2961 con
->response
->request
.status
.status_code
= IPP_OK
;
2966 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2967 * based upon the printer state...
2971 add_printer_state_reasons(
2972 cupsd_client_t
*con
, /* I - Client connection */
2973 cupsd_printer_t
*p
) /* I - Printer info */
2975 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2976 "add_printer_state_reasons(%p[%d], %p[%s])",
2977 con
, con
->http
.fd
, p
, p
->name
);
2979 if (p
->num_reasons
== 0)
2980 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2981 "printer-state-reasons", NULL
, "none");
2983 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2984 "printer-state-reasons", p
->num_reasons
, NULL
,
2985 (const char * const *)p
->reasons
);
2990 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2991 * the specified printer or class.
2995 add_queued_job_count(
2996 cupsd_client_t
*con
, /* I - Client connection */
2997 cupsd_printer_t
*p
) /* I - Printer or class */
2999 int count
; /* Number of jobs on destination */
3002 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3003 con
, con
->http
.fd
, p
, p
->name
);
3005 count
= cupsdGetPrinterJobCount(p
->name
);
3007 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3008 "queued-job-count", count
);
3014 * 'apple_init_profile()' - Initialize a color profile.
3019 ppd_file_t
*ppd
, /* I - PPD file */
3020 cups_array_t
*languages
, /* I - Languages in the PPD file */
3021 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3022 unsigned id
, /* I - Profile ID */
3023 const char *name
, /* I - Profile name */
3024 const char *text
, /* I - Profile UI text */
3025 const char *iccfile
) /* I - ICC filename */
3027 char url
[1024]; /* URL for profile filename */
3028 CFMutableDictionaryRef dict
; /* Dictionary for name */
3029 char *language
; /* Current language */
3030 ppd_attr_t
*attr
; /* Profile attribute */
3031 CFStringRef cflang
, /* Language string */
3032 cftext
; /* Localized text */
3036 * Build the profile name dictionary...
3039 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3040 &kCFTypeDictionaryKeyCallBacks
,
3041 &kCFTypeDictionaryValueCallBacks
);
3043 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3044 kCFStringEncodingUTF8
);
3048 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
3055 * Find localized names for the color profiles...
3058 cupsArraySave(ppd
->sorted_attrs
);
3060 for (language
= (char *)cupsArrayFirst(languages
);
3062 language
= (char *)cupsArrayNext(languages
))
3066 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3068 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3071 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3073 if (attr
&& attr
->text
[0])
3075 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3076 kCFStringEncodingUTF8
);
3077 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3078 kCFStringEncodingUTF8
);
3080 if (cflang
&& cftext
)
3081 CFDictionarySetValue(dict
, cflang
, cftext
);
3091 cupsArrayRestore(ppd
->sorted_attrs
);
3095 * Fill in the profile data...
3099 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3102 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3103 profile
->profileID
= id
;
3104 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3105 profile
->profileName
= dict
;
3108 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3109 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3114 * 'apple_register_profiles()' - Register color profiles for a printer.
3118 apple_register_profiles(
3119 cupsd_printer_t
*p
) /* I - Printer */
3121 int i
; /* Looping var */
3122 char ppdfile
[1024], /* PPD filename */
3123 iccfile
[1024], /* ICC filename */
3124 selector
[PPD_MAX_NAME
];
3125 /* Profile selection string */
3126 ppd_file_t
*ppd
; /* PPD file */
3127 ppd_attr_t
*attr
, /* Profile attributes */
3128 *profileid_attr
,/* cupsProfileID attribute */
3129 *q1_attr
, /* ColorModel (or other) qualifier */
3130 *q2_attr
, /* MediaType (or other) qualifier */
3131 *q3_attr
; /* Resolution (or other) qualifier */
3132 char q_keyword
[PPD_MAX_NAME
];
3133 /* Qualifier keyword */
3134 const char *q1_choice
, /* ColorModel (or other) choice */
3135 *q2_choice
, /* MediaType (or other) choice */
3136 *q3_choice
; /* Resolution (or other) choice */
3137 const char *profile_key
; /* Profile keyword */
3138 ppd_option_t
*cm_option
; /* Color model option */
3139 ppd_choice_t
*cm_choice
; /* Color model choice */
3140 int num_profiles
; /* Number of profiles */
3141 CMError error
; /* Last error */
3142 unsigned device_id
, /* Printer device ID */
3143 profile_id
, /* Profile ID */
3144 default_profile_id
= 0;
3145 /* Default profile ID */
3146 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3147 CFStringRef printer_name
; /* Printer name string */
3148 CMDeviceScope scope
= /* Scope of the registration */
3150 kCFPreferencesAnyUser
,
3151 kCFPreferencesCurrentHost
3153 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3154 CMDeviceProfileInfo
*profile
; /* Current profile */
3155 cups_array_t
*languages
; /* Languages array */
3159 * Make sure ColorSync is available...
3162 if (CMRegisterColorDevice
== NULL
)
3166 * Try opening the PPD file for this printer...
3169 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3170 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3174 * See if we have any profiles...
3177 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3178 profile_key
= "APTiogaProfile";
3181 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3182 profile_key
= "cupsICCProfile";
3185 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3186 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3188 if (attr
->value
[0] != '/')
3189 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3192 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3194 if (access(iccfile
, 0))
3202 * If we have profiles, add them...
3205 if (num_profiles
> 0)
3207 if (profile_key
[0] == 'A')
3210 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3214 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3216 default_profile_id
= atoi(attr
->value
);
3218 q1_choice
= q2_choice
= q3_choice
= NULL
;
3223 * For CUPS PPDs, figure out the default profile selector values...
3226 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3227 attr
->value
&& attr
->value
[0])
3229 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3230 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3232 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3233 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3235 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3236 q1_choice
= q1_attr
->value
;
3240 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3241 attr
->value
&& attr
->value
[0])
3243 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3244 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3247 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3249 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3250 q2_choice
= q2_attr
->value
;
3254 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3255 attr
->value
&& attr
->value
[0])
3257 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3258 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3261 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3263 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3264 q3_choice
= q3_attr
->value
;
3270 * Build the array of profiles...
3272 * Note: This calloc actually requests slightly more memory than needed.
3275 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3277 cupsdLogMessage(CUPSD_LOG_ERROR
,
3278 "Unable to allocate memory for %d profiles",
3284 profiles
->profileCount
= num_profiles
;
3285 languages
= _ppdGetLanguages(ppd
);
3287 for (profile
= profiles
->profiles
,
3288 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3290 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3291 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3294 * Add this profile...
3297 if (attr
->value
[0] != '/')
3298 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3301 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3303 if (access(iccfile
, 0))
3306 if (profile_key
[0] == 'c')
3308 cupsArraySave(ppd
->sorted_attrs
);
3310 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3311 attr
->spec
)) != NULL
&&
3312 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3313 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3315 profile_id
= _ppdHashName(attr
->spec
);
3317 cupsArrayRestore(ppd
->sorted_attrs
);
3320 profile_id
= atoi(attr
->spec
);
3322 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3323 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3328 * See if this is the default profile...
3331 if (!default_profile_id
)
3337 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3338 q1_choice
, q2_choice
, q3_choice
);
3339 if (!strcmp(selector
, attr
->spec
))
3340 default_profile_id
= profile_id
;
3343 if (!default_profile_id
)
3345 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3347 if (!strcmp(selector
, attr
->spec
))
3348 default_profile_id
= profile_id
;
3352 if (!default_profile_id
&& q3_choice
)
3354 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3356 if (!strcmp(selector
, attr
->spec
))
3357 default_profile_id
= profile_id
;
3360 if (!default_profile_id
)
3362 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3363 if (!strcmp(selector
, attr
->spec
))
3364 default_profile_id
= profile_id
;
3369 _ppdFreeLanguages(languages
);
3371 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3374 * Extract profiles from ColorModel option...
3377 const char *profile_name
; /* Name of generic profile */
3380 num_profiles
= cm_option
->num_choices
;
3382 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3384 cupsdLogMessage(CUPSD_LOG_ERROR
,
3385 "Unable to allocate memory for %d profiles",
3391 profiles
->profileCount
= num_profiles
;
3393 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3394 cm_choice
= cm_option
->choices
;
3396 i
--, cm_choice
++, profile
++)
3398 if (!strcmp(cm_choice
->choice
, "Gray") ||
3399 !strcmp(cm_choice
->choice
, "Black"))
3400 profile_name
= "Gray";
3401 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3402 !strcmp(cm_choice
->choice
, "CMY"))
3403 profile_name
= "RGB";
3404 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3405 !strcmp(cm_choice
->choice
, "KCMY"))
3406 profile_name
= "CMYK";
3408 profile_name
= "DeviceN";
3410 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3411 profile_id
= _ppdHashName(selector
);
3413 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3414 cm_choice
->text
, NULL
);
3416 if (cm_choice
->marked
)
3417 default_profile_id
= profile_id
;
3423 * Use the default colorspace...
3426 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3428 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3430 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3432 cupsdLogMessage(CUPSD_LOG_ERROR
,
3433 "Unable to allocate memory for %d profiles",
3439 profiles
->profileCount
= num_profiles
;
3441 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3442 "Gray", "Gray", NULL
);
3444 switch (ppd
->colorspace
)
3448 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3449 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3453 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3454 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3462 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3463 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3469 if (num_profiles
> 0)
3472 * Make sure we have a default profile ID...
3475 if (!default_profile_id
)
3476 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3479 * Get the device ID hash and pathelogical name dictionary.
3482 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3485 device_id
= _ppdHashName(p
->name
);
3486 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3487 &kCFTypeDictionaryKeyCallBacks
,
3488 &kCFTypeDictionaryValueCallBacks
);
3489 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3490 p
->name
, kCFStringEncodingUTF8
);
3492 if (device_name
&& printer_name
)
3494 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3497 * Register the device with ColorSync...
3500 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3501 device_name
, &scope
);
3504 * Register the profiles...
3508 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3509 default_profile_id
, profiles
);
3519 cupsdLogMessage(CUPSD_LOG_ERROR
,
3520 "Unable to register ICC color profiles for \"%s\" - %d",
3521 p
->name
, (int)error
);
3523 for (profile
= profiles
->profiles
;
3525 profile
++, num_profiles
--)
3526 CFRelease(profile
->profileName
);
3531 CFRelease(printer_name
);
3534 CFRelease(device_name
);
3542 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3547 apple_unregister_profiles(
3548 cupsd_printer_t
*p
) /* I - Printer */
3551 * Make sure ColorSync is available...
3554 if (CMUnregisterColorDevice
!= NULL
)
3555 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3557 #endif /* __APPLE__ */
3560 * 'apply_printer_defaults()' - Apply printer default options to a job.
3564 apply_printer_defaults(
3565 cupsd_printer_t
*printer
, /* I - Printer */
3566 cupsd_job_t
*job
) /* I - Job */
3568 int i
, /* Looping var */
3569 num_options
; /* Number of default options */
3570 cups_option_t
*options
, /* Default options */
3571 *option
; /* Current option */
3575 * Collect all of the default options and add the missing ones to the
3579 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3580 option
= printer
->options
;
3583 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3585 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3590 * Encode these options as attributes in the job object...
3593 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3594 cupsFreeOptions(num_options
, options
);
3599 * 'authenticate_job()' - Set job authentication info.
3603 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3604 ipp_attribute_t
*uri
) /* I - Job URI */
3606 ipp_attribute_t
*attr
, /* job-id attribute */
3607 *auth_info
; /* auth-info attribute */
3608 int jobid
; /* Job ID */
3609 cupsd_job_t
*job
; /* Current job */
3610 char scheme
[HTTP_MAX_URI
],
3611 /* Method portion of URI */
3612 username
[HTTP_MAX_URI
],
3613 /* Username portion of URI */
3615 /* Host portion of URI */
3616 resource
[HTTP_MAX_URI
];
3617 /* Resource portion of URI */
3618 int port
; /* Port portion of URI */
3621 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3622 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3625 * Start with "everything is OK" status...
3628 con
->response
->request
.status
.status_code
= IPP_OK
;
3631 * See if we have a job URI or a printer URI...
3634 if (!strcmp(uri
->name
, "printer-uri"))
3637 * Got a printer URI; see if we also have a job-id attribute...
3640 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3641 IPP_TAG_INTEGER
)) == NULL
)
3643 send_ipp_status(con
, IPP_BAD_REQUEST
,
3644 _("Got a printer-uri attribute but no job-id"));
3648 jobid
= attr
->values
[0].integer
;
3653 * Got a job URI; parse it to get the job ID...
3656 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3657 sizeof(scheme
), username
, sizeof(username
), host
,
3658 sizeof(host
), &port
, resource
, sizeof(resource
));
3660 if (strncmp(resource
, "/jobs/", 6))
3666 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\""),
3667 uri
->values
[0].string
.text
);
3671 jobid
= atoi(resource
+ 6);
3675 * See if the job exists...
3678 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3681 * Nope - return a "not found" error...
3684 send_ipp_status(con
, IPP_NOT_FOUND
,
3685 _("Job #%d does not exist"), jobid
);
3690 * See if the job has been completed...
3693 if (job
->state_value
!= IPP_JOB_HELD
)
3696 * Return a "not-possible" error...
3699 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3700 _("Job #%d is not held for authentication"),
3706 * See if we have already authenticated...
3709 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3711 if (!con
->username
[0] && !auth_info
)
3713 cupsd_printer_t
*printer
; /* Job destination */
3717 * No auth data. If we need to authenticate via Kerberos, send a
3718 * HTTP auth challenge, otherwise just return an IPP error...
3721 printer
= cupsdFindDest(job
->dest
);
3723 if (printer
&& printer
->num_auth_info_required
> 0 &&
3724 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3725 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3727 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3728 _("No authentication information provided"));
3733 * See if the job is owned by the requesting user...
3736 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3738 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3739 cupsdFindDest(job
->dest
));
3744 * Save the authentication information for this job...
3747 save_auth_info(con
, job
, auth_info
);
3750 * Reset the job-hold-until value to "no-hold"...
3753 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3754 IPP_TAG_KEYWORD
)) == NULL
)
3755 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3759 attr
->value_tag
= IPP_TAG_KEYWORD
;
3760 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3764 * Release the job and return...
3767 cupsdReleaseJob(job
);
3769 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3774 * 'cancel_all_jobs()' - Cancel all print jobs.
3778 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3779 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3781 http_status_t status
; /* Policy status */
3782 cups_ptype_t dtype
; /* Destination type */
3783 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3784 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3785 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3786 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3787 int port
; /* Port portion of URI */
3788 ipp_attribute_t
*attr
; /* Attribute in request */
3789 const char *username
; /* Username */
3790 cupsd_jobaction_t purge
; /* Purge? */
3791 cupsd_printer_t
*printer
; /* Printer */
3794 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3795 con
->http
.fd
, uri
->values
[0].string
.text
);
3798 * See if we have a printer URI...
3801 if (strcmp(uri
->name
, "printer-uri"))
3803 send_ipp_status(con
, IPP_BAD_REQUEST
,
3804 _("The printer-uri attribute is required"));
3809 * Get the username (if any) for the jobs we want to cancel (only if
3810 * "my-jobs" is specified...
3813 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3814 IPP_TAG_BOOLEAN
)) != NULL
&&
3815 attr
->values
[0].boolean
)
3817 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3818 IPP_TAG_NAME
)) != NULL
)
3819 username
= attr
->values
[0].string
.text
;
3822 send_ipp_status(con
, IPP_BAD_REQUEST
,
3823 _("Missing requesting-user-name attribute"));
3831 * Look for the "purge-jobs" attribute...
3834 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3835 IPP_TAG_BOOLEAN
)) != NULL
)
3836 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3838 purge
= CUPSD_JOB_PURGE
;
3841 * And if the destination is valid...
3844 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3850 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3851 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3852 hostname
, sizeof(hostname
), &port
,
3853 resource
, sizeof(resource
));
3855 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3856 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3858 send_ipp_status(con
, IPP_NOT_FOUND
,
3859 _("The printer or class was not found."));
3867 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3869 send_http_error(con
, status
, NULL
);
3874 * Cancel all jobs on all printers...
3877 cupsdCancelJobs(NULL
, username
, purge
);
3879 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3880 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3889 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3892 send_http_error(con
, status
, printer
);
3897 * Cancel all of the jobs on the named printer...
3900 cupsdCancelJobs(printer
->name
, username
, purge
);
3902 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3904 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3908 con
->response
->request
.status
.status_code
= IPP_OK
;
3913 * 'cancel_job()' - Cancel a print job.
3917 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3918 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3920 ipp_attribute_t
*attr
; /* Current attribute */
3921 int jobid
; /* Job ID */
3922 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3923 username
[HTTP_MAX_URI
], /* Username portion of URI */
3924 host
[HTTP_MAX_URI
], /* Host portion of URI */
3925 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3926 int port
; /* Port portion of URI */
3927 cupsd_job_t
*job
; /* Job information */
3928 cups_ptype_t dtype
; /* Destination type (printer/class) */
3929 cupsd_printer_t
*printer
; /* Printer data */
3930 cupsd_jobaction_t purge
; /* Purge the job? */
3933 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3934 con
->http
.fd
, uri
->values
[0].string
.text
);
3937 * See if we have a job URI or a printer URI...
3940 if (!strcmp(uri
->name
, "printer-uri"))
3943 * Got a printer URI; see if we also have a job-id attribute...
3946 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3947 IPP_TAG_INTEGER
)) == NULL
)
3949 send_ipp_status(con
, IPP_BAD_REQUEST
,
3950 _("Got a printer-uri attribute but no job-id"));
3954 if ((jobid
= attr
->values
[0].integer
) == 0)
3957 * Find the current job on the specified printer...
3960 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3966 send_ipp_status(con
, IPP_NOT_FOUND
,
3967 _("The printer or class was not found."));
3972 * See if there are any pending jobs...
3975 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3977 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3978 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3979 !strcasecmp(job
->dest
, printer
->name
))
3987 * No, try stopped jobs...
3990 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3992 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3993 if (job
->state_value
== IPP_JOB_STOPPED
&&
3994 !strcasecmp(job
->dest
, printer
->name
))
4001 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s"),
4011 * Got a job URI; parse it to get the job ID...
4014 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4015 sizeof(scheme
), username
, sizeof(username
), host
,
4016 sizeof(host
), &port
, resource
, sizeof(resource
));
4018 if (strncmp(resource
, "/jobs/", 6))
4024 send_ipp_status(con
, IPP_BAD_REQUEST
,
4025 _("Bad job-uri attribute \"%s\""),
4026 uri
->values
[0].string
.text
);
4030 jobid
= atoi(resource
+ 6);
4034 * Look for the "purge-job" attribute...
4037 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4038 IPP_TAG_BOOLEAN
)) != NULL
)
4039 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4041 purge
= CUPSD_JOB_DEFAULT
;
4044 * See if the job exists...
4047 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4050 * Nope - return a "not found" error...
4053 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
4058 * See if the job is owned by the requesting user...
4061 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4063 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4064 cupsdFindDest(job
->dest
));
4069 * See if the job is already completed, canceled, or aborted; if so,
4070 * we can't cancel...
4073 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4075 switch (job
->state_value
)
4077 case IPP_JOB_CANCELED
:
4078 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4079 _("Job #%d is already canceled - can\'t cancel."),
4083 case IPP_JOB_ABORTED
:
4084 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4085 _("Job #%d is already aborted - can\'t cancel."),
4090 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4091 _("Job #%d is already completed - can\'t cancel."),
4100 * Cancel the job and return...
4103 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4104 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4105 "Job canceled by \"%s\"",
4109 if (purge
== CUPSD_JOB_PURGE
)
4110 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4113 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4116 con
->response
->request
.status
.status_code
= IPP_OK
;
4121 * 'cancel_subscription()' - Cancel a subscription.
4125 cancel_subscription(
4126 cupsd_client_t
*con
, /* I - Client connection */
4127 int sub_id
) /* I - Subscription ID */
4129 http_status_t status
; /* Policy status */
4130 cupsd_subscription_t
*sub
; /* Subscription */
4133 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4134 "cancel_subscription(con=%p[%d], sub_id=%d)",
4135 con
, con
->http
.fd
, sub_id
);
4138 * Is the subscription ID valid?
4141 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4144 * Bad subscription ID...
4147 send_ipp_status(con
, IPP_NOT_FOUND
,
4148 _("notify-subscription-id %d no good"), sub_id
);
4156 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4158 con
, sub
->owner
)) != HTTP_OK
)
4160 send_http_error(con
, status
, sub
->dest
);
4165 * Cancel the subscription...
4168 cupsdDeleteSubscription(sub
, 1);
4170 con
->response
->request
.status
.status_code
= IPP_OK
;
4175 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4178 static int /* O - 1 if OK, 0 if not */
4179 check_rss_recipient(
4180 const char *recipient
) /* I - Recipient URI */
4182 cupsd_subscription_t
*sub
; /* Current subscription */
4185 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4187 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4191 * Compare the URIs up to the first ?...
4194 const char *r1
, *r2
;
4196 for (r1
= recipient
, r2
= sub
->recipient
;
4197 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4209 * 'check_quotas()' - Check quotas for a printer and user.
4212 static int /* O - 1 if OK, 0 if not */
4213 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4214 cupsd_printer_t
*p
) /* I - Printer or class */
4216 int i
; /* Looping var */
4217 char username
[33]; /* Username */
4218 cupsd_quota_t
*q
; /* Quota data */
4219 #ifdef HAVE_MBR_UID_TO_UUID
4221 * Use Apple membership APIs which require that all names represent
4222 * valid user account or group records accessible by the server.
4225 uuid_t usr_uuid
; /* UUID for job requesting user */
4226 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4227 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4228 int mbr_err
; /* Error from membership function */
4229 int is_member
; /* Is this user a member? */
4232 * Use standard POSIX APIs for checking users and groups...
4235 struct passwd
*pw
; /* User password data */
4236 #endif /* HAVE_MBR_UID_TO_UUID */
4239 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4240 con
, con
->http
.fd
, p
, p
->name
);
4243 * Figure out who is printing...
4246 strlcpy(username
, get_username(con
), sizeof(username
));
4249 * Check global active job limits for printers and users...
4252 if (MaxJobsPerPrinter
)
4255 * Check if there are too many pending jobs on this printer...
4258 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4260 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4269 * Check if there are too many pending jobs for this user...
4272 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4274 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4281 * Check against users...
4284 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4289 #ifdef HAVE_MBR_UID_TO_UUID
4291 * Get UUID for job requesting user...
4294 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4300 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4301 "check_quotas: UUID lookup failed for user \"%s\"",
4303 cupsdLogMessage(CUPSD_LOG_INFO
,
4304 "Denying user \"%s\" access to printer \"%s\" "
4305 "(unknown user)...",
4311 * Get UID and GID of requesting user...
4314 pw
= getpwnam(username
);
4316 #endif /* HAVE_MBR_UID_TO_UUID */
4318 for (i
= 0; i
< p
->num_users
; i
++)
4319 if (p
->users
[i
][0] == '@')
4322 * Check group membership...
4325 #ifdef HAVE_MBR_UID_TO_UUID
4326 if (p
->users
[i
][1] == '#')
4328 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4329 uuid_clear(grp_uuid
);
4331 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4335 * Invalid ACL entries are ignored for matching; just record a
4336 * warning in the log...
4339 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4340 "check_quotas: UUID lookup failed for ACL entry "
4341 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4342 cupsdLogMessage(CUPSD_LOG_WARN
,
4343 "Access control entry \"%s\" not a valid group name; "
4344 "entry ignored", p
->users
[i
]);
4347 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4351 * At this point, there should be no errors, but check anyways...
4354 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4355 "check_quotas: group \"%s\" membership check "
4356 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4361 * Stop if we found a match...
4368 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4370 #endif /* HAVE_MBR_UID_TO_UUID */
4372 #ifdef HAVE_MBR_UID_TO_UUID
4375 if (p
->users
[i
][0] == '#')
4377 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4378 uuid_clear(usr2_uuid
);
4380 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4384 * Invalid ACL entries are ignored for matching; just record a
4385 * warning in the log...
4388 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4389 "check_quotas: UUID lookup failed for ACL entry "
4390 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4391 cupsdLogMessage(CUPSD_LOG_WARN
,
4392 "Access control entry \"%s\" not a valid user name; "
4393 "entry ignored", p
->users
[i
]);
4396 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4400 else if (!strcasecmp(username
, p
->users
[i
]))
4402 #endif /* HAVE_MBR_UID_TO_UUID */
4404 if ((i
< p
->num_users
) == p
->deny_users
)
4406 cupsdLogMessage(CUPSD_LOG_INFO
,
4407 "Denying user \"%s\" access to printer \"%s\"...",
4418 if (AppleQuotas
&& (q
= cupsdFindQuota(p
, username
)) != NULL
)
4421 * TODO: Define these special page count values as constants!
4424 if (q
->page_count
== -4) /* special case: unlimited user */
4426 cupsdLogMessage(CUPSD_LOG_INFO
,
4427 "User \"%s\" request approved for printer %s (%s): "
4429 username
, p
->name
, p
->info
);
4430 q
->page_count
= 0; /* allow user to print */
4433 else if (q
->page_count
== -3) /* quota exceeded */
4435 cupsdLogMessage(CUPSD_LOG_INFO
,
4436 "User \"%s\" request denied for printer %s (%s): "
4437 "quota limit exceeded.",
4438 username
, p
->name
, p
->info
);
4439 q
->page_count
= 2; /* force quota exceeded failure */
4442 else if (q
->page_count
== -2) /* quota disabled for user */
4444 cupsdLogMessage(CUPSD_LOG_INFO
,
4445 "User \"%s\" request denied for printer %s (%s): "
4446 "printing disabled for user.",
4447 username
, p
->name
, p
->info
);
4448 q
->page_count
= 2; /* force quota exceeded failure */
4451 else if (q
->page_count
== -1) /* quota access error */
4453 cupsdLogMessage(CUPSD_LOG_INFO
,
4454 "User \"%s\" request denied for printer %s (%s): "
4455 "unable to determine quota limit.",
4456 username
, p
->name
, p
->info
);
4457 q
->page_count
= 2; /* force quota exceeded failure */
4460 else if (q
->page_count
< 0) /* user not found or other error */
4462 cupsdLogMessage(CUPSD_LOG_INFO
,
4463 "User \"%s\" request denied for printer %s (%s): "
4464 "user disabled / missing quota.",
4465 username
, p
->name
, p
->info
);
4466 q
->page_count
= 2; /* force quota exceeded failure */
4469 else /* page within user limits */
4471 q
->page_count
= 0; /* allow user to print */
4476 #endif /* __APPLE__ */
4477 if (p
->k_limit
|| p
->page_limit
)
4479 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4481 cupsdLogMessage(CUPSD_LOG_ERROR
,
4482 "Unable to allocate quota data for user \"%s\"",
4487 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4488 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4490 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4497 * If we have gotten this far, we're done!
4505 * 'copy_attribute()' - Copy a single attribute.
4508 static ipp_attribute_t
* /* O - New attribute */
4510 ipp_t
*to
, /* O - Destination request/response */
4511 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4512 int quickcopy
) /* I - Do a quick copy? */
4514 int i
; /* Looping var */
4515 ipp_attribute_t
*toattr
; /* Destination attribute */
4518 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4519 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4520 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4523 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4526 toattr
= ippAddSeparator(to
);
4529 case IPP_TAG_INTEGER
:
4531 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4532 attr
->name
, attr
->num_values
, NULL
);
4534 for (i
= 0; i
< attr
->num_values
; i
++)
4535 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4538 case IPP_TAG_BOOLEAN
:
4539 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4540 attr
->num_values
, NULL
);
4542 for (i
= 0; i
< attr
->num_values
; i
++)
4543 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4546 case IPP_TAG_STRING
:
4549 case IPP_TAG_KEYWORD
:
4551 case IPP_TAG_URISCHEME
:
4552 case IPP_TAG_CHARSET
:
4553 case IPP_TAG_LANGUAGE
:
4554 case IPP_TAG_MIMETYPE
:
4555 toattr
= ippAddStrings(to
, attr
->group_tag
,
4556 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4557 attr
->name
, attr
->num_values
, NULL
, NULL
);
4561 for (i
= 0; i
< attr
->num_values
; i
++)
4562 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4564 else if (attr
->value_tag
& IPP_TAG_COPY
)
4566 for (i
= 0; i
< attr
->num_values
; i
++)
4567 toattr
->values
[i
].string
.text
=
4568 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4572 for (i
= 0; i
< attr
->num_values
; i
++)
4573 toattr
->values
[i
].string
.text
=
4574 _cupsStrRetain(attr
->values
[i
].string
.text
);
4579 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4580 attr
->values
[0].date
);
4583 case IPP_TAG_RESOLUTION
:
4584 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4585 attr
->num_values
, IPP_RES_PER_INCH
,
4588 for (i
= 0; i
< attr
->num_values
; i
++)
4590 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4591 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4592 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4596 case IPP_TAG_RANGE
:
4597 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4598 attr
->num_values
, NULL
, NULL
);
4600 for (i
= 0; i
< attr
->num_values
; i
++)
4602 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4603 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4607 case IPP_TAG_TEXTLANG
:
4608 case IPP_TAG_NAMELANG
:
4609 toattr
= ippAddStrings(to
, attr
->group_tag
,
4610 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4611 attr
->name
, attr
->num_values
, NULL
, NULL
);
4615 for (i
= 0; i
< attr
->num_values
; i
++)
4617 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4618 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4621 else if (attr
->value_tag
& IPP_TAG_COPY
)
4623 for (i
= 0; i
< attr
->num_values
; i
++)
4626 toattr
->values
[i
].string
.charset
=
4627 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4629 toattr
->values
[i
].string
.charset
=
4630 toattr
->values
[0].string
.charset
;
4632 toattr
->values
[i
].string
.text
=
4633 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4638 for (i
= 0; i
< attr
->num_values
; i
++)
4641 toattr
->values
[i
].string
.charset
=
4642 _cupsStrRetain(attr
->values
[i
].string
.charset
);
4644 toattr
->values
[i
].string
.charset
=
4645 toattr
->values
[0].string
.charset
;
4647 toattr
->values
[i
].string
.text
=
4648 _cupsStrRetain(attr
->values
[i
].string
.text
);
4653 case IPP_TAG_BEGIN_COLLECTION
:
4654 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4655 attr
->num_values
, NULL
);
4657 for (i
= 0; i
< attr
->num_values
; i
++)
4659 toattr
->values
[i
].collection
= ippNew();
4660 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
4661 NULL
, IPP_TAG_ZERO
, 0);
4666 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4667 attr
->name
, attr
->num_values
, NULL
);
4669 for (i
= 0; i
< attr
->num_values
; i
++)
4671 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4673 if (toattr
->values
[i
].unknown
.length
> 0)
4675 if ((toattr
->values
[i
].unknown
.data
=
4676 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4677 toattr
->values
[i
].unknown
.length
= 0;
4679 memcpy(toattr
->values
[i
].unknown
.data
,
4680 attr
->values
[i
].unknown
.data
,
4681 toattr
->values
[i
].unknown
.length
);
4684 break; /* anti-compiler-warning-code */
4692 * 'copy_attrs()' - Copy attributes from one request to another.
4696 copy_attrs(ipp_t
*to
, /* I - Destination request */
4697 ipp_t
*from
, /* I - Source request */
4698 cups_array_t
*ra
, /* I - Requested attributes */
4699 ipp_tag_t group
, /* I - Group to copy */
4700 int quickcopy
) /* I - Do a quick copy? */
4702 ipp_attribute_t
*fromattr
; /* Source attribute */
4705 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4706 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4707 to
, from
, ra
, group
, quickcopy
);
4712 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4715 * Filter attributes as needed...
4718 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4719 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4722 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4725 * Don't send collection attributes by default to IPP/1.x clients
4726 * since many do not support collections...
4729 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4730 !ra
&& to
->request
.status
.version
[0] == 1)
4733 copy_attribute(to
, fromattr
, quickcopy
);
4740 * 'copy_banner()' - Copy a banner file to the requests directory for the
4744 static int /* O - Size of banner file in kbytes */
4745 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4746 cupsd_job_t
*job
, /* I - Job information */
4747 const char *name
) /* I - Name of banner */
4749 int i
; /* Looping var */
4750 int kbytes
; /* Size of banner file in kbytes */
4751 char filename
[1024]; /* Job filename */
4752 cupsd_banner_t
*banner
; /* Pointer to banner */
4753 cups_file_t
*in
; /* Input file */
4754 cups_file_t
*out
; /* Output file */
4755 int ch
; /* Character from file */
4756 char attrname
[255], /* Name of attribute */
4757 *s
; /* Pointer into name */
4758 ipp_attribute_t
*attr
; /* Attribute */
4761 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4762 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4763 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4764 name
? name
: "(null)");
4767 * Find the banner; return if not found or "none"...
4770 if (!name
|| !strcmp(name
, "none") ||
4771 (banner
= cupsdFindBanner(name
)) == NULL
)
4775 * Open the banner and job files...
4778 if (add_file(con
, job
, banner
->filetype
, 0))
4781 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4783 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4785 cupsdLogMessage(CUPSD_LOG_ERROR
,
4786 "Unable to create banner job file %s - %s",
4787 filename
, strerror(errno
));
4792 fchmod(cupsFileNumber(out
), 0640);
4793 fchown(cupsFileNumber(out
), RunUser
, Group
);
4796 * Try the localized banner file under the subdirectory...
4799 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4801 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4804 * Convert ll-cc to ll_CC...
4808 attrname
[3] = toupper(attrname
[3] & 255);
4809 attrname
[4] = toupper(attrname
[4] & 255);
4812 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4815 if (access(filename
, 0) && strlen(attrname
) > 2)
4818 * Wasn't able to find "ll_CC" locale file; try the non-national
4819 * localization banner directory.
4824 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4828 if (access(filename
, 0))
4831 * Use the non-localized banner file.
4834 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4837 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4841 cupsdLogMessage(CUPSD_LOG_ERROR
,
4842 "Unable to open banner template file %s - %s",
4843 filename
, strerror(errno
));
4849 * Parse the file to the end...
4852 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4856 * Get an attribute name...
4859 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4860 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4862 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4872 * Ignore { followed by stuff that is not an attribute name...
4875 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4880 * See if it is defined...
4883 if (attrname
[0] == '?')
4888 if (!strcmp(s
, "printer-name"))
4890 cupsFilePuts(out
, job
->dest
);
4893 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4896 * See if we have a leading question mark...
4899 if (attrname
[0] != '?')
4902 * Nope, write to file as-is; probably a PostScript procedure...
4905 cupsFilePrintf(out
, "{%s}", attrname
);
4912 * Output value(s)...
4915 for (i
= 0; i
< attr
->num_values
; i
++)
4918 cupsFilePutChar(out
, ',');
4920 switch (attr
->value_tag
)
4922 case IPP_TAG_INTEGER
:
4924 if (!strncmp(s
, "time-at-", 8))
4926 struct timeval tv
= { attr
->values
[i
].integer
, 0 };
4927 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4930 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4933 case IPP_TAG_BOOLEAN
:
4934 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4937 case IPP_TAG_NOVALUE
:
4938 cupsFilePuts(out
, "novalue");
4941 case IPP_TAG_RANGE
:
4942 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4943 attr
->values
[i
].range
.upper
);
4946 case IPP_TAG_RESOLUTION
:
4947 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4948 attr
->values
[i
].resolution
.yres
,
4949 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4954 case IPP_TAG_STRING
:
4957 case IPP_TAG_KEYWORD
:
4958 case IPP_TAG_CHARSET
:
4959 case IPP_TAG_LANGUAGE
:
4960 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
4963 * Need to quote strings for PS banners...
4968 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4970 if (*p
== '(' || *p
== ')' || *p
== '\\')
4972 cupsFilePutChar(out
, '\\');
4973 cupsFilePutChar(out
, *p
);
4975 else if (*p
< 32 || *p
> 126)
4976 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4978 cupsFilePutChar(out
, *p
);
4982 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4986 break; /* anti-compiler-warning-code */
4990 else if (ch
== '\\') /* Quoted char */
4992 ch
= cupsFileGetChar(in
);
4994 if (ch
!= '{') /* Only do special handling for \{ */
4995 cupsFilePutChar(out
, '\\');
4997 cupsFilePutChar(out
, ch
);
5000 cupsFilePutChar(out
, ch
);
5004 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5006 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5007 IPP_TAG_INTEGER
)) != NULL
)
5008 attr
->values
[0].integer
+= kbytes
;
5017 * 'copy_file()' - Copy a PPD file or interface script...
5020 static int /* O - 0 = success, -1 = error */
5021 copy_file(const char *from
, /* I - Source file */
5022 const char *to
) /* I - Destination file */
5024 cups_file_t
*src
, /* Source file */
5025 *dst
; /* Destination file */
5026 int bytes
; /* Bytes to read/write */
5027 char buffer
[2048]; /* Copy buffer */
5030 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5033 * Open the source and destination file for a copy...
5036 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5039 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5046 * Copy the source file to the destination...
5049 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5050 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5058 * Close both files and return...
5063 return (cupsFileClose(dst
));
5068 * 'copy_model()' - Copy a PPD model file, substituting default values
5072 static int /* O - 0 = success, -1 = error */
5073 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5074 const char *from
, /* I - Source file */
5075 const char *to
) /* I - Destination file */
5077 fd_set input
; /* select() input set */
5078 struct timeval timeout
; /* select() timeout */
5079 int maxfd
; /* Max file descriptor for select() */
5080 char tempfile
[1024]; /* Temporary PPD file */
5081 int tempfd
; /* Temporary PPD file descriptor */
5082 int temppid
; /* Process ID of cups-driverd */
5083 int temppipe
[2]; /* Temporary pipes */
5084 char *argv
[4], /* Command-line arguments */
5085 *envp
[MAX_ENV
]; /* Environment */
5086 cups_file_t
*src
, /* Source file */
5087 *dst
; /* Destination file */
5088 ppd_file_t
*ppd
; /* PPD file */
5089 int bytes
, /* Bytes from pipe */
5090 total
; /* Total bytes from pipe */
5091 char buffer
[2048]; /* Copy buffer */
5092 int i
; /* Looping var */
5093 char option
[PPD_MAX_NAME
], /* Option name */
5094 choice
[PPD_MAX_NAME
]; /* Choice name */
5095 int num_defaults
; /* Number of default options */
5096 cups_option_t
*defaults
; /* Default options */
5097 char cups_protocol
[PPD_MAX_LINE
];
5098 /* cupsProtocol attribute */
5101 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5102 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5106 * Run cups-driverd to get the PPD file...
5109 argv
[0] = "cups-driverd";
5111 argv
[2] = (char *)from
;
5114 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5116 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5117 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5118 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5122 cupsdOpenPipe(temppipe
);
5124 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5125 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5127 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5128 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5139 * Wait up to 30 seconds for the PPD file to be copied...
5144 if (temppipe
[0] > CGIPipes
[0])
5145 maxfd
= temppipe
[0] + 1;
5147 maxfd
= CGIPipes
[0] + 1;
5152 * See if we have data ready...
5156 FD_SET(temppipe
[0], &input
);
5157 FD_SET(CGIPipes
[0], &input
);
5159 timeout
.tv_sec
= 30;
5160 timeout
.tv_usec
= 0;
5162 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5172 * We have timed out...
5178 if (FD_ISSET(temppipe
[0], &input
))
5181 * Read the PPD file from the pipe, and write it to the PPD file.
5184 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5186 if (write(tempfd
, buffer
, bytes
) < bytes
)
5195 if (FD_ISSET(CGIPipes
[0], &input
))
5205 * No data from cups-deviced...
5208 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5214 * Read the source file and see what page sizes are supported...
5217 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5224 * Open the destination (if possible) and set the default options...
5229 cups_protocol
[0] = '\0';
5231 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5234 * Read all of the default lines from the old PPD...
5237 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5238 if (!strncmp(buffer
, "*Default", 8))
5241 * Add the default option...
5244 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5245 choice
, sizeof(choice
)))
5247 ppd_option_t
*ppdo
; /* PPD option */
5251 * Only add the default if the default hasn't already been
5252 * set and the choice exists in the new PPD...
5255 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5256 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5257 ppdFindChoice(ppdo
, choice
))
5258 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5262 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5263 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5267 else if (ppdPageSize(ppd
, DefaultPaperSize
))
5270 * Add the default media sizes...
5273 num_defaults
= cupsAddOption("PageSize", DefaultPaperSize
,
5274 num_defaults
, &defaults
);
5275 num_defaults
= cupsAddOption("PageRegion", DefaultPaperSize
,
5276 num_defaults
, &defaults
);
5277 num_defaults
= cupsAddOption("PaperDimension", DefaultPaperSize
,
5278 num_defaults
, &defaults
);
5279 num_defaults
= cupsAddOption("ImageableArea", DefaultPaperSize
,
5280 num_defaults
, &defaults
);
5286 * Open the source file for a copy...
5289 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5291 cupsFreeOptions(num_defaults
, defaults
);
5297 * Open the destination file for a copy...
5300 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5302 cupsFreeOptions(num_defaults
, defaults
);
5309 * Copy the source file to the destination...
5312 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5314 if (!strncmp(buffer
, "*Default", 8))
5317 * Check for an previous default option choice...
5320 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5321 choice
, sizeof(choice
)))
5323 const char *val
; /* Default option value */
5326 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5329 * Substitute the previous choice...
5332 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5337 cupsFilePrintf(dst
, "%s\n", buffer
);
5340 if (cups_protocol
[0])
5341 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5343 cupsFreeOptions(num_defaults
, defaults
);
5346 * Close both files and return...
5353 return (cupsFileClose(dst
));
5358 * 'copy_job_attrs()' - Copy job attributes.
5362 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5363 cupsd_job_t
*job
, /* I - Job */
5364 cups_array_t
*ra
) /* I - Requested attributes array */
5366 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5370 * Send the requested attributes for each job...
5373 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5374 con
->servername
, con
->serverport
, "/jobs/%d",
5377 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5378 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5379 "document-count", job
->num_files
);
5381 if (!ra
|| cupsArrayFind(ra
, "job-media-progress"))
5382 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5383 "job-media-progress", job
->progress
);
5385 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5386 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5387 "job-more-info", NULL
, job_uri
);
5389 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5390 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5391 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5392 job
->num_files
> 0);
5394 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5395 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5396 "job-printer-up-time", time(NULL
));
5398 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5399 add_job_state_reasons(con
, job
);
5401 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5402 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5403 "job-uri", NULL
, job_uri
);
5405 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5410 * 'copy_printer_attrs()' - Copy printer attributes.
5415 cupsd_client_t
*con
, /* I - Client connection */
5416 cupsd_printer_t
*printer
, /* I - Printer */
5417 cups_array_t
*ra
) /* I - Requested attributes array */
5419 char printer_uri
[HTTP_MAX_URI
];
5421 time_t curtime
; /* Current time */
5422 int i
; /* Looping var */
5423 ipp_attribute_t
*history
; /* History collection */
5427 * Copy the printer attributes to the response using requested-attributes
5428 * and document-format attributes that may be provided by the client.
5431 curtime
= time(NULL
);
5434 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
5435 printer
->recoverable
)
5436 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5437 "com.apple.print.recoverable-message", NULL
,
5438 printer
->recoverable
);
5439 #endif /* __APPLE__ */
5441 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5442 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5443 "marker-change-time", printer
->marker_time
);
5445 if (printer
->num_printers
> 0 &&
5446 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5448 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5449 cupsd_printer_t
*p2
; /* Printer in class */
5450 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5453 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5454 IPP_TAG_URI
, "member-uris",
5455 printer
->num_printers
, NULL
,
5458 for (i
= 0; i
< printer
->num_printers
; i
++)
5460 p2
= printer
->printers
[i
];
5462 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5463 IPP_TAG_URI
)) != NULL
)
5464 member_uris
->values
[i
].string
.text
=
5465 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5468 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5469 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5471 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5472 "/classes/%s" : "/printers/%s", p2
->name
);
5473 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5479 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5480 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5481 "printer-alert", NULL
, printer
->alert
);
5483 if (printer
->alert_description
&&
5484 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5485 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5486 "printer-alert-description", NULL
,
5487 printer
->alert_description
);
5489 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5490 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5491 ippTimeToDate(curtime
));
5494 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5496 if (printer
->reg_name
)
5497 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5498 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5500 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5501 "printer-dns-sd-name", 0);
5503 #endif /* HAVE_DNSSD */
5505 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5506 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5507 "printer-error-policy", NULL
, printer
->error_policy
);
5509 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
5511 static const char * const errors
[] =/* printer-error-policy-supported values */
5514 "retry-current-job",
5519 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
5520 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5521 "printer-error-policy-supported", NULL
, "retry-current-job");
5523 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5524 "printer-error-policy-supported",
5525 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
5528 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5529 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5530 printer
->accepting
);
5532 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5533 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5536 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5537 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5539 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5540 "http", NULL
, con
->servername
, con
->serverport
,
5541 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5542 "/classes/%s" : "/printers/%s", printer
->name
);
5543 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5544 "printer-more-info", NULL
, printer_uri
);
5547 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5548 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5549 "printer-op-policy", NULL
, printer
->op_policy
);
5551 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5552 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5555 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5556 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5557 "printer-state-change-time", printer
->state_time
);
5559 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5560 cupsArrayFind(ra
, "printer-state-history"))
5563 * Printer history is only sent if specifically requested, so that
5564 * older CUPS/IPP clients won't barf on the collection attributes.
5567 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5568 "printer-state-history",
5569 printer
->num_history
, NULL
);
5571 for (i
= 0; i
< printer
->num_history
; i
++)
5572 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5573 NULL
, IPP_TAG_ZERO
, 0);
5576 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5577 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5578 "printer-state-message", NULL
, printer
->state_message
);
5580 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5581 add_printer_state_reasons(con
, printer
);
5583 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5585 int type
; /* printer-type value */
5589 * Add the CUPS-specific printer-type attribute...
5592 type
= printer
->type
;
5594 if (printer
== DefaultPrinter
)
5595 type
|= CUPS_PRINTER_DEFAULT
;
5597 if (!printer
->accepting
)
5598 type
|= CUPS_PRINTER_REJECTING
;
5600 if (!printer
->shared
)
5601 type
|= CUPS_PRINTER_NOT_SHARED
;
5603 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5607 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5608 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5609 "printer-up-time", curtime
);
5611 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5612 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5614 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5615 "ipp", NULL
, con
->servername
, con
->serverport
,
5616 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5617 "/classes/%s" : "/printers/%s", printer
->name
);
5618 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5619 "printer-uri-supported", NULL
, printer_uri
);
5620 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5624 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5625 add_queued_job_count(con
, printer
);
5627 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5628 if (printer
->ppd_attrs
)
5629 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0);
5630 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5635 * 'copy_subscription_attrs()' - Copy subscription attributes.
5639 copy_subscription_attrs(
5640 cupsd_client_t
*con
, /* I - Client connection */
5641 cupsd_subscription_t
*sub
, /* I - Subscription */
5642 cups_array_t
*ra
) /* I - Requested attributes array */
5644 ipp_attribute_t
*attr
; /* Current attribute */
5645 char printer_uri
[HTTP_MAX_URI
];
5647 int count
; /* Number of events */
5648 unsigned mask
; /* Current event mask */
5649 const char *name
; /* Current event name */
5653 * Copy the subscription attributes to the response using the
5654 * requested-attributes attribute that may be provided by the client.
5657 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5659 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5662 * Simple event list...
5665 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5666 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5667 "notify-events", NULL
, name
);
5672 * Complex event list...
5675 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5676 if (sub
->mask
& mask
)
5679 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5680 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5681 "notify-events", count
, NULL
, NULL
);
5683 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5684 if (sub
->mask
& mask
)
5686 attr
->values
[count
].string
.text
=
5687 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5694 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5695 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5696 "notify-job-id", sub
->job
->id
);
5698 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5699 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5700 "notify-lease-duration", sub
->lease
);
5702 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5704 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5705 "ipp", NULL
, con
->servername
, con
->serverport
,
5706 "/printers/%s", sub
->dest
->name
);
5707 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5708 "notify-printer-uri", NULL
, printer_uri
);
5711 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5712 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5713 "notify-recipient-uri", NULL
, sub
->recipient
);
5714 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5715 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5716 "notify-pull-method", NULL
, "ippget");
5718 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5719 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5720 "notify-subscriber-user-name", NULL
, sub
->owner
);
5722 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5723 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5724 "notify-subscription-id", sub
->id
);
5726 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5727 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5728 "notify-time-interval", sub
->interval
);
5730 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5731 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5732 sub
->user_data
, sub
->user_data_len
);
5737 * 'create_job()' - Print a file to a printer or class.
5741 create_job(cupsd_client_t
*con
, /* I - Client connection */
5742 ipp_attribute_t
*uri
) /* I - Printer URI */
5744 cupsd_printer_t
*printer
; /* Printer */
5745 cupsd_job_t
*job
; /* New job */
5748 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5749 con
->http
.fd
, uri
->values
[0].string
.text
);
5752 * Is the destination valid?
5755 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5761 send_ipp_status(con
, IPP_NOT_FOUND
,
5762 _("The printer or class was not found."));
5767 * Create the job object...
5770 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5773 job
->pending_timeout
= 1;
5776 * Save and log the job...
5779 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5780 job
->dest
, job
->username
);
5785 * 'create_requested_array()' - Create an array for the requested-attributes.
5788 static cups_array_t
* /* O - Array of attributes or NULL */
5789 create_requested_array(ipp_t
*request
) /* I - IPP request */
5791 int i
; /* Looping var */
5792 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5793 cups_array_t
*ra
; /* Requested attributes array */
5794 char *value
; /* Current value */
5798 * Get the requested-attributes attribute, and return NULL if we don't
5802 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5803 IPP_TAG_KEYWORD
)) == NULL
)
5807 * If the attribute contains a single "all" keyword, return NULL...
5810 if (requested
->num_values
== 1 &&
5811 !strcmp(requested
->values
[0].string
.text
, "all"))
5815 * Create an array using "strcmp" as the comparison function...
5818 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5820 for (i
= 0; i
< requested
->num_values
; i
++)
5822 value
= requested
->values
[i
].string
.text
;
5824 if (!strcmp(value
, "job-template"))
5826 cupsArrayAdd(ra
, "copies");
5827 cupsArrayAdd(ra
, "copies-default");
5828 cupsArrayAdd(ra
, "copies-supported");
5829 cupsArrayAdd(ra
, "finishings");
5830 cupsArrayAdd(ra
, "finishings-default");
5831 cupsArrayAdd(ra
, "finishings-supported");
5832 cupsArrayAdd(ra
, "job-hold-until");
5833 cupsArrayAdd(ra
, "job-hold-until-default");
5834 cupsArrayAdd(ra
, "job-hold-until-supported");
5835 cupsArrayAdd(ra
, "job-priority");
5836 cupsArrayAdd(ra
, "job-priority-default");
5837 cupsArrayAdd(ra
, "job-priority-supported");
5838 cupsArrayAdd(ra
, "job-sheets");
5839 cupsArrayAdd(ra
, "job-sheets-default");
5840 cupsArrayAdd(ra
, "job-sheets-supported");
5841 cupsArrayAdd(ra
, "media");
5842 cupsArrayAdd(ra
, "media-default");
5843 cupsArrayAdd(ra
, "media-supported");
5844 cupsArrayAdd(ra
, "multiple-document-handling");
5845 cupsArrayAdd(ra
, "multiple-document-handling-default");
5846 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5847 cupsArrayAdd(ra
, "number-up");
5848 cupsArrayAdd(ra
, "number-up-default");
5849 cupsArrayAdd(ra
, "number-up-supported");
5850 cupsArrayAdd(ra
, "orientation-requested");
5851 cupsArrayAdd(ra
, "orientation-requested-default");
5852 cupsArrayAdd(ra
, "orientation-requested-supported");
5853 cupsArrayAdd(ra
, "page-ranges");
5854 cupsArrayAdd(ra
, "page-ranges-supported");
5855 cupsArrayAdd(ra
, "printer-resolution");
5856 cupsArrayAdd(ra
, "printer-resolution-default");
5857 cupsArrayAdd(ra
, "printer-resolution-supported");
5858 cupsArrayAdd(ra
, "print-quality");
5859 cupsArrayAdd(ra
, "print-quality-default");
5860 cupsArrayAdd(ra
, "print-quality-supported");
5861 cupsArrayAdd(ra
, "sides");
5862 cupsArrayAdd(ra
, "sides-default");
5863 cupsArrayAdd(ra
, "sides-supported");
5865 else if (!strcmp(value
, "job-description"))
5867 cupsArrayAdd(ra
, "date-time-at-completed");
5868 cupsArrayAdd(ra
, "date-time-at-creation");
5869 cupsArrayAdd(ra
, "date-time-at-processing");
5870 cupsArrayAdd(ra
, "job-detailed-status-message");
5871 cupsArrayAdd(ra
, "job-document-access-errors");
5872 cupsArrayAdd(ra
, "job-id");
5873 cupsArrayAdd(ra
, "job-impressions");
5874 cupsArrayAdd(ra
, "job-impressions-completed");
5875 cupsArrayAdd(ra
, "job-k-octets");
5876 cupsArrayAdd(ra
, "job-k-octets-processed");
5877 cupsArrayAdd(ra
, "job-media-progress");
5878 cupsArrayAdd(ra
, "job-media-sheets");
5879 cupsArrayAdd(ra
, "job-media-sheets-completed");
5880 cupsArrayAdd(ra
, "job-message-from-operator");
5881 cupsArrayAdd(ra
, "job-more-info");
5882 cupsArrayAdd(ra
, "job-name");
5883 cupsArrayAdd(ra
, "job-originating-user-name");
5884 cupsArrayAdd(ra
, "job-printer-up-time");
5885 cupsArrayAdd(ra
, "job-printer-uri");
5886 cupsArrayAdd(ra
, "job-state");
5887 cupsArrayAdd(ra
, "job-state-message");
5888 cupsArrayAdd(ra
, "job-state-reasons");
5889 cupsArrayAdd(ra
, "job-uri");
5890 cupsArrayAdd(ra
, "number-of-documents");
5891 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5892 cupsArrayAdd(ra
, "output-device-assigned");
5893 cupsArrayAdd(ra
, "time-at-completed");
5894 cupsArrayAdd(ra
, "time-at-creation");
5895 cupsArrayAdd(ra
, "time-at-processing");
5897 else if (!strcmp(value
, "printer-description"))
5899 cupsArrayAdd(ra
, "charset-configured");
5900 cupsArrayAdd(ra
, "charset-supported");
5901 cupsArrayAdd(ra
, "color-supported");
5902 cupsArrayAdd(ra
, "compression-supported");
5903 cupsArrayAdd(ra
, "document-format-default");
5904 cupsArrayAdd(ra
, "document-format-supported");
5905 cupsArrayAdd(ra
, "generated-natural-language-supported");
5906 cupsArrayAdd(ra
, "ipp-versions-supported");
5907 cupsArrayAdd(ra
, "job-impressions-supported");
5908 cupsArrayAdd(ra
, "job-k-octets-supported");
5909 cupsArrayAdd(ra
, "job-media-sheets-supported");
5910 cupsArrayAdd(ra
, "job-settable-attributes-supported");
5911 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5912 cupsArrayAdd(ra
, "multiple-operation-time-out");
5913 cupsArrayAdd(ra
, "natural-language-configured");
5914 cupsArrayAdd(ra
, "notify-attributes-supported");
5915 cupsArrayAdd(ra
, "notify-lease-duration-default");
5916 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5917 cupsArrayAdd(ra
, "notify-max-events-supported");
5918 cupsArrayAdd(ra
, "notify-events-default");
5919 cupsArrayAdd(ra
, "notify-events-supported");
5920 cupsArrayAdd(ra
, "notify-pull-method-supported");
5921 cupsArrayAdd(ra
, "notify-schemes-supported");
5922 cupsArrayAdd(ra
, "operations-supported");
5923 cupsArrayAdd(ra
, "pages-per-minute");
5924 cupsArrayAdd(ra
, "pages-per-minute-color");
5925 cupsArrayAdd(ra
, "pdl-override-supported");
5926 cupsArrayAdd(ra
, "printer-alert");
5927 cupsArrayAdd(ra
, "printer-alert-description");
5928 cupsArrayAdd(ra
, "printer-commands");
5929 cupsArrayAdd(ra
, "printer-current-time");
5930 cupsArrayAdd(ra
, "printer-driver-installer");
5931 cupsArrayAdd(ra
, "printer-dns-sd-name");
5932 cupsArrayAdd(ra
, "printer-info");
5933 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5934 cupsArrayAdd(ra
, "printer-location");
5935 cupsArrayAdd(ra
, "printer-make-and-model");
5936 cupsArrayAdd(ra
, "printer-message-from-operator");
5937 cupsArrayAdd(ra
, "printer-more-info");
5938 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5939 cupsArrayAdd(ra
, "printer-name");
5940 cupsArrayAdd(ra
, "printer-state");
5941 cupsArrayAdd(ra
, "printer-state-message");
5942 cupsArrayAdd(ra
, "printer-state-reasons");
5943 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
5944 cupsArrayAdd(ra
, "printer-type");
5945 cupsArrayAdd(ra
, "printer-up-time");
5946 cupsArrayAdd(ra
, "printer-uri-supported");
5947 cupsArrayAdd(ra
, "queued-job-count");
5948 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5949 cupsArrayAdd(ra
, "uri-authentication-supported");
5950 cupsArrayAdd(ra
, "uri-security-supported");
5952 else if (!strcmp(value
, "printer-defaults"))
5954 char *name
; /* Option name */
5957 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5959 name
= (char *)cupsArrayNext(CommonDefaults
))
5960 cupsArrayAdd(ra
, name
);
5962 else if (!strcmp(value
, "subscription-template"))
5964 cupsArrayAdd(ra
, "notify-attributes");
5965 cupsArrayAdd(ra
, "notify-charset");
5966 cupsArrayAdd(ra
, "notify-events");
5967 cupsArrayAdd(ra
, "notify-lease-duration");
5968 cupsArrayAdd(ra
, "notify-natural-language");
5969 cupsArrayAdd(ra
, "notify-pull-method");
5970 cupsArrayAdd(ra
, "notify-recipient-uri");
5971 cupsArrayAdd(ra
, "notify-time-interval");
5972 cupsArrayAdd(ra
, "notify-user-data");
5975 cupsArrayAdd(ra
, value
);
5983 * 'create_subscription()' - Create a notification subscription.
5987 create_subscription(
5988 cupsd_client_t
*con
, /* I - Client connection */
5989 ipp_attribute_t
*uri
) /* I - Printer URI */
5991 http_status_t status
; /* Policy status */
5992 int i
; /* Looping var */
5993 ipp_attribute_t
*attr
; /* Current attribute */
5994 cups_ptype_t dtype
; /* Destination type (printer/class) */
5995 char scheme
[HTTP_MAX_URI
],
5996 /* Scheme portion of URI */
5997 userpass
[HTTP_MAX_URI
],
5998 /* Username portion of URI */
6000 /* Host portion of URI */
6001 resource
[HTTP_MAX_URI
];
6002 /* Resource portion of URI */
6003 int port
; /* Port portion of URI */
6004 cupsd_printer_t
*printer
; /* Printer/class */
6005 cupsd_job_t
*job
; /* Job */
6006 int jobid
; /* Job ID */
6007 cupsd_subscription_t
*sub
; /* Subscription object */
6008 const char *username
, /* requesting-user-name or
6009 authenticated username */
6010 *recipient
, /* notify-recipient-uri */
6011 *pullmethod
; /* notify-pull-method */
6012 ipp_attribute_t
*user_data
; /* notify-user-data */
6013 int interval
, /* notify-time-interval */
6014 lease
; /* notify-lease-duration */
6015 unsigned mask
; /* notify-events */
6016 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6017 *notify_lease
; /* notify-lease-duration(-default) */
6021 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6023 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6024 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6025 attr
->value_tag
, attr
->name
);
6027 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6032 * Is the destination valid?
6035 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6036 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6037 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6039 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6040 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6041 sizeof(host
), &port
, resource
, sizeof(resource
));
6043 if (!strcmp(resource
, "/"))
6045 dtype
= (cups_ptype_t
)0;
6048 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6050 dtype
= (cups_ptype_t
)0;
6053 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6055 dtype
= CUPS_PRINTER_CLASS
;
6058 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6064 send_ipp_status(con
, IPP_NOT_FOUND
,
6065 _("The printer or class was not found."));
6075 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6078 send_http_error(con
, status
, printer
);
6082 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6084 send_http_error(con
, status
, NULL
);
6089 * Get the user that is requesting the subscription...
6092 username
= get_username(con
);
6095 * Find the first subscription group attribute; return if we have
6099 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6100 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6105 send_ipp_status(con
, IPP_BAD_REQUEST
,
6106 _("No subscription attributes in request"));
6111 * Process the subscription attributes in the request...
6114 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6122 lease
= DefaultLeaseDuration
;
6124 mask
= CUPSD_EVENT_NONE
;
6128 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6130 notify_lease
= ippFindAttribute(printer
->attrs
,
6131 "notify-lease-duration-default",
6135 lease
= notify_lease
->values
[0].integer
;
6139 notify_events
= NULL
;
6140 notify_lease
= NULL
;
6143 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6145 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6146 attr
->value_tag
== IPP_TAG_URI
)
6149 * Validate the recipient scheme against the ServerBin/notifier
6153 char notifier
[1024]; /* Notifier filename */
6156 recipient
= attr
->values
[0].string
.text
;
6158 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6159 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6160 host
, sizeof(host
), &port
,
6161 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6163 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6164 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
6165 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6166 "notify-status-code", IPP_URI_SCHEME
);
6170 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6172 if (access(notifier
, X_OK
))
6174 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6175 _("notify-recipient-uri URI \"%s\" uses unknown "
6176 "scheme"), recipient
);
6177 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6178 "notify-status-code", IPP_URI_SCHEME
);
6182 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6184 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6185 _("notify-recipient-uri URI \"%s\" is already used"),
6187 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6188 "notify-status-code", IPP_ATTRIBUTES
);
6192 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6193 attr
->value_tag
== IPP_TAG_KEYWORD
)
6195 pullmethod
= attr
->values
[0].string
.text
;
6197 if (strcmp(pullmethod
, "ippget"))
6199 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6200 _("Bad notify-pull-method \"%s\""), pullmethod
);
6201 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6202 "notify-status-code", IPP_ATTRIBUTES
);
6206 else if (!strcmp(attr
->name
, "notify-charset") &&
6207 attr
->value_tag
== IPP_TAG_CHARSET
&&
6208 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6209 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6211 send_ipp_status(con
, IPP_CHARSET
,
6212 _("Character set \"%s\" not supported"),
6213 attr
->values
[0].string
.text
);
6216 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6217 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6218 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6220 send_ipp_status(con
, IPP_CHARSET
,
6221 _("Language \"%s\" not supported"),
6222 attr
->values
[0].string
.text
);
6225 else if (!strcmp(attr
->name
, "notify-user-data") &&
6226 attr
->value_tag
== IPP_TAG_STRING
)
6228 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6230 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6231 _("The notify-user-data value is too large "
6232 "(%d > 63 octets)"),
6233 attr
->values
[0].unknown
.length
);
6239 else if (!strcmp(attr
->name
, "notify-events") &&
6240 attr
->value_tag
== IPP_TAG_KEYWORD
)
6241 notify_events
= attr
;
6242 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6243 attr
->value_tag
== IPP_TAG_INTEGER
)
6244 lease
= attr
->values
[0].integer
;
6245 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6246 attr
->value_tag
== IPP_TAG_INTEGER
)
6247 interval
= attr
->values
[0].integer
;
6248 else if (!strcmp(attr
->name
, "notify-job-id") &&
6249 attr
->value_tag
== IPP_TAG_INTEGER
)
6250 jobid
= attr
->values
[0].integer
;
6257 for (i
= 0; i
< notify_events
->num_values
; i
++)
6258 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6262 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6264 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6265 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6266 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6268 if (!recipient
&& !pullmethod
)
6271 if (mask
== CUPSD_EVENT_NONE
)
6274 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6276 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6279 send_ipp_status(con
, IPP_BAD_REQUEST
,
6280 _("notify-events not specified"));
6285 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6287 cupsdLogMessage(CUPSD_LOG_INFO
,
6288 "create_subscription: Limiting notify-lease-duration to "
6291 lease
= MaxLeaseDuration
;
6296 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6298 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found"), jobid
);
6305 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6307 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6308 _("There are too many subscriptions."));
6313 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6316 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6317 "Added subscription %d for printer \"%s\"",
6318 sub
->id
, printer
->name
);
6320 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6323 sub
->interval
= interval
;
6325 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6327 cupsdSetString(&sub
->owner
, username
);
6331 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6332 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6333 sub
->user_data_len
);
6336 ippAddSeparator(con
->response
);
6337 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6338 "notify-subscription-id", sub
->id
);
6340 con
->response
->request
.status
.status_code
= IPP_OK
;
6346 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6351 * 'delete_printer()' - Remove a printer or class from the system.
6355 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6356 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6358 http_status_t status
; /* Policy status */
6359 cups_ptype_t dtype
; /* Destination type (printer/class) */
6360 cupsd_printer_t
*printer
; /* Printer/class */
6361 char filename
[1024]; /* Script/PPD filename */
6364 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6365 con
->http
.fd
, uri
->values
[0].string
.text
);
6368 * Do we have a valid URI?
6371 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6377 send_ipp_status(con
, IPP_NOT_FOUND
,
6378 _("The printer or class was not found."));
6386 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6388 send_http_error(con
, status
, NULL
);
6393 * Remove old jobs...
6396 cupsdCancelJobs(printer
->name
, NULL
, 1);
6399 * Remove old subscriptions and send a "deleted printer" event...
6402 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6403 "%s \"%s\" deleted by \"%s\".",
6404 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6405 printer
->name
, get_username(con
));
6407 cupsdExpireSubscriptions(printer
, NULL
);
6410 * Remove any old PPD or script files...
6413 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6417 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6421 snprintf(filename
, sizeof(filename
), "%s/%s.ipp", CacheDir
, printer
->name
);
6426 * Unregister color profiles...
6429 apple_unregister_profiles(printer
);
6430 #endif /* __APPLE__ */
6432 if (dtype
& CUPS_PRINTER_CLASS
)
6434 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6435 printer
->name
, get_username(con
));
6437 cupsdDeletePrinter(printer
, 0);
6438 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6442 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6443 printer
->name
, get_username(con
));
6445 cupsdDeletePrinter(printer
, 0);
6446 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6449 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6452 * Return with no errors...
6455 con
->response
->request
.status
.status_code
= IPP_OK
;
6460 * 'get_default()' - Get the default destination.
6464 get_default(cupsd_client_t
*con
) /* I - Client connection */
6466 http_status_t status
; /* Policy status */
6467 cups_array_t
*ra
; /* Requested attributes array */
6470 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6476 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6478 send_http_error(con
, status
, NULL
);
6484 ra
= create_requested_array(con
->request
);
6486 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6488 cupsArrayDelete(ra
);
6490 con
->response
->request
.status
.status_code
= IPP_OK
;
6493 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6498 * 'get_devices()' - Get the list of available devices on the local system.
6502 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6504 http_status_t status
; /* Policy status */
6505 ipp_attribute_t
*limit
, /* limit attribute */
6506 *timeout
, /* timeout attribute */
6507 *requested
, /* requested-attributes attribute */
6508 *exclude
, /* exclude-schemes attribute */
6509 *include
; /* include-schemes attribute */
6510 char command
[1024], /* cups-deviced command */
6511 options
[2048], /* Options to pass to command */
6513 /* String for requested attributes */
6515 /* String for excluded schemes */
6517 /* String for included schemes */
6520 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6526 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6528 send_http_error(con
, status
, NULL
);
6533 * Run cups-deviced command with the given options...
6536 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6537 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6538 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6540 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6541 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6544 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6546 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6549 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6551 exclude_str
[0] = '\0';
6554 url_encode_attr(include
, include_str
, sizeof(include_str
));
6556 include_str
[0] = '\0';
6558 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6559 snprintf(options
, sizeof(options
),
6560 "%d+%d+%d+%d+%s%s%s%s%s",
6561 con
->request
->request
.op
.request_id
,
6562 limit
? limit
->values
[0].integer
: 0,
6563 timeout
? timeout
->values
[0].integer
: 15,
6566 exclude_str
[0] ? "%20" : "", exclude_str
,
6567 include_str
[0] ? "%20" : "", include_str
);
6569 if (cupsdSendCommand(con
, command
, options
, 1))
6572 * Command started successfully, don't send an IPP response here...
6575 ippDelete(con
->response
);
6576 con
->response
= NULL
;
6581 * Command failed, return "internal error" so the user knows something
6585 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6586 _("cups-deviced failed to execute."));
6592 * 'get_document()' - Get a copy of a job file.
6596 get_document(cupsd_client_t
*con
, /* I - Client connection */
6597 ipp_attribute_t
*uri
) /* I - Job URI */
6599 http_status_t status
; /* Policy status */
6600 ipp_attribute_t
*attr
; /* Current attribute */
6601 int jobid
; /* Job ID */
6602 int docnum
; /* Document number */
6603 cupsd_job_t
*job
; /* Current job */
6604 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6605 username
[HTTP_MAX_URI
], /* Username portion of URI */
6606 host
[HTTP_MAX_URI
], /* Host portion of URI */
6607 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6608 int port
; /* Port portion of URI */
6609 char filename
[1024], /* Filename for document */
6610 format
[1024]; /* Format for document */
6613 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6614 con
->http
.fd
, uri
->values
[0].string
.text
);
6617 * See if we have a job URI or a printer URI...
6620 if (!strcmp(uri
->name
, "printer-uri"))
6623 * Got a printer URI; see if we also have a job-id attribute...
6626 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6627 IPP_TAG_INTEGER
)) == NULL
)
6629 send_ipp_status(con
, IPP_BAD_REQUEST
,
6630 _("Got a printer-uri attribute but no job-id"));
6634 jobid
= attr
->values
[0].integer
;
6639 * Got a job URI; parse it to get the job ID...
6642 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6643 sizeof(scheme
), username
, sizeof(username
), host
,
6644 sizeof(host
), &port
, resource
, sizeof(resource
));
6646 if (strncmp(resource
, "/jobs/", 6))
6652 send_ipp_status(con
, IPP_BAD_REQUEST
,
6653 _("Bad job-uri attribute \"%s\""),
6654 uri
->values
[0].string
.text
);
6658 jobid
= atoi(resource
+ 6);
6662 * See if the job exists...
6665 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6668 * Nope - return a "not found" error...
6671 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
6679 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6681 send_http_error(con
, status
, NULL
);
6686 * Get the document number...
6689 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6690 IPP_TAG_INTEGER
)) == NULL
)
6692 send_ipp_status(con
, IPP_BAD_REQUEST
,
6693 _("Missing document-number attribute"));
6697 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6698 attr
->num_values
> 1)
6700 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6705 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6707 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6709 cupsdLogMessage(CUPSD_LOG_ERROR
,
6710 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6712 send_ipp_status(con
, IPP_NOT_FOUND
,
6713 _("Unable to open document %d in job %d"), docnum
, jobid
);
6717 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6721 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6722 job
->filetypes
[docnum
- 1]->type
);
6724 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6726 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6728 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6729 IPP_TAG_NAME
)) != NULL
)
6730 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6731 NULL
, attr
->values
[0].string
.text
);
6736 * 'get_job_attrs()' - Get job attributes.
6740 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6741 ipp_attribute_t
*uri
) /* I - Job URI */
6743 http_status_t status
; /* Policy status */
6744 ipp_attribute_t
*attr
; /* Current attribute */
6745 int jobid
; /* Job ID */
6746 cupsd_job_t
*job
; /* Current job */
6747 cupsd_printer_t
*printer
; /* Current printer */
6748 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6749 username
[HTTP_MAX_URI
], /* Username portion of URI */
6750 host
[HTTP_MAX_URI
], /* Host portion of URI */
6751 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6752 int port
; /* Port portion of URI */
6753 cups_array_t
*ra
; /* Requested attributes array */
6756 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6757 con
->http
.fd
, uri
->values
[0].string
.text
);
6760 * See if we have a job URI or a printer URI...
6763 if (!strcmp(uri
->name
, "printer-uri"))
6766 * Got a printer URI; see if we also have a job-id attribute...
6769 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6770 IPP_TAG_INTEGER
)) == NULL
)
6772 send_ipp_status(con
, IPP_BAD_REQUEST
,
6773 _("Got a printer-uri attribute but no job-id"));
6777 jobid
= attr
->values
[0].integer
;
6782 * Got a job URI; parse it to get the job ID...
6785 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6786 sizeof(scheme
), username
, sizeof(username
), host
,
6787 sizeof(host
), &port
, resource
, sizeof(resource
));
6789 if (strncmp(resource
, "/jobs/", 6))
6795 send_ipp_status(con
, IPP_BAD_REQUEST
,
6796 _("Bad job-uri attribute \"%s\""),
6797 uri
->values
[0].string
.text
);
6801 jobid
= atoi(resource
+ 6);
6805 * See if the job exists...
6808 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6811 * Nope - return a "not found" error...
6814 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
6822 if ((printer
= job
->printer
) == NULL
)
6823 printer
= cupsdFindDest(job
->dest
);
6827 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6830 send_http_error(con
, status
, printer
);
6834 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6836 send_http_error(con
, status
, NULL
);
6841 * Copy attributes...
6846 ra
= create_requested_array(con
->request
);
6847 copy_job_attrs(con
, job
, ra
);
6848 cupsArrayDelete(ra
);
6850 con
->response
->request
.status
.status_code
= IPP_OK
;
6855 * 'get_jobs()' - Get a list of jobs for the specified printer.
6859 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6860 ipp_attribute_t
*uri
) /* I - Printer URI */
6862 http_status_t status
; /* Policy status */
6863 ipp_attribute_t
*attr
; /* Current attribute */
6864 const char *dest
; /* Destination */
6865 cups_ptype_t dtype
; /* Destination type (printer/class) */
6866 cups_ptype_t dmask
; /* Destination type mask */
6867 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6868 username
[HTTP_MAX_URI
], /* Username portion of URI */
6869 host
[HTTP_MAX_URI
], /* Host portion of URI */
6870 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6871 int port
; /* Port portion of URI */
6872 int completed
; /* Completed jobs? */
6873 int first_job_id
; /* First job ID */
6874 int limit
; /* Maximum number of jobs to return */
6875 int count
; /* Number of jobs that match */
6876 cupsd_job_t
*job
; /* Current job pointer */
6877 cupsd_printer_t
*printer
; /* Printer */
6878 cups_array_t
*list
; /* Which job list... */
6879 cups_array_t
*ra
; /* Requested attributes array */
6882 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6883 uri
->values
[0].string
.text
);
6886 * Is the destination valid?
6889 if (strcmp(uri
->name
, "printer-uri"))
6891 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request"));
6895 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6896 sizeof(scheme
), username
, sizeof(username
), host
,
6897 sizeof(host
), &port
, resource
, sizeof(resource
));
6899 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6902 dtype
= (cups_ptype_t
)0;
6903 dmask
= (cups_ptype_t
)0;
6906 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6909 dtype
= (cups_ptype_t
)0;
6910 dmask
= CUPS_PRINTER_CLASS
;
6913 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6916 dtype
= CUPS_PRINTER_CLASS
;
6917 dmask
= CUPS_PRINTER_CLASS
;
6920 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6927 send_ipp_status(con
, IPP_NOT_FOUND
,
6928 _("The printer or class was not found."));
6933 dtype
&= CUPS_PRINTER_CLASS
;
6934 dmask
= CUPS_PRINTER_CLASS
;
6943 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6946 send_http_error(con
, status
, printer
);
6950 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6952 send_http_error(con
, status
, NULL
);
6957 * See if the "which-jobs" attribute have been specified...
6960 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6961 IPP_TAG_KEYWORD
)) != NULL
&&
6962 !strcmp(attr
->values
[0].string
.text
, "completed"))
6967 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
6972 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "processing"))
6975 list
= PrintingJobs
;
6984 * See if they want to limit the number of jobs reported...
6987 if ((attr
= ippFindAttribute(con
->request
, "limit",
6988 IPP_TAG_INTEGER
)) != NULL
)
6989 limit
= attr
->values
[0].integer
;
6993 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6994 IPP_TAG_INTEGER
)) != NULL
)
6995 first_job_id
= attr
->values
[0].integer
;
7000 * See if we only want to see jobs for a specific user...
7003 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7004 IPP_TAG_BOOLEAN
)) != NULL
&&
7005 attr
->values
[0].boolean
)
7006 strlcpy(username
, get_username(con
), sizeof(username
));
7010 ra
= create_requested_array(con
->request
);
7013 * OK, build a list of jobs for this printer...
7016 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7017 (limit
<= 0 || count
< limit
) && job
;
7018 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7021 * Filter out jobs that don't match...
7024 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7025 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7026 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7027 job
->username
, job
->state_value
, job
->attrs
);
7029 if (!job
->dest
|| !job
->username
)
7032 if (!job
->dest
|| !job
->username
)
7035 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7036 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7038 if ((job
->dtype
& dmask
) != dtype
&&
7039 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7041 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
7044 if (job
->id
< first_job_id
)
7051 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7056 if (username
[0] && strcasecmp(username
, job
->username
))
7060 ippAddSeparator(con
->response
);
7064 copy_job_attrs(con
, job
, ra
);
7067 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7069 cupsArrayDelete(ra
);
7071 con
->response
->request
.status
.status_code
= IPP_OK
;
7076 * 'get_notifications()' - Get events for a subscription.
7080 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7082 int i
, j
; /* Looping vars */
7083 http_status_t status
; /* Policy status */
7084 cupsd_subscription_t
*sub
; /* Subscription */
7085 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7086 *sequences
; /* notify-sequence-numbers */
7087 int min_seq
; /* Minimum sequence number */
7088 int interval
; /* Poll interval */
7091 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7095 * Get subscription attributes...
7098 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7100 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7105 send_ipp_status(con
, IPP_BAD_REQUEST
,
7106 _("Missing notify-subscription-ids attribute"));
7111 * Are the subscription IDs valid?
7114 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7116 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7119 * Bad subscription ID...
7122 send_ipp_status(con
, IPP_NOT_FOUND
,
7123 _("notify-subscription-id %d no good"),
7124 ids
->values
[i
].integer
);
7132 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7134 con
, sub
->owner
)) != HTTP_OK
)
7136 send_http_error(con
, status
, sub
->dest
);
7141 * Check the subscription type and update the interval accordingly.
7144 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7147 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7149 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7155 * Tell the client to poll again in N seconds...
7159 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7160 "notify-get-interval", interval
);
7162 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7163 "printer-up-time", time(NULL
));
7166 * Copy the subscription event attributes to the response.
7169 con
->response
->request
.status
.status_code
=
7170 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7172 for (i
= 0; i
< ids
->num_values
; i
++)
7175 * Get the subscription and sequence number...
7178 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7180 if (sequences
&& i
< sequences
->num_values
)
7181 min_seq
= sequences
->values
[i
].integer
;
7186 * If we don't have any new events, nothing to do here...
7189 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7193 * Otherwise copy all of the new events...
7196 if (sub
->first_event_id
> min_seq
)
7199 j
= min_seq
- sub
->first_event_id
;
7201 for (; j
< sub
->num_events
; j
++)
7203 ippAddSeparator(con
->response
);
7205 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7206 IPP_TAG_EVENT_NOTIFICATION
, 0);
7213 * 'get_ppd()' - Get a named PPD from the local system.
7217 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7218 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7220 http_status_t status
; /* Policy status */
7221 cupsd_printer_t
*dest
; /* Destination */
7222 cups_ptype_t dtype
; /* Destination type */
7225 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7226 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7228 if (!strcmp(uri
->name
, "ppd-name"))
7231 * Return a PPD file from cups-driverd...
7234 char command
[1024], /* cups-driverd command */
7235 options
[1024], /* Options to pass to command */
7236 ppd_name
[1024]; /* ppd-name */
7243 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7245 send_http_error(con
, status
, NULL
);
7250 * Run cups-driverd command with the given options...
7253 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7254 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7255 snprintf(options
, sizeof(options
), "get+%d+%s",
7256 con
->request
->request
.op
.request_id
, ppd_name
);
7258 if (cupsdSendCommand(con
, command
, options
, 0))
7261 * Command started successfully, don't send an IPP response here...
7264 ippDelete(con
->response
);
7265 con
->response
= NULL
;
7270 * Command failed, return "internal error" so the user knows something
7274 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7275 _("cups-driverd failed to execute."));
7278 else if (!strcmp(uri
->name
, "printer-uri") &&
7279 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7281 int i
; /* Looping var */
7282 char filename
[1024]; /* PPD filename */
7289 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7291 send_http_error(con
, status
, dest
);
7296 * See if we need the PPD for a class or remote printer...
7299 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7302 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7304 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7305 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7306 "printer-uri", NULL
, dest
->uri
);
7309 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7311 for (i
= 0; i
< dest
->num_printers
; i
++)
7312 if (!(dest
->printers
[i
]->type
&
7313 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7315 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7316 dest
->printers
[i
]->name
);
7318 if (!access(filename
, 0))
7322 if (i
< dest
->num_printers
)
7323 dest
= dest
->printers
[i
];
7326 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7327 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7328 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7334 * Found the printer with the PPD file, now see if there is one...
7337 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7339 send_ipp_status(con
, IPP_NOT_FOUND
,
7340 _("The PPD file \"%s\" could not be opened: %s"),
7341 uri
->values
[0].string
.text
, strerror(errno
));
7345 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7349 con
->response
->request
.status
.status_code
= IPP_OK
;
7352 send_ipp_status(con
, IPP_NOT_FOUND
,
7353 _("The PPD file \"%s\" could not be found."),
7354 uri
->values
[0].string
.text
);
7359 * 'get_ppds()' - Get the list of PPD files on the local system.
7363 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7365 http_status_t status
; /* Policy status */
7366 ipp_attribute_t
*limit
, /* Limit attribute */
7367 *device
, /* ppd-device-id attribute */
7368 *language
, /* ppd-natural-language attribute */
7369 *make
, /* ppd-make attribute */
7370 *model
, /* ppd-make-and-model attribute */
7371 *model_number
, /* ppd-model-number attribute */
7372 *product
, /* ppd-product attribute */
7373 *psversion
, /* ppd-psverion attribute */
7374 *type
, /* ppd-type attribute */
7375 *requested
, /* requested-attributes attribute */
7376 *exclude
, /* exclude-schemes attribute */
7377 *include
; /* include-schemes attribute */
7378 char command
[1024], /* cups-driverd command */
7379 options
[4096], /* Options to pass to command */
7380 device_str
[256],/* Escaped ppd-device-id string */
7382 /* Escaped ppd-natural-language */
7383 make_str
[256], /* Escaped ppd-make string */
7384 model_str
[256], /* Escaped ppd-make-and-model string */
7385 model_number_str
[256],
7386 /* ppd-model-number string */
7388 /* Escaped ppd-product string */
7390 /* Escaped ppd-psversion string */
7391 type_str
[256], /* Escaped ppd-type string */
7393 /* String for requested attributes */
7395 /* String for excluded schemes */
7397 /* String for included schemes */
7400 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7406 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7408 send_http_error(con
, status
, NULL
);
7413 * Run cups-driverd command with the given options...
7416 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7417 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7418 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7420 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7421 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7423 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7425 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7426 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7427 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7428 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7430 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7432 include
= ippFindAttribute(con
->request
, "include-schemes",
7436 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7438 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7441 url_encode_attr(device
, device_str
, sizeof(device_str
));
7443 device_str
[0] = '\0';
7446 url_encode_attr(language
, language_str
, sizeof(language_str
));
7448 language_str
[0] = '\0';
7451 url_encode_attr(make
, make_str
, sizeof(make_str
));
7456 url_encode_attr(model
, model_str
, sizeof(model_str
));
7458 model_str
[0] = '\0';
7461 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7462 model_number
->values
[0].integer
);
7464 model_number_str
[0] = '\0';
7467 url_encode_attr(product
, product_str
, sizeof(product_str
));
7469 product_str
[0] = '\0';
7472 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7474 psversion_str
[0] = '\0';
7477 url_encode_attr(type
, type_str
, sizeof(type_str
));
7482 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7484 exclude_str
[0] = '\0';
7487 url_encode_attr(include
, include_str
, sizeof(include_str
));
7489 include_str
[0] = '\0';
7491 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7492 snprintf(options
, sizeof(options
),
7493 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7494 con
->request
->request
.op
.request_id
,
7495 limit
? limit
->values
[0].integer
: 0,
7497 device
? "%20" : "", device_str
,
7498 language
? "%20" : "", language_str
,
7499 make
? "%20" : "", make_str
,
7500 model
? "%20" : "", model_str
,
7501 model_number
? "%20" : "", model_number_str
,
7502 product
? "%20" : "", product_str
,
7503 psversion
? "%20" : "", psversion_str
,
7504 type
? "%20" : "", type_str
,
7505 exclude_str
[0] ? "%20" : "", exclude_str
,
7506 include_str
[0] ? "%20" : "", include_str
);
7508 if (cupsdSendCommand(con
, command
, options
, 0))
7511 * Command started successfully, don't send an IPP response here...
7514 ippDelete(con
->response
);
7515 con
->response
= NULL
;
7520 * Command failed, return "internal error" so the user knows something
7524 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7525 _("cups-driverd failed to execute."));
7531 * 'get_printer_attrs()' - Get printer attributes.
7535 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7536 ipp_attribute_t
*uri
) /* I - Printer URI */
7538 http_status_t status
; /* Policy status */
7539 cups_ptype_t dtype
; /* Destination type (printer/class) */
7540 cupsd_printer_t
*printer
; /* Printer/class */
7541 cups_array_t
*ra
; /* Requested attributes array */
7544 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7545 con
->http
.fd
, uri
->values
[0].string
.text
);
7548 * Is the destination valid?
7551 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7557 send_ipp_status(con
, IPP_NOT_FOUND
,
7558 _("The printer or class was not found."));
7566 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7568 send_http_error(con
, status
, printer
);
7573 * Send the attributes...
7576 ra
= create_requested_array(con
->request
);
7578 copy_printer_attrs(con
, printer
, ra
);
7580 cupsArrayDelete(ra
);
7582 con
->response
->request
.status
.status_code
= IPP_OK
;
7587 * 'get_printer_supported()' - Get printer supported values.
7591 get_printer_supported(
7592 cupsd_client_t
*con
, /* I - Client connection */
7593 ipp_attribute_t
*uri
) /* I - Printer URI */
7595 http_status_t status
; /* Policy status */
7596 cups_ptype_t dtype
; /* Destination type (printer/class) */
7597 cupsd_printer_t
*printer
; /* Printer/class */
7600 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7601 con
->http
.fd
, uri
->values
[0].string
.text
);
7604 * Is the destination valid?
7607 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7613 send_ipp_status(con
, IPP_NOT_FOUND
,
7614 _("The printer or class was not found."));
7622 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7624 send_http_error(con
, status
, printer
);
7629 * Return a list of attributes that can be set via Set-Printer-Attributes.
7632 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7634 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7635 "printer-location", 0);
7637 con
->response
->request
.status
.status_code
= IPP_OK
;
7642 * 'get_printers()' - Get a list of printers or classes.
7646 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7647 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7649 http_status_t status
; /* Policy status */
7650 ipp_attribute_t
*attr
; /* Current attribute */
7651 int limit
; /* Max number of printers to return */
7652 int count
; /* Number of printers that match */
7653 cupsd_printer_t
*printer
; /* Current printer pointer */
7654 int printer_type
, /* printer-type attribute */
7655 printer_mask
; /* printer-type-mask attribute */
7656 char *location
; /* Location string */
7657 const char *username
; /* Current user */
7658 char *first_printer_name
; /* first-printer-name attribute */
7659 cups_array_t
*ra
; /* Requested attributes array */
7660 int local
; /* Local connection? */
7663 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7664 con
->http
.fd
, type
);
7670 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7672 send_http_error(con
, status
, NULL
);
7677 * Check for printers...
7680 if (!Printers
|| !cupsArrayCount(Printers
))
7682 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7687 * See if they want to limit the number of printers reported...
7690 if ((attr
= ippFindAttribute(con
->request
, "limit",
7691 IPP_TAG_INTEGER
)) != NULL
)
7692 limit
= attr
->values
[0].integer
;
7696 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7697 IPP_TAG_NAME
)) != NULL
)
7698 first_printer_name
= attr
->values
[0].string
.text
;
7700 first_printer_name
= NULL
;
7703 * Support filtering...
7706 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7707 IPP_TAG_ENUM
)) != NULL
)
7708 printer_type
= attr
->values
[0].integer
;
7712 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7713 IPP_TAG_ENUM
)) != NULL
)
7714 printer_mask
= attr
->values
[0].integer
;
7718 local
= httpAddrLocalhost(&(con
->clientaddr
));
7720 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7721 IPP_TAG_TEXT
)) != NULL
)
7722 location
= attr
->values
[0].string
.text
;
7726 if (con
->username
[0])
7727 username
= con
->username
;
7728 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7729 IPP_TAG_NAME
)) != NULL
)
7730 username
= attr
->values
[0].string
.text
;
7734 ra
= create_requested_array(con
->request
);
7737 * OK, build a list of printers for this printer...
7740 if (first_printer_name
)
7742 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7743 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7746 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7749 count
< limit
&& printer
;
7750 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7752 if (!local
&& !printer
->shared
)
7755 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7756 (printer
->type
& printer_mask
) == printer_type
&&
7758 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
7761 * If HideImplicitMembers is enabled, see if this printer or class
7762 * is a member of an implicit class...
7765 if (ImplicitClasses
&& HideImplicitMembers
&&
7766 printer
->in_implicit_class
)
7770 * If a username is specified, see if it is allowed or denied
7774 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
7778 * Add the group separator as needed...
7782 ippAddSeparator(con
->response
);
7787 * Send the attributes...
7790 copy_printer_attrs(con
, printer
, ra
);
7794 cupsArrayDelete(ra
);
7796 con
->response
->request
.status
.status_code
= IPP_OK
;
7801 * 'get_subscription_attrs()' - Get subscription attributes.
7805 get_subscription_attrs(
7806 cupsd_client_t
*con
, /* I - Client connection */
7807 int sub_id
) /* I - Subscription ID */
7809 http_status_t status
; /* Policy status */
7810 cupsd_subscription_t
*sub
; /* Subscription */
7811 cups_array_t
*ra
; /* Requested attributes array */
7814 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7815 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7816 con
, con
->http
.fd
, sub_id
);
7819 * Is the subscription ID valid?
7822 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7825 * Bad subscription ID...
7828 send_ipp_status(con
, IPP_NOT_FOUND
,
7829 _("notify-subscription-id %d no good"), sub_id
);
7837 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7839 con
, sub
->owner
)) != HTTP_OK
)
7841 send_http_error(con
, status
, sub
->dest
);
7846 * Copy the subscription attributes to the response using the
7847 * requested-attributes attribute that may be provided by the client.
7850 ra
= create_requested_array(con
->request
);
7852 copy_subscription_attrs(con
, sub
, ra
);
7854 cupsArrayDelete(ra
);
7856 con
->response
->request
.status
.status_code
= IPP_OK
;
7861 * 'get_subscriptions()' - Get subscriptions.
7865 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7866 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7868 http_status_t status
; /* Policy status */
7869 int count
; /* Number of subscriptions */
7870 int limit
; /* Limit */
7871 cupsd_subscription_t
*sub
; /* Subscription */
7872 cups_array_t
*ra
; /* Requested attributes array */
7873 ipp_attribute_t
*attr
; /* Attribute */
7874 cups_ptype_t dtype
; /* Destination type (printer/class) */
7875 char scheme
[HTTP_MAX_URI
],
7876 /* Scheme portion of URI */
7877 username
[HTTP_MAX_URI
],
7878 /* Username portion of URI */
7880 /* Host portion of URI */
7881 resource
[HTTP_MAX_URI
];
7882 /* Resource portion of URI */
7883 int port
; /* Port portion of URI */
7884 cupsd_job_t
*job
; /* Job pointer */
7885 cupsd_printer_t
*printer
; /* Printer */
7888 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7889 "get_subscriptions(con=%p[%d], uri=%s)",
7890 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7893 * Is the destination valid?
7896 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7897 sizeof(scheme
), username
, sizeof(username
), host
,
7898 sizeof(host
), &port
, resource
, sizeof(resource
));
7900 if (!strcmp(resource
, "/") ||
7901 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7902 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7903 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7908 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7911 job
= cupsdFindJob(atoi(resource
+ 6));
7915 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist"),
7920 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7926 send_ipp_status(con
, IPP_NOT_FOUND
,
7927 _("The printer or class was not found."));
7930 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7931 IPP_TAG_INTEGER
)) != NULL
)
7933 job
= cupsdFindJob(attr
->values
[0].integer
);
7937 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
7938 attr
->values
[0].integer
);
7949 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
7951 con
, NULL
)) != HTTP_OK
)
7953 send_http_error(con
, status
, printer
);
7958 * Copy the subscription attributes to the response using the
7959 * requested-attributes attribute that may be provided by the client.
7962 ra
= create_requested_array(con
->request
);
7964 if ((attr
= ippFindAttribute(con
->request
, "limit",
7965 IPP_TAG_INTEGER
)) != NULL
)
7966 limit
= attr
->values
[0].integer
;
7971 * See if we only want to see subscriptions for a specific user...
7974 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7975 IPP_TAG_BOOLEAN
)) != NULL
&&
7976 attr
->values
[0].boolean
)
7977 strlcpy(username
, get_username(con
), sizeof(username
));
7981 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7983 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7984 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7985 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
7987 ippAddSeparator(con
->response
);
7988 copy_subscription_attrs(con
, sub
, ra
);
7991 if (limit
&& count
>= limit
)
7995 cupsArrayDelete(ra
);
7998 con
->response
->request
.status
.status_code
= IPP_OK
;
8000 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8005 * 'get_username()' - Get the username associated with a request.
8008 static const char * /* O - Username */
8009 get_username(cupsd_client_t
*con
) /* I - Connection */
8011 ipp_attribute_t
*attr
; /* Attribute */
8014 if (con
->username
[0])
8015 return (con
->username
);
8016 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8017 IPP_TAG_NAME
)) != NULL
)
8018 return (attr
->values
[0].string
.text
);
8020 return ("anonymous");
8025 * 'hold_job()' - Hold a print job.
8029 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8030 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8032 ipp_attribute_t
*attr
; /* Current job-hold-until */
8033 const char *when
; /* New value */
8034 int jobid
; /* Job ID */
8035 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8036 username
[HTTP_MAX_URI
], /* Username portion of URI */
8037 host
[HTTP_MAX_URI
], /* Host portion of URI */
8038 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8039 int port
; /* Port portion of URI */
8040 cupsd_job_t
*job
; /* Job information */
8043 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8044 uri
->values
[0].string
.text
);
8047 * See if we have a job URI or a printer URI...
8050 if (!strcmp(uri
->name
, "printer-uri"))
8053 * Got a printer URI; see if we also have a job-id attribute...
8056 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8057 IPP_TAG_INTEGER
)) == NULL
)
8059 send_ipp_status(con
, IPP_BAD_REQUEST
,
8060 _("Got a printer-uri attribute but no job-id"));
8064 jobid
= attr
->values
[0].integer
;
8069 * Got a job URI; parse it to get the job ID...
8072 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8073 sizeof(scheme
), username
, sizeof(username
), host
,
8074 sizeof(host
), &port
, resource
, sizeof(resource
));
8076 if (strncmp(resource
, "/jobs/", 6))
8082 send_ipp_status(con
, IPP_BAD_REQUEST
,
8083 _("Bad job-uri attribute \"%s\""),
8084 uri
->values
[0].string
.text
);
8088 jobid
= atoi(resource
+ 6);
8092 * See if the job exists...
8095 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8098 * Nope - return a "not found" error...
8101 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
8106 * See if the job is owned by the requesting user...
8109 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8111 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8112 cupsdFindDest(job
->dest
));
8117 * Hold the job and return...
8120 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8121 IPP_TAG_KEYWORD
)) == NULL
)
8122 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8126 when
= attr
->values
[0].string
.text
;
8128 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8129 "Job job-hold-until value changed by user.");
8132 when
= "indefinite";
8134 cupsdSetJobHoldUntil(job
, when
, 1);
8135 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8138 con
->response
->request
.status
.status_code
= IPP_OK
;
8143 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8147 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8148 ipp_attribute_t
*uri
) /* I - Printer URI */
8150 http_status_t status
; /* Policy status */
8151 cups_ptype_t dtype
; /* Destination type (printer/class) */
8152 cupsd_printer_t
*printer
; /* Printer data */
8155 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8156 con
->http
.fd
, uri
->values
[0].string
.text
);
8159 * Is the destination valid?
8162 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8168 send_ipp_status(con
, IPP_NOT_FOUND
,
8169 _("The printer or class was not found."));
8177 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8179 send_http_error(con
, status
, printer
);
8184 * Hold pending/new jobs sent to the printer...
8187 printer
->holding_new_jobs
= 1;
8189 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8190 cupsdAddPrinterHistory(printer
);
8192 if (dtype
& CUPS_PRINTER_CLASS
)
8193 cupsdLogMessage(CUPSD_LOG_INFO
,
8194 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8195 printer
->name
, get_username(con
));
8197 cupsdLogMessage(CUPSD_LOG_INFO
,
8198 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8199 printer
->name
, get_username(con
));
8202 * Everything was ok, so return OK status...
8205 con
->response
->request
.status
.status_code
= IPP_OK
;
8210 * 'move_job()' - Move a job to a new destination.
8214 move_job(cupsd_client_t
*con
, /* I - Client connection */
8215 ipp_attribute_t
*uri
) /* I - Job URI */
8217 http_status_t status
; /* Policy status */
8218 ipp_attribute_t
*attr
; /* Current attribute */
8219 int jobid
; /* Job ID */
8220 cupsd_job_t
*job
; /* Current job */
8221 const char *src
; /* Source printer/class */
8222 cups_ptype_t stype
, /* Source type (printer or class) */
8223 dtype
; /* Destination type (printer/class) */
8224 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8225 username
[HTTP_MAX_URI
], /* Username portion of URI */
8226 host
[HTTP_MAX_URI
], /* Host portion of URI */
8227 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8228 int port
; /* Port portion of URI */
8229 cupsd_printer_t
*sprinter
, /* Source printer */
8230 *dprinter
; /* Destination printer */
8233 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8234 uri
->values
[0].string
.text
);
8237 * Get the new printer or class...
8240 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8241 IPP_TAG_URI
)) == NULL
)
8244 * Need job-printer-uri...
8247 send_ipp_status(con
, IPP_BAD_REQUEST
,
8248 _("job-printer-uri attribute missing"));
8252 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8258 send_ipp_status(con
, IPP_NOT_FOUND
,
8259 _("The printer or class was not found."));
8264 * See if we have a job URI or a printer URI...
8267 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8268 sizeof(scheme
), username
, sizeof(username
), host
,
8269 sizeof(host
), &port
, resource
, sizeof(resource
));
8271 if (!strcmp(uri
->name
, "printer-uri"))
8274 * Got a printer URI; see if we also have a job-id attribute...
8277 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8278 IPP_TAG_INTEGER
)) == NULL
)
8284 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8285 &sprinter
)) == NULL
)
8291 send_ipp_status(con
, IPP_NOT_FOUND
,
8292 _("The printer or class was not found."));
8301 * Otherwise, just move a single job...
8304 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8307 * Nope - return a "not found" error...
8310 send_ipp_status(con
, IPP_NOT_FOUND
,
8311 _("Job #%d does not exist"), attr
->values
[0].integer
);
8317 * Job found, initialize source pointers...
8328 * Got a job URI; parse it to get the job ID...
8331 if (strncmp(resource
, "/jobs/", 6))
8337 send_ipp_status(con
, IPP_BAD_REQUEST
,
8338 _("Bad job-uri attribute \"%s\""),
8339 uri
->values
[0].string
.text
);
8344 * See if the job exists...
8347 jobid
= atoi(resource
+ 6);
8349 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8352 * Nope - return a "not found" error...
8355 send_ipp_status(con
, IPP_NOT_FOUND
,
8356 _("Job #%d does not exist"), jobid
);
8362 * Job found, initialize source pointers...
8371 * Check the policy of the destination printer...
8374 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8375 job
? job
->username
: NULL
)) != HTTP_OK
)
8377 send_http_error(con
, status
, dprinter
);
8382 * Now move the job or jobs...
8388 * See if the job has been completed...
8391 if (job
->state_value
> IPP_JOB_STOPPED
)
8394 * Return a "not-possible" error...
8397 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8398 _("Job #%d is finished and cannot be altered"),
8404 * See if the job is owned by the requesting user...
8407 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8409 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8410 cupsdFindDest(job
->dest
));
8415 * Move the job to a different printer or class...
8418 cupsdMoveJob(job
, dprinter
);
8423 * Got the source printer, now look through the jobs...
8426 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8428 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8431 * See if the job is pointing at the source printer or has not been
8435 if (strcasecmp(job
->dest
, src
) ||
8436 job
->state_value
> IPP_JOB_STOPPED
)
8440 * See if the job can be moved by the requesting user...
8443 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8447 * Move the job to a different printer or class...
8450 cupsdMoveJob(job
, dprinter
);
8455 * Start jobs if possible...
8461 * Return with "everything is OK" status...
8464 con
->response
->request
.status
.status_code
= IPP_OK
;
8469 * 'ppd_parse_line()' - Parse a PPD default line.
8472 static int /* O - 0 on success, -1 on failure */
8473 ppd_parse_line(const char *line
, /* I - Line */
8474 char *option
, /* O - Option name */
8475 int olen
, /* I - Size of option name */
8476 char *choice
, /* O - Choice name */
8477 int clen
) /* I - Size of choice name */
8480 * Verify this is a default option line...
8483 if (strncmp(line
, "*Default", 8))
8487 * Read the option name...
8490 for (line
+= 8, olen
--;
8491 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8502 * Skip everything else up to the colon (:)...
8505 while (*line
&& *line
!= ':')
8514 * Now grab the option choice, skipping leading whitespace...
8517 while (isspace(*line
& 255))
8521 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8532 * Return with no errors...
8540 * 'print_job()' - Print a file to a printer or class.
8544 print_job(cupsd_client_t
*con
, /* I - Client connection */
8545 ipp_attribute_t
*uri
) /* I - Printer URI */
8547 ipp_attribute_t
*attr
; /* Current attribute */
8548 ipp_attribute_t
*format
; /* Document-format attribute */
8549 const char *default_format
; /* document-format-default value */
8550 cupsd_job_t
*job
; /* New job */
8551 char filename
[1024]; /* Job filename */
8552 mime_type_t
*filetype
; /* Type of file */
8553 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8554 type
[MIME_MAX_TYPE
], /* Subtype of file */
8555 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8556 /* Textual name of mime type */
8557 cupsd_printer_t
*printer
; /* Printer data */
8558 struct stat fileinfo
; /* File information */
8559 int kbytes
; /* Size of file */
8560 int compression
; /* Document compression */
8563 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8564 uri
->values
[0].string
.text
);
8567 * Validate print file attributes, for now just document-format and
8568 * compression (CUPS only supports "none" and "gzip")...
8571 compression
= CUPS_FILE_NONE
;
8573 if ((attr
= ippFindAttribute(con
->request
, "compression",
8574 IPP_TAG_KEYWORD
)) != NULL
)
8576 if (strcmp(attr
->values
[0].string
.text
, "none")
8578 && strcmp(attr
->values
[0].string
.text
, "gzip")
8579 #endif /* HAVE_LIBZ */
8582 send_ipp_status(con
, IPP_ATTRIBUTES
,
8583 _("Unsupported compression \"%s\""),
8584 attr
->values
[0].string
.text
);
8585 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8586 "compression", NULL
, attr
->values
[0].string
.text
);
8591 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8592 compression
= CUPS_FILE_GZIP
;
8593 #endif /* HAVE_LIBZ */
8597 * Do we have a file to print?
8602 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
8607 * Is the destination valid?
8610 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8616 send_ipp_status(con
, IPP_NOT_FOUND
,
8617 _("The printer or class was not found."));
8622 * Is it a format we support?
8625 if ((format
= ippFindAttribute(con
->request
, "document-format",
8626 IPP_TAG_MIMETYPE
)) != NULL
)
8629 * Grab format from client...
8632 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8635 send_ipp_status(con
, IPP_BAD_REQUEST
,
8636 _("Could not scan type \"%s\""),
8637 format
->values
[0].string
.text
);
8641 else if ((default_format
= cupsGetOption("document-format",
8642 printer
->num_options
,
8643 printer
->options
)) != NULL
)
8646 * Use default document format...
8649 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8651 send_ipp_status(con
, IPP_BAD_REQUEST
,
8652 _("Could not scan type \"%s\""),
8663 strcpy(super
, "application");
8664 strcpy(type
, "octet-stream");
8667 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8670 * Auto-type the file...
8673 ipp_attribute_t
*doc_name
; /* document-name attribute */
8676 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8678 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8679 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8680 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8684 filetype
= mimeType(MimeDatabase
, super
, type
);
8686 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8687 filetype
->super
, filetype
->type
);
8690 filetype
= mimeType(MimeDatabase
, super
, type
);
8694 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8697 * Replace the document-format attribute value with the auto-typed or
8701 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8706 _cupsStrFree(format
->values
[0].string
.text
);
8708 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8711 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8712 "document-format", NULL
, mimetype
);
8716 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8717 _("Unsupported format \'%s/%s\'"), super
, type
);
8718 cupsdLogMessage(CUPSD_LOG_INFO
,
8719 "Hint: Do you have the raw file printing rules enabled?");
8722 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8723 "document-format", NULL
, format
->values
[0].string
.text
);
8729 * Read any embedded job ticket info from PS files...
8732 if (!strcasecmp(filetype
->super
, "application") &&
8733 (!strcasecmp(filetype
->type
, "postscript") ||
8734 !strcasecmp(filetype
->type
, "pdf")))
8735 read_job_ticket(con
);
8738 * Create the job object...
8741 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8745 * Update quota data...
8748 if (stat(con
->filename
, &fileinfo
))
8751 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8753 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8755 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8756 IPP_TAG_INTEGER
)) != NULL
)
8757 attr
->values
[0].integer
+= kbytes
;
8760 * Add the job file...
8763 if (add_file(con
, job
, filetype
, compression
))
8766 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8768 rename(con
->filename
, filename
);
8769 cupsdClearString(&con
->filename
);
8772 * See if we need to add the ending sheet...
8775 if (cupsdTimeoutJob(job
))
8779 * Log and save the job...
8782 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8783 "File of type %s/%s queued by \"%s\".",
8784 filetype
->super
, filetype
->type
, job
->username
);
8785 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8786 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8787 job
->dest
, job
->username
);
8790 * Start the job if possible...
8798 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8800 * This function only gets called when printing a single PDF or PostScript
8801 * file using the Print-Job operation. It doesn't work for Create-Job +
8802 * Send-File, since the job attributes need to be set at job creation
8803 * time for banners to work. The embedded job ticket stuff is here
8804 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8805 * options and IPP attributes which otherwise would be lost.
8807 * The format of a job ticket is simple:
8809 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8811 * %cupsJobTicket: attr1=value1
8812 * %cupsJobTicket: attr2=value2
8814 * %cupsJobTicket: attrN=valueN
8816 * Job ticket lines must appear immediately after the first line that
8817 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8818 * stops looking for job ticket info when it finds a line that does not begin
8819 * with "%cupsJobTicket:".
8821 * The maximum length of a job ticket line, including the prefix, is
8822 * 255 characters to conform with the Adobe DSC.
8824 * Read-only attributes are rejected with a notice to the error log in
8825 * case a malicious user tries anything. Since the job ticket is read
8826 * prior to attribute validation in print_job(), job ticket attributes
8827 * will go through the same validation as IPP attributes...
8831 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8833 cups_file_t
*fp
; /* File to read from */
8834 char line
[256]; /* Line data */
8835 int num_options
; /* Number of options */
8836 cups_option_t
*options
; /* Options */
8837 ipp_t
*ticket
; /* New attributes */
8838 ipp_attribute_t
*attr
, /* Current attribute */
8839 *attr2
, /* Job attribute */
8840 *prev2
; /* Previous job attribute */
8844 * First open the print file...
8847 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8849 cupsdLogMessage(CUPSD_LOG_ERROR
,
8850 "Unable to open print file for job ticket - %s",
8856 * Skip the first line...
8859 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8861 cupsdLogMessage(CUPSD_LOG_ERROR
,
8862 "Unable to read from print file for job ticket - %s",
8868 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8871 * Not a DSC-compliant file, so no job ticket info will be available...
8879 * Read job ticket info from the file...
8885 while (cupsFileGets(fp
, line
, sizeof(line
)))
8888 * Stop at the first non-ticket line...
8891 if (strncmp(line
, "%cupsJobTicket:", 15))
8895 * Add the options to the option array...
8898 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8902 * Done with the file; see if we have any options...
8907 if (num_options
== 0)
8911 * OK, convert the options to an attribute list, and apply them to
8916 cupsEncodeOptions(ticket
, num_options
, options
);
8919 * See what the user wants to change.
8922 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8924 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8927 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8928 !strcmp(attr
->name
, "job-originating-user-name") ||
8929 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8930 !strcmp(attr
->name
, "job-k-octets") ||
8931 !strcmp(attr
->name
, "job-id") ||
8932 !strncmp(attr
->name
, "job-state", 9) ||
8933 !strncmp(attr
->name
, "time-at-", 8))
8934 continue; /* Read-only attrs */
8936 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8937 IPP_TAG_ZERO
)) != NULL
)
8940 * Some other value; first free the old value...
8943 if (con
->request
->attrs
== attr2
)
8945 con
->request
->attrs
= attr2
->next
;
8950 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8951 if (prev2
->next
== attr2
)
8953 prev2
->next
= attr2
->next
;
8958 if (con
->request
->last
== attr2
)
8959 con
->request
->last
= prev2
;
8961 _ippFreeAttr(attr2
);
8965 * Add new option by copying it...
8968 copy_attribute(con
->request
, attr
, 0);
8972 * Then free the attribute list and option array...
8976 cupsFreeOptions(num_options
, options
);
8981 * 'reject_jobs()' - Reject print jobs to a printer.
8985 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8986 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8988 http_status_t status
; /* Policy status */
8989 cups_ptype_t dtype
; /* Destination type (printer/class) */
8990 cupsd_printer_t
*printer
; /* Printer data */
8991 ipp_attribute_t
*attr
; /* printer-state-message text */
8994 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8995 con
->http
.fd
, uri
->values
[0].string
.text
);
8998 * Is the destination valid?
9001 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9007 send_ipp_status(con
, IPP_NOT_FOUND
,
9008 _("The printer or class was not found."));
9016 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9018 send_http_error(con
, status
, printer
);
9023 * Reject jobs sent to the printer...
9026 printer
->accepting
= 0;
9028 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9029 IPP_TAG_TEXT
)) == NULL
)
9030 strcpy(printer
->state_message
, "Rejecting Jobs");
9032 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9033 sizeof(printer
->state_message
));
9035 cupsdAddPrinterHistory(printer
);
9037 if (dtype
& CUPS_PRINTER_CLASS
)
9039 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9041 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9042 printer
->name
, get_username(con
));
9046 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9048 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9049 printer
->name
, get_username(con
));
9053 * Everything was ok, so return OK status...
9056 con
->response
->request
.status
.status_code
= IPP_OK
;
9061 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9065 release_held_new_jobs(
9066 cupsd_client_t
*con
, /* I - Connection */
9067 ipp_attribute_t
*uri
) /* I - Printer URI */
9069 http_status_t status
; /* Policy status */
9070 cups_ptype_t dtype
; /* Destination type (printer/class) */
9071 cupsd_printer_t
*printer
; /* Printer data */
9074 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9075 con
->http
.fd
, uri
->values
[0].string
.text
);
9078 * Is the destination valid?
9081 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9087 send_ipp_status(con
, IPP_NOT_FOUND
,
9088 _("The printer or class was not found."));
9096 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9098 send_http_error(con
, status
, printer
);
9103 * Hold pending/new jobs sent to the printer...
9106 printer
->holding_new_jobs
= 0;
9108 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9109 cupsdAddPrinterHistory(printer
);
9111 if (dtype
& CUPS_PRINTER_CLASS
)
9112 cupsdLogMessage(CUPSD_LOG_INFO
,
9113 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9114 printer
->name
, get_username(con
));
9116 cupsdLogMessage(CUPSD_LOG_INFO
,
9117 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9118 printer
->name
, get_username(con
));
9121 * Everything was ok, so return OK status...
9124 con
->response
->request
.status
.status_code
= IPP_OK
;
9129 * 'release_job()' - Release a held print job.
9133 release_job(cupsd_client_t
*con
, /* I - Client connection */
9134 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9136 ipp_attribute_t
*attr
; /* Current attribute */
9137 int jobid
; /* Job ID */
9138 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9139 username
[HTTP_MAX_URI
], /* Username portion of URI */
9140 host
[HTTP_MAX_URI
], /* Host portion of URI */
9141 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9142 int port
; /* Port portion of URI */
9143 cupsd_job_t
*job
; /* Job information */
9146 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9147 con
->http
.fd
, uri
->values
[0].string
.text
);
9150 * See if we have a job URI or a printer URI...
9153 if (!strcmp(uri
->name
, "printer-uri"))
9156 * Got a printer URI; see if we also have a job-id attribute...
9159 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9160 IPP_TAG_INTEGER
)) == NULL
)
9162 send_ipp_status(con
, IPP_BAD_REQUEST
,
9163 _("Got a printer-uri attribute but no job-id"));
9167 jobid
= attr
->values
[0].integer
;
9172 * Got a job URI; parse it to get the job ID...
9175 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9176 sizeof(scheme
), username
, sizeof(username
), host
,
9177 sizeof(host
), &port
, resource
, sizeof(resource
));
9179 if (strncmp(resource
, "/jobs/", 6))
9185 send_ipp_status(con
, IPP_BAD_REQUEST
,
9186 _("Bad job-uri attribute \"%s\""),
9187 uri
->values
[0].string
.text
);
9191 jobid
= atoi(resource
+ 6);
9195 * See if the job exists...
9198 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9201 * Nope - return a "not found" error...
9204 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9209 * See if job is "held"...
9212 if (job
->state_value
!= IPP_JOB_HELD
)
9215 * Nope - return a "not possible" error...
9218 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held"), jobid
);
9223 * See if the job is owned by the requesting user...
9226 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9228 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9229 cupsdFindDest(job
->dest
));
9234 * Reset the job-hold-until value to "no-hold"...
9237 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9238 IPP_TAG_KEYWORD
)) == NULL
)
9239 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9243 _cupsStrFree(attr
->values
[0].string
.text
);
9245 attr
->value_tag
= IPP_TAG_KEYWORD
;
9246 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9248 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9249 "Job job-hold-until value changed by user.");
9253 * Release the job and return...
9256 cupsdReleaseJob(job
);
9258 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9259 "Job released by user.");
9261 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9263 con
->response
->request
.status
.status_code
= IPP_OK
;
9270 * 'renew_subscription()' - Renew an existing subscription...
9275 cupsd_client_t
*con
, /* I - Client connection */
9276 int sub_id
) /* I - Subscription ID */
9278 http_status_t status
; /* Policy status */
9279 cupsd_subscription_t
*sub
; /* Subscription */
9280 ipp_attribute_t
*lease
; /* notify-lease-duration */
9283 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9284 "renew_subscription(con=%p[%d], sub_id=%d)",
9285 con
, con
->http
.fd
, sub_id
);
9288 * Is the subscription ID valid?
9291 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9294 * Bad subscription ID...
9297 send_ipp_status(con
, IPP_NOT_FOUND
,
9298 _("notify-subscription-id %d no good"), sub_id
);
9305 * Job subscriptions cannot be renewed...
9308 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9309 _("Job subscriptions cannot be renewed"));
9317 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9319 con
, sub
->owner
)) != HTTP_OK
)
9321 send_http_error(con
, status
, sub
->dest
);
9326 * Renew the subscription...
9329 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9332 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9334 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9336 cupsdLogMessage(CUPSD_LOG_INFO
,
9337 "renew_subscription: Limiting notify-lease-duration to "
9340 sub
->lease
= MaxLeaseDuration
;
9343 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9345 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9347 con
->response
->request
.status
.status_code
= IPP_OK
;
9349 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9350 "notify-lease-duration", sub
->lease
);
9355 * 'restart_job()' - Restart an old print job.
9359 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9360 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9362 ipp_attribute_t
*attr
; /* Current attribute */
9363 int jobid
; /* Job ID */
9364 cupsd_job_t
*job
; /* Job information */
9365 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9366 username
[HTTP_MAX_URI
], /* Username portion of URI */
9367 host
[HTTP_MAX_URI
], /* Host portion of URI */
9368 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9369 int port
; /* Port portion of URI */
9372 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9373 con
->http
.fd
, uri
->values
[0].string
.text
);
9376 * See if we have a job URI or a printer URI...
9379 if (!strcmp(uri
->name
, "printer-uri"))
9382 * Got a printer URI; see if we also have a job-id attribute...
9385 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9386 IPP_TAG_INTEGER
)) == NULL
)
9388 send_ipp_status(con
, IPP_BAD_REQUEST
,
9389 _("Got a printer-uri attribute but no job-id"));
9393 jobid
= attr
->values
[0].integer
;
9398 * Got a job URI; parse it to get the job ID...
9401 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9402 sizeof(scheme
), username
, sizeof(username
), host
,
9403 sizeof(host
), &port
, resource
, sizeof(resource
));
9405 if (strncmp(resource
, "/jobs/", 6))
9411 send_ipp_status(con
, IPP_BAD_REQUEST
,
9412 _("Bad job-uri attribute \"%s\""),
9413 uri
->values
[0].string
.text
);
9417 jobid
= atoi(resource
+ 6);
9421 * See if the job exists...
9424 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9427 * Nope - return a "not found" error...
9430 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9435 * See if job is in any of the "completed" states...
9438 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9441 * Nope - return a "not possible" error...
9444 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete"),
9450 * See if we have retained the job files...
9455 if (!job
->attrs
|| job
->num_files
== 0)
9458 * Nope - return a "not possible" error...
9461 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9462 _("Job #%d cannot be restarted - no files"), jobid
);
9467 * See if the job is owned by the requesting user...
9470 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9472 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9473 cupsdFindDest(job
->dest
));
9478 * See if the job-hold-until attribute is specified...
9481 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9482 IPP_TAG_KEYWORD
)) == NULL
)
9483 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9485 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9488 * Return the job to a held state...
9491 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9492 "Restarted by \"%s\" with job-hold-until=%s.",
9493 username
, attr
->values
[0].string
.text
);
9494 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9496 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9497 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9498 attr
->values
[0].string
.text
);
9503 * Restart the job...
9506 cupsdRestartJob(job
);
9510 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9512 con
->response
->request
.status
.status_code
= IPP_OK
;
9517 * 'save_auth_info()' - Save authentication information for a job.
9522 cupsd_client_t
*con
, /* I - Client connection */
9523 cupsd_job_t
*job
, /* I - Job */
9524 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9526 int i
; /* Looping var */
9527 char filename
[1024]; /* Job authentication filename */
9528 cups_file_t
*fp
; /* Job authentication file */
9529 char line
[2048]; /* Line for file */
9530 cupsd_printer_t
*dest
; /* Destination printer/class */
9534 * This function saves the in-memory authentication information for
9535 * a job so that it can be used to authenticate with a remote host.
9536 * The information is stored in a file that is readable only by the
9537 * root user. The fields are Base-64 encoded, each on a separate line,
9538 * followed by random number (up to 1024) of newlines to limit the
9539 * amount of information that is exposed.
9541 * Because of the potential for exposing of authentication information,
9542 * this functionality is only enabled when running cupsd as root.
9544 * This caching only works for the Basic and BasicDigest authentication
9545 * types. Digest authentication cannot be cached this way, and in
9546 * the future Kerberos authentication may make all of this obsolete.
9548 * Authentication information is saved whenever an authenticated
9549 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9552 * This information is deleted after a job is completed or canceled,
9553 * so reprints may require subsequent re-authentication.
9559 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9563 * Create the authentication file and change permissions...
9566 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9567 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9569 cupsdLogMessage(CUPSD_LOG_ERROR
,
9570 "Unable to save authentication info to \"%s\" - %s",
9571 filename
, strerror(errno
));
9575 fchown(cupsFileNumber(fp
), 0, 0);
9576 fchmod(cupsFileNumber(fp
), 0400);
9578 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9581 * Write 1 to 3 auth values...
9584 cupsdClearString(&job
->auth_username
);
9585 cupsdClearString(&job
->auth_domain
);
9586 cupsdClearString(&job
->auth_password
);
9588 for (i
= 0; i
< auth_info
->num_values
; i
++)
9590 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9591 strlen(auth_info
->values
[i
].string
.text
));
9592 cupsFilePrintf(fp
, "%s\n", line
);
9594 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9595 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9596 auth_info
->values
[i
].string
.text
);
9597 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9598 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9599 auth_info
->values
[i
].string
.text
);
9600 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9601 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9602 auth_info
->values
[i
].string
.text
);
9605 else if (con
->username
[0])
9608 * Write the authenticated username...
9611 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9612 cupsFilePrintf(fp
, "%s\n", line
);
9614 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9615 cupsdClearString(&job
->auth_domain
);
9618 * Write the authenticated password...
9621 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9622 cupsFilePrintf(fp
, "%s\n", line
);
9624 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
9628 * Write a random number of newlines to the end of the file...
9631 for (i
= (rand() % 1024); i
>= 0; i
--)
9632 cupsFilePutChar(fp
, '\n');
9635 * Close the file and return...
9640 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9641 # ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
9642 if (con
->have_gss
&&
9643 (con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
|| con
->gss_creds
))
9645 if (con
->have_gss
&& con
->gss_creds
)
9646 # endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
9647 save_krb5_creds(con
, job
);
9648 else if (job
->ccname
)
9649 cupsdClearString(&(job
->ccname
));
9650 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9654 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9656 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
9660 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
9661 cupsd_job_t
*job
) /* I - Job */
9664 * Get the credentials...
9667 job
->ccache
= cupsdCopyKrb5Creds(con
);
9670 * Add the KRB5CCNAME environment variable to the job so that the
9671 * backend can use the credentials when printing.
9676 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
9677 krb5_cc_get_name(KerberosContext
, job
->ccache
));
9679 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
9682 cupsdClearString(&(job
->ccname
));
9684 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9688 * 'send_document()' - Send a file to a printer or class.
9692 send_document(cupsd_client_t
*con
, /* I - Client connection */
9693 ipp_attribute_t
*uri
) /* I - Printer URI */
9695 ipp_attribute_t
*attr
; /* Current attribute */
9696 ipp_attribute_t
*format
; /* Request's document-format attribute */
9697 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9698 const char *default_format
;/* document-format-default value */
9699 int jobid
; /* Job ID number */
9700 cupsd_job_t
*job
; /* Current job */
9701 char job_uri
[HTTP_MAX_URI
],
9703 scheme
[HTTP_MAX_URI
],
9704 /* Method portion of URI */
9705 username
[HTTP_MAX_URI
],
9706 /* Username portion of URI */
9708 /* Host portion of URI */
9709 resource
[HTTP_MAX_URI
];
9710 /* Resource portion of URI */
9711 int port
; /* Port portion of URI */
9712 mime_type_t
*filetype
; /* Type of file */
9713 char super
[MIME_MAX_SUPER
],
9714 /* Supertype of file */
9715 type
[MIME_MAX_TYPE
],
9716 /* Subtype of file */
9717 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9718 /* Textual name of mime type */
9719 char filename
[1024]; /* Job filename */
9720 cupsd_printer_t
*printer
; /* Current printer */
9721 struct stat fileinfo
; /* File information */
9722 int kbytes
; /* Size of file */
9723 int compression
; /* Type of compression */
9724 int start_job
; /* Start the job? */
9727 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9728 con
->http
.fd
, uri
->values
[0].string
.text
);
9731 * See if we have a job URI or a printer URI...
9734 if (!strcmp(uri
->name
, "printer-uri"))
9737 * Got a printer URI; see if we also have a job-id attribute...
9740 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9741 IPP_TAG_INTEGER
)) == NULL
)
9743 send_ipp_status(con
, IPP_BAD_REQUEST
,
9744 _("Got a printer-uri attribute but no job-id"));
9748 jobid
= attr
->values
[0].integer
;
9753 * Got a job URI; parse it to get the job ID...
9756 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9757 sizeof(scheme
), username
, sizeof(username
), host
,
9758 sizeof(host
), &port
, resource
, sizeof(resource
));
9760 if (strncmp(resource
, "/jobs/", 6))
9766 send_ipp_status(con
, IPP_BAD_REQUEST
,
9767 _("Bad job-uri attribute \"%s\""),
9768 uri
->values
[0].string
.text
);
9772 jobid
= atoi(resource
+ 6);
9776 * See if the job exists...
9779 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9782 * Nope - return a "not found" error...
9785 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9789 printer
= cupsdFindDest(job
->dest
);
9792 * See if the job is owned by the requesting user...
9795 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9797 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9798 cupsdFindDest(job
->dest
));
9803 * OK, see if the client is sending the document compressed - CUPS
9804 * only supports "none" and "gzip".
9807 compression
= CUPS_FILE_NONE
;
9809 if ((attr
= ippFindAttribute(con
->request
, "compression",
9810 IPP_TAG_KEYWORD
)) != NULL
)
9812 if (strcmp(attr
->values
[0].string
.text
, "none")
9814 && strcmp(attr
->values
[0].string
.text
, "gzip")
9815 #endif /* HAVE_LIBZ */
9818 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\""),
9819 attr
->values
[0].string
.text
);
9820 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9821 "compression", NULL
, attr
->values
[0].string
.text
);
9826 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9827 compression
= CUPS_FILE_GZIP
;
9828 #endif /* HAVE_LIBZ */
9832 * Do we have a file to print?
9837 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
9842 * Is it a format we support?
9845 if ((format
= ippFindAttribute(con
->request
, "document-format",
9846 IPP_TAG_MIMETYPE
)) != NULL
)
9849 * Grab format from client...
9852 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9855 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
9856 format
->values
[0].string
.text
);
9860 else if ((default_format
= cupsGetOption("document-format",
9861 printer
->num_options
,
9862 printer
->options
)) != NULL
)
9865 * Use default document format...
9868 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9870 send_ipp_status(con
, IPP_BAD_REQUEST
,
9871 _("Could not scan type \"%s\""),
9879 * No document format attribute? Auto-type it!
9882 strcpy(super
, "application");
9883 strcpy(type
, "octet-stream");
9886 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9889 * Auto-type the file...
9892 ipp_attribute_t
*doc_name
; /* document-name attribute */
9895 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9897 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9898 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9899 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9903 filetype
= mimeType(MimeDatabase
, super
, type
);
9905 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9906 filetype
->super
, filetype
->type
);
9909 filetype
= mimeType(MimeDatabase
, super
, type
);
9914 * Replace the document-format attribute value with the auto-typed or
9918 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9921 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9922 IPP_TAG_MIMETYPE
)) != NULL
)
9924 _cupsStrFree(jformat
->values
[0].string
.text
);
9926 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9929 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9930 "document-format", NULL
, mimetype
);
9934 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9935 _("Unsupported format \'%s/%s\'"), super
, type
);
9936 cupsdLogMessage(CUPSD_LOG_INFO
,
9937 "Hint: Do you have the raw file printing rules enabled?");
9940 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9941 "document-format", NULL
, format
->values
[0].string
.text
);
9946 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9948 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9951 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9952 _("Unsupported format \'%s\'"), mimetype
);
9954 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9955 "document-format", NULL
, mimetype
);
9961 * Add the file to the job...
9966 if (add_file(con
, job
, filetype
, compression
))
9969 if (stat(con
->filename
, &fileinfo
))
9972 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9974 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9976 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9977 IPP_TAG_INTEGER
)) != NULL
)
9978 attr
->values
[0].integer
+= kbytes
;
9980 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9982 rename(con
->filename
, filename
);
9984 cupsdClearString(&con
->filename
);
9986 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9987 filetype
->super
, filetype
->type
, job
->username
);
9990 * Start the job if this is the last document...
9993 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9994 IPP_TAG_BOOLEAN
)) != NULL
&&
9995 attr
->values
[0].boolean
)
9998 * See if we need to add the ending sheet...
10001 if (cupsdTimeoutJob(job
))
10004 if (job
->state_value
== IPP_JOB_STOPPED
)
10006 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10007 job
->state_value
= IPP_JOB_PENDING
;
10009 else if (job
->state_value
== IPP_JOB_HELD
)
10011 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10012 IPP_TAG_KEYWORD
)) == NULL
)
10013 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10015 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10017 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10018 job
->state_value
= IPP_JOB_PENDING
;
10023 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10029 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10030 IPP_TAG_KEYWORD
)) == NULL
)
10031 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10033 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10035 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10036 job
->state_value
= IPP_JOB_HELD
;
10037 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10040 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10047 * Fill in the response info...
10050 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10053 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10056 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10058 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10060 add_job_state_reasons(con
, job
);
10062 con
->response
->request
.status
.status_code
= IPP_OK
;
10065 * Start the job if necessary...
10074 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10079 cupsd_client_t
*con
, /* I - Client connection */
10080 http_status_t status
, /* I - HTTP status code */
10081 cupsd_printer_t
*printer
) /* I - Printer, if any */
10083 ipp_attribute_t
*uri
; /* Request URI, if any */
10086 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10087 IPP_TAG_URI
)) == NULL
)
10088 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10090 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10091 "Returning HTTP %s for %s (%s) from %s",
10092 httpStatus(status
),
10093 ippOpString(con
->request
->request
.op
.operation_id
),
10094 uri
? uri
->values
[0].string
.text
: "no URI",
10095 con
->http
.hostname
);
10099 int auth_type
; /* Type of authentication required */
10102 auth_type
= CUPSD_AUTH_NONE
;
10104 if (status
== HTTP_UNAUTHORIZED
&&
10105 printer
->num_auth_info_required
> 0 &&
10106 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10108 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10109 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10110 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10113 * Creating and authenticating jobs requires Kerberos...
10116 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10121 * Use policy/location-defined authentication requirements...
10124 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10125 cupsd_location_t
*auth
; /* Pointer to authentication element */
10128 if (printer
->type
& CUPS_PRINTER_CLASS
)
10129 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10131 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10133 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10134 auth
->type
== CUPSD_AUTH_NONE
)
10135 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10137 con
->request
->request
.op
.operation_id
:
10142 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10143 auth_type
= DefaultAuthType
;
10145 auth_type
= auth
->type
;
10149 cupsdSendError(con
, status
, auth_type
);
10152 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10154 ippDelete(con
->response
);
10155 con
->response
= NULL
;
10162 * 'send_ipp_status()' - Send a status back to the IPP client.
10166 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10167 ipp_status_t status
, /* I - IPP status code */
10168 const char *message
,/* I - Status message */
10169 ...) /* I - Additional args as needed */
10171 va_list ap
; /* Pointer to additional args */
10172 char formatted
[1024]; /* Formatted errror message */
10175 va_start(ap
, message
);
10176 vsnprintf(formatted
, sizeof(formatted
),
10177 _cupsLangString(con
->language
, message
), ap
);
10180 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10181 ippOpString(con
->request
->request
.op
.operation_id
),
10182 ippErrorString(status
), formatted
);
10184 con
->response
->request
.status
.status_code
= status
;
10186 if (ippFindAttribute(con
->response
, "attributes-charset",
10187 IPP_TAG_ZERO
) == NULL
)
10188 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10189 "attributes-charset", NULL
, DefaultCharset
);
10191 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10192 IPP_TAG_ZERO
) == NULL
)
10193 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10194 "attributes-natural-language", NULL
, DefaultLanguage
);
10196 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10197 "status-message", NULL
, formatted
);
10202 * 'set_default()' - Set the default destination...
10206 set_default(cupsd_client_t
*con
, /* I - Client connection */
10207 ipp_attribute_t
*uri
) /* I - Printer URI */
10209 http_status_t status
; /* Policy status */
10210 cups_ptype_t dtype
; /* Destination type (printer/class) */
10211 cupsd_printer_t
*printer
, /* Printer */
10212 *oldprinter
; /* Old default printer */
10215 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10216 con
->http
.fd
, uri
->values
[0].string
.text
);
10219 * Is the destination valid?
10222 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10228 send_ipp_status(con
, IPP_NOT_FOUND
,
10229 _("The printer or class was not found."));
10237 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10239 send_http_error(con
, status
, NULL
);
10244 * Set it as the default...
10247 oldprinter
= DefaultPrinter
;
10248 DefaultPrinter
= printer
;
10251 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10252 "%s is no longer the default printer.", oldprinter
->name
);
10254 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10255 "%s is now the default printer.", printer
->name
);
10257 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10258 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10260 cupsdLogMessage(CUPSD_LOG_INFO
,
10261 "Default destination set to \"%s\" by \"%s\".",
10262 printer
->name
, get_username(con
));
10265 * Everything was ok, so return OK status...
10268 con
->response
->request
.status
.status_code
= IPP_OK
;
10273 * 'set_job_attrs()' - Set job attributes.
10277 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10278 ipp_attribute_t
*uri
) /* I - Job URI */
10280 ipp_attribute_t
*attr
, /* Current attribute */
10281 *attr2
; /* Job attribute */
10282 int jobid
; /* Job ID */
10283 cupsd_job_t
*job
; /* Current job */
10284 char scheme
[HTTP_MAX_URI
],
10285 /* Method portion of URI */
10286 username
[HTTP_MAX_URI
],
10287 /* Username portion of URI */
10288 host
[HTTP_MAX_URI
],
10289 /* Host portion of URI */
10290 resource
[HTTP_MAX_URI
];
10291 /* Resource portion of URI */
10292 int port
; /* Port portion of URI */
10293 int event
; /* Events? */
10294 int check_jobs
; /* Check jobs? */
10297 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10298 con
->http
.fd
, uri
->values
[0].string
.text
);
10301 * Start with "everything is OK" status...
10304 con
->response
->request
.status
.status_code
= IPP_OK
;
10307 * See if we have a job URI or a printer URI...
10310 if (!strcmp(uri
->name
, "printer-uri"))
10313 * Got a printer URI; see if we also have a job-id attribute...
10316 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10317 IPP_TAG_INTEGER
)) == NULL
)
10319 send_ipp_status(con
, IPP_BAD_REQUEST
,
10320 _("Got a printer-uri attribute but no job-id"));
10324 jobid
= attr
->values
[0].integer
;
10329 * Got a job URI; parse it to get the job ID...
10332 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10333 sizeof(scheme
), username
, sizeof(username
), host
,
10334 sizeof(host
), &port
, resource
, sizeof(resource
));
10336 if (strncmp(resource
, "/jobs/", 6))
10342 send_ipp_status(con
, IPP_BAD_REQUEST
,
10343 _("Bad job-uri attribute \"%s\""),
10344 uri
->values
[0].string
.text
);
10348 jobid
= atoi(resource
+ 6);
10352 * See if the job exists...
10355 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10358 * Nope - return a "not found" error...
10361 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10366 * See if the job has been completed...
10369 if (job
->state_value
> IPP_JOB_STOPPED
)
10372 * Return a "not-possible" error...
10375 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10376 _("Job #%d is finished and cannot be altered"), jobid
);
10381 * See if the job is owned by the requesting user...
10384 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10386 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10387 cupsdFindDest(job
->dest
));
10392 * See what the user wants to change.
10400 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10402 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10405 if (!strcmp(attr
->name
, "attributes-charset") ||
10406 !strcmp(attr
->name
, "attributes-natural-language") ||
10407 !strcmp(attr
->name
, "document-compression") ||
10408 !strcmp(attr
->name
, "document-format") ||
10409 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10410 !strcmp(attr
->name
, "job-document-access-errors") ||
10411 !strcmp(attr
->name
, "job-id") ||
10412 !strcmp(attr
->name
, "job-impressions-completed") ||
10413 !strcmp(attr
->name
, "job-k-octets") ||
10414 !strcmp(attr
->name
, "job-originating-host-name") ||
10415 !strcmp(attr
->name
, "job-originating-user-name") ||
10416 !strcmp(attr
->name
, "job-printer-up-time") ||
10417 !strcmp(attr
->name
, "job-printer-uri") ||
10418 !strcmp(attr
->name
, "job-sheets") ||
10419 !strcmp(attr
->name
, "job-state-message") ||
10420 !strcmp(attr
->name
, "job-state-reasons") ||
10421 !strcmp(attr
->name
, "job-uri") ||
10422 !strcmp(attr
->name
, "number-of-documents") ||
10423 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10424 !strcmp(attr
->name
, "output-device-assigned") ||
10425 !strncmp(attr
->name
, "date-time-at-", 13) ||
10426 !strncmp(attr
->name
, "job-k-octets", 12) ||
10427 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10428 !strncmp(attr
->name
, "time-at-", 8))
10434 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10435 _("%s cannot be changed."), attr
->name
);
10437 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10438 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10443 if (!strcmp(attr
->name
, "job-priority"))
10446 * Change the job priority...
10449 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10451 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value"));
10453 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10454 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10456 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10458 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10459 _("Job is completed and cannot be changed."));
10462 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10464 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10465 attr
->values
[0].integer
);
10466 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10469 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10470 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10473 else if (!strcmp(attr
->name
, "job-state"))
10476 * Change the job state...
10479 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10481 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value"));
10483 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10484 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10488 switch (attr
->values
[0].integer
)
10490 case IPP_JOB_PENDING
:
10491 case IPP_JOB_HELD
:
10492 if (job
->state_value
> IPP_JOB_HELD
)
10494 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10495 _("Job state cannot be changed."));
10498 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10500 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10501 attr
->values
[0].integer
);
10502 cupsdSetJobState(job
, attr
->values
[0].integer
,
10504 "Job state changed by \"%s\"", username
);
10509 case IPP_JOB_PROCESSING
:
10510 case IPP_JOB_STOPPED
:
10511 if (job
->state_value
!= attr
->values
[0].integer
)
10513 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10514 _("Job state cannot be changed."));
10519 case IPP_JOB_CANCELED
:
10520 case IPP_JOB_ABORTED
:
10521 case IPP_JOB_COMPLETED
:
10522 if (job
->state_value
> IPP_JOB_PROCESSING
)
10524 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10525 _("Job state cannot be changed."));
10528 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10530 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10531 attr
->values
[0].integer
);
10532 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10534 "Job state changed by \"%s\"", username
);
10541 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10543 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10544 IPP_TAG_ZERO
)) != NULL
)
10547 * Some other value; first free the old value...
10550 if (job
->attrs
->prev
)
10551 job
->attrs
->prev
->next
= attr2
->next
;
10553 job
->attrs
->attrs
= attr2
->next
;
10555 if (job
->attrs
->last
== attr2
)
10556 job
->attrs
->last
= job
->attrs
->prev
;
10558 _ippFreeAttr(attr2
);
10561 * Then copy the attribute...
10564 copy_attribute(job
->attrs
, attr
, 0);
10567 * See if the job-name or job-hold-until is being changed.
10570 if (!strcmp(attr
->name
, "job-hold-until"))
10572 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10573 attr
->values
[0].string
.text
);
10574 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10576 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10578 cupsdReleaseJob(job
);
10582 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10583 "Job held by \"%s\".", username
);
10585 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10588 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10591 * Delete the attribute...
10594 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10595 IPP_TAG_ZERO
)) != NULL
)
10597 if (job
->attrs
->prev
)
10598 job
->attrs
->prev
->next
= attr2
->next
;
10600 job
->attrs
->attrs
= attr2
->next
;
10602 if (attr2
== job
->attrs
->last
)
10603 job
->attrs
->last
= job
->attrs
->prev
;
10605 _ippFreeAttr(attr2
);
10607 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10613 * Add new option by copying it...
10616 copy_attribute(job
->attrs
, attr
, 0);
10618 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10627 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10630 * Send events as needed...
10633 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10634 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10635 cupsdFindDest(job
->dest
), job
,
10636 "Job priority changed by user.");
10638 if (event
& CUPSD_EVENT_JOB_STATE
)
10639 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10640 job
->state_value
== IPP_JOB_HELD
?
10641 "Job held by user." : "Job restarted by user.");
10643 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10644 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10645 "Job options changed by user.");
10648 * Start jobs if possible...
10657 * 'set_printer_attrs()' - Set printer attributes.
10661 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10662 ipp_attribute_t
*uri
) /* I - Printer */
10664 http_status_t status
; /* Policy status */
10665 cups_ptype_t dtype
; /* Destination type (printer/class) */
10666 cupsd_printer_t
*printer
; /* Printer/class */
10667 ipp_attribute_t
*attr
; /* Printer attribute */
10668 int changed
= 0; /* Was anything changed? */
10671 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10672 con
->http
.fd
, uri
->values
[0].string
.text
);
10675 * Is the destination valid?
10678 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10684 send_ipp_status(con
, IPP_NOT_FOUND
,
10685 _("The printer or class was not found."));
10693 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10695 send_http_error(con
, status
, printer
);
10700 * Return a list of attributes that can be set via Set-Printer-Attributes.
10703 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10704 IPP_TAG_TEXT
)) != NULL
)
10706 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10710 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10711 IPP_TAG_TEXT
)) != NULL
)
10713 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10718 * Update the printer attributes and return...
10723 cupsdSetPrinterAttrs(printer
);
10724 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10726 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10727 "Printer \"%s\" description or location changed by \"%s\".",
10728 printer
->name
, get_username(con
));
10730 cupsdLogMessage(CUPSD_LOG_INFO
,
10731 "Printer \"%s\" description or location changed by \"%s\".",
10732 printer
->name
, get_username(con
));
10735 con
->response
->request
.status
.status_code
= IPP_OK
;
10740 * 'set_printer_defaults()' - Set printer default options from a request.
10744 set_printer_defaults(
10745 cupsd_client_t
*con
, /* I - Client connection */
10746 cupsd_printer_t
*printer
) /* I - Printer */
10748 int i
; /* Looping var */
10749 ipp_attribute_t
*attr
; /* Current attribute */
10750 int namelen
; /* Length of attribute name */
10751 char name
[256], /* New attribute name */
10752 value
[256]; /* String version of integer attrs */
10755 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10758 * Skip non-printer attributes...
10761 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10764 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10766 if (!strcmp(attr
->name
, "job-sheets-default"))
10769 * Only allow keywords and names...
10772 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10776 * Only allow job-sheets-default to be set when running without a
10777 * system high classification level...
10780 if (Classification
)
10783 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10785 if (attr
->num_values
> 1)
10786 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10788 cupsdSetString(&printer
->job_sheets
[1], "none");
10790 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10792 cupsdFreePrinterUsers(printer
);
10794 printer
->deny_users
= 0;
10796 if (attr
->value_tag
== IPP_TAG_NAME
&&
10797 (attr
->num_values
> 1 ||
10798 strcmp(attr
->values
[0].string
.text
, "all")))
10800 for (i
= 0; i
< attr
->num_values
; i
++)
10801 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10804 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10806 cupsdFreePrinterUsers(printer
);
10808 printer
->deny_users
= 1;
10810 if (attr
->value_tag
== IPP_TAG_NAME
&&
10811 (attr
->num_values
> 1 ||
10812 strcmp(attr
->values
[0].string
.text
, "none")))
10814 for (i
= 0; i
< attr
->num_values
; i
++)
10815 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10818 else if (!strcmp(attr
->name
, "job-quota-period"))
10820 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10823 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10824 attr
->values
[0].integer
);
10825 cupsdFreeQuotas(printer
);
10827 printer
->quota_period
= attr
->values
[0].integer
;
10829 else if (!strcmp(attr
->name
, "job-k-limit"))
10831 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10834 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10835 attr
->values
[0].integer
);
10836 cupsdFreeQuotas(printer
);
10838 printer
->k_limit
= attr
->values
[0].integer
;
10840 else if (!strcmp(attr
->name
, "job-page-limit"))
10842 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10845 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10846 attr
->values
[0].integer
);
10847 cupsdFreeQuotas(printer
);
10849 printer
->page_limit
= attr
->values
[0].integer
;
10851 else if (!strcmp(attr
->name
, "printer-op-policy"))
10853 cupsd_policy_t
*p
; /* Policy */
10856 if (attr
->value_tag
!= IPP_TAG_NAME
)
10859 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10861 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10862 "Setting printer-op-policy to \"%s\"...",
10863 attr
->values
[0].string
.text
);
10864 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10865 printer
->op_policy_ptr
= p
;
10869 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10870 _("Unknown printer-op-policy \"%s\"."),
10871 attr
->values
[0].string
.text
);
10875 else if (!strcmp(attr
->name
, "printer-error-policy"))
10877 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10880 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10881 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
10882 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10883 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10884 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10886 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10887 _("Unknown printer-error-policy \"%s\"."),
10888 attr
->values
[0].string
.text
);
10892 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10893 "Setting printer-error-policy to \"%s\"...",
10894 attr
->values
[0].string
.text
);
10895 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10899 * Skip any other non-default attributes...
10902 namelen
= strlen(attr
->name
);
10903 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10904 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10908 * OK, anything else must be a user-defined default...
10911 strlcpy(name
, attr
->name
, sizeof(name
));
10912 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10914 switch (attr
->value_tag
)
10916 case IPP_TAG_DELETEATTR
:
10917 printer
->num_options
= cupsRemoveOption(name
,
10918 printer
->num_options
,
10919 &(printer
->options
));
10920 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10921 "Deleting %s", attr
->name
);
10924 case IPP_TAG_NAME
:
10925 case IPP_TAG_KEYWORD
:
10927 printer
->num_options
= cupsAddOption(name
,
10928 attr
->values
[0].string
.text
,
10929 printer
->num_options
,
10930 &(printer
->options
));
10931 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10932 "Setting %s to \"%s\"...", attr
->name
,
10933 attr
->values
[0].string
.text
);
10936 case IPP_TAG_BOOLEAN
:
10937 printer
->num_options
= cupsAddOption(name
,
10938 attr
->values
[0].boolean
?
10940 printer
->num_options
,
10941 &(printer
->options
));
10942 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10943 "Setting %s to %s...", attr
->name
,
10944 attr
->values
[0].boolean
? "true" : "false");
10947 case IPP_TAG_INTEGER
:
10948 case IPP_TAG_ENUM
:
10949 sprintf(value
, "%d", attr
->values
[0].integer
);
10950 printer
->num_options
= cupsAddOption(name
, value
,
10951 printer
->num_options
,
10952 &(printer
->options
));
10953 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10954 "Setting %s to %s...", attr
->name
, value
);
10957 case IPP_TAG_RANGE
:
10958 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10959 attr
->values
[0].range
.upper
);
10960 printer
->num_options
= cupsAddOption(name
, value
,
10961 printer
->num_options
,
10962 &(printer
->options
));
10963 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10964 "Setting %s to %s...", attr
->name
, value
);
10967 case IPP_TAG_RESOLUTION
:
10968 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10969 attr
->values
[0].resolution
.yres
,
10970 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10972 printer
->num_options
= cupsAddOption(name
, value
,
10973 printer
->num_options
,
10974 &(printer
->options
));
10975 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10976 "Setting %s to %s...", attr
->name
, value
);
10980 /* Do nothing for other values */
10988 * 'start_printer()' - Start a printer.
10992 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10993 ipp_attribute_t
*uri
) /* I - Printer URI */
10995 http_status_t status
; /* Policy status */
10996 cups_ptype_t dtype
; /* Destination type (printer/class) */
10997 cupsd_printer_t
*printer
; /* Printer data */
11000 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11001 con
->http
.fd
, uri
->values
[0].string
.text
);
11004 * Is the destination valid?
11007 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11013 send_ipp_status(con
, IPP_NOT_FOUND
,
11014 _("The printer or class was not found."));
11022 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11024 send_http_error(con
, status
, printer
);
11029 * Start the printer...
11032 printer
->state_message
[0] = '\0';
11034 cupsdStartPrinter(printer
, 1);
11036 if (dtype
& CUPS_PRINTER_CLASS
)
11037 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11038 printer
->name
, get_username(con
));
11040 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11041 printer
->name
, get_username(con
));
11046 * Everything was ok, so return OK status...
11049 con
->response
->request
.status
.status_code
= IPP_OK
;
11054 * 'stop_printer()' - Stop a printer.
11058 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11059 ipp_attribute_t
*uri
) /* I - Printer URI */
11061 http_status_t status
; /* Policy status */
11062 cups_ptype_t dtype
; /* Destination type (printer/class) */
11063 cupsd_printer_t
*printer
; /* Printer data */
11064 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11067 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11068 con
->http
.fd
, uri
->values
[0].string
.text
);
11071 * Is the destination valid?
11074 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11080 send_ipp_status(con
, IPP_NOT_FOUND
,
11081 _("The printer or class was not found."));
11089 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11091 send_http_error(con
, status
, printer
);
11096 * Stop the printer...
11099 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11100 IPP_TAG_TEXT
)) == NULL
)
11101 strcpy(printer
->state_message
, "Paused");
11104 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11105 sizeof(printer
->state_message
));
11108 cupsdStopPrinter(printer
, 1);
11110 if (dtype
& CUPS_PRINTER_CLASS
)
11111 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11112 printer
->name
, get_username(con
));
11114 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11115 printer
->name
, get_username(con
));
11118 * Everything was ok, so return OK status...
11121 con
->response
->request
.status
.status_code
= IPP_OK
;
11126 * 'url_encode_attr()' - URL-encode a string attribute.
11130 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11131 char *buffer
,/* I - String buffer */
11132 int bufsize
)/* I - Size of buffer */
11134 int i
; /* Looping var */
11135 char *bufptr
, /* Pointer into buffer */
11136 *bufend
; /* End of buffer */
11139 strlcpy(buffer
, attr
->name
, bufsize
);
11140 bufptr
= buffer
+ strlen(buffer
);
11141 bufend
= buffer
+ bufsize
- 1;
11143 for (i
= 0; i
< attr
->num_values
; i
++)
11145 if (bufptr
>= bufend
)
11153 if (bufptr
>= bufend
)
11158 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11159 bufptr
, bufend
- bufptr
+ 1);
11161 if (bufptr
>= bufend
)
11172 * 'url_encode_string()' - URL-encode a string.
11175 static char * /* O - End of string */
11176 url_encode_string(const char *s
, /* I - String */
11177 char *buffer
, /* I - String buffer */
11178 int bufsize
) /* I - Size of buffer */
11180 char *bufptr
, /* Pointer into buffer */
11181 *bufend
; /* End of buffer */
11182 static const char *hex
= "0123456789ABCDEF";
11187 bufend
= buffer
+ bufsize
- 1;
11189 while (*s
&& bufptr
< bufend
)
11191 if (*s
== ' ' || *s
== '%' || *s
== '+')
11193 if (bufptr
>= (bufend
- 2))
11197 *bufptr
++ = hex
[(*s
>> 4) & 15];
11198 *bufptr
++ = hex
[*s
& 15];
11202 else if (*s
== '\'' || *s
== '\\')
11204 if (bufptr
>= (bufend
- 1))
11221 * 'user_allowed()' - See if a user is allowed to print to a queue.
11224 static int /* O - 0 if not allowed, 1 if allowed */
11225 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11226 const char *username
) /* I - Username */
11228 int i
; /* Looping var */
11229 struct passwd
*pw
; /* User password data */
11230 char baseuser
[256], /* Base username */
11231 *baseptr
; /* Pointer to "@" in base username */
11234 if (p
->num_users
== 0)
11237 if (!strcmp(username
, "root"))
11240 if (strchr(username
, '@'))
11243 * Strip @REALM for username check...
11246 strlcpy(baseuser
, username
, sizeof(baseuser
));
11248 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11251 username
= baseuser
;
11254 pw
= getpwnam(username
);
11257 for (i
= 0; i
< p
->num_users
; i
++)
11259 if (p
->users
[i
][0] == '@')
11262 * Check group membership...
11265 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
11268 else if (p
->users
[i
][0] == '#')
11274 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
11277 else if (!strcasecmp(username
, p
->users
[i
]))
11281 return ((i
< p
->num_users
) != p
->deny_users
);
11286 * 'validate_job()' - Validate printer options and destination.
11290 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11291 ipp_attribute_t
*uri
) /* I - Printer URI */
11293 http_status_t status
; /* Policy status */
11294 ipp_attribute_t
*attr
; /* Current attribute */
11295 ipp_attribute_t
*format
; /* Document-format attribute */
11296 cups_ptype_t dtype
; /* Destination type (printer/class) */
11297 char super
[MIME_MAX_SUPER
],
11298 /* Supertype of file */
11299 type
[MIME_MAX_TYPE
];
11300 /* Subtype of file */
11301 cupsd_printer_t
*printer
; /* Printer */
11304 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11305 con
->http
.fd
, uri
->values
[0].string
.text
);
11308 * OK, see if the client is sending the document compressed - CUPS
11309 * doesn't support compression yet...
11312 if ((attr
= ippFindAttribute(con
->request
, "compression",
11313 IPP_TAG_KEYWORD
)) != NULL
&&
11314 !strcmp(attr
->values
[0].string
.text
, "none"))
11316 send_ipp_status(con
, IPP_ATTRIBUTES
,
11317 _("Unsupported compression attribute %s"),
11318 attr
->values
[0].string
.text
);
11319 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11320 "compression", NULL
, attr
->values
[0].string
.text
);
11325 * Is it a format we support?
11328 if ((format
= ippFindAttribute(con
->request
, "document-format",
11329 IPP_TAG_MIMETYPE
)) != NULL
)
11331 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11334 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
11335 format
->values
[0].string
.text
);
11339 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11340 !mimeType(MimeDatabase
, super
, type
))
11342 cupsdLogMessage(CUPSD_LOG_INFO
,
11343 "Hint: Do you have the raw file printing rules enabled?");
11344 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11345 _("Unsupported format \"%s\""),
11346 format
->values
[0].string
.text
);
11347 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11348 "document-format", NULL
, format
->values
[0].string
.text
);
11354 * Is the destination valid?
11357 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11363 send_ipp_status(con
, IPP_NOT_FOUND
,
11364 _("The printer or class was not found."));
11372 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11374 send_http_error(con
, status
, printer
);
11379 * Everything was ok, so return OK status...
11382 con
->response
->request
.status
.status_code
= IPP_OK
;
11387 * 'validate_name()' - Make sure the printer name only contains valid chars.
11390 static int /* O - 0 if name is no good, 1 if good */
11391 validate_name(const char *name
) /* I - Name to check */
11393 const char *ptr
; /* Pointer into name */
11397 * Scan the whole name...
11400 for (ptr
= name
; *ptr
; ptr
++)
11401 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11405 * All the characters are good; validate the length, too...
11408 return ((ptr
- name
) < 128);
11413 * 'validate_user()' - Validate the user for the request.
11416 static int /* O - 1 if permitted, 0 otherwise */
11417 validate_user(cupsd_job_t
*job
, /* I - Job */
11418 cupsd_client_t
*con
, /* I - Client connection */
11419 const char *owner
, /* I - Owner of job/resource */
11420 char *username
, /* O - Authenticated username */
11421 int userlen
) /* I - Length of username */
11423 cupsd_printer_t
*printer
; /* Printer for job */
11426 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11427 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11429 job
->id
, con
? con
->http
.fd
: 0,
11430 owner
? owner
: "(null)", username
, userlen
);
11433 * Validate input...
11436 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11440 * Get the best authenticated username that is available.
11443 strlcpy(username
, get_username(con
), userlen
);
11446 * Check the username against the owner...
11449 printer
= cupsdFindDest(job
->dest
);
11451 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11452 con
, owner
) == HTTP_OK
);
11457 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".