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>
114 #endif /* HAVE_LIBPAPER */
117 # include <ApplicationServices/ApplicationServices.h>
118 # include <CoreFoundation/CoreFoundation.h>
119 # ifdef HAVE_MEMBERSHIP_H
120 # include <membership.h>
121 # endif /* HAVE_MEMBERSHIP_H */
122 # ifdef HAVE_MEMBERSHIPPRIV_H
123 # include <membershipPriv.h>
125 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
126 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
127 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
128 # endif /* HAVE_MEMBERSHIPPRIV_H */
129 #endif /* __APPLE__ */
136 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
137 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
138 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
139 mime_type_t
*filetype
, int compression
);
140 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
141 mime_type_t
*filetype
);
142 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
143 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
144 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
145 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
146 static void add_printer_state_reasons(cupsd_client_t
*con
,
148 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
150 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
151 CMDeviceProfileInfo
*profile
, unsigned id
,
152 const char *name
, const char *text
,
153 const char *iccfile
);
154 static void apple_register_profiles(cupsd_printer_t
*p
);
155 static void apple_unregister_profiles(cupsd_printer_t
*p
);
156 #endif /* __APPLE__ */
157 static void apply_printer_defaults(cupsd_printer_t
*printer
,
159 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
160 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
161 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
162 static void cancel_subscription(cupsd_client_t
*con
, int id
);
163 static int check_rss_recipient(const char *recipient
);
164 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
165 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
167 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
168 ipp_tag_t group
, int quickcopy
);
169 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
171 static int copy_file(const char *from
, const char *to
);
172 static int copy_model(cupsd_client_t
*con
, const char *from
,
174 static void copy_job_attrs(cupsd_client_t
*con
,
177 static void copy_printer_attrs(cupsd_client_t
*con
,
178 cupsd_printer_t
*printer
,
180 static void copy_subscription_attrs(cupsd_client_t
*con
,
181 cupsd_subscription_t
*sub
,
183 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
184 static cups_array_t
*create_requested_array(ipp_t
*request
);
185 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
187 static void get_default(cupsd_client_t
*con
);
188 static void get_devices(cupsd_client_t
*con
);
189 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
191 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
192 static void get_notifications(cupsd_client_t
*con
);
193 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
194 static void get_ppds(cupsd_client_t
*con
);
195 static void get_printers(cupsd_client_t
*con
, int type
);
196 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
197 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
199 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
200 static const char *get_username(cupsd_client_t
*con
);
201 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
202 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
203 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
204 static int ppd_parse_line(const char *line
, char *option
, int olen
,
205 char *choice
, int clen
);
206 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
207 static void read_job_ticket(cupsd_client_t
*con
);
208 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
209 static void release_held_new_jobs(cupsd_client_t
*con
,
210 ipp_attribute_t
*uri
);
211 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
212 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
213 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
214 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
215 ipp_attribute_t
*auth_info
);
216 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
217 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
218 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
219 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
220 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
221 cupsd_printer_t
*printer
);
222 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
223 const char *message
, ...)
225 __attribute__ ((__format__ (__printf__
, 3, 4)))
226 # endif /* __GNUC__ */
228 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
229 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
230 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
231 static void set_printer_defaults(cupsd_client_t
*con
,
232 cupsd_printer_t
*printer
);
233 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
234 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
235 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
237 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
238 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
239 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
240 static int validate_name(const char *name
);
241 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
242 const char *owner
, char *username
,
247 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
250 int /* O - 1 on success, 0 on failure */
251 cupsdProcessIPPRequest(
252 cupsd_client_t
*con
) /* I - Client connection */
254 ipp_tag_t group
; /* Current group tag */
255 ipp_attribute_t
*attr
; /* Current attribute */
256 ipp_attribute_t
*charset
; /* Character set attribute */
257 ipp_attribute_t
*language
; /* Language attribute */
258 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
259 ipp_attribute_t
*username
; /* requesting-user-name attr */
260 int sub_id
; /* Subscription ID */
263 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
264 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
265 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
268 * First build an empty response message for this request...
271 con
->response
= ippNew();
273 con
->response
->request
.status
.version
[0] =
274 con
->request
->request
.op
.version
[0];
275 con
->response
->request
.status
.version
[1] =
276 con
->request
->request
.op
.version
[1];
277 con
->response
->request
.status
.request_id
=
278 con
->request
->request
.op
.request_id
;
281 * Then validate the request header and required attributes...
284 if (con
->request
->request
.any
.version
[0] != 1 &&
285 con
->request
->request
.any
.version
[0] != 2)
288 * Return an error, since we only support IPP 1.x and 2.x.
291 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
292 "%04X %s Bad request version number %d.%d",
293 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
294 con
->request
->request
.any
.version
[0],
295 con
->request
->request
.any
.version
[1]);
297 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
298 _("Bad request version number %d.%d!"),
299 con
->request
->request
.any
.version
[0],
300 con
->request
->request
.any
.version
[1]);
302 else if (con
->request
->request
.any
.request_id
< 1)
305 * Return an error, since request IDs must be between 1 and 2^31-1
308 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
309 "%04X %s Bad request ID %d",
310 IPP_BAD_REQUEST
, con
->http
.hostname
,
311 con
->request
->request
.any
.request_id
);
313 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d!"),
314 con
->request
->request
.any
.request_id
);
316 else if (!con
->request
->attrs
)
318 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
319 "%04X %s No attributes in request",
320 IPP_BAD_REQUEST
, con
->http
.hostname
);
322 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request!"));
327 * Make sure that the attributes are provided in the correct order and
328 * don't repeat groups...
331 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
334 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
337 * Out of order; return an error...
340 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
341 "%04X %s Attribute groups are out of order",
342 IPP_BAD_REQUEST
, con
->http
.hostname
);
344 send_ipp_status(con
, IPP_BAD_REQUEST
,
345 _("Attribute groups are out of order (%x < %x)!"),
346 attr
->group_tag
, group
);
350 group
= attr
->group_tag
;
355 * Then make sure that the first three attributes are:
358 * attributes-natural-language
359 * printer-uri/job-uri
362 attr
= con
->request
->attrs
;
363 if (attr
&& attr
->name
&&
364 !strcmp(attr
->name
, "attributes-charset") &&
365 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
373 if (attr
&& attr
->name
&&
374 !strcmp(attr
->name
, "attributes-natural-language") &&
375 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
380 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
381 IPP_TAG_URI
)) != NULL
)
383 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
384 IPP_TAG_URI
)) != NULL
)
386 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
387 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
392 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
393 "attributes-charset", NULL
,
394 charset
->values
[0].string
.text
);
396 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
397 "attributes-charset", NULL
, DefaultCharset
);
400 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
401 "attributes-natural-language", NULL
,
402 language
->values
[0].string
.text
);
404 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
405 "attributes-natural-language", NULL
, DefaultLanguage
);
408 strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
409 strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
412 * Bad character set...
415 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"!",
416 charset
->values
[0].string
.text
);
417 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
418 "%04X %s Unsupported attributes-charset value \"%s\"",
419 IPP_CHARSET
, con
->http
.hostname
,
420 charset
->values
[0].string
.text
);
421 send_ipp_status(con
, IPP_BAD_REQUEST
,
422 _("Unsupported character set \"%s\"!"),
423 charset
->values
[0].string
.text
);
425 else if (!charset
|| !language
||
427 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
428 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
429 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
430 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
431 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
434 * Return an error, since attributes-charset,
435 * attributes-natural-language, and printer-uri/job-uri are required
436 * for all operations.
441 cupsdLogMessage(CUPSD_LOG_ERROR
,
442 "Missing attributes-charset attribute!");
444 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
445 "%04X %s Missing attributes-charset attribute",
446 IPP_BAD_REQUEST
, con
->http
.hostname
);
451 cupsdLogMessage(CUPSD_LOG_ERROR
,
452 "Missing attributes-natural-language attribute!");
454 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
455 "%04X %s Missing attributes-natural-language attribute",
456 IPP_BAD_REQUEST
, con
->http
.hostname
);
461 cupsdLogMessage(CUPSD_LOG_ERROR
,
462 "Missing printer-uri, job-uri, or ppd-name "
465 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
466 "%04X %s Missing printer-uri, job-uri, or ppd-name "
467 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
470 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
472 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
473 cupsdLogMessage(CUPSD_LOG_DEBUG
,
474 "attr \"%s\": group_tag = %x, value_tag = %x",
475 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
478 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
480 send_ipp_status(con
, IPP_BAD_REQUEST
,
481 _("Missing required attributes!"));
486 * OK, all the checks pass so far; make sure requesting-user-name is
487 * not "root" from a remote host...
490 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
491 IPP_TAG_NAME
)) != NULL
)
494 * Check for root user...
497 if (!strcmp(username
->values
[0].string
.text
, "root") &&
498 strcasecmp(con
->http
.hostname
, "localhost") &&
499 strcmp(con
->username
, "root"))
502 * Remote unauthenticated user masquerading as local root...
505 _cupsStrFree(username
->values
[0].string
.text
);
506 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
510 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
511 IPP_TAG_INTEGER
)) != NULL
)
512 sub_id
= attr
->values
[0].integer
;
517 * Then try processing the operation...
521 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
522 ippOpString(con
->request
->request
.op
.operation_id
),
523 uri
->values
[0].string
.text
);
525 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
526 ippOpString(con
->request
->request
.op
.operation_id
));
528 switch (con
->request
->request
.op
.operation_id
)
534 case IPP_VALIDATE_JOB
:
535 validate_job(con
, uri
);
538 case IPP_CREATE_JOB
:
539 create_job(con
, uri
);
542 case IPP_SEND_DOCUMENT
:
543 send_document(con
, uri
);
546 case IPP_CANCEL_JOB
:
547 cancel_job(con
, uri
);
550 case IPP_GET_JOB_ATTRIBUTES
:
551 get_job_attrs(con
, uri
);
558 case IPP_GET_PRINTER_ATTRIBUTES
:
559 get_printer_attrs(con
, uri
);
562 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
563 get_printer_supported(con
, uri
);
570 case IPP_RELEASE_JOB
:
571 release_job(con
, uri
);
574 case IPP_RESTART_JOB
:
575 restart_job(con
, uri
);
578 case IPP_PAUSE_PRINTER
:
579 stop_printer(con
, uri
);
582 case IPP_RESUME_PRINTER
:
583 start_printer(con
, uri
);
586 case IPP_PURGE_JOBS
:
587 cancel_all_jobs(con
, uri
);
590 case IPP_SET_JOB_ATTRIBUTES
:
591 set_job_attrs(con
, uri
);
594 case IPP_SET_PRINTER_ATTRIBUTES
:
595 set_printer_attrs(con
, uri
);
598 case IPP_HOLD_NEW_JOBS
:
599 hold_new_jobs(con
, uri
);
602 case IPP_RELEASE_HELD_NEW_JOBS
:
603 release_held_new_jobs(con
, uri
);
606 case CUPS_GET_DEFAULT
:
610 case CUPS_GET_PRINTERS
:
611 get_printers(con
, 0);
614 case CUPS_GET_CLASSES
:
615 get_printers(con
, CUPS_PRINTER_CLASS
);
618 case CUPS_ADD_PRINTER
:
619 add_printer(con
, uri
);
622 case CUPS_DELETE_PRINTER
:
623 delete_printer(con
, uri
);
626 case CUPS_ADD_CLASS
:
630 case CUPS_DELETE_CLASS
:
631 delete_printer(con
, uri
);
634 case CUPS_ACCEPT_JOBS
:
635 case IPP_ENABLE_PRINTER
:
636 accept_jobs(con
, uri
);
639 case CUPS_REJECT_JOBS
:
640 case IPP_DISABLE_PRINTER
:
641 reject_jobs(con
, uri
);
644 case CUPS_SET_DEFAULT
:
645 set_default(con
, uri
);
648 case CUPS_GET_DEVICES
:
652 case CUPS_GET_DOCUMENT
:
653 get_document(con
, uri
);
668 case CUPS_AUTHENTICATE_JOB
:
669 authenticate_job(con
, uri
);
672 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
673 case IPP_CREATE_JOB_SUBSCRIPTION
:
674 create_subscription(con
, uri
);
677 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
678 get_subscription_attrs(con
, sub_id
);
681 case IPP_GET_SUBSCRIPTIONS
:
682 get_subscriptions(con
, uri
);
685 case IPP_RENEW_SUBSCRIPTION
:
686 renew_subscription(con
, sub_id
);
689 case IPP_CANCEL_SUBSCRIPTION
:
690 cancel_subscription(con
, sub_id
);
693 case IPP_GET_NOTIFICATIONS
:
694 get_notifications(con
);
698 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
699 "%04X %s Operation %04X (%s) not supported",
700 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
701 con
->request
->request
.op
.operation_id
,
702 ippOpString(con
->request
->request
.op
.operation_id
));
704 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
705 _("%s not supported!"),
707 con
->request
->request
.op
.operation_id
));
717 * Sending data from the scheduler...
720 cupsdLogMessage(con
->response
->request
.status
.status_code
721 >= IPP_BAD_REQUEST
&&
722 con
->response
->request
.status
.status_code
723 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
724 "Returning IPP %s for %s (%s) from %s",
725 ippErrorString(con
->response
->request
.status
.status_code
),
726 ippOpString(con
->request
->request
.op
.operation_id
),
727 uri
? uri
->values
[0].string
.text
: "no URI",
730 if (LogLevel
== CUPSD_LOG_DEBUG2
)
731 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
732 "cupsdProcessIPPRequest: ippLength(response)=%ld",
733 (long)ippLength(con
->response
));
735 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
737 #ifdef CUPSD_USE_CHUNKING
739 * Because older versions of CUPS (1.1.17 and older) and some IPP
740 * clients do not implement chunking properly, we cannot use
741 * chunking by default. This may become the default in future
742 * CUPS releases, or we might add a configuration directive for
746 if (con
->http
.version
== HTTP_1_1
)
748 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
751 if (cupsdFlushHeader(con
) < 0)
754 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
757 #endif /* CUPSD_USE_CHUNKING */
759 size_t length
; /* Length of response */
762 length
= ippLength(con
->response
);
764 if (con
->file
>= 0 && !con
->pipe_pid
)
766 struct stat fileinfo
; /* File information */
769 if (!fstat(con
->file
, &fileinfo
))
770 length
+= fileinfo
.st_size
;
773 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
774 CUPS_LLCAST length
) < 0)
777 if (cupsdFlushHeader(con
) < 0)
780 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
781 con
->http
.data_remaining
= length
;
783 if (con
->http
.data_remaining
<= INT_MAX
)
784 con
->http
._data_remaining
= con
->http
.data_remaining
;
786 con
->http
._data_remaining
= INT_MAX
;
789 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
790 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
793 * Tell the caller the response header was sent successfully...
801 * Tell the caller the response header could not be sent...
810 * Sending data from a subprocess like cups-deviced; tell the caller
811 * everything is A-OK so far...
820 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
823 int /* O - 0 on success, -1 on error */
824 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
826 cupsd_printer_t
*printer
; /* Destination printer or class */
827 ipp_attribute_t
*attr
; /* job-sheets attribute */
828 int kbytes
; /* Kilobytes in banner */
831 job
->pending_timeout
= 0;
834 * See if we need to add the ending sheet...
837 printer
= cupsdFindDest(job
->dest
);
838 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
841 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
842 attr
&& attr
->num_values
> 1)
848 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
849 attr
->values
[1].string
.text
);
851 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
854 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
862 * 'accept_jobs()' - Accept print jobs to a printer.
866 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
867 ipp_attribute_t
*uri
) /* I - Printer or class URI */
869 http_status_t status
; /* Policy status */
870 cups_ptype_t dtype
; /* Destination type (printer/class) */
871 cupsd_printer_t
*printer
; /* Printer data */
874 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
875 con
->http
.fd
, uri
->values
[0].string
.text
);
878 * Is the destination valid?
881 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
887 send_ipp_status(con
, IPP_NOT_FOUND
,
888 _("The printer or class was not found."));
896 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
898 send_http_error(con
, status
, printer
);
903 * Accept jobs sent to the printer...
906 printer
->accepting
= 1;
907 printer
->state_message
[0] = '\0';
909 cupsdAddPrinterHistory(printer
);
911 if (dtype
& CUPS_PRINTER_CLASS
)
913 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
915 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
916 printer
->name
, get_username(con
));
920 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
922 cupsdLogMessage(CUPSD_LOG_INFO
,
923 "Printer \"%s\" now accepting jobs (\"%s\").",
924 printer
->name
, get_username(con
));
928 * Everything was ok, so return OK status...
931 con
->response
->request
.status
.status_code
= IPP_OK
;
936 * 'add_class()' - Add a class to the system.
940 add_class(cupsd_client_t
*con
, /* I - Client connection */
941 ipp_attribute_t
*uri
) /* I - URI of class */
943 http_status_t status
; /* Policy status */
944 int i
; /* Looping var */
945 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
946 username
[HTTP_MAX_URI
], /* Username portion of URI */
947 host
[HTTP_MAX_URI
], /* Host portion of URI */
948 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
949 int port
; /* Port portion of URI */
950 cupsd_printer_t
*pclass
, /* Class */
951 *member
; /* Member printer/class */
952 cups_ptype_t dtype
; /* Destination type */
953 ipp_attribute_t
*attr
; /* Printer attribute */
954 int modify
; /* Non-zero if we just modified */
955 char newname
[IPP_MAX_NAME
]; /* New class name */
956 int need_restart_job
; /* Need to restart job? */
959 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
960 con
->http
.fd
, uri
->values
[0].string
.text
);
963 * Do we have a valid URI?
966 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
967 sizeof(scheme
), username
, sizeof(username
), host
,
968 sizeof(host
), &port
, resource
, sizeof(resource
));
971 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
974 * No, return an error...
977 send_ipp_status(con
, IPP_BAD_REQUEST
,
978 _("The printer-uri must be of the form "
979 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
984 * Do we have a valid printer name?
987 if (!validate_name(resource
+ 9))
990 * No, return an error...
993 send_ipp_status(con
, IPP_BAD_REQUEST
,
994 _("The printer-uri \"%s\" contains invalid characters."),
995 uri
->values
[0].string
.text
);
1000 * See if the class already exists; if not, create a new class...
1003 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1006 * Class doesn't exist; see if we have a printer of the same name...
1009 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
1010 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
1013 * Yes, return an error...
1016 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1017 _("A printer named \"%s\" already exists!"),
1023 * No, check the default policy and then add the class...
1026 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1028 send_http_error(con
, status
, NULL
);
1032 pclass
= cupsdAddClass(resource
+ 9);
1035 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1038 * Check the default policy, then rename the implicit class to "AnyClass"
1042 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1044 send_http_error(con
, status
, NULL
);
1048 if (ImplicitAnyClasses
)
1050 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1051 cupsdRenamePrinter(pclass
, newname
);
1054 cupsdDeletePrinter(pclass
, 1);
1057 * Add the class as a new local class...
1060 pclass
= cupsdAddClass(resource
+ 9);
1063 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1066 * Check the default policy, then rename the remote class to "Class"...
1069 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1071 send_http_error(con
, status
, NULL
);
1075 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1076 cupsdRenamePrinter(pclass
, newname
);
1079 * Add the class as a new local class...
1082 pclass
= cupsdAddClass(resource
+ 9);
1085 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1088 send_http_error(con
, status
, pclass
);
1095 * Look for attributes and copy them over as needed...
1098 need_restart_job
= 0;
1100 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1101 IPP_TAG_TEXT
)) != NULL
)
1102 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1104 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1105 IPP_TAG_TEXT
)) != NULL
)
1106 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1108 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1109 IPP_TAG_BOOLEAN
)) != NULL
)
1111 cupsdLogMessage(CUPSD_LOG_INFO
,
1112 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1113 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1115 pclass
->accepting
= attr
->values
[0].boolean
;
1116 cupsdAddPrinterHistory(pclass
);
1119 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1120 IPP_TAG_BOOLEAN
)) != NULL
)
1122 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1123 cupsdDeregisterPrinter(pclass
, 1);
1125 cupsdLogMessage(CUPSD_LOG_INFO
,
1126 "Setting %s printer-is-shared to %d (was %d.)",
1127 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1129 pclass
->shared
= attr
->values
[0].boolean
;
1132 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1133 IPP_TAG_ENUM
)) != NULL
)
1135 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1136 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1138 send_ipp_status(con
, IPP_BAD_REQUEST
,
1139 _("Attempt to set %s printer-state to bad value %d!"),
1140 pclass
->name
, attr
->values
[0].integer
);
1144 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1145 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1147 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1148 cupsdStopPrinter(pclass
, 0);
1151 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1152 need_restart_job
= 1;
1155 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1156 IPP_TAG_TEXT
)) != NULL
)
1158 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1159 sizeof(pclass
->state_message
));
1160 cupsdAddPrinterHistory(pclass
);
1162 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1163 IPP_TAG_URI
)) != NULL
)
1166 * Clear the printer array as needed...
1169 need_restart_job
= 1;
1171 if (pclass
->num_printers
> 0)
1173 free(pclass
->printers
);
1174 pclass
->num_printers
= 0;
1178 * Add each printer or class that is listed...
1181 for (i
= 0; i
< attr
->num_values
; i
++)
1184 * Search for the printer or class URI...
1187 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1193 send_ipp_status(con
, IPP_NOT_FOUND
,
1194 _("The printer or class was not found."));
1199 * Add it to the class...
1202 cupsdAddPrinterToClass(pclass
, member
);
1206 set_printer_defaults(con
, pclass
);
1208 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1209 IPP_TAG_KEYWORD
)) != NULL
)
1210 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1213 * Update the printer class attributes and return...
1216 cupsdSetPrinterAttrs(pclass
);
1217 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1219 if (need_restart_job
&& pclass
->job
)
1222 * Reset the current job to a "pending" status...
1225 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1226 "Job restarted because the class was modified.");
1229 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1233 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, pclass
, NULL
,
1234 "Class \"%s\" modified by \"%s\".", pclass
->name
,
1237 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1238 pclass
->name
, get_username(con
));
1242 cupsdAddPrinterHistory(pclass
);
1244 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, pclass
, NULL
,
1245 "New class \"%s\" added by \"%s\".", pclass
->name
,
1248 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1249 pclass
->name
, get_username(con
));
1252 con
->response
->request
.status
.status_code
= IPP_OK
;
1257 * 'add_file()' - Add a file to a job.
1260 static int /* O - 0 on success, -1 on error */
1261 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1262 cupsd_job_t
*job
, /* I - Job to add to */
1263 mime_type_t
*filetype
, /* I - Type of file */
1264 int compression
) /* I - Compression */
1266 mime_type_t
**filetypes
; /* New filetypes array... */
1267 int *compressions
; /* New compressions array... */
1270 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1271 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1272 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1273 filetype
->super
, filetype
->type
, compression
);
1276 * Add the file to the job...
1279 if (job
->num_files
== 0)
1281 compressions
= (int *)malloc(sizeof(int));
1282 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1286 compressions
= (int *)realloc(job
->compressions
,
1287 (job
->num_files
+ 1) * sizeof(int));
1288 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1289 (job
->num_files
+ 1) *
1290 sizeof(mime_type_t
*));
1293 if (!compressions
|| !filetypes
)
1295 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1296 "Job aborted because the scheduler ran out of memory.");
1299 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1300 _("Unable to allocate memory for file types!"));
1305 job
->compressions
= compressions
;
1306 job
->compressions
[job
->num_files
] = compression
;
1307 job
->filetypes
= filetypes
;
1308 job
->filetypes
[job
->num_files
] = filetype
;
1313 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1320 * 'add_job()' - Add a job to a print queue.
1323 static cupsd_job_t
* /* O - Job object */
1324 add_job(cupsd_client_t
*con
, /* I - Client connection */
1325 cupsd_printer_t
*printer
, /* I - Destination printer */
1326 mime_type_t
*filetype
) /* I - First print file type, if any */
1328 http_status_t status
; /* Policy status */
1329 ipp_attribute_t
*attr
, /* Current attribute */
1330 *auth_info
; /* auth-info attribute */
1331 const char *val
; /* Default option value */
1332 int priority
; /* Job priority */
1333 char *title
; /* Job name/title */
1334 cupsd_job_t
*job
; /* Current job */
1335 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1336 int kbytes
; /* Size of print file */
1337 int i
; /* Looping var */
1338 int lowerpagerange
; /* Page range bound */
1341 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1342 con
, con
->http
.fd
, printer
, printer
->name
,
1343 filetype
, filetype
? filetype
->super
: "none",
1344 filetype
? filetype
->type
: "none");
1347 * Check remote printing to non-shared printer...
1350 if (!printer
->shared
&&
1351 strcasecmp(con
->http
.hostname
, "localhost") &&
1352 strcasecmp(con
->http
.hostname
, ServerName
))
1354 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1355 _("The printer or class is not shared!"));
1363 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1365 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1367 send_http_error(con
, status
, printer
);
1370 else if (printer
->num_auth_info_required
== 1 &&
1371 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1374 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1378 else if (auth_info
&& !con
->http
.tls
&&
1379 !httpAddrLocalhost(con
->http
.hostaddr
))
1382 * Require encryption of auth-info over non-local connections...
1385 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1388 #endif /* HAVE_SSL */
1391 * See if the printer is accepting jobs...
1394 if (!printer
->accepting
)
1396 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1397 _("Destination \"%s\" is not accepting jobs."),
1403 * Validate job template attributes; for now just document-format,
1404 * copies, number-up, and page-ranges...
1407 if (filetype
&& printer
->filetypes
&&
1408 !cupsArrayFind(printer
->filetypes
, filetype
))
1410 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1411 /* MIME media type string */
1414 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1417 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1418 _("Unsupported format \'%s\'!"), mimetype
);
1420 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1421 "document-format", NULL
, mimetype
);
1426 if ((attr
= ippFindAttribute(con
->request
, "copies",
1427 IPP_TAG_INTEGER
)) != NULL
)
1429 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1431 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1432 attr
->values
[0].integer
);
1433 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1434 "copies", attr
->values
[0].integer
);
1439 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1440 IPP_TAG_ZERO
)) != NULL
)
1442 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1443 attr
->value_tag
!= IPP_TAG_NAME
)
1445 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type!"));
1449 if (attr
->num_values
> 2)
1451 send_ipp_status(con
, IPP_BAD_REQUEST
,
1452 _("Too many job-sheets values (%d > 2)!"),
1457 for (i
= 0; i
< attr
->num_values
; i
++)
1458 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1459 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1461 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"!"),
1462 attr
->values
[i
].string
.text
);
1467 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1468 IPP_TAG_INTEGER
)) != NULL
)
1470 if (attr
->values
[0].integer
!= 1 &&
1471 attr
->values
[0].integer
!= 2 &&
1472 attr
->values
[0].integer
!= 4 &&
1473 attr
->values
[0].integer
!= 6 &&
1474 attr
->values
[0].integer
!= 9 &&
1475 attr
->values
[0].integer
!= 16)
1477 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1478 attr
->values
[0].integer
);
1479 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1480 "number-up", attr
->values
[0].integer
);
1485 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1486 IPP_TAG_RANGE
)) != NULL
)
1488 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1490 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1491 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1493 send_ipp_status(con
, IPP_BAD_REQUEST
,
1494 _("Bad page-ranges values %d-%d."),
1495 attr
->values
[i
].range
.lower
,
1496 attr
->values
[i
].range
.upper
);
1500 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1505 * Make sure we aren't over our limit...
1508 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1511 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1513 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1514 _("Too many active jobs."));
1518 if ((i
= check_quotas(con
, printer
)) < 0)
1520 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1525 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1530 * Create the job and set things up...
1533 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1534 IPP_TAG_INTEGER
)) != NULL
)
1535 priority
= attr
->values
[0].integer
;
1538 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1539 printer
->options
)) != NULL
)
1540 priority
= atoi(val
);
1544 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1548 if ((attr
= ippFindAttribute(con
->request
, "job-name",
1549 IPP_TAG_NAME
)) != NULL
)
1550 title
= attr
->values
[0].string
.text
;
1552 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1553 title
= "Untitled");
1555 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1557 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1558 _("Unable to add job for destination \"%s\"!"),
1563 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1564 CUPS_PRINTER_REMOTE
);
1565 job
->attrs
= con
->request
;
1567 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1569 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1571 add_job_uuid(con
, job
);
1572 apply_printer_defaults(printer
, job
);
1574 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1576 if (con
->username
[0])
1578 cupsdSetString(&job
->username
, con
->username
);
1581 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1585 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1586 "add_job: requesting-user-name=\"%s\"",
1587 attr
->values
[0].string
.text
);
1589 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1592 cupsdSetString(&job
->username
, "anonymous");
1595 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1596 "job-originating-user-name", NULL
, job
->username
);
1599 attr
->group_tag
= IPP_TAG_JOB
;
1600 _cupsStrFree(attr
->name
);
1601 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1604 if (con
->username
[0] || auth_info
)
1606 save_auth_info(con
, job
, auth_info
);
1609 * Remove the auth-info attribute from the attribute data...
1613 ippDeleteAttribute(job
->attrs
, auth_info
);
1616 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1617 IPP_TAG_ZERO
)) != NULL
)
1620 * Request contains a job-originating-host-name attribute; validate it...
1623 if (attr
->value_tag
!= IPP_TAG_NAME
||
1624 attr
->num_values
!= 1 ||
1625 strcmp(con
->http
.hostname
, "localhost"))
1628 * Can't override the value if we aren't connected via localhost.
1629 * Also, we can only have 1 value and it must be a name value.
1632 switch (attr
->value_tag
)
1634 case IPP_TAG_STRING
:
1635 case IPP_TAG_TEXTLANG
:
1636 case IPP_TAG_NAMELANG
:
1639 case IPP_TAG_KEYWORD
:
1641 case IPP_TAG_URISCHEME
:
1642 case IPP_TAG_CHARSET
:
1643 case IPP_TAG_LANGUAGE
:
1644 case IPP_TAG_MIMETYPE
:
1646 * Free old strings...
1649 for (i
= 0; i
< attr
->num_values
; i
++)
1651 _cupsStrFree(attr
->values
[i
].string
.text
);
1652 attr
->values
[i
].string
.text
= NULL
;
1653 if (attr
->values
[i
].string
.charset
)
1655 _cupsStrFree(attr
->values
[i
].string
.charset
);
1656 attr
->values
[i
].string
.charset
= NULL
;
1665 * Use the default connection hostname instead...
1668 attr
->value_tag
= IPP_TAG_NAME
;
1669 attr
->num_values
= 1;
1670 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1673 attr
->group_tag
= IPP_TAG_JOB
;
1678 * No job-originating-host-name attribute, so use the hostname from
1682 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1683 "job-originating-host-name", NULL
, con
->http
.hostname
);
1686 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1688 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1689 "time-at-processing", 0);
1690 attr
->value_tag
= IPP_TAG_NOVALUE
;
1691 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1692 "time-at-completed", 0);
1693 attr
->value_tag
= IPP_TAG_NOVALUE
;
1696 * Add remaining job attributes...
1699 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1700 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1701 "job-state", IPP_JOB_STOPPED
);
1702 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1703 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1704 "job-media-sheets-completed", 0);
1705 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1707 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", 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") &&
1729 !(printer
->type
& CUPS_PRINTER_REMOTE
))
1732 * Hold job until specified time...
1735 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1737 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1738 job
->state_value
= IPP_JOB_HELD
;
1740 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1742 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1743 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1744 job
->state_value
= IPP_JOB_HELD
;
1748 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1749 job
->state_value
= IPP_JOB_PENDING
;
1752 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1756 * Add job sheets options...
1759 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1760 IPP_TAG_ZERO
)) == NULL
)
1762 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1763 "Adding default job-sheets values \"%s,%s\"...",
1764 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1766 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1768 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1769 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1772 job
->job_sheets
= attr
;
1775 * Enforce classification level if set...
1780 cupsdLogMessage(CUPSD_LOG_INFO
,
1781 "Classification=\"%s\", ClassifyOverride=%d",
1782 Classification
? Classification
: "(null)",
1785 if (ClassifyOverride
)
1787 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1788 (attr
->num_values
== 1 ||
1789 !strcmp(attr
->values
[1].string
.text
, "none")))
1792 * Force the leading banner to have the classification on it...
1795 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1797 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1798 "job-sheets=\"%s,none\", "
1799 "job-originating-user-name=\"%s\"",
1800 Classification
, job
->username
);
1802 else if (attr
->num_values
== 2 &&
1803 strcmp(attr
->values
[0].string
.text
,
1804 attr
->values
[1].string
.text
) &&
1805 strcmp(attr
->values
[0].string
.text
, "none") &&
1806 strcmp(attr
->values
[1].string
.text
, "none"))
1809 * Can't put two different security markings on the same document!
1812 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1814 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1815 "job-sheets=\"%s,%s\", "
1816 "job-originating-user-name=\"%s\"",
1817 attr
->values
[0].string
.text
,
1818 attr
->values
[1].string
.text
, job
->username
);
1820 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1821 strcmp(attr
->values
[0].string
.text
, "none") &&
1822 (attr
->num_values
== 1 ||
1823 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1824 strcmp(attr
->values
[1].string
.text
, "none"))))
1826 if (attr
->num_values
== 1)
1827 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1828 "CLASSIFICATION OVERRIDDEN "
1829 "job-sheets=\"%s\", "
1830 "job-originating-user-name=\"%s\"",
1831 attr
->values
[0].string
.text
, job
->username
);
1833 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1834 "CLASSIFICATION OVERRIDDEN "
1835 "job-sheets=\"%s,%s\",fffff "
1836 "job-originating-user-name=\"%s\"",
1837 attr
->values
[0].string
.text
,
1838 attr
->values
[1].string
.text
, job
->username
);
1841 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1842 (attr
->num_values
== 1 ||
1843 strcmp(attr
->values
[1].string
.text
, Classification
)))
1846 * Force the banner to have the classification on it...
1849 if (attr
->num_values
> 1 &&
1850 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1852 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1853 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1857 if (attr
->num_values
== 1 ||
1858 strcmp(attr
->values
[0].string
.text
, "none"))
1859 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1861 if (attr
->num_values
> 1 &&
1862 strcmp(attr
->values
[1].string
.text
, "none"))
1863 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1866 if (attr
->num_values
> 1)
1867 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1868 "CLASSIFICATION FORCED "
1869 "job-sheets=\"%s,%s\", "
1870 "job-originating-user-name=\"%s\"",
1871 attr
->values
[0].string
.text
,
1872 attr
->values
[1].string
.text
, job
->username
);
1874 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1875 "CLASSIFICATION FORCED "
1876 "job-sheets=\"%s\", "
1877 "job-originating-user-name=\"%s\"",
1878 Classification
, job
->username
);
1883 * See if we need to add the starting sheet...
1886 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1888 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1889 attr
->values
[0].string
.text
);
1891 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1893 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1894 "Aborting job because the start banner could not be "
1899 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1902 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1903 IPP_TAG_ZERO
)) != NULL
)
1907 * Fill in the response info...
1910 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1911 LocalPort
, job
->id
);
1913 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1916 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1918 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1920 add_job_state_reasons(con
, job
);
1922 con
->response
->request
.status
.status_code
= IPP_OK
;
1925 * Add any job subscriptions...
1928 add_job_subscriptions(con
, job
);
1931 * Set all but the first two attributes to the job attributes group...
1934 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1935 attr
->group_tag
= IPP_TAG_JOB
;
1938 * Fire the "job created" event...
1941 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1944 * Return the new job...
1952 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1953 * upon the job and printer state...
1957 add_job_state_reasons(
1958 cupsd_client_t
*con
, /* I - Client connection */
1959 cupsd_job_t
*job
) /* I - Job info */
1961 cupsd_printer_t
*dest
; /* Destination printer */
1964 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1965 con
, con
->http
.fd
, job
? job
->id
: 0);
1967 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1969 case IPP_JOB_PENDING
:
1970 dest
= cupsdFindDest(job
->dest
);
1972 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1973 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1974 "job-state-reasons", NULL
, "printer-stopped");
1976 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1977 "job-state-reasons", NULL
, "none");
1981 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1982 IPP_TAG_KEYWORD
) != NULL
||
1983 ippFindAttribute(job
->attrs
, "job-hold-until",
1984 IPP_TAG_NAME
) != NULL
)
1985 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1986 "job-state-reasons", NULL
, "job-hold-until-specified");
1988 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1989 "job-state-reasons", NULL
, "job-incoming");
1992 case IPP_JOB_PROCESSING
:
1993 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1994 "job-state-reasons", NULL
, "job-printing");
1997 case IPP_JOB_STOPPED
:
1998 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1999 "job-state-reasons", NULL
, "job-stopped");
2002 case IPP_JOB_CANCELED
:
2003 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2004 "job-state-reasons", NULL
, "job-canceled-by-user");
2007 case IPP_JOB_ABORTED
:
2008 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2009 "job-state-reasons", NULL
, "aborted-by-system");
2012 case IPP_JOB_COMPLETED
:
2013 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2014 "job-state-reasons", NULL
, "job-completed-successfully");
2021 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2025 add_job_subscriptions(
2026 cupsd_client_t
*con
, /* I - Client connection */
2027 cupsd_job_t
*job
) /* I - Newly created job */
2029 int i
; /* Looping var */
2030 ipp_attribute_t
*prev
, /* Previous attribute */
2031 *next
, /* Next attribute */
2032 *attr
; /* Current attribute */
2033 cupsd_subscription_t
*sub
; /* Subscription object */
2034 const char *recipient
, /* notify-recipient-uri */
2035 *pullmethod
; /* notify-pull-method */
2036 ipp_attribute_t
*user_data
; /* notify-user-data */
2037 int interval
; /* notify-time-interval */
2038 unsigned mask
; /* notify-events */
2042 * Find the first subscription group attribute; return if we have
2046 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2047 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2054 * Process the subscription attributes in the request...
2063 mask
= CUPSD_EVENT_NONE
;
2065 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2067 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2068 attr
->value_tag
== IPP_TAG_URI
)
2071 * Validate the recipient scheme against the ServerBin/notifier
2075 char notifier
[1024], /* Notifier filename */
2076 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2077 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2078 host
[HTTP_MAX_URI
], /* Host portion of URI */
2079 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2080 int port
; /* Port portion of URI */
2083 recipient
= attr
->values
[0].string
.text
;
2085 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2086 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2087 host
, sizeof(host
), &port
,
2088 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2090 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2091 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
2092 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2093 "notify-status-code", IPP_URI_SCHEME
);
2097 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2099 if (access(notifier
, X_OK
))
2101 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2102 _("notify-recipient-uri URI \"%s\" uses unknown "
2103 "scheme!"), recipient
);
2104 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2105 "notify-status-code", IPP_URI_SCHEME
);
2109 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2111 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2112 _("notify-recipient-uri URI \"%s\" is already used!"),
2114 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2115 "notify-status-code", IPP_ATTRIBUTES
);
2119 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2120 attr
->value_tag
== IPP_TAG_KEYWORD
)
2122 pullmethod
= attr
->values
[0].string
.text
;
2124 if (strcmp(pullmethod
, "ippget"))
2126 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2127 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
2128 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2129 "notify-status-code", IPP_ATTRIBUTES
);
2133 else if (!strcmp(attr
->name
, "notify-charset") &&
2134 attr
->value_tag
== IPP_TAG_CHARSET
&&
2135 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2136 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2138 send_ipp_status(con
, IPP_CHARSET
,
2139 _("Character set \"%s\" not supported!"),
2140 attr
->values
[0].string
.text
);
2143 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2144 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2145 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2147 send_ipp_status(con
, IPP_CHARSET
,
2148 _("Language \"%s\" not supported!"),
2149 attr
->values
[0].string
.text
);
2152 else if (!strcmp(attr
->name
, "notify-user-data") &&
2153 attr
->value_tag
== IPP_TAG_STRING
)
2155 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2157 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2158 _("The notify-user-data value is too large "
2159 "(%d > 63 octets)!"),
2160 attr
->values
[0].unknown
.length
);
2166 else if (!strcmp(attr
->name
, "notify-events") &&
2167 attr
->value_tag
== IPP_TAG_KEYWORD
)
2169 for (i
= 0; i
< attr
->num_values
; i
++)
2170 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2172 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2174 send_ipp_status(con
, IPP_BAD_REQUEST
,
2175 _("The notify-lease-duration attribute cannot be "
2176 "used with job subscriptions."));
2179 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2180 attr
->value_tag
== IPP_TAG_INTEGER
)
2181 interval
= attr
->values
[0].integer
;
2186 if (!recipient
&& !pullmethod
)
2189 if (mask
== CUPSD_EVENT_NONE
)
2190 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2192 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2193 recipient
, 0)) != NULL
)
2195 sub
->interval
= interval
;
2197 cupsdSetString(&sub
->owner
, job
->username
);
2201 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2202 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2203 sub
->user_data_len
);
2206 ippAddSeparator(con
->response
);
2207 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2208 "notify-subscription-id", sub
->id
);
2215 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2218 * Remove all of the subscription attributes from the job request...
2220 * TODO: Optimize this since subscription groups have to come at the
2221 * end of the request...
2224 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2228 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2229 attr
->group_tag
== IPP_TAG_ZERO
)
2232 * Free and remove this attribute...
2240 job
->attrs
->attrs
= next
;
2246 job
->attrs
->last
= prev
;
2247 job
->attrs
->current
= prev
;
2252 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2254 * See RFC 4122 for the definition of UUIDs and the format.
2258 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2259 cupsd_job_t
*job
) /* I - Job */
2261 char uuid
[1024]; /* job-uuid string */
2262 _cups_md5_state_t md5state
; /* MD5 state */
2263 unsigned char md5sum
[16]; /* MD5 digest/sum */
2267 * First see if the job already has a job-uuid attribute; if so, return...
2270 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2274 * No job-uuid attribute, so build a version 3 UUID with the local job
2275 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2276 * the ServerName, server name and port that the client connected to,
2277 * and local job ID...
2280 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2281 con
->serverport
, job
->id
);
2283 _cupsMD5Init(&md5state
);
2284 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2285 _cupsMD5Finish(&md5state
, md5sum
);
2288 * Format the UUID URI using the MD5 sum and job ID.
2291 snprintf(uuid
, sizeof(uuid
),
2292 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2293 "%02x%02x%02x%02x%02x%02x",
2294 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2295 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2296 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2297 md5sum
[14], md5sum
[15]);
2299 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2304 * 'add_printer()' - Add a printer to the system.
2308 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2309 ipp_attribute_t
*uri
) /* I - URI of printer */
2311 http_status_t status
; /* Policy status */
2312 int i
; /* Looping var */
2313 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2314 username
[HTTP_MAX_URI
], /* Username portion of URI */
2315 host
[HTTP_MAX_URI
], /* Host portion of URI */
2316 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2317 int port
; /* Port portion of URI */
2318 cupsd_printer_t
*printer
; /* Printer/class */
2319 ipp_attribute_t
*attr
; /* Printer attribute */
2320 cups_file_t
*fp
; /* Script/PPD file */
2321 char line
[1024]; /* Line from file... */
2322 char srcfile
[1024], /* Source Script/PPD file */
2323 dstfile
[1024]; /* Destination Script/PPD file */
2324 int modify
; /* Non-zero if we are modifying */
2325 char newname
[IPP_MAX_NAME
]; /* New printer name */
2326 int need_restart_job
; /* Need to restart job? */
2327 int 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...
2471 need_restart_job
= 0;
2473 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2474 IPP_TAG_TEXT
)) != NULL
)
2475 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2477 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2478 IPP_TAG_TEXT
)) != NULL
)
2479 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2483 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2484 IPP_TAG_URI
)) != NULL
)
2487 * Do we have a valid device URI?
2490 http_uri_status_t uri_status
; /* URI separation status */
2491 char old_device_uri
[1024];
2492 /* Old device URI */
2495 need_restart_job
= 1;
2497 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2498 attr
->values
[0].string
.text
,
2499 scheme
, sizeof(scheme
),
2500 username
, sizeof(username
),
2501 host
, sizeof(host
), &port
,
2502 resource
, sizeof(resource
));
2504 if (uri_status
< HTTP_URI_OK
)
2506 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"!"),
2507 attr
->values
[0].string
.text
);
2508 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2509 "add_printer: httpSeparateURI returned %d", uri_status
);
2513 if (!strcmp(scheme
, "file"))
2516 * See if the administrator has enabled file devices...
2519 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2522 * File devices are disabled and the URL is not file:/dev/null...
2525 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2526 _("File device URIs have been disabled! "
2527 "To enable, see the FileDevice directive in "
2528 "\"%s/cupsd.conf\"."),
2536 * See if the backend exists and is executable...
2539 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2540 if (access(srcfile
, X_OK
))
2543 * Could not find device in list!
2546 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\"!"),
2552 if (printer
->sanitized_device_uri
)
2553 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2554 sizeof(old_device_uri
));
2556 old_device_uri
[0] = '\0';
2558 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2560 cupsdLogMessage(CUPSD_LOG_INFO
,
2561 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2562 printer
->name
, printer
->sanitized_device_uri
,
2568 set_port_monitor
= 0;
2570 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2571 IPP_TAG_NAME
)) != NULL
)
2573 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2576 need_restart_job
= 1;
2578 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2582 for (i
= 0; i
< supported
->num_values
; i
++)
2583 if (!strcmp(supported
->values
[i
].string
.text
,
2584 attr
->values
[0].string
.text
))
2588 if (!supported
|| i
>= supported
->num_values
)
2590 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"!"),
2591 attr
->values
[0].string
.text
);
2595 cupsdLogMessage(CUPSD_LOG_INFO
,
2596 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2597 printer
->name
, attr
->values
[0].string
.text
,
2598 printer
->port_monitor
? printer
->port_monitor
: "none");
2600 if (strcmp(attr
->values
[0].string
.text
, "none"))
2601 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2603 cupsdClearString(&printer
->port_monitor
);
2605 set_port_monitor
= 1;
2608 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2609 IPP_TAG_BOOLEAN
)) != NULL
)
2611 cupsdLogMessage(CUPSD_LOG_INFO
,
2612 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2613 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2615 printer
->accepting
= attr
->values
[0].boolean
;
2616 cupsdAddPrinterHistory(printer
);
2619 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2620 IPP_TAG_BOOLEAN
)) != NULL
)
2622 if (printer
->shared
&& !attr
->values
[0].boolean
)
2623 cupsdDeregisterPrinter(printer
, 1);
2625 cupsdLogMessage(CUPSD_LOG_INFO
,
2626 "Setting %s printer-is-shared to %d (was %d.)",
2627 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2629 printer
->shared
= attr
->values
[0].boolean
;
2632 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2633 IPP_TAG_ENUM
)) != NULL
)
2635 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2636 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2638 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d!"),
2639 attr
->values
[0].integer
);
2643 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2644 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2646 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2647 cupsdStopPrinter(printer
, 0);
2650 need_restart_job
= 1;
2651 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2655 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2656 IPP_TAG_TEXT
)) != NULL
)
2658 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2659 sizeof(printer
->state_message
));
2660 cupsdAddPrinterHistory(printer
);
2663 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2664 IPP_TAG_KEYWORD
)) != NULL
)
2666 if (attr
->num_values
>
2667 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2669 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2670 _("Too many printer-state-reasons values (%d > %d)!"),
2672 (int)(sizeof(printer
->reasons
) /
2673 sizeof(printer
->reasons
[0])));
2677 for (i
= 0; i
< printer
->num_reasons
; i
++)
2678 _cupsStrFree(printer
->reasons
[i
]);
2680 printer
->num_reasons
= 0;
2681 for (i
= 0; i
< attr
->num_values
; i
++)
2683 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2686 printer
->reasons
[printer
->num_reasons
] =
2687 _cupsStrRetain(attr
->values
[i
].string
.text
);
2688 printer
->num_reasons
++;
2690 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2691 printer
->state
!= IPP_PRINTER_STOPPED
)
2693 cupsdLogMessage(CUPSD_LOG_INFO
,
2694 "Setting %s printer-state to %d (was %d.)",
2695 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2696 cupsdStopPrinter(printer
, 0);
2700 if (PrintcapFormat
== PRINTCAP_PLIST
)
2701 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2704 set_printer_defaults(con
, printer
);
2706 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2707 IPP_TAG_KEYWORD
)) != NULL
)
2708 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2711 * See if we have all required attributes...
2714 if (!printer
->device_uri
)
2715 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2718 * See if we have an interface script or PPD file attached to the request...
2723 need_restart_job
= 1;
2725 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2727 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2730 * Yes; get the first line from it...
2734 cupsFileGets(fp
, line
, sizeof(line
));
2738 * Then see what kind of file it is...
2741 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2744 if (!strncmp(line
, "*PPD-Adobe", 10))
2747 * The new file is a PPD file, so remove any old interface script
2748 * that might be lying around...
2756 * This must be an interface script, so move the file over to the
2757 * interfaces directory and make it executable...
2760 if (copy_file(srcfile
, dstfile
))
2762 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2763 _("Unable to copy interface script - %s!"),
2768 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2769 "Copied interface script successfully!");
2770 chmod(dstfile
, 0755);
2773 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2776 if (!strncmp(line
, "*PPD-Adobe", 10))
2779 * The new file is a PPD file, so move the file over to the
2780 * ppd directory and make it readable by all...
2783 if (copy_file(srcfile
, dstfile
))
2785 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2786 _("Unable to copy PPD file - %s!"),
2791 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2792 "Copied PPD file successfully!");
2793 chmod(dstfile
, 0644);
2797 * (Re)register color profiles...
2802 apple_unregister_profiles(printer
);
2803 apple_register_profiles(printer
);
2805 #endif /* __APPLE__ */
2810 * This must be an interface script, so remove any old PPD file that
2811 * may be lying around...
2818 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2819 IPP_TAG_NAME
)) != NULL
)
2821 need_restart_job
= 1;
2823 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2826 * Raw driver, remove any existing PPD or interface script files.
2829 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2833 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2843 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2847 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2850 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2852 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file!"));
2856 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2857 "Copied PPD file successfully!");
2858 chmod(dstfile
, 0644);
2862 * (Re)register color profiles...
2867 apple_unregister_profiles(printer
);
2868 apple_register_profiles(printer
);
2870 #endif /* __APPLE__ */
2875 * If we set the device URI but not the port monitor, check which port
2876 * monitor to use by default...
2879 if (set_device_uri
&& !set_port_monitor
)
2881 ppd_file_t
*ppd
; /* PPD file */
2882 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2885 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2886 sizeof(scheme
), username
, sizeof(username
), host
,
2887 sizeof(host
), &port
, resource
, sizeof(resource
));
2889 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2891 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2893 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2895 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2896 if (!strcmp(scheme
, ppdattr
->spec
))
2898 cupsdLogMessage(CUPSD_LOG_INFO
,
2899 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2900 printer
->name
, ppdattr
->value
,
2901 printer
->port_monitor
? printer
->port_monitor
2904 if (strcmp(ppdattr
->value
, "none"))
2905 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2907 cupsdClearString(&printer
->port_monitor
);
2917 * Update the printer attributes and return...
2920 cupsdSetPrinterAttrs(printer
);
2921 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2923 if (need_restart_job
&& printer
->job
)
2926 * Restart the current job...
2929 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2930 "Job restarted because the printer was modified.");
2933 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2937 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2938 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2941 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2942 printer
->name
, get_username(con
));
2946 cupsdAddPrinterHistory(printer
);
2948 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2949 "New printer \"%s\" added by \"%s\".", printer
->name
,
2952 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2953 printer
->name
, get_username(con
));
2956 con
->response
->request
.status
.status_code
= IPP_OK
;
2961 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2962 * based upon the printer state...
2966 add_printer_state_reasons(
2967 cupsd_client_t
*con
, /* I - Client connection */
2968 cupsd_printer_t
*p
) /* I - Printer info */
2970 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2971 "add_printer_state_reasons(%p[%d], %p[%s])",
2972 con
, con
->http
.fd
, p
, p
->name
);
2974 if (p
->num_reasons
== 0)
2975 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2976 "printer-state-reasons", NULL
, "none");
2978 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2979 "printer-state-reasons", p
->num_reasons
, NULL
,
2980 (const char * const *)p
->reasons
);
2985 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2986 * the specified printer or class.
2990 add_queued_job_count(
2991 cupsd_client_t
*con
, /* I - Client connection */
2992 cupsd_printer_t
*p
) /* I - Printer or class */
2994 int count
; /* Number of jobs on destination */
2997 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2998 con
, con
->http
.fd
, p
, p
->name
);
3000 count
= cupsdGetPrinterJobCount(p
->name
);
3002 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3003 "queued-job-count", count
);
3009 * 'apple_init_profile()' - Initialize a color profile.
3014 ppd_file_t
*ppd
, /* I - PPD file */
3015 cups_array_t
*languages
, /* I - Languages in the PPD file */
3016 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3017 unsigned id
, /* I - Profile ID */
3018 const char *name
, /* I - Profile name */
3019 const char *text
, /* I - Profile UI text */
3020 const char *iccfile
) /* I - ICC filename */
3022 char url
[1024]; /* URL for profile filename */
3023 CFMutableDictionaryRef dict
; /* Dictionary for name */
3024 char *language
; /* Current language */
3025 ppd_attr_t
*attr
; /* Profile attribute */
3026 CFStringRef cflang
, /* Language string */
3027 cftext
; /* Localized text */
3031 * Build the profile name dictionary...
3034 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3035 &kCFTypeDictionaryKeyCallBacks
,
3036 &kCFTypeDictionaryValueCallBacks
);
3038 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3039 kCFStringEncodingUTF8
);
3043 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
3050 * Find localized names for the color profiles...
3053 cupsArraySave(ppd
->sorted_attrs
);
3055 for (language
= (char *)cupsArrayFirst(languages
);
3057 language
= (char *)cupsArrayNext(languages
))
3061 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3063 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3066 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3068 if (attr
&& attr
->text
[0])
3070 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3071 kCFStringEncodingUTF8
);
3072 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3073 kCFStringEncodingUTF8
);
3075 if (cflang
&& cftext
)
3076 CFDictionarySetValue(dict
, cflang
, cftext
);
3086 cupsArrayRestore(ppd
->sorted_attrs
);
3090 * Fill in the profile data...
3094 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3097 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3098 profile
->profileID
= id
;
3099 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3100 profile
->profileName
= dict
;
3103 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3104 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3109 * 'apple_register_profiles()' - Register color profiles for a printer.
3113 apple_register_profiles(
3114 cupsd_printer_t
*p
) /* I - Printer */
3116 int i
; /* Looping var */
3117 char ppdfile
[1024], /* PPD filename */
3118 iccfile
[1024], /* ICC filename */
3119 selector
[PPD_MAX_NAME
];
3120 /* Profile selection string */
3121 ppd_file_t
*ppd
; /* PPD file */
3122 ppd_attr_t
*attr
, /* Profile attributes */
3123 *profileid_attr
,/* cupsProfileID attribute */
3124 *q1_attr
, /* ColorModel (or other) qualifier */
3125 *q2_attr
, /* MediaType (or other) qualifier */
3126 *q3_attr
; /* Resolution (or other) qualifier */
3127 char q_keyword
[PPD_MAX_NAME
];
3128 /* Qualifier keyword */
3129 const char *q1_choice
, /* ColorModel (or other) choice */
3130 *q2_choice
, /* MediaType (or other) choice */
3131 *q3_choice
; /* Resolution (or other) choice */
3132 const char *profile_key
; /* Profile keyword */
3133 ppd_option_t
*cm_option
; /* Color model option */
3134 ppd_choice_t
*cm_choice
; /* Color model choice */
3135 int num_profiles
; /* Number of profiles */
3136 CMError error
; /* Last error */
3137 unsigned device_id
, /* Printer device ID */
3138 profile_id
, /* Profile ID */
3139 default_profile_id
= 0;
3140 /* Default profile ID */
3141 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3142 CFStringRef printer_name
; /* Printer name string */
3143 CMDeviceScope scope
= /* Scope of the registration */
3145 kCFPreferencesAnyUser
,
3146 kCFPreferencesCurrentHost
3148 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3149 CMDeviceProfileInfo
*profile
; /* Current profile */
3150 cups_array_t
*languages
; /* Languages array */
3154 * Make sure ColorSync is available...
3157 if (CMRegisterColorDevice
== NULL
)
3161 * Try opening the PPD file for this printer...
3164 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3165 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3169 * See if we have any profiles...
3172 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3173 profile_key
= "APTiogaProfile";
3176 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3177 profile_key
= "cupsICCProfile";
3180 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3181 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3183 if (attr
->value
[0] != '/')
3184 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3187 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3189 if (access(iccfile
, 0))
3197 * If we have profiles, add them...
3200 if (num_profiles
> 0)
3202 if (profile_key
[0] == 'A')
3205 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3209 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3211 default_profile_id
= atoi(attr
->value
);
3213 q1_choice
= q2_choice
= q3_choice
= NULL
;
3218 * For CUPS PPDs, figure out the default profile selector values...
3221 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3222 attr
->value
&& attr
->value
[0])
3224 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3225 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3227 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3228 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3230 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3231 q1_choice
= q1_attr
->value
;
3235 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3236 attr
->value
&& attr
->value
[0])
3238 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3239 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3242 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3244 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3245 q2_choice
= q2_attr
->value
;
3249 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3250 attr
->value
&& attr
->value
[0])
3252 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3253 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3256 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3258 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3259 q3_choice
= q3_attr
->value
;
3265 * Build the array of profiles...
3267 * Note: This calloc actually requests slightly more memory than needed.
3270 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3272 cupsdLogMessage(CUPSD_LOG_ERROR
,
3273 "Unable to allocate memory for %d profiles!",
3279 profiles
->profileCount
= num_profiles
;
3280 languages
= _ppdGetLanguages(ppd
);
3282 for (profile
= profiles
->profiles
,
3283 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3285 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3286 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3289 * Add this profile...
3292 if (attr
->value
[0] != '/')
3293 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3296 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3298 if (access(iccfile
, 0))
3301 if (profile_key
[0] == 'c')
3303 cupsArraySave(ppd
->sorted_attrs
);
3305 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3306 attr
->spec
)) != NULL
&&
3307 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3308 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3310 profile_id
= _ppdHashName(attr
->spec
);
3312 cupsArrayRestore(ppd
->sorted_attrs
);
3315 profile_id
= atoi(attr
->spec
);
3317 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3318 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3323 * See if this is the default profile...
3326 if (!default_profile_id
)
3332 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3333 q1_choice
, q2_choice
, q3_choice
);
3334 if (!strcmp(selector
, attr
->spec
))
3335 default_profile_id
= profile_id
;
3338 if (!default_profile_id
)
3340 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3342 if (!strcmp(selector
, attr
->spec
))
3343 default_profile_id
= profile_id
;
3347 if (!default_profile_id
&& q3_choice
)
3349 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3351 if (!strcmp(selector
, attr
->spec
))
3352 default_profile_id
= profile_id
;
3355 if (!default_profile_id
)
3357 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3358 if (!strcmp(selector
, attr
->spec
))
3359 default_profile_id
= profile_id
;
3364 _ppdFreeLanguages(languages
);
3366 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3369 * Extract profiles from ColorModel option...
3372 const char *profile_name
; /* Name of generic profile */
3375 num_profiles
= cm_option
->num_choices
;
3377 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3379 cupsdLogMessage(CUPSD_LOG_ERROR
,
3380 "Unable to allocate memory for %d profiles!",
3386 profiles
->profileCount
= num_profiles
;
3388 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3389 cm_choice
= cm_option
->choices
;
3391 i
--, cm_choice
++, profile
++)
3393 if (!strcmp(cm_choice
->choice
, "Gray") ||
3394 !strcmp(cm_choice
->choice
, "Black"))
3395 profile_name
= "Gray";
3396 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3397 !strcmp(cm_choice
->choice
, "CMY"))
3398 profile_name
= "RGB";
3399 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3400 !strcmp(cm_choice
->choice
, "KCMY"))
3401 profile_name
= "CMYK";
3403 profile_name
= "DeviceN";
3405 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3406 profile_id
= _ppdHashName(selector
);
3408 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3409 cm_choice
->text
, NULL
);
3411 if (cm_choice
->marked
)
3412 default_profile_id
= profile_id
;
3418 * Use the default colorspace...
3421 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3423 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3425 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3427 cupsdLogMessage(CUPSD_LOG_ERROR
,
3428 "Unable to allocate memory for %d profiles!",
3434 profiles
->profileCount
= num_profiles
;
3436 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3437 "Gray", "Gray", NULL
);
3439 switch (ppd
->colorspace
)
3443 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3444 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3448 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3449 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3457 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3458 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3464 if (num_profiles
> 0)
3467 * Make sure we have a default profile ID...
3470 if (!default_profile_id
)
3471 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3474 * Get the device ID hash and pathelogical name dictionary.
3477 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3480 device_id
= _ppdHashName(p
->name
);
3481 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3482 &kCFTypeDictionaryKeyCallBacks
,
3483 &kCFTypeDictionaryValueCallBacks
);
3484 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3485 p
->name
, kCFStringEncodingUTF8
);
3487 if (device_name
&& printer_name
)
3489 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3492 * Register the device with ColorSync...
3495 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3496 device_name
, &scope
);
3499 * Register the profiles...
3503 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3504 default_profile_id
, profiles
);
3514 cupsdLogMessage(CUPSD_LOG_ERROR
,
3515 "Unable to register ICC color profiles for \"%s\" - %d",
3516 p
->name
, (int)error
);
3518 for (profile
= profiles
->profiles
;
3520 profile
++, num_profiles
--)
3521 CFRelease(profile
->profileName
);
3526 CFRelease(printer_name
);
3529 CFRelease(device_name
);
3537 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3542 apple_unregister_profiles(
3543 cupsd_printer_t
*p
) /* I - Printer */
3546 * Make sure ColorSync is available...
3549 if (CMUnregisterColorDevice
!= NULL
)
3550 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3552 #endif /* __APPLE__ */
3555 * 'apply_printer_defaults()' - Apply printer default options to a job.
3559 apply_printer_defaults(
3560 cupsd_printer_t
*printer
, /* I - Printer */
3561 cupsd_job_t
*job
) /* I - Job */
3563 int i
, /* Looping var */
3564 num_options
; /* Number of default options */
3565 cups_option_t
*options
, /* Default options */
3566 *option
; /* Current option */
3570 * Collect all of the default options and add the missing ones to the
3574 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3575 option
= printer
->options
;
3578 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3580 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3585 * Encode these options as attributes in the job object...
3588 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3589 cupsFreeOptions(num_options
, options
);
3594 * 'authenticate_job()' - Set job authentication info.
3598 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3599 ipp_attribute_t
*uri
) /* I - Job URI */
3601 ipp_attribute_t
*attr
, /* job-id attribute */
3602 *auth_info
; /* auth-info attribute */
3603 int jobid
; /* Job ID */
3604 cupsd_job_t
*job
; /* Current job */
3605 char scheme
[HTTP_MAX_URI
],
3606 /* Method portion of URI */
3607 username
[HTTP_MAX_URI
],
3608 /* Username portion of URI */
3610 /* Host portion of URI */
3611 resource
[HTTP_MAX_URI
];
3612 /* Resource portion of URI */
3613 int port
; /* Port portion of URI */
3616 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3617 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3620 * Start with "everything is OK" status...
3623 con
->response
->request
.status
.status_code
= IPP_OK
;
3626 * See if we have a job URI or a printer URI...
3629 if (!strcmp(uri
->name
, "printer-uri"))
3632 * Got a printer URI; see if we also have a job-id attribute...
3635 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3636 IPP_TAG_INTEGER
)) == NULL
)
3638 send_ipp_status(con
, IPP_BAD_REQUEST
,
3639 _("Got a printer-uri attribute but no job-id!"));
3643 jobid
= attr
->values
[0].integer
;
3648 * Got a job URI; parse it to get the job ID...
3651 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3652 sizeof(scheme
), username
, sizeof(username
), host
,
3653 sizeof(host
), &port
, resource
, sizeof(resource
));
3655 if (strncmp(resource
, "/jobs/", 6))
3661 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
3662 uri
->values
[0].string
.text
);
3666 jobid
= atoi(resource
+ 6);
3670 * See if the job exists...
3673 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3676 * Nope - return a "not found" error...
3679 send_ipp_status(con
, IPP_NOT_FOUND
,
3680 _("Job #%d does not exist!"), jobid
);
3685 * See if the job has been completed...
3688 if (job
->state_value
!= IPP_JOB_HELD
)
3691 * Return a "not-possible" error...
3694 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3695 _("Job #%d is not held for authentication!"),
3701 * See if we have already authenticated...
3704 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3706 if (!con
->username
[0] && !auth_info
)
3708 cupsd_printer_t
*printer
; /* Job destination */
3712 * No auth data. If we need to authenticate via Kerberos, send a
3713 * HTTP auth challenge, otherwise just return an IPP error...
3716 printer
= cupsdFindDest(job
->dest
);
3718 if (printer
&& printer
->num_auth_info_required
> 0 &&
3719 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3720 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3722 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3723 _("No authentication information provided!"));
3728 * See if the job is owned by the requesting user...
3731 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3733 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
3738 * Save the authentication information for this job...
3741 save_auth_info(con
, job
, auth_info
);
3744 * Reset the job-hold-until value to "no-hold"...
3747 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3748 IPP_TAG_KEYWORD
)) == NULL
)
3749 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3753 attr
->value_tag
= IPP_TAG_KEYWORD
;
3754 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3758 * Release the job and return...
3761 cupsdReleaseJob(job
);
3763 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3768 * 'cancel_all_jobs()' - Cancel all print jobs.
3772 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3773 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3775 http_status_t status
; /* Policy status */
3776 cups_ptype_t dtype
; /* Destination type */
3777 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3778 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3779 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3780 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3781 int port
; /* Port portion of URI */
3782 ipp_attribute_t
*attr
; /* Attribute in request */
3783 const char *username
; /* Username */
3784 int purge
; /* Purge? */
3785 cupsd_printer_t
*printer
; /* Printer */
3788 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3789 con
->http
.fd
, uri
->values
[0].string
.text
);
3792 * See if we have a printer URI...
3795 if (strcmp(uri
->name
, "printer-uri"))
3797 send_ipp_status(con
, IPP_BAD_REQUEST
,
3798 _("The printer-uri attribute is required!"));
3803 * Get the username (if any) for the jobs we want to cancel (only if
3804 * "my-jobs" is specified...
3807 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3808 IPP_TAG_BOOLEAN
)) != NULL
&&
3809 attr
->values
[0].boolean
)
3811 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3812 IPP_TAG_NAME
)) != NULL
)
3813 username
= attr
->values
[0].string
.text
;
3816 send_ipp_status(con
, IPP_BAD_REQUEST
,
3817 _("Missing requesting-user-name attribute!"));
3825 * Look for the "purge-jobs" attribute...
3828 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3829 IPP_TAG_BOOLEAN
)) != NULL
)
3830 purge
= attr
->values
[0].boolean
;
3835 * And if the destination is valid...
3838 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3844 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3845 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3846 hostname
, sizeof(hostname
), &port
,
3847 resource
, sizeof(resource
));
3849 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3850 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3852 send_ipp_status(con
, IPP_NOT_FOUND
,
3853 _("The printer or class was not found."));
3861 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3863 send_http_error(con
, status
, NULL
);
3868 * Cancel all jobs on all printers...
3871 cupsdCancelJobs(NULL
, username
, purge
);
3873 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3874 purge
? "purged" : "canceled", get_username(con
));
3882 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3885 send_http_error(con
, status
, printer
);
3890 * Cancel all of the jobs on the named printer...
3893 cupsdCancelJobs(printer
->name
, username
, purge
);
3895 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3896 printer
->name
, purge
? "purged" : "canceled",
3900 con
->response
->request
.status
.status_code
= IPP_OK
;
3905 * 'cancel_job()' - Cancel a print job.
3909 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3910 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3912 ipp_attribute_t
*attr
; /* Current attribute */
3913 int jobid
; /* Job ID */
3914 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3915 username
[HTTP_MAX_URI
], /* Username portion of URI */
3916 host
[HTTP_MAX_URI
], /* Host portion of URI */
3917 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3918 int port
; /* Port portion of URI */
3919 cupsd_job_t
*job
; /* Job information */
3920 cups_ptype_t dtype
; /* Destination type (printer/class) */
3921 cupsd_printer_t
*printer
; /* Printer data */
3922 int purge
; /* Purge the job? */
3925 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3926 con
->http
.fd
, uri
->values
[0].string
.text
);
3929 * See if we have a job URI or a printer URI...
3932 if (!strcmp(uri
->name
, "printer-uri"))
3935 * Got a printer URI; see if we also have a job-id attribute...
3938 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3939 IPP_TAG_INTEGER
)) == NULL
)
3941 send_ipp_status(con
, IPP_BAD_REQUEST
,
3942 _("Got a printer-uri attribute but no job-id!"));
3946 if ((jobid
= attr
->values
[0].integer
) == 0)
3949 * Find the current job on the specified printer...
3952 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3958 send_ipp_status(con
, IPP_NOT_FOUND
,
3959 _("The printer or class was not found."));
3964 * See if there are any pending jobs...
3967 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3969 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3970 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3971 !strcasecmp(job
->dest
, printer
->name
))
3979 * No, try stopped jobs...
3982 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3984 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3985 if (job
->state_value
== IPP_JOB_STOPPED
&&
3986 !strcasecmp(job
->dest
, printer
->name
))
3993 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s!"),
4003 * Got a job URI; parse it to get the job ID...
4006 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4007 sizeof(scheme
), username
, sizeof(username
), host
,
4008 sizeof(host
), &port
, resource
, sizeof(resource
));
4010 if (strncmp(resource
, "/jobs/", 6))
4016 send_ipp_status(con
, IPP_BAD_REQUEST
,
4017 _("Bad job-uri attribute \"%s\"!"),
4018 uri
->values
[0].string
.text
);
4022 jobid
= atoi(resource
+ 6);
4026 * Look for the "purge-job" attribute...
4029 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4030 IPP_TAG_BOOLEAN
)) != NULL
)
4031 purge
= attr
->values
[0].boolean
;
4036 * See if the job exists...
4039 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4042 * Nope - return a "not found" error...
4045 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
4050 * See if the job is owned by the requesting user...
4053 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4055 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
4060 * See if the job is already completed, canceled, or aborted; if so,
4061 * we can't cancel...
4064 if (job
->state_value
>= IPP_JOB_CANCELED
&& !purge
)
4066 switch (job
->state_value
)
4068 case IPP_JOB_CANCELED
:
4069 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4070 _("Job #%d is already canceled - can\'t cancel."),
4074 case IPP_JOB_ABORTED
:
4075 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4076 _("Job #%d is already aborted - can\'t cancel."),
4081 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4082 _("Job #%d is already completed - can\'t cancel."),
4091 * Cancel the job and return...
4094 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4095 purge
? "Job purged by \"%s\"" : "Job canceled by \"%s\"",
4100 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4103 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4106 con
->response
->request
.status
.status_code
= IPP_OK
;
4111 * 'cancel_subscription()' - Cancel a subscription.
4115 cancel_subscription(
4116 cupsd_client_t
*con
, /* I - Client connection */
4117 int sub_id
) /* I - Subscription ID */
4119 http_status_t status
; /* Policy status */
4120 cupsd_subscription_t
*sub
; /* Subscription */
4123 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4124 "cancel_subscription(con=%p[%d], sub_id=%d)",
4125 con
, con
->http
.fd
, sub_id
);
4128 * Is the subscription ID valid?
4131 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4134 * Bad subscription ID...
4137 send_ipp_status(con
, IPP_NOT_FOUND
,
4138 _("notify-subscription-id %d no good!"), sub_id
);
4146 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4148 con
, sub
->owner
)) != HTTP_OK
)
4150 send_http_error(con
, status
, sub
->dest
);
4155 * Cancel the subscription...
4158 cupsdDeleteSubscription(sub
, 1);
4160 con
->response
->request
.status
.status_code
= IPP_OK
;
4165 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4168 static int /* O - 1 if OK, 0 if not */
4169 check_rss_recipient(
4170 const char *recipient
) /* I - Recipient URI */
4172 cupsd_subscription_t
*sub
; /* Current subscription */
4175 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4177 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4181 * Compare the URIs up to the first ?...
4184 const char *r1
, *r2
;
4186 for (r1
= recipient
, r2
= sub
->recipient
;
4187 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4199 * 'check_quotas()' - Check quotas for a printer and user.
4202 static int /* O - 1 if OK, 0 if not */
4203 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4204 cupsd_printer_t
*p
) /* I - Printer or class */
4206 int i
; /* Looping var */
4207 char username
[33]; /* Username */
4208 cupsd_quota_t
*q
; /* Quota data */
4209 #ifdef HAVE_MBR_UID_TO_UUID
4211 * Use Apple membership APIs which require that all names represent
4212 * valid user account or group records accessible by the server.
4215 uuid_t usr_uuid
; /* UUID for job requesting user */
4216 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4217 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4218 int mbr_err
; /* Error from membership function */
4219 int is_member
; /* Is this user a member? */
4222 * Use standard POSIX APIs for checking users and groups...
4225 struct passwd
*pw
; /* User password data */
4226 #endif /* HAVE_MBR_UID_TO_UUID */
4229 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4230 con
, con
->http
.fd
, p
, p
->name
);
4233 * Figure out who is printing...
4236 strlcpy(username
, get_username(con
), sizeof(username
));
4239 * Check global active job limits for printers and users...
4242 if (MaxJobsPerPrinter
)
4245 * Check if there are too many pending jobs on this printer...
4248 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4250 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4259 * Check if there are too many pending jobs for this user...
4262 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4264 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4271 * Check against users...
4274 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4279 #ifdef HAVE_MBR_UID_TO_UUID
4281 * Get UUID for job requesting user...
4284 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4290 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4291 "check_quotas: UUID lookup failed for user \"%s\"",
4293 cupsdLogMessage(CUPSD_LOG_INFO
,
4294 "Denying user \"%s\" access to printer \"%s\" "
4295 "(unknown user)...",
4301 * Get UID and GID of requesting user...
4304 pw
= getpwnam(username
);
4306 #endif /* HAVE_MBR_UID_TO_UUID */
4308 for (i
= 0; i
< p
->num_users
; i
++)
4309 if (p
->users
[i
][0] == '@')
4312 * Check group membership...
4315 #ifdef HAVE_MBR_UID_TO_UUID
4316 if (p
->users
[i
][1] == '#')
4318 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4319 uuid_clear(grp_uuid
);
4321 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4325 * Invalid ACL entries are ignored for matching; just record a
4326 * warning in the log...
4329 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4330 "check_quotas: UUID lookup failed for ACL entry "
4331 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4332 cupsdLogMessage(CUPSD_LOG_WARN
,
4333 "Access control entry \"%s\" not a valid group name; "
4334 "entry ignored", p
->users
[i
]);
4337 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4341 * At this point, there should be no errors, but check anyways...
4344 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4345 "check_quotas: group \"%s\" membership check "
4346 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4351 * Stop if we found a match...
4358 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4360 #endif /* HAVE_MBR_UID_TO_UUID */
4362 #ifdef HAVE_MBR_UID_TO_UUID
4365 if (p
->users
[i
][0] == '#')
4367 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4368 uuid_clear(usr2_uuid
);
4370 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4374 * Invalid ACL entries are ignored for matching; just record a
4375 * warning in the log...
4378 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4379 "check_quotas: UUID lookup failed for ACL entry "
4380 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4381 cupsdLogMessage(CUPSD_LOG_WARN
,
4382 "Access control entry \"%s\" not a valid user name; "
4383 "entry ignored", p
->users
[i
]);
4386 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4390 else if (!strcasecmp(username
, p
->users
[i
]))
4392 #endif /* HAVE_MBR_UID_TO_UUID */
4394 if ((i
< p
->num_users
) == p
->deny_users
)
4396 cupsdLogMessage(CUPSD_LOG_INFO
,
4397 "Denying user \"%s\" access to printer \"%s\"...",
4408 if (AppleQuotas
&& (q
= cupsdFindQuota(p
, username
)) != NULL
)
4411 * TODO: Define these special page count values as constants!
4414 if (q
->page_count
== -4) /* special case: unlimited user */
4416 cupsdLogMessage(CUPSD_LOG_INFO
,
4417 "User \"%s\" request approved for printer %s (%s): "
4419 username
, p
->name
, p
->info
);
4420 q
->page_count
= 0; /* allow user to print */
4423 else if (q
->page_count
== -3) /* quota exceeded */
4425 cupsdLogMessage(CUPSD_LOG_INFO
,
4426 "User \"%s\" request denied for printer %s (%s): "
4427 "quota limit exceeded.",
4428 username
, p
->name
, p
->info
);
4429 q
->page_count
= 2; /* force quota exceeded failure */
4432 else if (q
->page_count
== -2) /* quota disabled for user */
4434 cupsdLogMessage(CUPSD_LOG_INFO
,
4435 "User \"%s\" request denied for printer %s (%s): "
4436 "printing disabled for user.",
4437 username
, p
->name
, p
->info
);
4438 q
->page_count
= 2; /* force quota exceeded failure */
4441 else if (q
->page_count
== -1) /* quota access error */
4443 cupsdLogMessage(CUPSD_LOG_INFO
,
4444 "User \"%s\" request denied for printer %s (%s): "
4445 "unable to determine quota limit.",
4446 username
, p
->name
, p
->info
);
4447 q
->page_count
= 2; /* force quota exceeded failure */
4450 else if (q
->page_count
< 0) /* user not found or other error */
4452 cupsdLogMessage(CUPSD_LOG_INFO
,
4453 "User \"%s\" request denied for printer %s (%s): "
4454 "user disabled / missing quota.",
4455 username
, p
->name
, p
->info
);
4456 q
->page_count
= 2; /* force quota exceeded failure */
4459 else /* page within user limits */
4461 q
->page_count
= 0; /* allow user to print */
4466 #endif /* __APPLE__ */
4467 if (p
->k_limit
|| p
->page_limit
)
4469 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4471 cupsdLogMessage(CUPSD_LOG_ERROR
,
4472 "Unable to allocate quota data for user \"%s\"!",
4477 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4478 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4480 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4487 * If we have gotten this far, we're done!
4495 * 'copy_attribute()' - Copy a single attribute.
4498 static ipp_attribute_t
* /* O - New attribute */
4500 ipp_t
*to
, /* O - Destination request/response */
4501 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4502 int quickcopy
) /* I - Do a quick copy? */
4504 int i
; /* Looping var */
4505 ipp_attribute_t
*toattr
; /* Destination attribute */
4508 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4509 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4510 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4513 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4516 toattr
= ippAddSeparator(to
);
4519 case IPP_TAG_INTEGER
:
4521 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4522 attr
->name
, attr
->num_values
, NULL
);
4524 for (i
= 0; i
< attr
->num_values
; i
++)
4525 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4528 case IPP_TAG_BOOLEAN
:
4529 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4530 attr
->num_values
, NULL
);
4532 for (i
= 0; i
< attr
->num_values
; i
++)
4533 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4536 case IPP_TAG_STRING
:
4539 case IPP_TAG_KEYWORD
:
4541 case IPP_TAG_URISCHEME
:
4542 case IPP_TAG_CHARSET
:
4543 case IPP_TAG_LANGUAGE
:
4544 case IPP_TAG_MIMETYPE
:
4545 toattr
= ippAddStrings(to
, attr
->group_tag
,
4546 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4547 attr
->name
, attr
->num_values
, NULL
, NULL
);
4551 for (i
= 0; i
< attr
->num_values
; i
++)
4552 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4554 else if (attr
->value_tag
& IPP_TAG_COPY
)
4556 for (i
= 0; i
< attr
->num_values
; i
++)
4557 toattr
->values
[i
].string
.text
=
4558 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4562 for (i
= 0; i
< attr
->num_values
; i
++)
4563 toattr
->values
[i
].string
.text
=
4564 _cupsStrRetain(attr
->values
[i
].string
.text
);
4569 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4570 attr
->values
[0].date
);
4573 case IPP_TAG_RESOLUTION
:
4574 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4575 attr
->num_values
, IPP_RES_PER_INCH
,
4578 for (i
= 0; i
< attr
->num_values
; i
++)
4580 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4581 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4582 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4586 case IPP_TAG_RANGE
:
4587 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4588 attr
->num_values
, NULL
, NULL
);
4590 for (i
= 0; i
< attr
->num_values
; i
++)
4592 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4593 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4597 case IPP_TAG_TEXTLANG
:
4598 case IPP_TAG_NAMELANG
:
4599 toattr
= ippAddStrings(to
, attr
->group_tag
,
4600 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4601 attr
->name
, attr
->num_values
, NULL
, NULL
);
4605 for (i
= 0; i
< attr
->num_values
; i
++)
4607 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4608 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4611 else if (attr
->value_tag
& IPP_TAG_COPY
)
4613 for (i
= 0; i
< attr
->num_values
; i
++)
4616 toattr
->values
[i
].string
.charset
=
4617 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4619 toattr
->values
[i
].string
.charset
=
4620 toattr
->values
[0].string
.charset
;
4622 toattr
->values
[i
].string
.text
=
4623 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4628 for (i
= 0; i
< attr
->num_values
; i
++)
4631 toattr
->values
[i
].string
.charset
=
4632 _cupsStrRetain(attr
->values
[i
].string
.charset
);
4634 toattr
->values
[i
].string
.charset
=
4635 toattr
->values
[0].string
.charset
;
4637 toattr
->values
[i
].string
.text
=
4638 _cupsStrRetain(attr
->values
[i
].string
.text
);
4643 case IPP_TAG_BEGIN_COLLECTION
:
4644 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4645 attr
->num_values
, NULL
);
4647 for (i
= 0; i
< attr
->num_values
; i
++)
4649 toattr
->values
[i
].collection
= ippNew();
4650 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
4651 NULL
, IPP_TAG_ZERO
, 0);
4656 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4657 attr
->name
, attr
->num_values
, NULL
);
4659 for (i
= 0; i
< attr
->num_values
; i
++)
4661 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4663 if (toattr
->values
[i
].unknown
.length
> 0)
4665 if ((toattr
->values
[i
].unknown
.data
=
4666 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4667 toattr
->values
[i
].unknown
.length
= 0;
4669 memcpy(toattr
->values
[i
].unknown
.data
,
4670 attr
->values
[i
].unknown
.data
,
4671 toattr
->values
[i
].unknown
.length
);
4674 break; /* anti-compiler-warning-code */
4682 * 'copy_attrs()' - Copy attributes from one request to another.
4686 copy_attrs(ipp_t
*to
, /* I - Destination request */
4687 ipp_t
*from
, /* I - Source request */
4688 cups_array_t
*ra
, /* I - Requested attributes */
4689 ipp_tag_t group
, /* I - Group to copy */
4690 int quickcopy
) /* I - Do a quick copy? */
4692 ipp_attribute_t
*fromattr
; /* Source attribute */
4695 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4696 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4697 to
, from
, ra
, group
, quickcopy
);
4702 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4705 * Filter attributes as needed...
4708 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4709 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4712 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4715 * Don't send collection attributes by default to IPP/1.x clients
4716 * since many do not support collections...
4719 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4720 !ra
&& to
->request
.status
.version
[0] == 1)
4723 copy_attribute(to
, fromattr
, quickcopy
);
4730 * 'copy_banner()' - Copy a banner file to the requests directory for the
4734 static int /* O - Size of banner file in kbytes */
4735 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4736 cupsd_job_t
*job
, /* I - Job information */
4737 const char *name
) /* I - Name of banner */
4739 int i
; /* Looping var */
4740 int kbytes
; /* Size of banner file in kbytes */
4741 char filename
[1024]; /* Job filename */
4742 cupsd_banner_t
*banner
; /* Pointer to banner */
4743 cups_file_t
*in
; /* Input file */
4744 cups_file_t
*out
; /* Output file */
4745 int ch
; /* Character from file */
4746 char attrname
[255], /* Name of attribute */
4747 *s
; /* Pointer into name */
4748 ipp_attribute_t
*attr
; /* Attribute */
4751 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4752 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4753 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4754 name
? name
: "(null)");
4757 * Find the banner; return if not found or "none"...
4760 if (!name
|| !strcmp(name
, "none") ||
4761 (banner
= cupsdFindBanner(name
)) == NULL
)
4765 * Open the banner and job files...
4768 if (add_file(con
, job
, banner
->filetype
, 0))
4771 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4773 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4775 cupsdLogMessage(CUPSD_LOG_ERROR
,
4776 "Unable to create banner job file %s - %s",
4777 filename
, strerror(errno
));
4782 fchmod(cupsFileNumber(out
), 0640);
4783 fchown(cupsFileNumber(out
), RunUser
, Group
);
4786 * Try the localized banner file under the subdirectory...
4789 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4791 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4794 * Convert ll-cc to ll_CC...
4798 attrname
[3] = toupper(attrname
[3] & 255);
4799 attrname
[4] = toupper(attrname
[4] & 255);
4802 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4805 if (access(filename
, 0) && strlen(attrname
) > 2)
4808 * Wasn't able to find "ll_CC" locale file; try the non-national
4809 * localization banner directory.
4814 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4818 if (access(filename
, 0))
4821 * Use the non-localized banner file.
4824 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4827 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4831 cupsdLogMessage(CUPSD_LOG_ERROR
,
4832 "Unable to open banner template file %s - %s",
4833 filename
, strerror(errno
));
4839 * Parse the file to the end...
4842 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4846 * Get an attribute name...
4849 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4850 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4852 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4862 * Ignore { followed by stuff that is not an attribute name...
4865 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4870 * See if it is defined...
4873 if (attrname
[0] == '?')
4878 if (!strcmp(s
, "printer-name"))
4880 cupsFilePuts(out
, job
->dest
);
4883 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4886 * See if we have a leading question mark...
4889 if (attrname
[0] != '?')
4892 * Nope, write to file as-is; probably a PostScript procedure...
4895 cupsFilePrintf(out
, "{%s}", attrname
);
4902 * Output value(s)...
4905 for (i
= 0; i
< attr
->num_values
; i
++)
4908 cupsFilePutChar(out
, ',');
4910 switch (attr
->value_tag
)
4912 case IPP_TAG_INTEGER
:
4914 if (!strncmp(s
, "time-at-", 8))
4916 struct timeval tv
= { attr
->values
[i
].integer
, 0 };
4917 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4920 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4923 case IPP_TAG_BOOLEAN
:
4924 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4927 case IPP_TAG_NOVALUE
:
4928 cupsFilePuts(out
, "novalue");
4931 case IPP_TAG_RANGE
:
4932 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4933 attr
->values
[i
].range
.upper
);
4936 case IPP_TAG_RESOLUTION
:
4937 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4938 attr
->values
[i
].resolution
.yres
,
4939 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4944 case IPP_TAG_STRING
:
4947 case IPP_TAG_KEYWORD
:
4948 case IPP_TAG_CHARSET
:
4949 case IPP_TAG_LANGUAGE
:
4950 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
4953 * Need to quote strings for PS banners...
4958 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4960 if (*p
== '(' || *p
== ')' || *p
== '\\')
4962 cupsFilePutChar(out
, '\\');
4963 cupsFilePutChar(out
, *p
);
4965 else if (*p
< 32 || *p
> 126)
4966 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4968 cupsFilePutChar(out
, *p
);
4972 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4976 break; /* anti-compiler-warning-code */
4980 else if (ch
== '\\') /* Quoted char */
4982 ch
= cupsFileGetChar(in
);
4984 if (ch
!= '{') /* Only do special handling for \{ */
4985 cupsFilePutChar(out
, '\\');
4987 cupsFilePutChar(out
, ch
);
4990 cupsFilePutChar(out
, ch
);
4994 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4996 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4997 IPP_TAG_INTEGER
)) != NULL
)
4998 attr
->values
[0].integer
+= kbytes
;
5007 * 'copy_file()' - Copy a PPD file or interface script...
5010 static int /* O - 0 = success, -1 = error */
5011 copy_file(const char *from
, /* I - Source file */
5012 const char *to
) /* I - Destination file */
5014 cups_file_t
*src
, /* Source file */
5015 *dst
; /* Destination file */
5016 int bytes
; /* Bytes to read/write */
5017 char buffer
[2048]; /* Copy buffer */
5020 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5023 * Open the source and destination file for a copy...
5026 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5029 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5036 * Copy the source file to the destination...
5039 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5040 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5048 * Close both files and return...
5053 return (cupsFileClose(dst
));
5058 * 'copy_model()' - Copy a PPD model file, substituting default values
5062 static int /* O - 0 = success, -1 = error */
5063 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5064 const char *from
, /* I - Source file */
5065 const char *to
) /* I - Destination file */
5067 fd_set input
; /* select() input set */
5068 struct timeval timeout
; /* select() timeout */
5069 int maxfd
; /* Max file descriptor for select() */
5070 char tempfile
[1024]; /* Temporary PPD file */
5071 int tempfd
; /* Temporary PPD file descriptor */
5072 int temppid
; /* Process ID of cups-driverd */
5073 int temppipe
[2]; /* Temporary pipes */
5074 char *argv
[4], /* Command-line arguments */
5075 *envp
[MAX_ENV
]; /* Environment */
5076 cups_file_t
*src
, /* Source file */
5077 *dst
; /* Destination file */
5078 ppd_file_t
*ppd
; /* PPD file */
5079 int bytes
, /* Bytes from pipe */
5080 total
; /* Total bytes from pipe */
5081 char buffer
[2048]; /* Copy buffer */
5082 int i
; /* Looping var */
5083 char option
[PPD_MAX_NAME
], /* Option name */
5084 choice
[PPD_MAX_NAME
]; /* Choice name */
5085 int num_defaults
; /* Number of default options */
5086 cups_option_t
*defaults
; /* Default options */
5087 char cups_protocol
[PPD_MAX_LINE
];
5088 /* cupsProtocol attribute */
5091 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5092 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5096 * Run cups-driverd to get the PPD file...
5099 argv
[0] = "cups-driverd";
5101 argv
[2] = (char *)from
;
5104 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5106 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5107 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5108 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5112 cupsdOpenPipe(temppipe
);
5114 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5115 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5117 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5118 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5129 * Wait up to 30 seconds for the PPD file to be copied...
5134 if (temppipe
[0] > CGIPipes
[0])
5135 maxfd
= temppipe
[0] + 1;
5137 maxfd
= CGIPipes
[0] + 1;
5142 * See if we have data ready...
5146 FD_SET(temppipe
[0], &input
);
5147 FD_SET(CGIPipes
[0], &input
);
5149 timeout
.tv_sec
= 30;
5150 timeout
.tv_usec
= 0;
5152 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5162 * We have timed out...
5168 if (FD_ISSET(temppipe
[0], &input
))
5171 * Read the PPD file from the pipe, and write it to the PPD file.
5174 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5176 if (write(tempfd
, buffer
, bytes
) < bytes
)
5185 if (FD_ISSET(CGIPipes
[0], &input
))
5195 * No data from cups-deviced...
5198 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
5204 * Read the source file and see what page sizes are supported...
5207 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5214 * Open the destination (if possible) and set the default options...
5219 cups_protocol
[0] = '\0';
5221 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5224 * Read all of the default lines from the old PPD...
5227 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5228 if (!strncmp(buffer
, "*Default", 8))
5231 * Add the default option...
5234 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5235 choice
, sizeof(choice
)))
5237 ppd_option_t
*ppdo
; /* PPD option */
5241 * Only add the default if the default hasn't already been
5242 * set and the choice exists in the new PPD...
5245 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5246 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5247 ppdFindChoice(ppdo
, choice
))
5248 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5252 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5253 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5257 else if (ppdPageSize(ppd
, DefaultPaperSize
))
5260 * Add the default media sizes...
5263 num_defaults
= cupsAddOption("PageSize", DefaultPaperSize
,
5264 num_defaults
, &defaults
);
5265 num_defaults
= cupsAddOption("PageRegion", DefaultPaperSize
,
5266 num_defaults
, &defaults
);
5267 num_defaults
= cupsAddOption("PaperDimension", DefaultPaperSize
,
5268 num_defaults
, &defaults
);
5269 num_defaults
= cupsAddOption("ImageableArea", DefaultPaperSize
,
5270 num_defaults
, &defaults
);
5276 * Open the source file for a copy...
5279 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5281 cupsFreeOptions(num_defaults
, defaults
);
5287 * Open the destination file for a copy...
5290 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5292 cupsFreeOptions(num_defaults
, defaults
);
5299 * Copy the source file to the destination...
5302 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5304 if (!strncmp(buffer
, "*Default", 8))
5307 * Check for an previous default option choice...
5310 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5311 choice
, sizeof(choice
)))
5313 const char *val
; /* Default option value */
5316 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5319 * Substitute the previous choice...
5322 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5327 cupsFilePrintf(dst
, "%s\n", buffer
);
5330 if (cups_protocol
[0])
5331 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5333 cupsFreeOptions(num_defaults
, defaults
);
5336 * Close both files and return...
5343 return (cupsFileClose(dst
));
5348 * 'copy_job_attrs()' - Copy job attributes.
5352 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5353 cupsd_job_t
*job
, /* I - Job */
5354 cups_array_t
*ra
) /* I - Requested attributes array */
5356 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5360 * Send the requested attributes for each job...
5363 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5364 con
->servername
, con
->serverport
, "/jobs/%d",
5367 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5368 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5369 "document-count", job
->num_files
);
5371 if (!ra
|| cupsArrayFind(ra
, "job-media-progress"))
5372 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5373 "job-media-progress", job
->progress
);
5375 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5376 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5377 "job-more-info", NULL
, job_uri
);
5379 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5380 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5381 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5382 job
->num_files
> 0);
5384 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5385 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5386 "job-printer-up-time", time(NULL
));
5388 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5389 add_job_state_reasons(con
, job
);
5391 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5392 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5393 "job-uri", NULL
, job_uri
);
5395 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5400 * 'copy_printer_attrs()' - Copy printer attributes.
5405 cupsd_client_t
*con
, /* I - Client connection */
5406 cupsd_printer_t
*printer
, /* I - Printer */
5407 cups_array_t
*ra
) /* I - Requested attributes array */
5409 char printer_uri
[HTTP_MAX_URI
];
5411 time_t curtime
; /* Current time */
5412 int i
; /* Looping var */
5413 ipp_attribute_t
*history
; /* History collection */
5417 * Copy the printer attributes to the response using requested-attributes
5418 * and document-format attributes that may be provided by the client.
5421 curtime
= time(NULL
);
5424 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
5425 printer
->recoverable
)
5426 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5427 "com.apple.print.recoverable-message", NULL
,
5428 printer
->recoverable
);
5429 #endif /* __APPLE__ */
5431 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5432 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5433 "marker-change-time", printer
->marker_time
);
5435 if (printer
->num_printers
> 0 &&
5436 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5438 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5439 cupsd_printer_t
*p2
; /* Printer in class */
5440 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5443 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5444 IPP_TAG_URI
, "member-uris",
5445 printer
->num_printers
, NULL
,
5448 for (i
= 0; i
< printer
->num_printers
; i
++)
5450 p2
= printer
->printers
[i
];
5452 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5453 IPP_TAG_URI
)) != NULL
)
5454 member_uris
->values
[i
].string
.text
=
5455 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5458 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5459 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5461 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5462 "/classes/%s" : "/printers/%s", p2
->name
);
5463 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5469 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5470 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5471 "printer-alert", NULL
, printer
->alert
);
5473 if (printer
->alert_description
&&
5474 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5475 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5476 "printer-alert-description", NULL
,
5477 printer
->alert_description
);
5479 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5480 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5481 ippTimeToDate(curtime
));
5484 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5486 if (printer
->reg_name
)
5487 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5488 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5490 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5491 "printer-dns-sd-name", 0);
5493 #endif /* HAVE_DNSSD */
5495 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5496 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5497 "printer-error-policy", NULL
, printer
->error_policy
);
5499 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
5501 static const char * const errors
[] =/* printer-error-policy-supported values */
5504 "retry-current-job",
5509 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
5510 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5511 "printer-error-policy-supported", NULL
, "retry-current-job");
5513 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5514 "printer-error-policy-supported",
5515 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
5518 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5519 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5520 printer
->accepting
);
5522 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5523 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5526 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5527 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5529 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5530 "http", NULL
, con
->servername
, con
->serverport
,
5531 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5532 "/classes/%s" : "/printers/%s", printer
->name
);
5533 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5534 "printer-more-info", NULL
, printer_uri
);
5537 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5538 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5539 "printer-op-policy", NULL
, printer
->op_policy
);
5541 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5542 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5545 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5546 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5547 "printer-state-change-time", printer
->state_time
);
5549 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5550 cupsArrayFind(ra
, "printer-state-history"))
5553 * Printer history is only sent if specifically requested, so that
5554 * older CUPS/IPP clients won't barf on the collection attributes.
5557 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5558 "printer-state-history",
5559 printer
->num_history
, NULL
);
5561 for (i
= 0; i
< printer
->num_history
; i
++)
5562 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5563 NULL
, IPP_TAG_ZERO
, 0);
5566 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5567 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5568 "printer-state-message", NULL
, printer
->state_message
);
5570 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5571 add_printer_state_reasons(con
, printer
);
5573 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5575 int type
; /* printer-type value */
5579 * Add the CUPS-specific printer-type attribute...
5582 type
= printer
->type
;
5584 if (printer
== DefaultPrinter
)
5585 type
|= CUPS_PRINTER_DEFAULT
;
5587 if (!printer
->accepting
)
5588 type
|= CUPS_PRINTER_REJECTING
;
5590 if (!printer
->shared
)
5591 type
|= CUPS_PRINTER_NOT_SHARED
;
5593 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5597 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5598 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5599 "printer-up-time", curtime
);
5601 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5602 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5604 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5605 "ipp", NULL
, con
->servername
, con
->serverport
,
5606 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5607 "/classes/%s" : "/printers/%s", printer
->name
);
5608 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5609 "printer-uri-supported", NULL
, printer_uri
);
5610 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5614 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5615 add_queued_job_count(con
, printer
);
5617 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5618 if (printer
->ppd_attrs
)
5619 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0);
5620 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5625 * 'copy_subscription_attrs()' - Copy subscription attributes.
5629 copy_subscription_attrs(
5630 cupsd_client_t
*con
, /* I - Client connection */
5631 cupsd_subscription_t
*sub
, /* I - Subscription */
5632 cups_array_t
*ra
) /* I - Requested attributes array */
5634 ipp_attribute_t
*attr
; /* Current attribute */
5635 char printer_uri
[HTTP_MAX_URI
];
5637 int count
; /* Number of events */
5638 unsigned mask
; /* Current event mask */
5639 const char *name
; /* Current event name */
5643 * Copy the subscription attributes to the response using the
5644 * requested-attributes attribute that may be provided by the client.
5647 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5649 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5652 * Simple event list...
5655 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5656 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5657 "notify-events", NULL
, name
);
5662 * Complex event list...
5665 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5666 if (sub
->mask
& mask
)
5669 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5670 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5671 "notify-events", count
, NULL
, NULL
);
5673 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5674 if (sub
->mask
& mask
)
5676 attr
->values
[count
].string
.text
=
5677 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5684 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5685 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5686 "notify-job-id", sub
->job
->id
);
5688 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5689 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5690 "notify-lease-duration", sub
->lease
);
5692 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5694 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5695 "ipp", NULL
, con
->servername
, con
->serverport
,
5696 "/printers/%s", sub
->dest
->name
);
5697 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5698 "notify-printer-uri", NULL
, printer_uri
);
5701 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5702 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5703 "notify-recipient-uri", NULL
, sub
->recipient
);
5704 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5705 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5706 "notify-pull-method", NULL
, "ippget");
5708 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5709 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5710 "notify-subscriber-user-name", NULL
, sub
->owner
);
5712 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5713 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5714 "notify-subscription-id", sub
->id
);
5716 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5717 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5718 "notify-time-interval", sub
->interval
);
5720 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5721 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5722 sub
->user_data
, sub
->user_data_len
);
5727 * 'create_job()' - Print a file to a printer or class.
5731 create_job(cupsd_client_t
*con
, /* I - Client connection */
5732 ipp_attribute_t
*uri
) /* I - Printer URI */
5734 cupsd_printer_t
*printer
; /* Printer */
5735 cupsd_job_t
*job
; /* New job */
5738 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5739 con
->http
.fd
, uri
->values
[0].string
.text
);
5742 * Is the destination valid?
5745 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5751 send_ipp_status(con
, IPP_NOT_FOUND
,
5752 _("The printer or class was not found."));
5757 * Create the job object...
5760 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5763 job
->pending_timeout
= 1;
5766 * Save and log the job...
5769 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5770 job
->dest
, job
->username
);
5775 * 'create_requested_array()' - Create an array for the requested-attributes.
5778 static cups_array_t
* /* O - Array of attributes or NULL */
5779 create_requested_array(ipp_t
*request
) /* I - IPP request */
5781 int i
; /* Looping var */
5782 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5783 cups_array_t
*ra
; /* Requested attributes array */
5784 char *value
; /* Current value */
5788 * Get the requested-attributes attribute, and return NULL if we don't
5792 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5793 IPP_TAG_KEYWORD
)) == NULL
)
5797 * If the attribute contains a single "all" keyword, return NULL...
5800 if (requested
->num_values
== 1 &&
5801 !strcmp(requested
->values
[0].string
.text
, "all"))
5805 * Create an array using "strcmp" as the comparison function...
5808 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5810 for (i
= 0; i
< requested
->num_values
; i
++)
5812 value
= requested
->values
[i
].string
.text
;
5814 if (!strcmp(value
, "job-template"))
5816 cupsArrayAdd(ra
, "copies");
5817 cupsArrayAdd(ra
, "copies-default");
5818 cupsArrayAdd(ra
, "copies-supported");
5819 cupsArrayAdd(ra
, "finishings");
5820 cupsArrayAdd(ra
, "finishings-default");
5821 cupsArrayAdd(ra
, "finishings-supported");
5822 cupsArrayAdd(ra
, "job-hold-until");
5823 cupsArrayAdd(ra
, "job-hold-until-default");
5824 cupsArrayAdd(ra
, "job-hold-until-supported");
5825 cupsArrayAdd(ra
, "job-priority");
5826 cupsArrayAdd(ra
, "job-priority-default");
5827 cupsArrayAdd(ra
, "job-priority-supported");
5828 cupsArrayAdd(ra
, "job-sheets");
5829 cupsArrayAdd(ra
, "job-sheets-default");
5830 cupsArrayAdd(ra
, "job-sheets-supported");
5831 cupsArrayAdd(ra
, "media");
5832 cupsArrayAdd(ra
, "media-default");
5833 cupsArrayAdd(ra
, "media-supported");
5834 cupsArrayAdd(ra
, "multiple-document-handling");
5835 cupsArrayAdd(ra
, "multiple-document-handling-default");
5836 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5837 cupsArrayAdd(ra
, "number-up");
5838 cupsArrayAdd(ra
, "number-up-default");
5839 cupsArrayAdd(ra
, "number-up-supported");
5840 cupsArrayAdd(ra
, "orientation-requested");
5841 cupsArrayAdd(ra
, "orientation-requested-default");
5842 cupsArrayAdd(ra
, "orientation-requested-supported");
5843 cupsArrayAdd(ra
, "page-ranges");
5844 cupsArrayAdd(ra
, "page-ranges-supported");
5845 cupsArrayAdd(ra
, "printer-resolution");
5846 cupsArrayAdd(ra
, "printer-resolution-default");
5847 cupsArrayAdd(ra
, "printer-resolution-supported");
5848 cupsArrayAdd(ra
, "print-quality");
5849 cupsArrayAdd(ra
, "print-quality-default");
5850 cupsArrayAdd(ra
, "print-quality-supported");
5851 cupsArrayAdd(ra
, "sides");
5852 cupsArrayAdd(ra
, "sides-default");
5853 cupsArrayAdd(ra
, "sides-supported");
5855 else if (!strcmp(value
, "job-description"))
5857 cupsArrayAdd(ra
, "date-time-at-completed");
5858 cupsArrayAdd(ra
, "date-time-at-creation");
5859 cupsArrayAdd(ra
, "date-time-at-processing");
5860 cupsArrayAdd(ra
, "job-detailed-status-message");
5861 cupsArrayAdd(ra
, "job-document-access-errors");
5862 cupsArrayAdd(ra
, "job-id");
5863 cupsArrayAdd(ra
, "job-impressions");
5864 cupsArrayAdd(ra
, "job-impressions-completed");
5865 cupsArrayAdd(ra
, "job-k-octets");
5866 cupsArrayAdd(ra
, "job-k-octets-processed");
5867 cupsArrayAdd(ra
, "job-media-progress");
5868 cupsArrayAdd(ra
, "job-media-sheets");
5869 cupsArrayAdd(ra
, "job-media-sheets-completed");
5870 cupsArrayAdd(ra
, "job-message-from-operator");
5871 cupsArrayAdd(ra
, "job-more-info");
5872 cupsArrayAdd(ra
, "job-name");
5873 cupsArrayAdd(ra
, "job-originating-user-name");
5874 cupsArrayAdd(ra
, "job-printer-up-time");
5875 cupsArrayAdd(ra
, "job-printer-uri");
5876 cupsArrayAdd(ra
, "job-state");
5877 cupsArrayAdd(ra
, "job-state-message");
5878 cupsArrayAdd(ra
, "job-state-reasons");
5879 cupsArrayAdd(ra
, "job-uri");
5880 cupsArrayAdd(ra
, "number-of-documents");
5881 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5882 cupsArrayAdd(ra
, "output-device-assigned");
5883 cupsArrayAdd(ra
, "time-at-completed");
5884 cupsArrayAdd(ra
, "time-at-creation");
5885 cupsArrayAdd(ra
, "time-at-processing");
5887 else if (!strcmp(value
, "printer-description"))
5889 cupsArrayAdd(ra
, "charset-configured");
5890 cupsArrayAdd(ra
, "charset-supported");
5891 cupsArrayAdd(ra
, "color-supported");
5892 cupsArrayAdd(ra
, "compression-supported");
5893 cupsArrayAdd(ra
, "document-format-default");
5894 cupsArrayAdd(ra
, "document-format-supported");
5895 cupsArrayAdd(ra
, "generated-natural-language-supported");
5896 cupsArrayAdd(ra
, "ipp-versions-supported");
5897 cupsArrayAdd(ra
, "job-impressions-supported");
5898 cupsArrayAdd(ra
, "job-k-octets-supported");
5899 cupsArrayAdd(ra
, "job-media-sheets-supported");
5900 cupsArrayAdd(ra
, "job-settable-attributes-supported");
5901 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5902 cupsArrayAdd(ra
, "multiple-operation-time-out");
5903 cupsArrayAdd(ra
, "natural-language-configured");
5904 cupsArrayAdd(ra
, "notify-attributes-supported");
5905 cupsArrayAdd(ra
, "notify-lease-duration-default");
5906 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5907 cupsArrayAdd(ra
, "notify-max-events-supported");
5908 cupsArrayAdd(ra
, "notify-events-default");
5909 cupsArrayAdd(ra
, "notify-events-supported");
5910 cupsArrayAdd(ra
, "notify-pull-method-supported");
5911 cupsArrayAdd(ra
, "notify-schemes-supported");
5912 cupsArrayAdd(ra
, "operations-supported");
5913 cupsArrayAdd(ra
, "pages-per-minute");
5914 cupsArrayAdd(ra
, "pages-per-minute-color");
5915 cupsArrayAdd(ra
, "pdl-override-supported");
5916 cupsArrayAdd(ra
, "printer-alert");
5917 cupsArrayAdd(ra
, "printer-alert-description");
5918 cupsArrayAdd(ra
, "printer-commands");
5919 cupsArrayAdd(ra
, "printer-current-time");
5920 cupsArrayAdd(ra
, "printer-driver-installer");
5921 cupsArrayAdd(ra
, "printer-dns-sd-name");
5922 cupsArrayAdd(ra
, "printer-info");
5923 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5924 cupsArrayAdd(ra
, "printer-location");
5925 cupsArrayAdd(ra
, "printer-make-and-model");
5926 cupsArrayAdd(ra
, "printer-message-from-operator");
5927 cupsArrayAdd(ra
, "printer-more-info");
5928 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5929 cupsArrayAdd(ra
, "printer-name");
5930 cupsArrayAdd(ra
, "printer-state");
5931 cupsArrayAdd(ra
, "printer-state-message");
5932 cupsArrayAdd(ra
, "printer-state-reasons");
5933 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
5934 cupsArrayAdd(ra
, "printer-type");
5935 cupsArrayAdd(ra
, "printer-up-time");
5936 cupsArrayAdd(ra
, "printer-uri-supported");
5937 cupsArrayAdd(ra
, "queued-job-count");
5938 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5939 cupsArrayAdd(ra
, "uri-authentication-supported");
5940 cupsArrayAdd(ra
, "uri-security-supported");
5942 else if (!strcmp(value
, "printer-defaults"))
5944 char *name
; /* Option name */
5947 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5949 name
= (char *)cupsArrayNext(CommonDefaults
))
5950 cupsArrayAdd(ra
, name
);
5952 else if (!strcmp(value
, "subscription-template"))
5954 cupsArrayAdd(ra
, "notify-attributes");
5955 cupsArrayAdd(ra
, "notify-charset");
5956 cupsArrayAdd(ra
, "notify-events");
5957 cupsArrayAdd(ra
, "notify-lease-duration");
5958 cupsArrayAdd(ra
, "notify-natural-language");
5959 cupsArrayAdd(ra
, "notify-pull-method");
5960 cupsArrayAdd(ra
, "notify-recipient-uri");
5961 cupsArrayAdd(ra
, "notify-time-interval");
5962 cupsArrayAdd(ra
, "notify-user-data");
5965 cupsArrayAdd(ra
, value
);
5973 * 'create_subscription()' - Create a notification subscription.
5977 create_subscription(
5978 cupsd_client_t
*con
, /* I - Client connection */
5979 ipp_attribute_t
*uri
) /* I - Printer URI */
5981 http_status_t status
; /* Policy status */
5982 int i
; /* Looping var */
5983 ipp_attribute_t
*attr
; /* Current attribute */
5984 cups_ptype_t dtype
; /* Destination type (printer/class) */
5985 char scheme
[HTTP_MAX_URI
],
5986 /* Scheme portion of URI */
5987 userpass
[HTTP_MAX_URI
],
5988 /* Username portion of URI */
5990 /* Host portion of URI */
5991 resource
[HTTP_MAX_URI
];
5992 /* Resource portion of URI */
5993 int port
; /* Port portion of URI */
5994 cupsd_printer_t
*printer
; /* Printer/class */
5995 cupsd_job_t
*job
; /* Job */
5996 int jobid
; /* Job ID */
5997 cupsd_subscription_t
*sub
; /* Subscription object */
5998 const char *username
, /* requesting-user-name or
5999 authenticated username */
6000 *recipient
, /* notify-recipient-uri */
6001 *pullmethod
; /* notify-pull-method */
6002 ipp_attribute_t
*user_data
; /* notify-user-data */
6003 int interval
, /* notify-time-interval */
6004 lease
; /* notify-lease-duration */
6005 unsigned mask
; /* notify-events */
6006 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6007 *notify_lease
; /* notify-lease-duration(-default) */
6011 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6013 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6014 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6015 attr
->value_tag
, attr
->name
);
6017 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6022 * Is the destination valid?
6025 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6026 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6027 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6029 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6030 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6031 sizeof(host
), &port
, resource
, sizeof(resource
));
6033 if (!strcmp(resource
, "/"))
6035 dtype
= (cups_ptype_t
)0;
6038 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6040 dtype
= (cups_ptype_t
)0;
6043 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6045 dtype
= CUPS_PRINTER_CLASS
;
6048 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6054 send_ipp_status(con
, IPP_NOT_FOUND
,
6055 _("The printer or class was not found."));
6065 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6068 send_http_error(con
, status
, printer
);
6072 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6074 send_http_error(con
, status
, NULL
);
6079 * Get the user that is requesting the subscription...
6082 username
= get_username(con
);
6085 * Find the first subscription group attribute; return if we have
6089 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6090 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6095 send_ipp_status(con
, IPP_BAD_REQUEST
,
6096 _("No subscription attributes in request!"));
6101 * Process the subscription attributes in the request...
6104 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6112 lease
= DefaultLeaseDuration
;
6114 mask
= CUPSD_EVENT_NONE
;
6118 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6120 notify_lease
= ippFindAttribute(printer
->attrs
,
6121 "notify-lease-duration-default",
6125 lease
= notify_lease
->values
[0].integer
;
6129 notify_events
= NULL
;
6130 notify_lease
= NULL
;
6133 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6135 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6136 attr
->value_tag
== IPP_TAG_URI
)
6139 * Validate the recipient scheme against the ServerBin/notifier
6143 char notifier
[1024]; /* Notifier filename */
6146 recipient
= attr
->values
[0].string
.text
;
6148 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6149 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6150 host
, sizeof(host
), &port
,
6151 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6153 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6154 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
6155 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6156 "notify-status-code", IPP_URI_SCHEME
);
6160 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6162 if (access(notifier
, X_OK
))
6164 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6165 _("notify-recipient-uri URI \"%s\" uses unknown "
6166 "scheme!"), recipient
);
6167 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6168 "notify-status-code", IPP_URI_SCHEME
);
6172 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6174 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6175 _("notify-recipient-uri URI \"%s\" is already used!"),
6177 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6178 "notify-status-code", IPP_ATTRIBUTES
);
6182 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6183 attr
->value_tag
== IPP_TAG_KEYWORD
)
6185 pullmethod
= attr
->values
[0].string
.text
;
6187 if (strcmp(pullmethod
, "ippget"))
6189 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6190 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
6191 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6192 "notify-status-code", IPP_ATTRIBUTES
);
6196 else if (!strcmp(attr
->name
, "notify-charset") &&
6197 attr
->value_tag
== IPP_TAG_CHARSET
&&
6198 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6199 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6201 send_ipp_status(con
, IPP_CHARSET
,
6202 _("Character set \"%s\" not supported!"),
6203 attr
->values
[0].string
.text
);
6206 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6207 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6208 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6210 send_ipp_status(con
, IPP_CHARSET
,
6211 _("Language \"%s\" not supported!"),
6212 attr
->values
[0].string
.text
);
6215 else if (!strcmp(attr
->name
, "notify-user-data") &&
6216 attr
->value_tag
== IPP_TAG_STRING
)
6218 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6220 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6221 _("The notify-user-data value is too large "
6222 "(%d > 63 octets)!"),
6223 attr
->values
[0].unknown
.length
);
6229 else if (!strcmp(attr
->name
, "notify-events") &&
6230 attr
->value_tag
== IPP_TAG_KEYWORD
)
6231 notify_events
= attr
;
6232 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6233 attr
->value_tag
== IPP_TAG_INTEGER
)
6234 lease
= attr
->values
[0].integer
;
6235 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6236 attr
->value_tag
== IPP_TAG_INTEGER
)
6237 interval
= attr
->values
[0].integer
;
6238 else if (!strcmp(attr
->name
, "notify-job-id") &&
6239 attr
->value_tag
== IPP_TAG_INTEGER
)
6240 jobid
= attr
->values
[0].integer
;
6247 for (i
= 0; i
< notify_events
->num_values
; i
++)
6248 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6252 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6254 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6255 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6256 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6258 if (!recipient
&& !pullmethod
)
6261 if (mask
== CUPSD_EVENT_NONE
)
6264 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6266 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6269 send_ipp_status(con
, IPP_BAD_REQUEST
,
6270 _("notify-events not specified!"));
6275 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6277 cupsdLogMessage(CUPSD_LOG_INFO
,
6278 "create_subscription: Limiting notify-lease-duration to "
6281 lease
= MaxLeaseDuration
;
6286 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6288 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
6295 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6297 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6298 _("There are too many subscriptions."));
6303 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6306 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6307 "Added subscription %d for printer \"%s\"",
6308 sub
->id
, printer
->name
);
6310 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6313 sub
->interval
= interval
;
6315 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6317 cupsdSetString(&sub
->owner
, username
);
6321 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6322 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6323 sub
->user_data_len
);
6326 ippAddSeparator(con
->response
);
6327 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6328 "notify-subscription-id", sub
->id
);
6330 con
->response
->request
.status
.status_code
= IPP_OK
;
6336 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6341 * 'delete_printer()' - Remove a printer or class from the system.
6345 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6346 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6348 http_status_t status
; /* Policy status */
6349 cups_ptype_t dtype
; /* Destination type (printer/class) */
6350 cupsd_printer_t
*printer
; /* Printer/class */
6351 char filename
[1024]; /* Script/PPD filename */
6354 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6355 con
->http
.fd
, uri
->values
[0].string
.text
);
6358 * Do we have a valid URI?
6361 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6367 send_ipp_status(con
, IPP_NOT_FOUND
,
6368 _("The printer or class was not found."));
6376 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6378 send_http_error(con
, status
, NULL
);
6383 * Remove old jobs...
6386 cupsdCancelJobs(printer
->name
, NULL
, 1);
6389 * Remove old subscriptions and send a "deleted printer" event...
6392 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6393 "%s \"%s\" deleted by \"%s\".",
6394 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6395 printer
->name
, get_username(con
));
6397 cupsdExpireSubscriptions(printer
, NULL
);
6400 * Remove any old PPD or script files...
6403 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6407 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6411 snprintf(filename
, sizeof(filename
), "%s/%s.ipp", CacheDir
, printer
->name
);
6416 * Unregister color profiles...
6419 apple_unregister_profiles(printer
);
6420 #endif /* __APPLE__ */
6422 if (dtype
& CUPS_PRINTER_CLASS
)
6424 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6425 printer
->name
, get_username(con
));
6427 cupsdDeletePrinter(printer
, 0);
6428 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6432 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6433 printer
->name
, get_username(con
));
6435 cupsdDeletePrinter(printer
, 0);
6436 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6439 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6442 * Return with no errors...
6445 con
->response
->request
.status
.status_code
= IPP_OK
;
6450 * 'get_default()' - Get the default destination.
6454 get_default(cupsd_client_t
*con
) /* I - Client connection */
6456 http_status_t status
; /* Policy status */
6457 cups_array_t
*ra
; /* Requested attributes array */
6460 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6466 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6468 send_http_error(con
, status
, NULL
);
6474 ra
= create_requested_array(con
->request
);
6476 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6478 cupsArrayDelete(ra
);
6480 con
->response
->request
.status
.status_code
= IPP_OK
;
6483 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6488 * 'get_devices()' - Get the list of available devices on the local system.
6492 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6494 http_status_t status
; /* Policy status */
6495 ipp_attribute_t
*limit
, /* limit attribute */
6496 *timeout
, /* timeout attribute */
6497 *requested
, /* requested-attributes attribute */
6498 *exclude
, /* exclude-schemes attribute */
6499 *include
; /* include-schemes attribute */
6500 char command
[1024], /* cups-deviced command */
6501 options
[2048], /* Options to pass to command */
6503 /* String for requested attributes */
6505 /* String for excluded schemes */
6507 /* String for included schemes */
6510 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6516 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6518 send_http_error(con
, status
, NULL
);
6523 * Run cups-deviced command with the given options...
6526 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6527 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6528 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6530 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6531 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6534 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6536 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6539 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6541 exclude_str
[0] = '\0';
6544 url_encode_attr(include
, include_str
, sizeof(include_str
));
6546 include_str
[0] = '\0';
6548 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6549 snprintf(options
, sizeof(options
),
6550 "%d+%d+%d+%d+%s%s%s%s%s",
6551 con
->request
->request
.op
.request_id
,
6552 limit
? limit
->values
[0].integer
: 0,
6553 timeout
? timeout
->values
[0].integer
: 10,
6556 exclude_str
[0] ? "%20" : "", exclude_str
,
6557 include_str
[0] ? "%20" : "", include_str
);
6559 if (cupsdSendCommand(con
, command
, options
, 1))
6562 * Command started successfully, don't send an IPP response here...
6565 ippDelete(con
->response
);
6566 con
->response
= NULL
;
6571 * Command failed, return "internal error" so the user knows something
6575 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6576 _("cups-deviced failed to execute."));
6582 * 'get_document()' - Get a copy of a job file.
6586 get_document(cupsd_client_t
*con
, /* I - Client connection */
6587 ipp_attribute_t
*uri
) /* I - Job URI */
6589 http_status_t status
; /* Policy status */
6590 ipp_attribute_t
*attr
; /* Current attribute */
6591 int jobid
; /* Job ID */
6592 int docnum
; /* Document number */
6593 cupsd_job_t
*job
; /* Current job */
6594 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6595 username
[HTTP_MAX_URI
], /* Username portion of URI */
6596 host
[HTTP_MAX_URI
], /* Host portion of URI */
6597 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6598 int port
; /* Port portion of URI */
6599 char filename
[1024], /* Filename for document */
6600 format
[1024]; /* Format for document */
6603 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6604 con
->http
.fd
, uri
->values
[0].string
.text
);
6607 * See if we have a job URI or a printer URI...
6610 if (!strcmp(uri
->name
, "printer-uri"))
6613 * Got a printer URI; see if we also have a job-id attribute...
6616 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6617 IPP_TAG_INTEGER
)) == NULL
)
6619 send_ipp_status(con
, IPP_BAD_REQUEST
,
6620 _("Got a printer-uri attribute but no job-id!"));
6624 jobid
= attr
->values
[0].integer
;
6629 * Got a job URI; parse it to get the job ID...
6632 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6633 sizeof(scheme
), username
, sizeof(username
), host
,
6634 sizeof(host
), &port
, resource
, sizeof(resource
));
6636 if (strncmp(resource
, "/jobs/", 6))
6642 send_ipp_status(con
, IPP_BAD_REQUEST
,
6643 _("Bad job-uri attribute \"%s\"!"),
6644 uri
->values
[0].string
.text
);
6648 jobid
= atoi(resource
+ 6);
6652 * See if the job exists...
6655 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6658 * Nope - return a "not found" error...
6661 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6669 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6671 send_http_error(con
, status
, NULL
);
6676 * Get the document number...
6679 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6680 IPP_TAG_INTEGER
)) == NULL
)
6682 send_ipp_status(con
, IPP_BAD_REQUEST
,
6683 _("Missing document-number attribute!"));
6687 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6688 attr
->num_values
> 1)
6690 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6695 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6697 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6699 cupsdLogMessage(CUPSD_LOG_ERROR
,
6700 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6702 send_ipp_status(con
, IPP_NOT_FOUND
,
6703 _("Unable to open document %d in job %d!"), docnum
, jobid
);
6707 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6711 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6712 job
->filetypes
[docnum
- 1]->type
);
6714 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6716 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6718 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6719 IPP_TAG_NAME
)) != NULL
)
6720 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6721 NULL
, attr
->values
[0].string
.text
);
6726 * 'get_job_attrs()' - Get job attributes.
6730 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6731 ipp_attribute_t
*uri
) /* I - Job URI */
6733 http_status_t status
; /* Policy status */
6734 ipp_attribute_t
*attr
; /* Current attribute */
6735 int jobid
; /* Job ID */
6736 cupsd_job_t
*job
; /* Current job */
6737 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6738 username
[HTTP_MAX_URI
], /* Username portion of URI */
6739 host
[HTTP_MAX_URI
], /* Host portion of URI */
6740 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6741 int port
; /* Port portion of URI */
6742 cups_array_t
*ra
; /* Requested attributes array */
6745 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6746 con
->http
.fd
, uri
->values
[0].string
.text
);
6749 * See if we have a job URI or a printer URI...
6752 if (!strcmp(uri
->name
, "printer-uri"))
6755 * Got a printer URI; see if we also have a job-id attribute...
6758 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6759 IPP_TAG_INTEGER
)) == NULL
)
6761 send_ipp_status(con
, IPP_BAD_REQUEST
,
6762 _("Got a printer-uri attribute but no job-id!"));
6766 jobid
= attr
->values
[0].integer
;
6771 * Got a job URI; parse it to get the job ID...
6774 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6775 sizeof(scheme
), username
, sizeof(username
), host
,
6776 sizeof(host
), &port
, resource
, sizeof(resource
));
6778 if (strncmp(resource
, "/jobs/", 6))
6784 send_ipp_status(con
, IPP_BAD_REQUEST
,
6785 _("Bad job-uri attribute \"%s\"!"),
6786 uri
->values
[0].string
.text
);
6790 jobid
= atoi(resource
+ 6);
6794 * See if the job exists...
6797 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6800 * Nope - return a "not found" error...
6803 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6811 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6813 send_http_error(con
, status
, NULL
);
6818 * Copy attributes...
6823 ra
= create_requested_array(con
->request
);
6824 copy_job_attrs(con
, job
, ra
);
6825 cupsArrayDelete(ra
);
6827 con
->response
->request
.status
.status_code
= IPP_OK
;
6832 * 'get_jobs()' - Get a list of jobs for the specified printer.
6836 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6837 ipp_attribute_t
*uri
) /* I - Printer URI */
6839 http_status_t status
; /* Policy status */
6840 ipp_attribute_t
*attr
; /* Current attribute */
6841 const char *dest
; /* Destination */
6842 cups_ptype_t dtype
; /* Destination type (printer/class) */
6843 cups_ptype_t dmask
; /* Destination type mask */
6844 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6845 username
[HTTP_MAX_URI
], /* Username portion of URI */
6846 host
[HTTP_MAX_URI
], /* Host portion of URI */
6847 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6848 int port
; /* Port portion of URI */
6849 int completed
; /* Completed jobs? */
6850 int first_job_id
; /* First job ID */
6851 int limit
; /* Maximum number of jobs to return */
6852 int count
; /* Number of jobs that match */
6853 cupsd_job_t
*job
; /* Current job pointer */
6854 cupsd_printer_t
*printer
; /* Printer */
6855 cups_array_t
*list
; /* Which job list... */
6856 cups_array_t
*ra
; /* Requested attributes array */
6859 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6860 uri
->values
[0].string
.text
);
6863 * Is the destination valid?
6866 if (strcmp(uri
->name
, "printer-uri"))
6868 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request!"));
6872 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6873 sizeof(scheme
), username
, sizeof(username
), host
,
6874 sizeof(host
), &port
, resource
, sizeof(resource
));
6876 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6879 dtype
= (cups_ptype_t
)0;
6880 dmask
= (cups_ptype_t
)0;
6883 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6886 dtype
= (cups_ptype_t
)0;
6887 dmask
= CUPS_PRINTER_CLASS
;
6890 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6893 dtype
= CUPS_PRINTER_CLASS
;
6894 dmask
= CUPS_PRINTER_CLASS
;
6897 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6904 send_ipp_status(con
, IPP_NOT_FOUND
,
6905 _("The printer or class was not found."));
6910 dtype
&= CUPS_PRINTER_CLASS
;
6911 dmask
= CUPS_PRINTER_CLASS
;
6920 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6923 send_http_error(con
, status
, printer
);
6927 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6929 send_http_error(con
, status
, NULL
);
6934 * See if the "which-jobs" attribute have been specified...
6937 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6938 IPP_TAG_KEYWORD
)) != NULL
&&
6939 !strcmp(attr
->values
[0].string
.text
, "completed"))
6944 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
6949 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "processing"))
6952 list
= PrintingJobs
;
6961 * See if they want to limit the number of jobs reported...
6964 if ((attr
= ippFindAttribute(con
->request
, "limit",
6965 IPP_TAG_INTEGER
)) != NULL
)
6966 limit
= attr
->values
[0].integer
;
6970 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6971 IPP_TAG_INTEGER
)) != NULL
)
6972 first_job_id
= attr
->values
[0].integer
;
6977 * See if we only want to see jobs for a specific user...
6980 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6981 IPP_TAG_BOOLEAN
)) != NULL
&&
6982 attr
->values
[0].boolean
)
6983 strlcpy(username
, get_username(con
), sizeof(username
));
6987 ra
= create_requested_array(con
->request
);
6990 * OK, build a list of jobs for this printer...
6993 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6994 (limit
<= 0 || count
< limit
) && job
;
6995 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6998 * Filter out jobs that don't match...
7001 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7002 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7003 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7004 job
->username
, job
->state_value
, job
->attrs
);
7006 if (!job
->dest
|| !job
->username
)
7009 if (!job
->dest
|| !job
->username
)
7012 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7013 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7015 if ((job
->dtype
& dmask
) != dtype
&&
7016 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7018 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
7021 if (job
->id
< first_job_id
)
7028 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d!",
7033 if (username
[0] && strcasecmp(username
, job
->username
))
7037 ippAddSeparator(con
->response
);
7041 copy_job_attrs(con
, job
, ra
);
7044 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7046 cupsArrayDelete(ra
);
7048 con
->response
->request
.status
.status_code
= IPP_OK
;
7053 * 'get_notifications()' - Get events for a subscription.
7057 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7059 int i
, j
; /* Looping vars */
7060 http_status_t status
; /* Policy status */
7061 cupsd_subscription_t
*sub
; /* Subscription */
7062 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7063 *sequences
; /* notify-sequence-numbers */
7064 int min_seq
; /* Minimum sequence number */
7065 int interval
; /* Poll interval */
7068 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7072 * Get subscription attributes...
7075 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7077 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7082 send_ipp_status(con
, IPP_BAD_REQUEST
,
7083 _("Missing notify-subscription-ids attribute!"));
7088 * Are the subscription IDs valid?
7091 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7093 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7096 * Bad subscription ID...
7099 send_ipp_status(con
, IPP_NOT_FOUND
,
7100 _("notify-subscription-id %d no good!"),
7101 ids
->values
[i
].integer
);
7109 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7111 con
, sub
->owner
)) != HTTP_OK
)
7113 send_http_error(con
, status
, sub
->dest
);
7118 * Check the subscription type and update the interval accordingly.
7121 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7124 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7126 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7132 * Tell the client to poll again in N seconds...
7136 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7137 "notify-get-interval", interval
);
7139 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7140 "printer-up-time", time(NULL
));
7143 * Copy the subscription event attributes to the response.
7146 con
->response
->request
.status
.status_code
=
7147 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7149 for (i
= 0; i
< ids
->num_values
; i
++)
7152 * Get the subscription and sequence number...
7155 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7157 if (sequences
&& i
< sequences
->num_values
)
7158 min_seq
= sequences
->values
[i
].integer
;
7163 * If we don't have any new events, nothing to do here...
7166 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7170 * Otherwise copy all of the new events...
7173 if (sub
->first_event_id
> min_seq
)
7176 j
= min_seq
- sub
->first_event_id
;
7178 for (; j
< sub
->num_events
; j
++)
7180 ippAddSeparator(con
->response
);
7182 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7183 IPP_TAG_EVENT_NOTIFICATION
, 0);
7190 * 'get_ppd()' - Get a named PPD from the local system.
7194 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7195 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7197 http_status_t status
; /* Policy status */
7198 cupsd_printer_t
*dest
; /* Destination */
7199 cups_ptype_t dtype
; /* Destination type */
7202 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7203 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7205 if (!strcmp(uri
->name
, "ppd-name"))
7208 * Return a PPD file from cups-driverd...
7211 char command
[1024], /* cups-driverd command */
7212 options
[1024], /* Options to pass to command */
7213 ppd_name
[1024]; /* ppd-name */
7220 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7222 send_http_error(con
, status
, NULL
);
7227 * Run cups-driverd command with the given options...
7230 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7231 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7232 snprintf(options
, sizeof(options
), "get+%d+%s",
7233 con
->request
->request
.op
.request_id
, ppd_name
);
7235 if (cupsdSendCommand(con
, command
, options
, 0))
7238 * Command started successfully, don't send an IPP response here...
7241 ippDelete(con
->response
);
7242 con
->response
= NULL
;
7247 * Command failed, return "internal error" so the user knows something
7251 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7252 _("cups-driverd failed to execute."));
7255 else if (!strcmp(uri
->name
, "printer-uri") &&
7256 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7258 int i
; /* Looping var */
7259 char filename
[1024]; /* PPD filename */
7266 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7268 send_http_error(con
, status
, dest
);
7273 * See if we need the PPD for a class or remote printer...
7276 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7279 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7281 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7282 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7283 "printer-uri", NULL
, dest
->uri
);
7286 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7288 for (i
= 0; i
< dest
->num_printers
; i
++)
7289 if (!(dest
->printers
[i
]->type
&
7290 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7292 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7293 dest
->printers
[i
]->name
);
7295 if (!access(filename
, 0))
7299 if (i
< dest
->num_printers
)
7300 dest
= dest
->printers
[i
];
7303 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7304 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7305 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7311 * Found the printer with the PPD file, now see if there is one...
7314 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7316 send_ipp_status(con
, IPP_NOT_FOUND
,
7317 _("The PPD file \"%s\" could not be opened: %s"),
7318 uri
->values
[0].string
.text
, strerror(errno
));
7322 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7326 con
->response
->request
.status
.status_code
= IPP_OK
;
7329 send_ipp_status(con
, IPP_NOT_FOUND
,
7330 _("The PPD file \"%s\" could not be found."),
7331 uri
->values
[0].string
.text
);
7336 * 'get_ppds()' - Get the list of PPD files on the local system.
7340 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7342 http_status_t status
; /* Policy status */
7343 ipp_attribute_t
*limit
, /* Limit attribute */
7344 *device
, /* ppd-device-id attribute */
7345 *language
, /* ppd-natural-language attribute */
7346 *make
, /* ppd-make attribute */
7347 *model
, /* ppd-make-and-model attribute */
7348 *model_number
, /* ppd-model-number attribute */
7349 *product
, /* ppd-product attribute */
7350 *psversion
, /* ppd-psverion attribute */
7351 *type
, /* ppd-type attribute */
7352 *requested
, /* requested-attributes attribute */
7353 *exclude
, /* exclude-schemes attribute */
7354 *include
; /* include-schemes attribute */
7355 char command
[1024], /* cups-driverd command */
7356 options
[4096], /* Options to pass to command */
7357 device_str
[256],/* Escaped ppd-device-id string */
7359 /* Escaped ppd-natural-language */
7360 make_str
[256], /* Escaped ppd-make string */
7361 model_str
[256], /* Escaped ppd-make-and-model string */
7362 model_number_str
[256],
7363 /* ppd-model-number string */
7365 /* Escaped ppd-product string */
7367 /* Escaped ppd-psversion string */
7368 type_str
[256], /* Escaped ppd-type string */
7370 /* String for requested attributes */
7372 /* String for excluded schemes */
7374 /* String for included schemes */
7377 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7383 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7385 send_http_error(con
, status
, NULL
);
7390 * Run cups-driverd command with the given options...
7393 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7394 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7395 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7397 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7398 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7400 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7402 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7403 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7404 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7405 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7407 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7409 include
= ippFindAttribute(con
->request
, "include-schemes",
7413 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7415 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7418 url_encode_attr(device
, device_str
, sizeof(device_str
));
7420 device_str
[0] = '\0';
7423 url_encode_attr(language
, language_str
, sizeof(language_str
));
7425 language_str
[0] = '\0';
7428 url_encode_attr(make
, make_str
, sizeof(make_str
));
7433 url_encode_attr(model
, model_str
, sizeof(model_str
));
7435 model_str
[0] = '\0';
7438 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7439 model_number
->values
[0].integer
);
7441 model_number_str
[0] = '\0';
7444 url_encode_attr(product
, product_str
, sizeof(product_str
));
7446 product_str
[0] = '\0';
7449 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7451 psversion_str
[0] = '\0';
7454 url_encode_attr(type
, type_str
, sizeof(type_str
));
7459 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7461 exclude_str
[0] = '\0';
7464 url_encode_attr(include
, include_str
, sizeof(include_str
));
7466 include_str
[0] = '\0';
7468 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7469 snprintf(options
, sizeof(options
),
7470 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7471 con
->request
->request
.op
.request_id
,
7472 limit
? limit
->values
[0].integer
: 0,
7474 device
? "%20" : "", device_str
,
7475 language
? "%20" : "", language_str
,
7476 make
? "%20" : "", make_str
,
7477 model
? "%20" : "", model_str
,
7478 model_number
? "%20" : "", model_number_str
,
7479 product
? "%20" : "", product_str
,
7480 psversion
? "%20" : "", psversion_str
,
7481 type
? "%20" : "", type_str
,
7482 exclude_str
[0] ? "%20" : "", exclude_str
,
7483 include_str
[0] ? "%20" : "", include_str
);
7485 if (cupsdSendCommand(con
, command
, options
, 0))
7488 * Command started successfully, don't send an IPP response here...
7491 ippDelete(con
->response
);
7492 con
->response
= NULL
;
7497 * Command failed, return "internal error" so the user knows something
7501 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7502 _("cups-driverd failed to execute."));
7508 * 'get_printer_attrs()' - Get printer attributes.
7512 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7513 ipp_attribute_t
*uri
) /* I - Printer URI */
7515 http_status_t status
; /* Policy status */
7516 cups_ptype_t dtype
; /* Destination type (printer/class) */
7517 cupsd_printer_t
*printer
; /* Printer/class */
7518 cups_array_t
*ra
; /* Requested attributes array */
7521 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7522 con
->http
.fd
, uri
->values
[0].string
.text
);
7525 * Is the destination valid?
7528 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7534 send_ipp_status(con
, IPP_NOT_FOUND
,
7535 _("The printer or class was not found."));
7543 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7545 send_http_error(con
, status
, printer
);
7550 * Send the attributes...
7553 ra
= create_requested_array(con
->request
);
7555 copy_printer_attrs(con
, printer
, ra
);
7557 cupsArrayDelete(ra
);
7559 con
->response
->request
.status
.status_code
= IPP_OK
;
7564 * 'get_printer_supported()' - Get printer supported values.
7568 get_printer_supported(
7569 cupsd_client_t
*con
, /* I - Client connection */
7570 ipp_attribute_t
*uri
) /* I - Printer URI */
7572 http_status_t status
; /* Policy status */
7573 cups_ptype_t dtype
; /* Destination type (printer/class) */
7574 cupsd_printer_t
*printer
; /* Printer/class */
7577 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7578 con
->http
.fd
, uri
->values
[0].string
.text
);
7581 * Is the destination valid?
7584 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7590 send_ipp_status(con
, IPP_NOT_FOUND
,
7591 _("The printer or class was not found."));
7599 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7601 send_http_error(con
, status
, printer
);
7606 * Return a list of attributes that can be set via Set-Printer-Attributes.
7609 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7611 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7612 "printer-location", 0);
7614 con
->response
->request
.status
.status_code
= IPP_OK
;
7619 * 'get_printers()' - Get a list of printers or classes.
7623 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7624 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7626 http_status_t status
; /* Policy status */
7627 ipp_attribute_t
*attr
; /* Current attribute */
7628 int limit
; /* Max number of printers to return */
7629 int count
; /* Number of printers that match */
7630 cupsd_printer_t
*printer
; /* Current printer pointer */
7631 int printer_type
, /* printer-type attribute */
7632 printer_mask
; /* printer-type-mask attribute */
7633 char *location
; /* Location string */
7634 const char *username
; /* Current user */
7635 char *first_printer_name
; /* first-printer-name attribute */
7636 cups_array_t
*ra
; /* Requested attributes array */
7637 int local
; /* Local connection? */
7640 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7641 con
->http
.fd
, type
);
7647 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7649 send_http_error(con
, status
, NULL
);
7654 * Check for printers...
7657 if (!Printers
|| !cupsArrayCount(Printers
))
7659 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7664 * See if they want to limit the number of printers reported...
7667 if ((attr
= ippFindAttribute(con
->request
, "limit",
7668 IPP_TAG_INTEGER
)) != NULL
)
7669 limit
= attr
->values
[0].integer
;
7673 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7674 IPP_TAG_NAME
)) != NULL
)
7675 first_printer_name
= attr
->values
[0].string
.text
;
7677 first_printer_name
= NULL
;
7680 * Support filtering...
7683 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7684 IPP_TAG_ENUM
)) != NULL
)
7685 printer_type
= attr
->values
[0].integer
;
7689 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7690 IPP_TAG_ENUM
)) != NULL
)
7691 printer_mask
= attr
->values
[0].integer
;
7695 local
= httpAddrLocalhost(&(con
->clientaddr
));
7697 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7698 IPP_TAG_TEXT
)) != NULL
)
7699 location
= attr
->values
[0].string
.text
;
7703 if (con
->username
[0])
7704 username
= con
->username
;
7705 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7706 IPP_TAG_NAME
)) != NULL
)
7707 username
= attr
->values
[0].string
.text
;
7711 ra
= create_requested_array(con
->request
);
7714 * OK, build a list of printers for this printer...
7717 if (first_printer_name
)
7719 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7720 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7723 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7726 count
< limit
&& printer
;
7727 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7729 if (!local
&& !printer
->shared
)
7732 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7733 (printer
->type
& printer_mask
) == printer_type
&&
7735 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
7738 * If HideImplicitMembers is enabled, see if this printer or class
7739 * is a member of an implicit class...
7742 if (ImplicitClasses
&& HideImplicitMembers
&&
7743 printer
->in_implicit_class
)
7747 * If a username is specified, see if it is allowed or denied
7751 if (!(printer
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
7752 printer
->num_users
&& username
&& !user_allowed(printer
, username
))
7756 * Add the group separator as needed...
7760 ippAddSeparator(con
->response
);
7765 * Send the attributes...
7768 copy_printer_attrs(con
, printer
, ra
);
7772 cupsArrayDelete(ra
);
7774 con
->response
->request
.status
.status_code
= IPP_OK
;
7779 * 'get_subscription_attrs()' - Get subscription attributes.
7783 get_subscription_attrs(
7784 cupsd_client_t
*con
, /* I - Client connection */
7785 int sub_id
) /* I - Subscription ID */
7787 http_status_t status
; /* Policy status */
7788 cupsd_subscription_t
*sub
; /* Subscription */
7789 cups_array_t
*ra
; /* Requested attributes array */
7792 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7793 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7794 con
, con
->http
.fd
, sub_id
);
7797 * Is the subscription ID valid?
7800 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7803 * Bad subscription ID...
7806 send_ipp_status(con
, IPP_NOT_FOUND
,
7807 _("notify-subscription-id %d no good!"), sub_id
);
7815 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7817 con
, sub
->owner
)) != HTTP_OK
)
7819 send_http_error(con
, status
, sub
->dest
);
7824 * Copy the subscription attributes to the response using the
7825 * requested-attributes attribute that may be provided by the client.
7828 ra
= create_requested_array(con
->request
);
7830 copy_subscription_attrs(con
, sub
, ra
);
7832 cupsArrayDelete(ra
);
7834 con
->response
->request
.status
.status_code
= IPP_OK
;
7839 * 'get_subscriptions()' - Get subscriptions.
7843 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7844 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7846 http_status_t status
; /* Policy status */
7847 int count
; /* Number of subscriptions */
7848 int limit
; /* Limit */
7849 cupsd_subscription_t
*sub
; /* Subscription */
7850 cups_array_t
*ra
; /* Requested attributes array */
7851 ipp_attribute_t
*attr
; /* Attribute */
7852 cups_ptype_t dtype
; /* Destination type (printer/class) */
7853 char scheme
[HTTP_MAX_URI
],
7854 /* Scheme portion of URI */
7855 username
[HTTP_MAX_URI
],
7856 /* Username portion of URI */
7858 /* Host portion of URI */
7859 resource
[HTTP_MAX_URI
];
7860 /* Resource portion of URI */
7861 int port
; /* Port portion of URI */
7862 cupsd_job_t
*job
; /* Job pointer */
7863 cupsd_printer_t
*printer
; /* Printer */
7866 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7867 "get_subscriptions(con=%p[%d], uri=%s)",
7868 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7871 * Is the destination valid?
7874 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7875 sizeof(scheme
), username
, sizeof(username
), host
,
7876 sizeof(host
), &port
, resource
, sizeof(resource
));
7878 if (!strcmp(resource
, "/") ||
7879 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7880 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7881 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7886 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7889 job
= cupsdFindJob(atoi(resource
+ 6));
7893 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
7898 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7904 send_ipp_status(con
, IPP_NOT_FOUND
,
7905 _("The printer or class was not found."));
7908 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7909 IPP_TAG_INTEGER
)) != NULL
)
7911 job
= cupsdFindJob(attr
->values
[0].integer
);
7915 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
7916 attr
->values
[0].integer
);
7927 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
7929 con
, NULL
)) != HTTP_OK
)
7931 send_http_error(con
, status
, printer
);
7936 * Copy the subscription attributes to the response using the
7937 * requested-attributes attribute that may be provided by the client.
7940 ra
= create_requested_array(con
->request
);
7942 if ((attr
= ippFindAttribute(con
->request
, "limit",
7943 IPP_TAG_INTEGER
)) != NULL
)
7944 limit
= attr
->values
[0].integer
;
7949 * See if we only want to see subscriptions for a specific user...
7952 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7953 IPP_TAG_BOOLEAN
)) != NULL
&&
7954 attr
->values
[0].boolean
)
7955 strlcpy(username
, get_username(con
), sizeof(username
));
7959 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7961 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7962 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7963 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
7965 ippAddSeparator(con
->response
);
7966 copy_subscription_attrs(con
, sub
, ra
);
7969 if (limit
&& count
>= limit
)
7973 cupsArrayDelete(ra
);
7976 con
->response
->request
.status
.status_code
= IPP_OK
;
7978 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7983 * 'get_username()' - Get the username associated with a request.
7986 static const char * /* O - Username */
7987 get_username(cupsd_client_t
*con
) /* I - Connection */
7989 ipp_attribute_t
*attr
; /* Attribute */
7992 if (con
->username
[0])
7993 return (con
->username
);
7994 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7995 IPP_TAG_NAME
)) != NULL
)
7996 return (attr
->values
[0].string
.text
);
7998 return ("anonymous");
8003 * 'hold_job()' - Hold a print job.
8007 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8008 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8010 ipp_attribute_t
*attr
; /* Current job-hold-until */
8011 const char *when
; /* New value */
8012 int jobid
; /* Job ID */
8013 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8014 username
[HTTP_MAX_URI
], /* Username portion of URI */
8015 host
[HTTP_MAX_URI
], /* Host portion of URI */
8016 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8017 int port
; /* Port portion of URI */
8018 cupsd_job_t
*job
; /* Job information */
8021 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8022 uri
->values
[0].string
.text
);
8025 * See if we have a job URI or a printer URI...
8028 if (!strcmp(uri
->name
, "printer-uri"))
8031 * Got a printer URI; see if we also have a job-id attribute...
8034 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8035 IPP_TAG_INTEGER
)) == NULL
)
8037 send_ipp_status(con
, IPP_BAD_REQUEST
,
8038 _("Got a printer-uri attribute but no job-id!"));
8042 jobid
= attr
->values
[0].integer
;
8047 * Got a job URI; parse it to get the job ID...
8050 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8051 sizeof(scheme
), username
, sizeof(username
), host
,
8052 sizeof(host
), &port
, resource
, sizeof(resource
));
8054 if (strncmp(resource
, "/jobs/", 6))
8060 send_ipp_status(con
, IPP_BAD_REQUEST
,
8061 _("Bad job-uri attribute \"%s\"!"),
8062 uri
->values
[0].string
.text
);
8066 jobid
= atoi(resource
+ 6);
8070 * See if the job exists...
8073 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8076 * Nope - return a "not found" error...
8079 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8084 * See if the job is owned by the requesting user...
8087 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8089 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8094 * Hold the job and return...
8097 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8098 IPP_TAG_KEYWORD
)) == NULL
)
8099 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8103 when
= attr
->values
[0].string
.text
;
8105 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8106 "Job job-hold-until value changed by user.");
8109 when
= "indefinite";
8111 cupsdSetJobHoldUntil(job
, when
, 1);
8112 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8115 con
->response
->request
.status
.status_code
= IPP_OK
;
8120 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8124 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8125 ipp_attribute_t
*uri
) /* I - Printer URI */
8127 http_status_t status
; /* Policy status */
8128 cups_ptype_t dtype
; /* Destination type (printer/class) */
8129 cupsd_printer_t
*printer
; /* Printer data */
8132 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8133 con
->http
.fd
, uri
->values
[0].string
.text
);
8136 * Is the destination valid?
8139 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8145 send_ipp_status(con
, IPP_NOT_FOUND
,
8146 _("The printer or class was not found."));
8154 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8156 send_http_error(con
, status
, printer
);
8161 * Hold pending/new jobs sent to the printer...
8164 printer
->holding_new_jobs
= 1;
8166 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8167 cupsdAddPrinterHistory(printer
);
8169 if (dtype
& CUPS_PRINTER_CLASS
)
8170 cupsdLogMessage(CUPSD_LOG_INFO
,
8171 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8172 printer
->name
, get_username(con
));
8174 cupsdLogMessage(CUPSD_LOG_INFO
,
8175 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8176 printer
->name
, get_username(con
));
8179 * Everything was ok, so return OK status...
8182 con
->response
->request
.status
.status_code
= IPP_OK
;
8187 * 'move_job()' - Move a job to a new destination.
8191 move_job(cupsd_client_t
*con
, /* I - Client connection */
8192 ipp_attribute_t
*uri
) /* I - Job URI */
8194 http_status_t status
; /* Policy status */
8195 ipp_attribute_t
*attr
; /* Current attribute */
8196 int jobid
; /* Job ID */
8197 cupsd_job_t
*job
; /* Current job */
8198 const char *src
; /* Source printer/class */
8199 cups_ptype_t stype
, /* Source type (printer or class) */
8200 dtype
; /* Destination type (printer/class) */
8201 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8202 username
[HTTP_MAX_URI
], /* Username portion of URI */
8203 host
[HTTP_MAX_URI
], /* Host portion of URI */
8204 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8205 int port
; /* Port portion of URI */
8206 cupsd_printer_t
*sprinter
, /* Source printer */
8207 *dprinter
; /* Destination printer */
8210 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8211 uri
->values
[0].string
.text
);
8214 * Get the new printer or class...
8217 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8218 IPP_TAG_URI
)) == NULL
)
8221 * Need job-printer-uri...
8224 send_ipp_status(con
, IPP_BAD_REQUEST
,
8225 _("job-printer-uri attribute missing!"));
8229 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8235 send_ipp_status(con
, IPP_NOT_FOUND
,
8236 _("The printer or class was not found."));
8241 * See if we have a job URI or a printer URI...
8244 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8245 sizeof(scheme
), username
, sizeof(username
), host
,
8246 sizeof(host
), &port
, resource
, sizeof(resource
));
8248 if (!strcmp(uri
->name
, "printer-uri"))
8251 * Got a printer URI; see if we also have a job-id attribute...
8254 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8255 IPP_TAG_INTEGER
)) == NULL
)
8261 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8262 &sprinter
)) == NULL
)
8268 send_ipp_status(con
, IPP_NOT_FOUND
,
8269 _("The printer or class was not found."));
8278 * Otherwise, just move a single job...
8281 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8284 * Nope - return a "not found" error...
8287 send_ipp_status(con
, IPP_NOT_FOUND
,
8288 _("Job #%d does not exist!"), attr
->values
[0].integer
);
8294 * Job found, initialize source pointers...
8305 * Got a job URI; parse it to get the job ID...
8308 if (strncmp(resource
, "/jobs/", 6))
8314 send_ipp_status(con
, IPP_BAD_REQUEST
,
8315 _("Bad job-uri attribute \"%s\"!"),
8316 uri
->values
[0].string
.text
);
8321 * See if the job exists...
8324 jobid
= atoi(resource
+ 6);
8326 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8329 * Nope - return a "not found" error...
8332 send_ipp_status(con
, IPP_NOT_FOUND
,
8333 _("Job #%d does not exist!"), jobid
);
8339 * Job found, initialize source pointers...
8348 * Check the policy of the destination printer...
8351 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8352 job
? job
->username
: NULL
)) != HTTP_OK
)
8354 send_http_error(con
, status
, dprinter
);
8359 * Now move the job or jobs...
8365 * See if the job has been completed...
8368 if (job
->state_value
> IPP_JOB_STOPPED
)
8371 * Return a "not-possible" error...
8374 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8375 _("Job #%d is finished and cannot be altered!"),
8381 * See if the job is owned by the requesting user...
8384 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8386 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8391 * Move the job to a different printer or class...
8394 cupsdMoveJob(job
, dprinter
);
8399 * Got the source printer, now look through the jobs...
8402 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8404 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8407 * See if the job is pointing at the source printer or has not been
8411 if (strcasecmp(job
->dest
, src
) ||
8412 job
->state_value
> IPP_JOB_STOPPED
)
8416 * See if the job can be moved by the requesting user...
8419 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8423 * Move the job to a different printer or class...
8426 cupsdMoveJob(job
, dprinter
);
8431 * Start jobs if possible...
8437 * Return with "everything is OK" status...
8440 con
->response
->request
.status
.status_code
= IPP_OK
;
8445 * 'ppd_parse_line()' - Parse a PPD default line.
8448 static int /* O - 0 on success, -1 on failure */
8449 ppd_parse_line(const char *line
, /* I - Line */
8450 char *option
, /* O - Option name */
8451 int olen
, /* I - Size of option name */
8452 char *choice
, /* O - Choice name */
8453 int clen
) /* I - Size of choice name */
8456 * Verify this is a default option line...
8459 if (strncmp(line
, "*Default", 8))
8463 * Read the option name...
8466 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
8476 * Skip everything else up to the colon (:)...
8479 while (*line
&& *line
!= ':')
8488 * Now grab the option choice, skipping leading whitespace...
8491 while (isspace(*line
& 255))
8494 for (clen
--; isalnum(*line
& 255); line
++)
8504 * Return with no errors...
8512 * 'print_job()' - Print a file to a printer or class.
8516 print_job(cupsd_client_t
*con
, /* I - Client connection */
8517 ipp_attribute_t
*uri
) /* I - Printer URI */
8519 ipp_attribute_t
*attr
; /* Current attribute */
8520 ipp_attribute_t
*format
; /* Document-format attribute */
8521 const char *default_format
; /* document-format-default value */
8522 cupsd_job_t
*job
; /* New job */
8523 char filename
[1024]; /* Job filename */
8524 mime_type_t
*filetype
; /* Type of file */
8525 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8526 type
[MIME_MAX_TYPE
], /* Subtype of file */
8527 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8528 /* Textual name of mime type */
8529 cupsd_printer_t
*printer
; /* Printer data */
8530 struct stat fileinfo
; /* File information */
8531 int kbytes
; /* Size of file */
8532 int compression
; /* Document compression */
8535 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8536 uri
->values
[0].string
.text
);
8539 * Validate print file attributes, for now just document-format and
8540 * compression (CUPS only supports "none" and "gzip")...
8543 compression
= CUPS_FILE_NONE
;
8545 if ((attr
= ippFindAttribute(con
->request
, "compression",
8546 IPP_TAG_KEYWORD
)) != NULL
)
8548 if (strcmp(attr
->values
[0].string
.text
, "none")
8550 && strcmp(attr
->values
[0].string
.text
, "gzip")
8551 #endif /* HAVE_LIBZ */
8554 send_ipp_status(con
, IPP_ATTRIBUTES
,
8555 _("Unsupported compression \"%s\"!"),
8556 attr
->values
[0].string
.text
);
8557 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8558 "compression", NULL
, attr
->values
[0].string
.text
);
8563 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8564 compression
= CUPS_FILE_GZIP
;
8565 #endif /* HAVE_LIBZ */
8569 * Do we have a file to print?
8574 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8579 * Is the destination valid?
8582 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8588 send_ipp_status(con
, IPP_NOT_FOUND
,
8589 _("The printer or class was not found."));
8594 * Is it a format we support?
8597 if ((format
= ippFindAttribute(con
->request
, "document-format",
8598 IPP_TAG_MIMETYPE
)) != NULL
)
8601 * Grab format from client...
8604 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8607 send_ipp_status(con
, IPP_BAD_REQUEST
,
8608 _("Could not scan type \"%s\"!"),
8609 format
->values
[0].string
.text
);
8613 else if ((default_format
= cupsGetOption("document-format",
8614 printer
->num_options
,
8615 printer
->options
)) != NULL
)
8618 * Use default document format...
8621 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8623 send_ipp_status(con
, IPP_BAD_REQUEST
,
8624 _("Could not scan type \"%s\"!"),
8635 strcpy(super
, "application");
8636 strcpy(type
, "octet-stream");
8639 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8642 * Auto-type the file...
8645 ipp_attribute_t
*doc_name
; /* document-name attribute */
8648 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8650 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8651 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8652 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8656 filetype
= mimeType(MimeDatabase
, super
, type
);
8658 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8659 filetype
->super
, filetype
->type
);
8662 filetype
= mimeType(MimeDatabase
, super
, type
);
8666 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8669 * Replace the document-format attribute value with the auto-typed or
8673 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8678 _cupsStrFree(format
->values
[0].string
.text
);
8680 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8683 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8684 "document-format", NULL
, mimetype
);
8688 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8689 _("Unsupported format \'%s/%s\'!"), super
, type
);
8690 cupsdLogMessage(CUPSD_LOG_INFO
,
8691 "Hint: Do you have the raw file printing rules enabled?");
8694 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8695 "document-format", NULL
, format
->values
[0].string
.text
);
8701 * Read any embedded job ticket info from PS files...
8704 if (!strcasecmp(filetype
->super
, "application") &&
8705 (!strcasecmp(filetype
->type
, "postscript") ||
8706 !strcasecmp(filetype
->type
, "pdf")))
8707 read_job_ticket(con
);
8710 * Create the job object...
8713 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8717 * Update quota data...
8720 if (stat(con
->filename
, &fileinfo
))
8723 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8725 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8727 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8728 IPP_TAG_INTEGER
)) != NULL
)
8729 attr
->values
[0].integer
+= kbytes
;
8732 * Add the job file...
8735 if (add_file(con
, job
, filetype
, compression
))
8738 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8740 rename(con
->filename
, filename
);
8741 cupsdClearString(&con
->filename
);
8744 * See if we need to add the ending sheet...
8747 if (cupsdTimeoutJob(job
))
8751 * Log and save the job...
8754 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8755 "File of type %s/%s queued by \"%s\".",
8756 filetype
->super
, filetype
->type
, job
->username
);
8757 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8758 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8759 job
->dest
, job
->username
);
8762 * Start the job if possible...
8770 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8772 * This function only gets called when printing a single PDF or PostScript
8773 * file using the Print-Job operation. It doesn't work for Create-Job +
8774 * Send-File, since the job attributes need to be set at job creation
8775 * time for banners to work. The embedded job ticket stuff is here
8776 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8777 * options and IPP attributes which otherwise would be lost.
8779 * The format of a job ticket is simple:
8781 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8783 * %cupsJobTicket: attr1=value1
8784 * %cupsJobTicket: attr2=value2
8786 * %cupsJobTicket: attrN=valueN
8788 * Job ticket lines must appear immediately after the first line that
8789 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8790 * stops looking for job ticket info when it finds a line that does not begin
8791 * with "%cupsJobTicket:".
8793 * The maximum length of a job ticket line, including the prefix, is
8794 * 255 characters to conform with the Adobe DSC.
8796 * Read-only attributes are rejected with a notice to the error log in
8797 * case a malicious user tries anything. Since the job ticket is read
8798 * prior to attribute validation in print_job(), job ticket attributes
8799 * will go through the same validation as IPP attributes...
8803 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8805 cups_file_t
*fp
; /* File to read from */
8806 char line
[256]; /* Line data */
8807 int num_options
; /* Number of options */
8808 cups_option_t
*options
; /* Options */
8809 ipp_t
*ticket
; /* New attributes */
8810 ipp_attribute_t
*attr
, /* Current attribute */
8811 *attr2
, /* Job attribute */
8812 *prev2
; /* Previous job attribute */
8816 * First open the print file...
8819 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8821 cupsdLogMessage(CUPSD_LOG_ERROR
,
8822 "Unable to open print file for job ticket - %s",
8828 * Skip the first line...
8831 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8833 cupsdLogMessage(CUPSD_LOG_ERROR
,
8834 "Unable to read from print file for job ticket - %s",
8840 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8843 * Not a DSC-compliant file, so no job ticket info will be available...
8851 * Read job ticket info from the file...
8857 while (cupsFileGets(fp
, line
, sizeof(line
)))
8860 * Stop at the first non-ticket line...
8863 if (strncmp(line
, "%cupsJobTicket:", 15))
8867 * Add the options to the option array...
8870 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8874 * Done with the file; see if we have any options...
8879 if (num_options
== 0)
8883 * OK, convert the options to an attribute list, and apply them to
8888 cupsEncodeOptions(ticket
, num_options
, options
);
8891 * See what the user wants to change.
8894 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8896 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8899 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8900 !strcmp(attr
->name
, "job-originating-user-name") ||
8901 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8902 !strcmp(attr
->name
, "job-k-octets") ||
8903 !strcmp(attr
->name
, "job-id") ||
8904 !strncmp(attr
->name
, "job-state", 9) ||
8905 !strncmp(attr
->name
, "time-at-", 8))
8906 continue; /* Read-only attrs */
8908 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8909 IPP_TAG_ZERO
)) != NULL
)
8912 * Some other value; first free the old value...
8915 if (con
->request
->attrs
== attr2
)
8917 con
->request
->attrs
= attr2
->next
;
8922 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8923 if (prev2
->next
== attr2
)
8925 prev2
->next
= attr2
->next
;
8930 if (con
->request
->last
== attr2
)
8931 con
->request
->last
= prev2
;
8933 _ippFreeAttr(attr2
);
8937 * Add new option by copying it...
8940 copy_attribute(con
->request
, attr
, 0);
8944 * Then free the attribute list and option array...
8948 cupsFreeOptions(num_options
, options
);
8953 * 'reject_jobs()' - Reject print jobs to a printer.
8957 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8958 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8960 http_status_t status
; /* Policy status */
8961 cups_ptype_t dtype
; /* Destination type (printer/class) */
8962 cupsd_printer_t
*printer
; /* Printer data */
8963 ipp_attribute_t
*attr
; /* printer-state-message text */
8966 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8967 con
->http
.fd
, uri
->values
[0].string
.text
);
8970 * Is the destination valid?
8973 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8979 send_ipp_status(con
, IPP_NOT_FOUND
,
8980 _("The printer or class was not found."));
8988 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8990 send_http_error(con
, status
, printer
);
8995 * Reject jobs sent to the printer...
8998 printer
->accepting
= 0;
9000 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9001 IPP_TAG_TEXT
)) == NULL
)
9002 strcpy(printer
->state_message
, "Rejecting Jobs");
9004 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9005 sizeof(printer
->state_message
));
9007 cupsdAddPrinterHistory(printer
);
9009 if (dtype
& CUPS_PRINTER_CLASS
)
9011 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9013 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9014 printer
->name
, get_username(con
));
9018 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9020 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9021 printer
->name
, get_username(con
));
9025 * Everything was ok, so return OK status...
9028 con
->response
->request
.status
.status_code
= IPP_OK
;
9033 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9037 release_held_new_jobs(
9038 cupsd_client_t
*con
, /* I - Connection */
9039 ipp_attribute_t
*uri
) /* I - Printer URI */
9041 http_status_t status
; /* Policy status */
9042 cups_ptype_t dtype
; /* Destination type (printer/class) */
9043 cupsd_printer_t
*printer
; /* Printer data */
9046 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9047 con
->http
.fd
, uri
->values
[0].string
.text
);
9050 * Is the destination valid?
9053 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9059 send_ipp_status(con
, IPP_NOT_FOUND
,
9060 _("The printer or class was not found."));
9068 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9070 send_http_error(con
, status
, printer
);
9075 * Hold pending/new jobs sent to the printer...
9078 printer
->holding_new_jobs
= 0;
9080 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9081 cupsdAddPrinterHistory(printer
);
9083 if (dtype
& CUPS_PRINTER_CLASS
)
9084 cupsdLogMessage(CUPSD_LOG_INFO
,
9085 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9086 printer
->name
, get_username(con
));
9088 cupsdLogMessage(CUPSD_LOG_INFO
,
9089 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9090 printer
->name
, get_username(con
));
9093 * Everything was ok, so return OK status...
9096 con
->response
->request
.status
.status_code
= IPP_OK
;
9101 * 'release_job()' - Release a held print job.
9105 release_job(cupsd_client_t
*con
, /* I - Client connection */
9106 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9108 ipp_attribute_t
*attr
; /* Current attribute */
9109 int jobid
; /* Job ID */
9110 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9111 username
[HTTP_MAX_URI
], /* Username portion of URI */
9112 host
[HTTP_MAX_URI
], /* Host portion of URI */
9113 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9114 int port
; /* Port portion of URI */
9115 cupsd_job_t
*job
; /* Job information */
9118 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9119 con
->http
.fd
, uri
->values
[0].string
.text
);
9122 * See if we have a job URI or a printer URI...
9125 if (!strcmp(uri
->name
, "printer-uri"))
9128 * Got a printer URI; see if we also have a job-id attribute...
9131 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9132 IPP_TAG_INTEGER
)) == NULL
)
9134 send_ipp_status(con
, IPP_BAD_REQUEST
,
9135 _("Got a printer-uri attribute but no job-id!"));
9139 jobid
= attr
->values
[0].integer
;
9144 * Got a job URI; parse it to get the job ID...
9147 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9148 sizeof(scheme
), username
, sizeof(username
), host
,
9149 sizeof(host
), &port
, resource
, sizeof(resource
));
9151 if (strncmp(resource
, "/jobs/", 6))
9157 send_ipp_status(con
, IPP_BAD_REQUEST
,
9158 _("Bad job-uri attribute \"%s\"!"),
9159 uri
->values
[0].string
.text
);
9163 jobid
= atoi(resource
+ 6);
9167 * See if the job exists...
9170 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9173 * Nope - return a "not found" error...
9176 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9181 * See if job is "held"...
9184 if (job
->state_value
!= IPP_JOB_HELD
)
9187 * Nope - return a "not possible" error...
9190 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
9195 * See if the job is owned by the requesting user...
9198 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9200 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9205 * Reset the job-hold-until value to "no-hold"...
9208 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9209 IPP_TAG_KEYWORD
)) == NULL
)
9210 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9214 _cupsStrFree(attr
->values
[0].string
.text
);
9216 attr
->value_tag
= IPP_TAG_KEYWORD
;
9217 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9219 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9220 "Job job-hold-until value changed by user.");
9224 * Release the job and return...
9227 cupsdReleaseJob(job
);
9229 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9230 "Job released by user.");
9232 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9234 con
->response
->request
.status
.status_code
= IPP_OK
;
9241 * 'renew_subscription()' - Renew an existing subscription...
9246 cupsd_client_t
*con
, /* I - Client connection */
9247 int sub_id
) /* I - Subscription ID */
9249 http_status_t status
; /* Policy status */
9250 cupsd_subscription_t
*sub
; /* Subscription */
9251 ipp_attribute_t
*lease
; /* notify-lease-duration */
9254 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9255 "renew_subscription(con=%p[%d], sub_id=%d)",
9256 con
, con
->http
.fd
, sub_id
);
9259 * Is the subscription ID valid?
9262 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9265 * Bad subscription ID...
9268 send_ipp_status(con
, IPP_NOT_FOUND
,
9269 _("notify-subscription-id %d no good!"), sub_id
);
9276 * Job subscriptions cannot be renewed...
9279 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9280 _("Job subscriptions cannot be renewed!"));
9288 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9290 con
, sub
->owner
)) != HTTP_OK
)
9292 send_http_error(con
, status
, sub
->dest
);
9297 * Renew the subscription...
9300 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9303 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9305 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9307 cupsdLogMessage(CUPSD_LOG_INFO
,
9308 "renew_subscription: Limiting notify-lease-duration to "
9311 sub
->lease
= MaxLeaseDuration
;
9314 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9316 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9318 con
->response
->request
.status
.status_code
= IPP_OK
;
9320 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9321 "notify-lease-duration", sub
->lease
);
9326 * 'restart_job()' - Restart an old print job.
9330 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9331 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9333 ipp_attribute_t
*attr
; /* Current attribute */
9334 int jobid
; /* Job ID */
9335 cupsd_job_t
*job
; /* Job information */
9336 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9337 username
[HTTP_MAX_URI
], /* Username portion of URI */
9338 host
[HTTP_MAX_URI
], /* Host portion of URI */
9339 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9340 int port
; /* Port portion of URI */
9343 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9344 con
->http
.fd
, uri
->values
[0].string
.text
);
9347 * See if we have a job URI or a printer URI...
9350 if (!strcmp(uri
->name
, "printer-uri"))
9353 * Got a printer URI; see if we also have a job-id attribute...
9356 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9357 IPP_TAG_INTEGER
)) == NULL
)
9359 send_ipp_status(con
, IPP_BAD_REQUEST
,
9360 _("Got a printer-uri attribute but no job-id!"));
9364 jobid
= attr
->values
[0].integer
;
9369 * Got a job URI; parse it to get the job ID...
9372 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9373 sizeof(scheme
), username
, sizeof(username
), host
,
9374 sizeof(host
), &port
, resource
, sizeof(resource
));
9376 if (strncmp(resource
, "/jobs/", 6))
9382 send_ipp_status(con
, IPP_BAD_REQUEST
,
9383 _("Bad job-uri attribute \"%s\"!"),
9384 uri
->values
[0].string
.text
);
9388 jobid
= atoi(resource
+ 6);
9392 * See if the job exists...
9395 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9398 * Nope - return a "not found" error...
9401 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9406 * See if job is in any of the "completed" states...
9409 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9412 * Nope - return a "not possible" error...
9415 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
9421 * See if we have retained the job files...
9426 if (!job
->attrs
|| job
->num_files
== 0)
9429 * Nope - return a "not possible" error...
9432 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9433 _("Job #%d cannot be restarted - no files!"), jobid
);
9438 * See if the job is owned by the requesting user...
9441 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9443 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9448 * See if the job-hold-until attribute is specified...
9451 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9452 IPP_TAG_KEYWORD
)) == NULL
)
9453 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9455 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9458 * Return the job to a held state...
9461 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9462 "Restarted by \"%s\" with job-hold-until=%s.",
9463 username
, attr
->values
[0].string
.text
);
9464 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9466 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9467 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9468 attr
->values
[0].string
.text
);
9473 * Restart the job...
9476 cupsdRestartJob(job
);
9480 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9482 con
->response
->request
.status
.status_code
= IPP_OK
;
9487 * 'save_auth_info()' - Save authentication information for a job.
9492 cupsd_client_t
*con
, /* I - Client connection */
9493 cupsd_job_t
*job
, /* I - Job */
9494 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9496 int i
; /* Looping var */
9497 char filename
[1024]; /* Job authentication filename */
9498 cups_file_t
*fp
; /* Job authentication file */
9499 char line
[2048]; /* Line for file */
9500 cupsd_printer_t
*dest
; /* Destination printer/class */
9504 * This function saves the in-memory authentication information for
9505 * a job so that it can be used to authenticate with a remote host.
9506 * The information is stored in a file that is readable only by the
9507 * root user. The fields are Base-64 encoded, each on a separate line,
9508 * followed by random number (up to 1024) of newlines to limit the
9509 * amount of information that is exposed.
9511 * Because of the potential for exposing of authentication information,
9512 * this functionality is only enabled when running cupsd as root.
9514 * This caching only works for the Basic and BasicDigest authentication
9515 * types. Digest authentication cannot be cached this way, and in
9516 * the future Kerberos authentication may make all of this obsolete.
9518 * Authentication information is saved whenever an authenticated
9519 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9522 * This information is deleted after a job is completed or canceled,
9523 * so reprints may require subsequent re-authentication.
9529 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9533 * Create the authentication file and change permissions...
9536 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9537 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9539 cupsdLogMessage(CUPSD_LOG_ERROR
,
9540 "Unable to save authentication info to \"%s\" - %s",
9541 filename
, strerror(errno
));
9545 fchown(cupsFileNumber(fp
), 0, 0);
9546 fchmod(cupsFileNumber(fp
), 0400);
9548 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9551 * Write 1 to 3 auth values...
9554 cupsdClearString(&job
->auth_username
);
9555 cupsdClearString(&job
->auth_domain
);
9556 cupsdClearString(&job
->auth_password
);
9558 for (i
= 0; i
< auth_info
->num_values
; i
++)
9560 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9561 strlen(auth_info
->values
[i
].string
.text
));
9562 cupsFilePrintf(fp
, "%s\n", line
);
9564 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9565 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9566 auth_info
->values
[i
].string
.text
);
9567 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9568 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9569 auth_info
->values
[i
].string
.text
);
9570 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9571 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9572 auth_info
->values
[i
].string
.text
);
9575 else if (con
->username
[0])
9578 * Write the authenticated username...
9581 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9582 cupsFilePrintf(fp
, "%s\n", line
);
9584 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9585 cupsdClearString(&job
->auth_domain
);
9588 * Write the authenticated password...
9591 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9592 cupsFilePrintf(fp
, "%s\n", line
);
9594 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
9598 * Write a random number of newlines to the end of the file...
9601 for (i
= (rand() % 1024); i
>= 0; i
--)
9602 cupsFilePutChar(fp
, '\n');
9605 * Close the file and return...
9610 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9612 save_krb5_creds(con
, job
);
9613 else if (job
->ccname
)
9614 cupsdClearString(&(job
->ccname
));
9615 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9619 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9621 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
9625 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
9626 cupsd_job_t
*job
) /* I - Job */
9629 * Get the credentials...
9632 job
->ccache
= cupsdCopyKrb5Creds(con
);
9635 * Add the KRB5CCNAME environment variable to the job so that the
9636 * backend can use the credentials when printing.
9641 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
9642 krb5_cc_get_name(KerberosContext
, job
->ccache
));
9644 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
9647 cupsdClearString(&(job
->ccname
));
9649 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9653 * 'send_document()' - Send a file to a printer or class.
9657 send_document(cupsd_client_t
*con
, /* I - Client connection */
9658 ipp_attribute_t
*uri
) /* I - Printer URI */
9660 ipp_attribute_t
*attr
; /* Current attribute */
9661 ipp_attribute_t
*format
; /* Request's document-format attribute */
9662 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9663 const char *default_format
;/* document-format-default value */
9664 int jobid
; /* Job ID number */
9665 cupsd_job_t
*job
; /* Current job */
9666 char job_uri
[HTTP_MAX_URI
],
9668 scheme
[HTTP_MAX_URI
],
9669 /* Method portion of URI */
9670 username
[HTTP_MAX_URI
],
9671 /* Username portion of URI */
9673 /* Host portion of URI */
9674 resource
[HTTP_MAX_URI
];
9675 /* Resource portion of URI */
9676 int port
; /* Port portion of URI */
9677 mime_type_t
*filetype
; /* Type of file */
9678 char super
[MIME_MAX_SUPER
],
9679 /* Supertype of file */
9680 type
[MIME_MAX_TYPE
],
9681 /* Subtype of file */
9682 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9683 /* Textual name of mime type */
9684 char filename
[1024]; /* Job filename */
9685 cupsd_printer_t
*printer
; /* Current printer */
9686 struct stat fileinfo
; /* File information */
9687 int kbytes
; /* Size of file */
9688 int compression
; /* Type of compression */
9689 int start_job
; /* Start the job? */
9692 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9693 con
->http
.fd
, uri
->values
[0].string
.text
);
9696 * See if we have a job URI or a printer URI...
9699 if (!strcmp(uri
->name
, "printer-uri"))
9702 * Got a printer URI; see if we also have a job-id attribute...
9705 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9706 IPP_TAG_INTEGER
)) == NULL
)
9708 send_ipp_status(con
, IPP_BAD_REQUEST
,
9709 _("Got a printer-uri attribute but no job-id!"));
9713 jobid
= attr
->values
[0].integer
;
9718 * Got a job URI; parse it to get the job ID...
9721 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9722 sizeof(scheme
), username
, sizeof(username
), host
,
9723 sizeof(host
), &port
, resource
, sizeof(resource
));
9725 if (strncmp(resource
, "/jobs/", 6))
9731 send_ipp_status(con
, IPP_BAD_REQUEST
,
9732 _("Bad job-uri attribute \"%s\"!"),
9733 uri
->values
[0].string
.text
);
9737 jobid
= atoi(resource
+ 6);
9741 * See if the job exists...
9744 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9747 * Nope - return a "not found" error...
9750 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9754 printer
= cupsdFindDest(job
->dest
);
9757 * See if the job is owned by the requesting user...
9760 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9762 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9767 * OK, see if the client is sending the document compressed - CUPS
9768 * only supports "none" and "gzip".
9771 compression
= CUPS_FILE_NONE
;
9773 if ((attr
= ippFindAttribute(con
->request
, "compression",
9774 IPP_TAG_KEYWORD
)) != NULL
)
9776 if (strcmp(attr
->values
[0].string
.text
, "none")
9778 && strcmp(attr
->values
[0].string
.text
, "gzip")
9779 #endif /* HAVE_LIBZ */
9782 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
9783 attr
->values
[0].string
.text
);
9784 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9785 "compression", NULL
, attr
->values
[0].string
.text
);
9790 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9791 compression
= CUPS_FILE_GZIP
;
9792 #endif /* HAVE_LIBZ */
9796 * Do we have a file to print?
9801 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
9806 * Is it a format we support?
9809 if ((format
= ippFindAttribute(con
->request
, "document-format",
9810 IPP_TAG_MIMETYPE
)) != NULL
)
9813 * Grab format from client...
9816 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9819 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9820 format
->values
[0].string
.text
);
9824 else if ((default_format
= cupsGetOption("document-format",
9825 printer
->num_options
,
9826 printer
->options
)) != NULL
)
9829 * Use default document format...
9832 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9834 send_ipp_status(con
, IPP_BAD_REQUEST
,
9835 _("Could not scan type \"%s\"!"),
9843 * No document format attribute? Auto-type it!
9846 strcpy(super
, "application");
9847 strcpy(type
, "octet-stream");
9850 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9853 * Auto-type the file...
9856 ipp_attribute_t
*doc_name
; /* document-name attribute */
9859 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9861 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9862 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9863 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9867 filetype
= mimeType(MimeDatabase
, super
, type
);
9869 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9870 filetype
->super
, filetype
->type
);
9873 filetype
= mimeType(MimeDatabase
, super
, type
);
9878 * Replace the document-format attribute value with the auto-typed or
9882 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9885 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9886 IPP_TAG_MIMETYPE
)) != NULL
)
9888 _cupsStrFree(jformat
->values
[0].string
.text
);
9890 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9893 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9894 "document-format", NULL
, mimetype
);
9898 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9899 _("Unsupported format \'%s/%s\'!"), super
, type
);
9900 cupsdLogMessage(CUPSD_LOG_INFO
,
9901 "Hint: Do you have the raw file printing rules enabled?");
9904 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9905 "document-format", NULL
, format
->values
[0].string
.text
);
9910 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9912 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9915 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9916 _("Unsupported format \'%s\'!"), mimetype
);
9918 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9919 "document-format", NULL
, mimetype
);
9925 * Add the file to the job...
9930 if (add_file(con
, job
, filetype
, compression
))
9933 if (stat(con
->filename
, &fileinfo
))
9936 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9938 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9940 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9941 IPP_TAG_INTEGER
)) != NULL
)
9942 attr
->values
[0].integer
+= kbytes
;
9944 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9946 rename(con
->filename
, filename
);
9948 cupsdClearString(&con
->filename
);
9950 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9951 filetype
->super
, filetype
->type
, job
->username
);
9954 * Start the job if this is the last document...
9957 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9958 IPP_TAG_BOOLEAN
)) != NULL
&&
9959 attr
->values
[0].boolean
)
9962 * See if we need to add the ending sheet...
9965 if (cupsdTimeoutJob(job
))
9968 if (job
->state_value
== IPP_JOB_STOPPED
)
9970 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9971 job
->state_value
= IPP_JOB_PENDING
;
9973 else if (job
->state_value
== IPP_JOB_HELD
)
9975 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9976 IPP_TAG_KEYWORD
)) == NULL
)
9977 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9979 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9981 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9982 job
->state_value
= IPP_JOB_PENDING
;
9987 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9993 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9994 IPP_TAG_KEYWORD
)) == NULL
)
9995 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9997 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9999 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10000 job
->state_value
= IPP_JOB_HELD
;
10001 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10004 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10011 * Fill in the response info...
10014 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10017 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10020 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10022 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10024 add_job_state_reasons(con
, job
);
10026 con
->response
->request
.status
.status_code
= IPP_OK
;
10029 * Start the job if necessary...
10038 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10043 cupsd_client_t
*con
, /* I - Client connection */
10044 http_status_t status
, /* I - HTTP status code */
10045 cupsd_printer_t
*printer
) /* I - Printer, if any */
10047 ipp_attribute_t
*uri
; /* Request URI, if any */
10050 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10051 IPP_TAG_URI
)) == NULL
)
10052 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10054 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10055 "Returning HTTP %s for %s (%s) from %s",
10056 httpStatus(status
),
10057 ippOpString(con
->request
->request
.op
.operation_id
),
10058 uri
? uri
->values
[0].string
.text
: "no URI",
10059 con
->http
.hostname
);
10063 int auth_type
; /* Type of authentication required */
10066 auth_type
= CUPSD_AUTH_NONE
;
10068 if (status
== HTTP_UNAUTHORIZED
&&
10069 printer
->num_auth_info_required
> 0 &&
10070 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10072 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10073 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10074 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10077 * Creating and authenticating jobs requires Kerberos...
10080 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10085 * Use policy/location-defined authentication requirements...
10088 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10089 cupsd_location_t
*auth
; /* Pointer to authentication element */
10092 if (printer
->type
& CUPS_PRINTER_CLASS
)
10093 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10095 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10097 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10098 auth
->type
== CUPSD_AUTH_NONE
)
10099 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10101 con
->request
->request
.op
.operation_id
:
10106 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10107 auth_type
= DefaultAuthType
;
10109 auth_type
= auth
->type
;
10113 cupsdSendError(con
, status
, auth_type
);
10116 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10118 ippDelete(con
->response
);
10119 con
->response
= NULL
;
10126 * 'send_ipp_status()' - Send a status back to the IPP client.
10130 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10131 ipp_status_t status
, /* I - IPP status code */
10132 const char *message
,/* I - Status message */
10133 ...) /* I - Additional args as needed */
10135 va_list ap
; /* Pointer to additional args */
10136 char formatted
[1024]; /* Formatted errror message */
10139 va_start(ap
, message
);
10140 vsnprintf(formatted
, sizeof(formatted
),
10141 _cupsLangString(con
->language
, message
), ap
);
10144 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10145 ippOpString(con
->request
->request
.op
.operation_id
),
10146 ippErrorString(status
), formatted
);
10148 con
->response
->request
.status
.status_code
= status
;
10150 if (ippFindAttribute(con
->response
, "attributes-charset",
10151 IPP_TAG_ZERO
) == NULL
)
10152 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10153 "attributes-charset", NULL
, DefaultCharset
);
10155 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10156 IPP_TAG_ZERO
) == NULL
)
10157 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10158 "attributes-natural-language", NULL
, DefaultLanguage
);
10160 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10161 "status-message", NULL
, formatted
);
10166 * 'set_default()' - Set the default destination...
10170 set_default(cupsd_client_t
*con
, /* I - Client connection */
10171 ipp_attribute_t
*uri
) /* I - Printer URI */
10173 http_status_t status
; /* Policy status */
10174 cups_ptype_t dtype
; /* Destination type (printer/class) */
10175 cupsd_printer_t
*printer
, /* Printer */
10176 *oldprinter
; /* Old default printer */
10179 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10180 con
->http
.fd
, uri
->values
[0].string
.text
);
10183 * Is the destination valid?
10186 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10192 send_ipp_status(con
, IPP_NOT_FOUND
,
10193 _("The printer or class was not found."));
10201 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10203 send_http_error(con
, status
, NULL
);
10208 * Set it as the default...
10211 oldprinter
= DefaultPrinter
;
10212 DefaultPrinter
= printer
;
10215 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10216 "%s is no longer the default printer.", oldprinter
->name
);
10218 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10219 "%s is now the default printer.", printer
->name
);
10221 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10222 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10224 cupsdLogMessage(CUPSD_LOG_INFO
,
10225 "Default destination set to \"%s\" by \"%s\".",
10226 printer
->name
, get_username(con
));
10229 * Everything was ok, so return OK status...
10232 con
->response
->request
.status
.status_code
= IPP_OK
;
10237 * 'set_job_attrs()' - Set job attributes.
10241 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10242 ipp_attribute_t
*uri
) /* I - Job URI */
10244 ipp_attribute_t
*attr
, /* Current attribute */
10245 *attr2
; /* Job attribute */
10246 int jobid
; /* Job ID */
10247 cupsd_job_t
*job
; /* Current job */
10248 char scheme
[HTTP_MAX_URI
],
10249 /* Method portion of URI */
10250 username
[HTTP_MAX_URI
],
10251 /* Username portion of URI */
10252 host
[HTTP_MAX_URI
],
10253 /* Host portion of URI */
10254 resource
[HTTP_MAX_URI
];
10255 /* Resource portion of URI */
10256 int port
; /* Port portion of URI */
10257 int event
; /* Events? */
10258 int check_jobs
; /* Check jobs? */
10261 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10262 con
->http
.fd
, uri
->values
[0].string
.text
);
10265 * Start with "everything is OK" status...
10268 con
->response
->request
.status
.status_code
= IPP_OK
;
10271 * See if we have a job URI or a printer URI...
10274 if (!strcmp(uri
->name
, "printer-uri"))
10277 * Got a printer URI; see if we also have a job-id attribute...
10280 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10281 IPP_TAG_INTEGER
)) == NULL
)
10283 send_ipp_status(con
, IPP_BAD_REQUEST
,
10284 _("Got a printer-uri attribute but no job-id!"));
10288 jobid
= attr
->values
[0].integer
;
10293 * Got a job URI; parse it to get the job ID...
10296 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10297 sizeof(scheme
), username
, sizeof(username
), host
,
10298 sizeof(host
), &port
, resource
, sizeof(resource
));
10300 if (strncmp(resource
, "/jobs/", 6))
10306 send_ipp_status(con
, IPP_BAD_REQUEST
,
10307 _("Bad job-uri attribute \"%s\"!"),
10308 uri
->values
[0].string
.text
);
10312 jobid
= atoi(resource
+ 6);
10316 * See if the job exists...
10319 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10322 * Nope - return a "not found" error...
10325 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
10330 * See if the job has been completed...
10333 if (job
->state_value
> IPP_JOB_STOPPED
)
10336 * Return a "not-possible" error...
10339 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10340 _("Job #%d is finished and cannot be altered!"), jobid
);
10345 * See if the job is owned by the requesting user...
10348 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10350 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
10355 * See what the user wants to change.
10363 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10365 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10368 if (!strcmp(attr
->name
, "attributes-charset") ||
10369 !strcmp(attr
->name
, "attributes-natural-language") ||
10370 !strcmp(attr
->name
, "document-compression") ||
10371 !strcmp(attr
->name
, "document-format") ||
10372 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10373 !strcmp(attr
->name
, "job-document-access-errors") ||
10374 !strcmp(attr
->name
, "job-id") ||
10375 !strcmp(attr
->name
, "job-impressions-completed") ||
10376 !strcmp(attr
->name
, "job-k-octets") ||
10377 !strcmp(attr
->name
, "job-originating-host-name") ||
10378 !strcmp(attr
->name
, "job-originating-user-name") ||
10379 !strcmp(attr
->name
, "job-printer-up-time") ||
10380 !strcmp(attr
->name
, "job-printer-uri") ||
10381 !strcmp(attr
->name
, "job-sheets") ||
10382 !strcmp(attr
->name
, "job-state-message") ||
10383 !strcmp(attr
->name
, "job-state-reasons") ||
10384 !strcmp(attr
->name
, "job-uri") ||
10385 !strcmp(attr
->name
, "number-of-documents") ||
10386 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10387 !strcmp(attr
->name
, "output-device-assigned") ||
10388 !strncmp(attr
->name
, "date-time-at-", 13) ||
10389 !strncmp(attr
->name
, "job-k-octets", 12) ||
10390 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10391 !strncmp(attr
->name
, "time-at-", 8))
10397 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10398 _("%s cannot be changed."), attr
->name
);
10400 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10401 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10406 if (!strcmp(attr
->name
, "job-priority"))
10409 * Change the job priority...
10412 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10414 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
10416 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10417 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10419 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10421 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10422 _("Job is completed and cannot be changed."));
10425 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10427 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10428 attr
->values
[0].integer
);
10429 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10432 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10433 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10436 else if (!strcmp(attr
->name
, "job-state"))
10439 * Change the job state...
10442 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10444 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
10446 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10447 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10451 switch (attr
->values
[0].integer
)
10453 case IPP_JOB_PENDING
:
10454 case IPP_JOB_HELD
:
10455 if (job
->state_value
> IPP_JOB_HELD
)
10457 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10458 _("Job state cannot be changed."));
10461 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10463 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10464 attr
->values
[0].integer
);
10465 cupsdSetJobState(job
, attr
->values
[0].integer
,
10467 "Job state changed by \"%s\"", username
);
10472 case IPP_JOB_PROCESSING
:
10473 case IPP_JOB_STOPPED
:
10474 if (job
->state_value
!= attr
->values
[0].integer
)
10476 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10477 _("Job state cannot be changed."));
10482 case IPP_JOB_CANCELED
:
10483 case IPP_JOB_ABORTED
:
10484 case IPP_JOB_COMPLETED
:
10485 if (job
->state_value
> IPP_JOB_PROCESSING
)
10487 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10488 _("Job state cannot be changed."));
10491 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10493 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10494 attr
->values
[0].integer
);
10495 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10497 "Job state changed by \"%s\"", username
);
10504 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10506 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10507 IPP_TAG_ZERO
)) != NULL
)
10510 * Some other value; first free the old value...
10513 if (job
->attrs
->prev
)
10514 job
->attrs
->prev
->next
= attr2
->next
;
10516 job
->attrs
->attrs
= attr2
->next
;
10518 if (job
->attrs
->last
== attr2
)
10519 job
->attrs
->last
= job
->attrs
->prev
;
10521 _ippFreeAttr(attr2
);
10524 * Then copy the attribute...
10527 copy_attribute(job
->attrs
, attr
, 0);
10530 * See if the job-name or job-hold-until is being changed.
10533 if (!strcmp(attr
->name
, "job-hold-until"))
10535 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10536 attr
->values
[0].string
.text
);
10537 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10539 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10541 cupsdReleaseJob(job
);
10545 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10546 "Job held by \"%s\".", username
);
10548 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10551 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10554 * Delete the attribute...
10557 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10558 IPP_TAG_ZERO
)) != NULL
)
10560 if (job
->attrs
->prev
)
10561 job
->attrs
->prev
->next
= attr2
->next
;
10563 job
->attrs
->attrs
= attr2
->next
;
10565 if (attr2
== job
->attrs
->last
)
10566 job
->attrs
->last
= job
->attrs
->prev
;
10568 _ippFreeAttr(attr2
);
10570 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10576 * Add new option by copying it...
10579 copy_attribute(job
->attrs
, attr
, 0);
10581 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10590 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10593 * Send events as needed...
10596 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10597 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10598 cupsdFindDest(job
->dest
), job
,
10599 "Job priority changed by user.");
10601 if (event
& CUPSD_EVENT_JOB_STATE
)
10602 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10603 job
->state_value
== IPP_JOB_HELD
?
10604 "Job held by user." : "Job restarted by user.");
10606 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10607 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10608 "Job options changed by user.");
10611 * Start jobs if possible...
10620 * 'set_printer_attrs()' - Set printer attributes.
10624 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10625 ipp_attribute_t
*uri
) /* I - Printer */
10627 http_status_t status
; /* Policy status */
10628 cups_ptype_t dtype
; /* Destination type (printer/class) */
10629 cupsd_printer_t
*printer
; /* Printer/class */
10630 ipp_attribute_t
*attr
; /* Printer attribute */
10631 int changed
= 0; /* Was anything changed? */
10634 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10635 con
->http
.fd
, uri
->values
[0].string
.text
);
10638 * Is the destination valid?
10641 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10647 send_ipp_status(con
, IPP_NOT_FOUND
,
10648 _("The printer or class was not found."));
10656 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10658 send_http_error(con
, status
, printer
);
10663 * Return a list of attributes that can be set via Set-Printer-Attributes.
10666 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10667 IPP_TAG_TEXT
)) != NULL
)
10669 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10673 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10674 IPP_TAG_TEXT
)) != NULL
)
10676 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10681 * Update the printer attributes and return...
10686 cupsdSetPrinterAttrs(printer
);
10687 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10689 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10690 "Printer \"%s\" description or location changed by \"%s\".",
10691 printer
->name
, get_username(con
));
10693 cupsdLogMessage(CUPSD_LOG_INFO
,
10694 "Printer \"%s\" description or location changed by \"%s\".",
10695 printer
->name
, get_username(con
));
10698 con
->response
->request
.status
.status_code
= IPP_OK
;
10703 * 'set_printer_defaults()' - Set printer default options from a request.
10707 set_printer_defaults(
10708 cupsd_client_t
*con
, /* I - Client connection */
10709 cupsd_printer_t
*printer
) /* I - Printer */
10711 int i
; /* Looping var */
10712 ipp_attribute_t
*attr
; /* Current attribute */
10713 int namelen
; /* Length of attribute name */
10714 char name
[256], /* New attribute name */
10715 value
[256]; /* String version of integer attrs */
10718 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10721 * Skip non-printer attributes...
10724 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10727 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10729 if (!strcmp(attr
->name
, "job-sheets-default"))
10732 * Only allow keywords and names...
10735 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10739 * Only allow job-sheets-default to be set when running without a
10740 * system high classification level...
10743 if (Classification
)
10746 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10748 if (attr
->num_values
> 1)
10749 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10751 cupsdSetString(&printer
->job_sheets
[1], "none");
10753 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10755 cupsdFreePrinterUsers(printer
);
10757 printer
->deny_users
= 0;
10759 if (attr
->value_tag
== IPP_TAG_NAME
&&
10760 (attr
->num_values
> 1 ||
10761 strcmp(attr
->values
[0].string
.text
, "all")))
10763 for (i
= 0; i
< attr
->num_values
; i
++)
10764 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10767 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10769 cupsdFreePrinterUsers(printer
);
10771 printer
->deny_users
= 1;
10773 if (attr
->value_tag
== IPP_TAG_NAME
&&
10774 (attr
->num_values
> 1 ||
10775 strcmp(attr
->values
[0].string
.text
, "none")))
10777 for (i
= 0; i
< attr
->num_values
; i
++)
10778 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10781 else if (!strcmp(attr
->name
, "job-quota-period"))
10783 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10786 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10787 attr
->values
[0].integer
);
10788 cupsdFreeQuotas(printer
);
10790 printer
->quota_period
= attr
->values
[0].integer
;
10792 else if (!strcmp(attr
->name
, "job-k-limit"))
10794 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10797 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10798 attr
->values
[0].integer
);
10799 cupsdFreeQuotas(printer
);
10801 printer
->k_limit
= attr
->values
[0].integer
;
10803 else if (!strcmp(attr
->name
, "job-page-limit"))
10805 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10808 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10809 attr
->values
[0].integer
);
10810 cupsdFreeQuotas(printer
);
10812 printer
->page_limit
= attr
->values
[0].integer
;
10814 else if (!strcmp(attr
->name
, "printer-op-policy"))
10816 cupsd_policy_t
*p
; /* Policy */
10819 if (attr
->value_tag
!= IPP_TAG_NAME
)
10822 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10824 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10825 "Setting printer-op-policy to \"%s\"...",
10826 attr
->values
[0].string
.text
);
10827 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10828 printer
->op_policy_ptr
= p
;
10832 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10833 _("Unknown printer-op-policy \"%s\"."),
10834 attr
->values
[0].string
.text
);
10838 else if (!strcmp(attr
->name
, "printer-error-policy"))
10840 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10843 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10844 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
10845 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10846 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10847 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10849 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10850 _("Unknown printer-error-policy \"%s\"."),
10851 attr
->values
[0].string
.text
);
10855 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10856 "Setting printer-error-policy to \"%s\"...",
10857 attr
->values
[0].string
.text
);
10858 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10862 * Skip any other non-default attributes...
10865 namelen
= strlen(attr
->name
);
10866 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10867 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10871 * OK, anything else must be a user-defined default...
10874 strlcpy(name
, attr
->name
, sizeof(name
));
10875 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10877 switch (attr
->value_tag
)
10879 case IPP_TAG_DELETEATTR
:
10880 printer
->num_options
= cupsRemoveOption(name
,
10881 printer
->num_options
,
10882 &(printer
->options
));
10883 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10884 "Deleting %s", attr
->name
);
10887 case IPP_TAG_NAME
:
10888 case IPP_TAG_KEYWORD
:
10890 printer
->num_options
= cupsAddOption(name
,
10891 attr
->values
[0].string
.text
,
10892 printer
->num_options
,
10893 &(printer
->options
));
10894 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10895 "Setting %s to \"%s\"...", attr
->name
,
10896 attr
->values
[0].string
.text
);
10899 case IPP_TAG_BOOLEAN
:
10900 printer
->num_options
= cupsAddOption(name
,
10901 attr
->values
[0].boolean
?
10903 printer
->num_options
,
10904 &(printer
->options
));
10905 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10906 "Setting %s to %s...", attr
->name
,
10907 attr
->values
[0].boolean
? "true" : "false");
10910 case IPP_TAG_INTEGER
:
10911 case IPP_TAG_ENUM
:
10912 sprintf(value
, "%d", attr
->values
[0].integer
);
10913 printer
->num_options
= cupsAddOption(name
, value
,
10914 printer
->num_options
,
10915 &(printer
->options
));
10916 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10917 "Setting %s to %s...", attr
->name
, value
);
10920 case IPP_TAG_RANGE
:
10921 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10922 attr
->values
[0].range
.upper
);
10923 printer
->num_options
= cupsAddOption(name
, value
,
10924 printer
->num_options
,
10925 &(printer
->options
));
10926 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10927 "Setting %s to %s...", attr
->name
, value
);
10930 case IPP_TAG_RESOLUTION
:
10931 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10932 attr
->values
[0].resolution
.yres
,
10933 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10935 printer
->num_options
= cupsAddOption(name
, value
,
10936 printer
->num_options
,
10937 &(printer
->options
));
10938 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10939 "Setting %s to %s...", attr
->name
, value
);
10943 /* Do nothing for other values */
10951 * 'start_printer()' - Start a printer.
10955 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10956 ipp_attribute_t
*uri
) /* I - Printer URI */
10958 http_status_t status
; /* Policy status */
10959 cups_ptype_t dtype
; /* Destination type (printer/class) */
10960 cupsd_printer_t
*printer
; /* Printer data */
10963 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10964 con
->http
.fd
, uri
->values
[0].string
.text
);
10967 * Is the destination valid?
10970 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10976 send_ipp_status(con
, IPP_NOT_FOUND
,
10977 _("The printer or class was not found."));
10985 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10987 send_http_error(con
, status
, printer
);
10992 * Start the printer...
10995 printer
->state_message
[0] = '\0';
10997 cupsdStartPrinter(printer
, 1);
10999 if (dtype
& CUPS_PRINTER_CLASS
)
11000 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11001 printer
->name
, get_username(con
));
11003 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11004 printer
->name
, get_username(con
));
11009 * Everything was ok, so return OK status...
11012 con
->response
->request
.status
.status_code
= IPP_OK
;
11017 * 'stop_printer()' - Stop a printer.
11021 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11022 ipp_attribute_t
*uri
) /* I - Printer URI */
11024 http_status_t status
; /* Policy status */
11025 cups_ptype_t dtype
; /* Destination type (printer/class) */
11026 cupsd_printer_t
*printer
; /* Printer data */
11027 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11030 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11031 con
->http
.fd
, uri
->values
[0].string
.text
);
11034 * Is the destination valid?
11037 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11043 send_ipp_status(con
, IPP_NOT_FOUND
,
11044 _("The printer or class was not found."));
11052 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11054 send_http_error(con
, status
, printer
);
11059 * Stop the printer...
11062 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11063 IPP_TAG_TEXT
)) == NULL
)
11064 strcpy(printer
->state_message
, "Paused");
11067 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11068 sizeof(printer
->state_message
));
11071 cupsdStopPrinter(printer
, 1);
11073 if (dtype
& CUPS_PRINTER_CLASS
)
11074 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11075 printer
->name
, get_username(con
));
11077 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11078 printer
->name
, get_username(con
));
11081 * Everything was ok, so return OK status...
11084 con
->response
->request
.status
.status_code
= IPP_OK
;
11089 * 'url_encode_attr()' - URL-encode a string attribute.
11093 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11094 char *buffer
,/* I - String buffer */
11095 int bufsize
)/* I - Size of buffer */
11097 int i
; /* Looping var */
11098 char *bufptr
, /* Pointer into buffer */
11099 *bufend
; /* End of buffer */
11102 strlcpy(buffer
, attr
->name
, bufsize
);
11103 bufptr
= buffer
+ strlen(buffer
);
11104 bufend
= buffer
+ bufsize
- 1;
11106 for (i
= 0; i
< attr
->num_values
; i
++)
11108 if (bufptr
>= bufend
)
11116 if (bufptr
>= bufend
)
11121 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11122 bufptr
, bufend
- bufptr
+ 1);
11124 if (bufptr
>= bufend
)
11135 * 'url_encode_string()' - URL-encode a string.
11138 static char * /* O - End of string */
11139 url_encode_string(const char *s
, /* I - String */
11140 char *buffer
, /* I - String buffer */
11141 int bufsize
) /* I - Size of buffer */
11143 char *bufptr
, /* Pointer into buffer */
11144 *bufend
; /* End of buffer */
11145 static const char *hex
= "0123456789ABCDEF";
11150 bufend
= buffer
+ bufsize
- 1;
11152 while (*s
&& bufptr
< bufend
)
11154 if (*s
== ' ' || *s
== '%')
11156 if (bufptr
>= (bufend
- 2))
11160 *bufptr
++ = hex
[(*s
>> 4) & 15];
11161 *bufptr
++ = hex
[*s
& 15];
11165 else if (*s
== '\'' || *s
== '\\')
11167 if (bufptr
>= (bufend
- 1))
11184 * 'user_allowed()' - See if a user is allowed to print to a queue.
11187 static int /* O - 0 if not allowed, 1 if allowed */
11188 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11189 const char *username
) /* I - Username */
11191 int i
; /* Looping var */
11192 struct passwd
*pw
; /* User password data */
11193 char baseuser
[256], /* Base username */
11194 *baseptr
; /* Pointer to "@" in base username */
11197 if (p
->num_users
== 0)
11200 if (!strcmp(username
, "root"))
11203 if (strchr(username
, '@'))
11206 * Strip @REALM for username check...
11209 strlcpy(baseuser
, username
, sizeof(baseuser
));
11211 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11214 username
= baseuser
;
11217 pw
= getpwnam(username
);
11220 for (i
= 0; i
< p
->num_users
; i
++)
11222 if (p
->users
[i
][0] == '@')
11225 * Check group membership...
11228 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
11231 else if (p
->users
[i
][0] == '#')
11237 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
11240 else if (!strcasecmp(username
, p
->users
[i
]))
11244 return ((i
< p
->num_users
) != p
->deny_users
);
11249 * 'validate_job()' - Validate printer options and destination.
11253 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11254 ipp_attribute_t
*uri
) /* I - Printer URI */
11256 http_status_t status
; /* Policy status */
11257 ipp_attribute_t
*attr
; /* Current attribute */
11258 ipp_attribute_t
*format
; /* Document-format attribute */
11259 cups_ptype_t dtype
; /* Destination type (printer/class) */
11260 char super
[MIME_MAX_SUPER
],
11261 /* Supertype of file */
11262 type
[MIME_MAX_TYPE
];
11263 /* Subtype of file */
11264 cupsd_printer_t
*printer
; /* Printer */
11267 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11268 con
->http
.fd
, uri
->values
[0].string
.text
);
11271 * OK, see if the client is sending the document compressed - CUPS
11272 * doesn't support compression yet...
11275 if ((attr
= ippFindAttribute(con
->request
, "compression",
11276 IPP_TAG_KEYWORD
)) != NULL
&&
11277 !strcmp(attr
->values
[0].string
.text
, "none"))
11279 send_ipp_status(con
, IPP_ATTRIBUTES
,
11280 _("Unsupported compression attribute %s!"),
11281 attr
->values
[0].string
.text
);
11282 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11283 "compression", NULL
, attr
->values
[0].string
.text
);
11288 * Is it a format we support?
11291 if ((format
= ippFindAttribute(con
->request
, "document-format",
11292 IPP_TAG_MIMETYPE
)) != NULL
)
11294 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11297 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
11298 format
->values
[0].string
.text
);
11302 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11303 !mimeType(MimeDatabase
, super
, type
))
11305 cupsdLogMessage(CUPSD_LOG_INFO
,
11306 "Hint: Do you have the raw file printing rules enabled?");
11307 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11308 _("Unsupported format \"%s\"!"),
11309 format
->values
[0].string
.text
);
11310 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11311 "document-format", NULL
, format
->values
[0].string
.text
);
11317 * Is the destination valid?
11320 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11326 send_ipp_status(con
, IPP_NOT_FOUND
,
11327 _("The printer or class was not found."));
11335 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11337 send_http_error(con
, status
, printer
);
11342 * Everything was ok, so return OK status...
11345 con
->response
->request
.status
.status_code
= IPP_OK
;
11350 * 'validate_name()' - Make sure the printer name only contains valid chars.
11353 static int /* O - 0 if name is no good, 1 if good */
11354 validate_name(const char *name
) /* I - Name to check */
11356 const char *ptr
; /* Pointer into name */
11360 * Scan the whole name...
11363 for (ptr
= name
; *ptr
; ptr
++)
11364 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11368 * All the characters are good; validate the length, too...
11371 return ((ptr
- name
) < 128);
11376 * 'validate_user()' - Validate the user for the request.
11379 static int /* O - 1 if permitted, 0 otherwise */
11380 validate_user(cupsd_job_t
*job
, /* I - Job */
11381 cupsd_client_t
*con
, /* I - Client connection */
11382 const char *owner
, /* I - Owner of job/resource */
11383 char *username
, /* O - Authenticated username */
11384 int userlen
) /* I - Length of username */
11386 cupsd_printer_t
*printer
; /* Printer for job */
11389 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11390 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11392 job
->id
, con
? con
->http
.fd
: 0,
11393 owner
? owner
: "(null)", username
, userlen
);
11396 * Validate input...
11399 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11403 * Get the best authenticated username that is available.
11406 strlcpy(username
, get_username(con
), userlen
);
11409 * Check the username against the owner...
11412 printer
= cupsdFindDest(job
->dest
);
11414 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11415 con
, owner
) == HTTP_OK
);
11420 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".