2 * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
4 * IPP routines for the Common UNIX Printing System (CUPS) scheduler.
6 * Copyright 2007-2009 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * This file contains Kerberos support code, copyright 2006 by
12 * These coded instructions, statements, and computer programs are the
13 * property of Apple Inc. and are protected by Federal copyright
14 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 * which should have been included with this file. If this file is
16 * file is missing or damaged, see the license at "http://www.cups.org/".
20 * cupsdProcessIPPRequest() - Process an incoming IPP request.
21 * cupsdTimeoutJob() - Timeout a job waiting on job files.
22 * accept_jobs() - Accept print jobs to a printer.
23 * add_class() - Add a class to the system.
24 * add_file() - Add a file to a job.
25 * add_job() - Add a job to a print queue.
26 * add_job_state_reasons() - Add the "job-state-reasons" attribute based
27 * upon the job and printer state...
28 * add_job_subscriptions() - Add any subscriptions for a job.
29 * add_job_uuid() - Add job-uuid attribute to a job.
30 * add_printer() - Add a printer to the system.
31 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
32 * based upon the printer state...
33 * add_queued_job_count() - Add the "queued-job-count" attribute for the
34 * specified printer or class.
35 * apple_init_profile() - Initialize a color profile.
36 * apple_register_profiles() - Register color profiles for a printer.
37 * apple_unregister_profiles() - Remove color profiles for the specified
39 * apply_printer_defaults() - Apply printer default options to a job.
40 * authenticate_job() - Set job authentication info.
41 * cancel_all_jobs() - Cancel all print jobs.
42 * cancel_job() - Cancel a print job.
43 * cancel_subscription() - Cancel a subscription.
44 * check_quotas() - Check quotas for a printer and user.
45 * check_rss_recipient() - Check that we do not have a duplicate RSS
47 * copy_attribute() - Copy a single attribute.
48 * copy_attrs() - Copy attributes from one request to another.
49 * copy_banner() - Copy a banner file to the requests directory
50 * for the specified job.
51 * copy_file() - Copy a PPD file or interface script...
52 * copy_model() - Copy a PPD model file, substituting default
54 * copy_job_attrs() - Copy job attributes.
55 * copy_printer_attrs() - Copy printer attributes.
56 * copy_subscription_attrs() - Copy subscription attributes.
57 * create_job() - Print a file to a printer or class.
58 * create_requested_array() - Create an array for the requested-attributes.
59 * create_subscription() - Create a notification subscription.
60 * delete_printer() - Remove a printer or class from the system.
61 * get_default() - Get the default destination.
62 * get_devices() - Get the list of available devices on the
64 * get_document() - Get a copy of a job file.
65 * get_job_attrs() - Get job attributes.
66 * get_jobs() - Get a list of jobs for the specified printer.
67 * get_notifications() - Get events for a subscription.
68 * get_ppd() - Get a named PPD from the local system.
69 * get_ppds() - Get the list of PPD files on the local
71 * get_printer_attrs() - Get printer attributes.
72 * get_printers() - Get a list of printers or classes.
73 * get_subscription_attrs() - Get subscription attributes.
74 * get_subscriptions() - Get subscriptions.
75 * get_username() - Get the username associated with a request.
76 * hold_job() - Hold a print job.
77 * move_job() - Move a job to a new destination.
78 * ppd_parse_line() - Parse a PPD default line.
79 * print_job() - Print a file to a printer or class.
80 * read_job_ticket() - Read a job ticket embedded in a print file.
81 * reject_jobs() - Reject print jobs to a printer.
82 * release_job() - Release a held print job.
83 * renew_subscription() - Renew an existing subscription...
84 * restart_job() - Restart an old print job.
85 * save_auth_info() - Save authentication information for a job.
86 * save_krb5_creds() - Save Kerberos credentials for the job.
87 * send_document() - Send a file to a printer or class.
88 * send_http_error() - Send a HTTP error back to the IPP client.
89 * send_ipp_status() - Send a status back to the IPP client.
90 * set_default() - Set the default destination...
91 * set_job_attrs() - Set job attributes.
92 * set_printer_attrs() - Set printer attributes.
93 * set_printer_defaults() - Set printer default options from a request.
94 * start_printer() - Start a printer.
95 * stop_printer() - Stop a printer.
96 * url_encode_attr() - URL-encode a string attribute.
97 * url_encode_string() - URL-encode a string.
98 * user_allowed() - See if a user is allowed to print to a queue.
99 * validate_job() - Validate printer options and destination.
100 * validate_name() - Make sure the printer name only contains
102 * validate_user() - Validate the user for the request.
106 * Include necessary headers...
110 #include <cups/ppd-private.h>
113 # include <ApplicationServices/ApplicationServices.h>
114 # include <CoreFoundation/CoreFoundation.h>
115 # ifdef HAVE_MEMBERSHIP_H
116 # include <membership.h>
117 # endif /* HAVE_MEMBERSHIP_H */
118 # ifdef HAVE_MEMBERSHIPPRIV_H
119 # include <membershipPriv.h>
121 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
122 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
123 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
124 # endif /* HAVE_MEMBERSHIPPRIV_H */
125 #endif /* __APPLE__ */
132 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
133 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
134 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
135 mime_type_t
*filetype
, int compression
);
136 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
137 mime_type_t
*filetype
);
138 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
139 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
140 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
141 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
142 static void add_printer_state_reasons(cupsd_client_t
*con
,
144 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
146 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
147 CMDeviceProfileInfo
*profile
, unsigned id
,
148 const char *name
, const char *text
,
149 const char *iccfile
);
150 static void apple_register_profiles(cupsd_printer_t
*p
);
151 static void apple_unregister_profiles(cupsd_printer_t
*p
);
152 #endif /* __APPLE__ */
153 static void apply_printer_defaults(cupsd_printer_t
*printer
,
155 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
156 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
157 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
158 static void cancel_subscription(cupsd_client_t
*con
, int id
);
159 static int check_rss_recipient(const char *recipient
);
160 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
161 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
163 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
164 ipp_tag_t group
, int quickcopy
);
165 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
167 static int copy_file(const char *from
, const char *to
);
168 static int copy_model(cupsd_client_t
*con
, const char *from
,
170 static void copy_job_attrs(cupsd_client_t
*con
,
173 static void copy_printer_attrs(cupsd_client_t
*con
,
174 cupsd_printer_t
*printer
,
176 static void copy_subscription_attrs(cupsd_client_t
*con
,
177 cupsd_subscription_t
*sub
,
179 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
180 static cups_array_t
*create_requested_array(ipp_t
*request
);
181 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
182 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
183 static void get_default(cupsd_client_t
*con
);
184 static void get_devices(cupsd_client_t
*con
);
185 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
187 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
188 static void get_notifications(cupsd_client_t
*con
);
189 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static void get_ppds(cupsd_client_t
*con
);
191 static void get_printers(cupsd_client_t
*con
, int type
);
192 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
193 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
194 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
195 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
196 static const char *get_username(cupsd_client_t
*con
);
197 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
199 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
200 static int ppd_parse_line(const char *line
, char *option
, int olen
,
201 char *choice
, int clen
);
202 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
203 static void read_job_ticket(cupsd_client_t
*con
);
204 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
205 static void release_held_new_jobs(cupsd_client_t
*con
,
206 ipp_attribute_t
*uri
);
207 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
208 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
209 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
210 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
211 ipp_attribute_t
*auth_info
);
212 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
213 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
214 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
215 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
216 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
217 cupsd_printer_t
*printer
);
218 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
219 const char *message
, ...)
221 __attribute__ ((__format__ (__printf__
, 3, 4)))
222 # endif /* __GNUC__ */
224 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
225 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
226 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
227 static void set_printer_defaults(cupsd_client_t
*con
,
228 cupsd_printer_t
*printer
);
229 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
230 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
231 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
233 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
234 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
235 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
236 static int validate_name(const char *name
);
237 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
238 const char *owner
, char *username
,
243 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
246 int /* O - 1 on success, 0 on failure */
247 cupsdProcessIPPRequest(
248 cupsd_client_t
*con
) /* I - Client connection */
250 ipp_tag_t group
; /* Current group tag */
251 ipp_attribute_t
*attr
; /* Current attribute */
252 ipp_attribute_t
*charset
; /* Character set attribute */
253 ipp_attribute_t
*language
; /* Language attribute */
254 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
255 ipp_attribute_t
*username
; /* requesting-user-name attr */
256 int sub_id
; /* Subscription ID */
259 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
260 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
261 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
264 * First build an empty response message for this request...
267 con
->response
= ippNew();
269 con
->response
->request
.status
.version
[0] =
270 con
->request
->request
.op
.version
[0];
271 con
->response
->request
.status
.version
[1] =
272 con
->request
->request
.op
.version
[1];
273 con
->response
->request
.status
.request_id
=
274 con
->request
->request
.op
.request_id
;
277 * Then validate the request header and required attributes...
280 if (con
->request
->request
.any
.version
[0] != 1 &&
281 con
->request
->request
.any
.version
[0] != 2)
284 * Return an error, since we only support IPP 1.x and 2.x.
287 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
288 "%04X %s Bad request version number %d.%d",
289 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
290 con
->request
->request
.any
.version
[0],
291 con
->request
->request
.any
.version
[1]);
293 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
294 _("Bad request version number %d.%d"),
295 con
->request
->request
.any
.version
[0],
296 con
->request
->request
.any
.version
[1]);
298 else if (con
->request
->request
.any
.request_id
< 1)
301 * Return an error, since request IDs must be between 1 and 2^31-1
304 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
305 "%04X %s Bad request ID %d",
306 IPP_BAD_REQUEST
, con
->http
.hostname
,
307 con
->request
->request
.any
.request_id
);
309 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d"),
310 con
->request
->request
.any
.request_id
);
312 else if (!con
->request
->attrs
)
314 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
315 "%04X %s No attributes in request",
316 IPP_BAD_REQUEST
, con
->http
.hostname
);
318 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request"));
323 * Make sure that the attributes are provided in the correct order and
324 * don't repeat groups...
327 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
330 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
333 * Out of order; return an error...
336 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
337 "%04X %s Attribute groups are out of order",
338 IPP_BAD_REQUEST
, con
->http
.hostname
);
340 send_ipp_status(con
, IPP_BAD_REQUEST
,
341 _("Attribute groups are out of order (%x < %x)"),
342 attr
->group_tag
, group
);
346 group
= attr
->group_tag
;
351 * Then make sure that the first three attributes are:
354 * attributes-natural-language
355 * printer-uri/job-uri
358 attr
= con
->request
->attrs
;
359 if (attr
&& attr
->name
&&
360 !strcmp(attr
->name
, "attributes-charset") &&
361 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
369 if (attr
&& attr
->name
&&
370 !strcmp(attr
->name
, "attributes-natural-language") &&
371 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
376 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
377 IPP_TAG_URI
)) != NULL
)
379 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
380 IPP_TAG_URI
)) != NULL
)
382 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
383 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
388 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
389 "attributes-charset", NULL
,
390 charset
->values
[0].string
.text
);
392 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
393 "attributes-charset", NULL
, DefaultCharset
);
396 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
397 "attributes-natural-language", NULL
,
398 language
->values
[0].string
.text
);
400 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
401 "attributes-natural-language", NULL
, DefaultLanguage
);
404 strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
405 strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
408 * Bad character set...
411 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
412 charset
->values
[0].string
.text
);
413 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
414 "%04X %s Unsupported attributes-charset value \"%s\"",
415 IPP_CHARSET
, con
->http
.hostname
,
416 charset
->values
[0].string
.text
);
417 send_ipp_status(con
, IPP_BAD_REQUEST
,
418 _("Unsupported character set \"%s\""),
419 charset
->values
[0].string
.text
);
421 else if (!charset
|| !language
||
423 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
424 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
425 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
426 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
427 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
430 * Return an error, since attributes-charset,
431 * attributes-natural-language, and printer-uri/job-uri are required
432 * for all operations.
437 cupsdLogMessage(CUPSD_LOG_ERROR
,
438 "Missing attributes-charset attribute");
440 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
441 "%04X %s Missing attributes-charset attribute",
442 IPP_BAD_REQUEST
, con
->http
.hostname
);
447 cupsdLogMessage(CUPSD_LOG_ERROR
,
448 "Missing attributes-natural-language attribute");
450 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
451 "%04X %s Missing attributes-natural-language attribute",
452 IPP_BAD_REQUEST
, con
->http
.hostname
);
457 cupsdLogMessage(CUPSD_LOG_ERROR
,
458 "Missing printer-uri, job-uri, or ppd-name "
461 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
462 "%04X %s Missing printer-uri, job-uri, or ppd-name "
463 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
466 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
468 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
469 cupsdLogMessage(CUPSD_LOG_DEBUG
,
470 "attr \"%s\": group_tag = %x, value_tag = %x",
471 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
474 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
476 send_ipp_status(con
, IPP_BAD_REQUEST
,
477 _("Missing required attributes"));
482 * OK, all the checks pass so far; make sure requesting-user-name is
483 * not "root" from a remote host...
486 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
487 IPP_TAG_NAME
)) != NULL
)
490 * Check for root user...
493 if (!strcmp(username
->values
[0].string
.text
, "root") &&
494 strcasecmp(con
->http
.hostname
, "localhost") &&
495 strcmp(con
->username
, "root"))
498 * Remote unauthenticated user masquerading as local root...
501 _cupsStrFree(username
->values
[0].string
.text
);
502 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
506 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
507 IPP_TAG_INTEGER
)) != NULL
)
508 sub_id
= attr
->values
[0].integer
;
513 * Then try processing the operation...
517 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
518 ippOpString(con
->request
->request
.op
.operation_id
),
519 uri
->values
[0].string
.text
);
521 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
522 ippOpString(con
->request
->request
.op
.operation_id
));
524 switch (con
->request
->request
.op
.operation_id
)
530 case IPP_VALIDATE_JOB
:
531 validate_job(con
, uri
);
534 case IPP_CREATE_JOB
:
535 create_job(con
, uri
);
538 case IPP_SEND_DOCUMENT
:
539 send_document(con
, uri
);
542 case IPP_CANCEL_JOB
:
543 cancel_job(con
, uri
);
546 case IPP_GET_JOB_ATTRIBUTES
:
547 get_job_attrs(con
, uri
);
554 case IPP_GET_PRINTER_ATTRIBUTES
:
555 get_printer_attrs(con
, uri
);
558 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
559 get_printer_supported(con
, uri
);
566 case IPP_RELEASE_JOB
:
567 release_job(con
, uri
);
570 case IPP_RESTART_JOB
:
571 restart_job(con
, uri
);
574 case IPP_PAUSE_PRINTER
:
575 stop_printer(con
, uri
);
578 case IPP_RESUME_PRINTER
:
579 start_printer(con
, uri
);
582 case IPP_PURGE_JOBS
:
583 cancel_all_jobs(con
, uri
);
586 case IPP_SET_JOB_ATTRIBUTES
:
587 set_job_attrs(con
, uri
);
590 case IPP_SET_PRINTER_ATTRIBUTES
:
591 set_printer_attrs(con
, uri
);
594 case IPP_HOLD_NEW_JOBS
:
595 hold_new_jobs(con
, uri
);
598 case IPP_RELEASE_HELD_NEW_JOBS
:
599 release_held_new_jobs(con
, uri
);
602 case CUPS_GET_DEFAULT
:
606 case CUPS_GET_PRINTERS
:
607 get_printers(con
, 0);
610 case CUPS_GET_CLASSES
:
611 get_printers(con
, CUPS_PRINTER_CLASS
);
614 case CUPS_ADD_PRINTER
:
615 add_printer(con
, uri
);
618 case CUPS_DELETE_PRINTER
:
619 delete_printer(con
, uri
);
622 case CUPS_ADD_CLASS
:
626 case CUPS_DELETE_CLASS
:
627 delete_printer(con
, uri
);
630 case CUPS_ACCEPT_JOBS
:
631 case IPP_ENABLE_PRINTER
:
632 accept_jobs(con
, uri
);
635 case CUPS_REJECT_JOBS
:
636 case IPP_DISABLE_PRINTER
:
637 reject_jobs(con
, uri
);
640 case CUPS_SET_DEFAULT
:
641 set_default(con
, uri
);
644 case CUPS_GET_DEVICES
:
648 case CUPS_GET_DOCUMENT
:
649 get_document(con
, uri
);
664 case CUPS_AUTHENTICATE_JOB
:
665 authenticate_job(con
, uri
);
668 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
669 case IPP_CREATE_JOB_SUBSCRIPTION
:
670 create_subscription(con
, uri
);
673 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
674 get_subscription_attrs(con
, sub_id
);
677 case IPP_GET_SUBSCRIPTIONS
:
678 get_subscriptions(con
, uri
);
681 case IPP_RENEW_SUBSCRIPTION
:
682 renew_subscription(con
, sub_id
);
685 case IPP_CANCEL_SUBSCRIPTION
:
686 cancel_subscription(con
, sub_id
);
689 case IPP_GET_NOTIFICATIONS
:
690 get_notifications(con
);
694 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
695 "%04X %s Operation %04X (%s) not supported",
696 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
697 con
->request
->request
.op
.operation_id
,
698 ippOpString(con
->request
->request
.op
.operation_id
));
700 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
701 _("%s not supported"),
703 con
->request
->request
.op
.operation_id
));
713 * Sending data from the scheduler...
716 cupsdLogMessage(con
->response
->request
.status
.status_code
717 >= IPP_BAD_REQUEST
&&
718 con
->response
->request
.status
.status_code
719 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
720 "Returning IPP %s for %s (%s) from %s",
721 ippErrorString(con
->response
->request
.status
.status_code
),
722 ippOpString(con
->request
->request
.op
.operation_id
),
723 uri
? uri
->values
[0].string
.text
: "no URI",
726 if (LogLevel
== CUPSD_LOG_DEBUG2
)
727 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
728 "cupsdProcessIPPRequest: ippLength(response)=%ld",
729 (long)ippLength(con
->response
));
731 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
733 #ifdef CUPSD_USE_CHUNKING
735 * Because older versions of CUPS (1.1.17 and older) and some IPP
736 * clients do not implement chunking properly, we cannot use
737 * chunking by default. This may become the default in future
738 * CUPS releases, or we might add a configuration directive for
742 if (con
->http
.version
== HTTP_1_1
)
744 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
747 if (cupsdFlushHeader(con
) < 0)
750 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
753 #endif /* CUPSD_USE_CHUNKING */
755 size_t length
; /* Length of response */
758 length
= ippLength(con
->response
);
760 if (con
->file
>= 0 && !con
->pipe_pid
)
762 struct stat fileinfo
; /* File information */
765 if (!fstat(con
->file
, &fileinfo
))
766 length
+= fileinfo
.st_size
;
769 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
770 CUPS_LLCAST length
) < 0)
773 if (cupsdFlushHeader(con
) < 0)
776 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
777 con
->http
.data_remaining
= length
;
779 if (con
->http
.data_remaining
<= INT_MAX
)
780 con
->http
._data_remaining
= con
->http
.data_remaining
;
782 con
->http
._data_remaining
= INT_MAX
;
785 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
786 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
789 * Tell the caller the response header was sent successfully...
797 * Tell the caller the response header could not be sent...
806 * Sending data from a subprocess like cups-deviced; tell the caller
807 * everything is A-OK so far...
816 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
819 int /* O - 0 on success, -1 on error */
820 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
822 cupsd_printer_t
*printer
; /* Destination printer or class */
823 ipp_attribute_t
*attr
; /* job-sheets attribute */
824 int kbytes
; /* Kilobytes in banner */
827 job
->pending_timeout
= 0;
830 * See if we need to add the ending sheet...
833 printer
= cupsdFindDest(job
->dest
);
834 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
837 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
838 attr
&& attr
->num_values
> 1)
844 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
845 attr
->values
[1].string
.text
);
847 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
850 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
858 * 'accept_jobs()' - Accept print jobs to a printer.
862 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
863 ipp_attribute_t
*uri
) /* I - Printer or class URI */
865 http_status_t status
; /* Policy status */
866 cups_ptype_t dtype
; /* Destination type (printer/class) */
867 cupsd_printer_t
*printer
; /* Printer data */
870 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
871 con
->http
.fd
, uri
->values
[0].string
.text
);
874 * Is the destination valid?
877 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
883 send_ipp_status(con
, IPP_NOT_FOUND
,
884 _("The printer or class was not found."));
892 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
894 send_http_error(con
, status
, printer
);
899 * Accept jobs sent to the printer...
902 printer
->accepting
= 1;
903 printer
->state_message
[0] = '\0';
905 cupsdAddPrinterHistory(printer
);
907 if (dtype
& CUPS_PRINTER_CLASS
)
909 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
911 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
912 printer
->name
, get_username(con
));
916 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
918 cupsdLogMessage(CUPSD_LOG_INFO
,
919 "Printer \"%s\" now accepting jobs (\"%s\").",
920 printer
->name
, get_username(con
));
924 * Everything was ok, so return OK status...
927 con
->response
->request
.status
.status_code
= IPP_OK
;
932 * 'add_class()' - Add a class to the system.
936 add_class(cupsd_client_t
*con
, /* I - Client connection */
937 ipp_attribute_t
*uri
) /* I - URI of class */
939 http_status_t status
; /* Policy status */
940 int i
; /* Looping var */
941 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
942 username
[HTTP_MAX_URI
], /* Username portion of URI */
943 host
[HTTP_MAX_URI
], /* Host portion of URI */
944 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
945 int port
; /* Port portion of URI */
946 cupsd_printer_t
*pclass
, /* Class */
947 *member
; /* Member printer/class */
948 cups_ptype_t dtype
; /* Destination type */
949 ipp_attribute_t
*attr
; /* Printer attribute */
950 int modify
; /* Non-zero if we just modified */
951 char newname
[IPP_MAX_NAME
]; /* New class name */
952 int need_restart_job
; /* Need to restart job? */
955 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
956 con
->http
.fd
, uri
->values
[0].string
.text
);
959 * Do we have a valid URI?
962 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
963 sizeof(scheme
), username
, sizeof(username
), host
,
964 sizeof(host
), &port
, resource
, sizeof(resource
));
967 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
970 * No, return an error...
973 send_ipp_status(con
, IPP_BAD_REQUEST
,
974 _("The printer-uri must be of the form "
975 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
980 * Do we have a valid printer name?
983 if (!validate_name(resource
+ 9))
986 * No, return an error...
989 send_ipp_status(con
, IPP_BAD_REQUEST
,
990 _("The printer-uri \"%s\" contains invalid characters."),
991 uri
->values
[0].string
.text
);
996 * See if the class already exists; if not, create a new class...
999 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1002 * Class doesn't exist; see if we have a printer of the same name...
1005 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
1006 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
1009 * Yes, return an error...
1012 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1013 _("A printer named \"%s\" already exists"),
1019 * No, check the default policy and then add the class...
1022 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1024 send_http_error(con
, status
, NULL
);
1028 pclass
= cupsdAddClass(resource
+ 9);
1031 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1034 * Check the default policy, then rename the implicit class to "AnyClass"
1038 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1040 send_http_error(con
, status
, NULL
);
1044 if (ImplicitAnyClasses
)
1046 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1047 cupsdRenamePrinter(pclass
, newname
);
1050 cupsdDeletePrinter(pclass
, 1);
1053 * Add the class as a new local class...
1056 pclass
= cupsdAddClass(resource
+ 9);
1059 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1062 * Check the default policy, then rename the remote class to "Class"...
1065 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1067 send_http_error(con
, status
, NULL
);
1071 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1072 cupsdRenamePrinter(pclass
, newname
);
1075 * Add the class as a new local class...
1078 pclass
= cupsdAddClass(resource
+ 9);
1081 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1084 send_http_error(con
, status
, pclass
);
1091 * Look for attributes and copy them over as needed...
1094 need_restart_job
= 0;
1096 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1097 IPP_TAG_TEXT
)) != NULL
)
1098 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1100 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1101 IPP_TAG_TEXT
)) != NULL
)
1102 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1104 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1105 IPP_TAG_BOOLEAN
)) != NULL
)
1107 cupsdLogMessage(CUPSD_LOG_INFO
,
1108 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1109 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1111 pclass
->accepting
= attr
->values
[0].boolean
;
1112 cupsdAddPrinterHistory(pclass
);
1115 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1116 IPP_TAG_BOOLEAN
)) != NULL
)
1118 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1119 cupsdDeregisterPrinter(pclass
, 1);
1121 cupsdLogMessage(CUPSD_LOG_INFO
,
1122 "Setting %s printer-is-shared to %d (was %d.)",
1123 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1125 pclass
->shared
= attr
->values
[0].boolean
;
1128 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1129 IPP_TAG_ENUM
)) != NULL
)
1131 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1132 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1134 send_ipp_status(con
, IPP_BAD_REQUEST
,
1135 _("Attempt to set %s printer-state to bad value %d"),
1136 pclass
->name
, attr
->values
[0].integer
);
1140 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1141 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1143 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1144 cupsdStopPrinter(pclass
, 0);
1147 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1148 need_restart_job
= 1;
1151 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1152 IPP_TAG_TEXT
)) != NULL
)
1154 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1155 sizeof(pclass
->state_message
));
1156 cupsdAddPrinterHistory(pclass
);
1158 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1159 IPP_TAG_URI
)) != NULL
)
1162 * Clear the printer array as needed...
1165 need_restart_job
= 1;
1167 if (pclass
->num_printers
> 0)
1169 free(pclass
->printers
);
1170 pclass
->num_printers
= 0;
1174 * Add each printer or class that is listed...
1177 for (i
= 0; i
< attr
->num_values
; i
++)
1180 * Search for the printer or class URI...
1183 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1189 send_ipp_status(con
, IPP_NOT_FOUND
,
1190 _("The printer or class was not found."));
1193 else if (dtype
& CUPS_PRINTER_CLASS
)
1195 send_ipp_status(con
, IPP_BAD_REQUEST
,
1196 _("Nested classes are not allowed"));
1201 * Add it to the class...
1204 cupsdAddPrinterToClass(pclass
, member
);
1208 set_printer_defaults(con
, pclass
);
1210 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1211 IPP_TAG_KEYWORD
)) != NULL
)
1212 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1215 * Update the printer class attributes and return...
1218 cupsdSetPrinterAttrs(pclass
);
1219 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1221 if (need_restart_job
&& pclass
->job
)
1224 * Reset the current job to a "pending" status...
1227 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1228 "Job restarted because the class was modified.");
1231 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1235 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, pclass
, NULL
,
1236 "Class \"%s\" modified by \"%s\".", pclass
->name
,
1239 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1240 pclass
->name
, get_username(con
));
1244 cupsdAddPrinterHistory(pclass
);
1246 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, pclass
, NULL
,
1247 "New class \"%s\" added by \"%s\".", pclass
->name
,
1250 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1251 pclass
->name
, get_username(con
));
1254 con
->response
->request
.status
.status_code
= IPP_OK
;
1259 * 'add_file()' - Add a file to a job.
1262 static int /* O - 0 on success, -1 on error */
1263 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1264 cupsd_job_t
*job
, /* I - Job to add to */
1265 mime_type_t
*filetype
, /* I - Type of file */
1266 int compression
) /* I - Compression */
1268 mime_type_t
**filetypes
; /* New filetypes array... */
1269 int *compressions
; /* New compressions array... */
1272 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1273 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1274 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1275 filetype
->super
, filetype
->type
, compression
);
1278 * Add the file to the job...
1281 if (job
->num_files
== 0)
1283 compressions
= (int *)malloc(sizeof(int));
1284 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1288 compressions
= (int *)realloc(job
->compressions
,
1289 (job
->num_files
+ 1) * sizeof(int));
1290 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1291 (job
->num_files
+ 1) *
1292 sizeof(mime_type_t
*));
1295 if (!compressions
|| !filetypes
)
1297 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1298 "Job aborted because the scheduler ran out of memory.");
1301 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1302 _("Unable to allocate memory for file types"));
1307 job
->compressions
= compressions
;
1308 job
->compressions
[job
->num_files
] = compression
;
1309 job
->filetypes
= filetypes
;
1310 job
->filetypes
[job
->num_files
] = filetype
;
1315 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1322 * 'add_job()' - Add a job to a print queue.
1325 static cupsd_job_t
* /* O - Job object */
1326 add_job(cupsd_client_t
*con
, /* I - Client connection */
1327 cupsd_printer_t
*printer
, /* I - Destination printer */
1328 mime_type_t
*filetype
) /* I - First print file type, if any */
1330 http_status_t status
; /* Policy status */
1331 ipp_attribute_t
*attr
, /* Current attribute */
1332 *auth_info
; /* auth-info attribute */
1333 const char *val
; /* Default option value */
1334 int priority
; /* Job priority */
1335 char *title
; /* Job name/title */
1336 cupsd_job_t
*job
; /* Current job */
1337 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1338 int kbytes
; /* Size of print file */
1339 int i
; /* Looping var */
1340 int lowerpagerange
; /* Page range bound */
1343 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1344 con
, con
->http
.fd
, printer
, printer
->name
,
1345 filetype
, filetype
? filetype
->super
: "none",
1346 filetype
? filetype
->type
: "none");
1349 * Check remote printing to non-shared printer...
1352 if (!printer
->shared
&&
1353 strcasecmp(con
->http
.hostname
, "localhost") &&
1354 strcasecmp(con
->http
.hostname
, ServerName
))
1356 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1357 _("The printer or class is not shared"));
1365 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1367 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1369 send_http_error(con
, status
, printer
);
1372 else if (printer
->num_auth_info_required
== 1 &&
1373 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1376 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1380 else if (auth_info
&& !con
->http
.tls
&&
1381 !httpAddrLocalhost(con
->http
.hostaddr
))
1384 * Require encryption of auth-info over non-local connections...
1387 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1390 #endif /* HAVE_SSL */
1393 * See if the printer is accepting jobs...
1396 if (!printer
->accepting
)
1398 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1399 _("Destination \"%s\" is not accepting jobs."),
1405 * Validate job template attributes; for now just document-format,
1406 * copies, number-up, and page-ranges...
1409 if (filetype
&& printer
->filetypes
&&
1410 !cupsArrayFind(printer
->filetypes
, filetype
))
1412 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1413 /* MIME media type string */
1416 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1419 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1420 _("Unsupported format \'%s\'"), mimetype
);
1422 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1423 "document-format", NULL
, mimetype
);
1428 if ((attr
= ippFindAttribute(con
->request
, "copies",
1429 IPP_TAG_INTEGER
)) != NULL
)
1431 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1433 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1434 attr
->values
[0].integer
);
1435 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1436 "copies", attr
->values
[0].integer
);
1441 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1442 IPP_TAG_ZERO
)) != NULL
)
1444 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1445 attr
->value_tag
!= IPP_TAG_NAME
)
1447 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type"));
1451 if (attr
->num_values
> 2)
1453 send_ipp_status(con
, IPP_BAD_REQUEST
,
1454 _("Too many job-sheets values (%d > 2)"),
1459 for (i
= 0; i
< attr
->num_values
; i
++)
1460 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1461 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1463 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\""),
1464 attr
->values
[i
].string
.text
);
1469 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1470 IPP_TAG_INTEGER
)) != NULL
)
1472 if (attr
->values
[0].integer
!= 1 &&
1473 attr
->values
[0].integer
!= 2 &&
1474 attr
->values
[0].integer
!= 4 &&
1475 attr
->values
[0].integer
!= 6 &&
1476 attr
->values
[0].integer
!= 9 &&
1477 attr
->values
[0].integer
!= 16)
1479 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1480 attr
->values
[0].integer
);
1481 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1482 "number-up", attr
->values
[0].integer
);
1487 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1488 IPP_TAG_RANGE
)) != NULL
)
1490 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1492 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1493 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1495 send_ipp_status(con
, IPP_BAD_REQUEST
,
1496 _("Bad page-ranges values %d-%d."),
1497 attr
->values
[i
].range
.lower
,
1498 attr
->values
[i
].range
.upper
);
1502 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1507 * Make sure we aren't over our limit...
1510 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1513 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1515 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1516 _("Too many active jobs."));
1520 if ((i
= check_quotas(con
, printer
)) < 0)
1522 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1527 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1532 * Create the job and set things up...
1535 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1536 IPP_TAG_INTEGER
)) != NULL
)
1537 priority
= attr
->values
[0].integer
;
1540 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1541 printer
->options
)) != NULL
)
1542 priority
= atoi(val
);
1546 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1550 if ((attr
= ippFindAttribute(con
->request
, "job-name",
1551 IPP_TAG_NAME
)) != NULL
)
1552 title
= attr
->values
[0].string
.text
;
1554 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1555 title
= "Untitled");
1557 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1559 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1560 _("Unable to add job for destination \"%s\""),
1565 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1566 CUPS_PRINTER_REMOTE
);
1567 job
->attrs
= con
->request
;
1569 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1571 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1573 add_job_uuid(con
, job
);
1574 apply_printer_defaults(printer
, job
);
1576 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1578 if (con
->username
[0])
1580 cupsdSetString(&job
->username
, con
->username
);
1583 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1587 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1588 "add_job: requesting-user-name=\"%s\"",
1589 attr
->values
[0].string
.text
);
1591 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1594 cupsdSetString(&job
->username
, "anonymous");
1597 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1598 "job-originating-user-name", NULL
, job
->username
);
1601 attr
->group_tag
= IPP_TAG_JOB
;
1602 _cupsStrFree(attr
->name
);
1603 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1606 if (con
->username
[0] || auth_info
)
1608 save_auth_info(con
, job
, auth_info
);
1611 * Remove the auth-info attribute from the attribute data...
1615 ippDeleteAttribute(job
->attrs
, auth_info
);
1618 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1619 IPP_TAG_ZERO
)) != NULL
)
1622 * Request contains a job-originating-host-name attribute; validate it...
1625 if (attr
->value_tag
!= IPP_TAG_NAME
||
1626 attr
->num_values
!= 1 ||
1627 strcmp(con
->http
.hostname
, "localhost"))
1630 * Can't override the value if we aren't connected via localhost.
1631 * Also, we can only have 1 value and it must be a name value.
1634 switch (attr
->value_tag
)
1636 case IPP_TAG_STRING
:
1637 case IPP_TAG_TEXTLANG
:
1638 case IPP_TAG_NAMELANG
:
1641 case IPP_TAG_KEYWORD
:
1643 case IPP_TAG_URISCHEME
:
1644 case IPP_TAG_CHARSET
:
1645 case IPP_TAG_LANGUAGE
:
1646 case IPP_TAG_MIMETYPE
:
1648 * Free old strings...
1651 for (i
= 0; i
< attr
->num_values
; i
++)
1653 _cupsStrFree(attr
->values
[i
].string
.text
);
1654 attr
->values
[i
].string
.text
= NULL
;
1655 if (attr
->values
[i
].string
.charset
)
1657 _cupsStrFree(attr
->values
[i
].string
.charset
);
1658 attr
->values
[i
].string
.charset
= NULL
;
1667 * Use the default connection hostname instead...
1670 attr
->value_tag
= IPP_TAG_NAME
;
1671 attr
->num_values
= 1;
1672 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1675 attr
->group_tag
= IPP_TAG_JOB
;
1680 * No job-originating-host-name attribute, so use the hostname from
1684 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1685 "job-originating-host-name", NULL
, con
->http
.hostname
);
1688 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1690 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1691 "time-at-processing", 0);
1692 attr
->value_tag
= IPP_TAG_NOVALUE
;
1693 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1694 "time-at-completed", 0);
1695 attr
->value_tag
= IPP_TAG_NOVALUE
;
1698 * Add remaining job attributes...
1701 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1702 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1703 "job-state", IPP_JOB_STOPPED
);
1704 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1705 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1706 "job-media-sheets-completed", 0);
1707 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1709 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1712 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1713 IPP_TAG_INTEGER
)) != NULL
)
1714 attr
->values
[0].integer
= 0;
1716 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1718 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1719 IPP_TAG_KEYWORD
)) == NULL
)
1720 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1723 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1724 printer
->options
)) == NULL
)
1727 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1728 "job-hold-until", NULL
, val
);
1730 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1733 * Hold job until specified time...
1736 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1738 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1739 job
->state_value
= IPP_JOB_HELD
;
1741 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1743 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1744 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1745 job
->state_value
= IPP_JOB_HELD
;
1749 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1750 job
->state_value
= IPP_JOB_PENDING
;
1753 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1757 * Add job sheets options...
1760 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1761 IPP_TAG_ZERO
)) == NULL
)
1763 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1764 "Adding default job-sheets values \"%s,%s\"...",
1765 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1767 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1769 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1770 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1773 job
->job_sheets
= attr
;
1776 * Enforce classification level if set...
1781 cupsdLogMessage(CUPSD_LOG_INFO
,
1782 "Classification=\"%s\", ClassifyOverride=%d",
1783 Classification
? Classification
: "(null)",
1786 if (ClassifyOverride
)
1788 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1789 (attr
->num_values
== 1 ||
1790 !strcmp(attr
->values
[1].string
.text
, "none")))
1793 * Force the leading banner to have the classification on it...
1796 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1798 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1799 "job-sheets=\"%s,none\", "
1800 "job-originating-user-name=\"%s\"",
1801 Classification
, job
->username
);
1803 else if (attr
->num_values
== 2 &&
1804 strcmp(attr
->values
[0].string
.text
,
1805 attr
->values
[1].string
.text
) &&
1806 strcmp(attr
->values
[0].string
.text
, "none") &&
1807 strcmp(attr
->values
[1].string
.text
, "none"))
1810 * Can't put two different security markings on the same document!
1813 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1815 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1816 "job-sheets=\"%s,%s\", "
1817 "job-originating-user-name=\"%s\"",
1818 attr
->values
[0].string
.text
,
1819 attr
->values
[1].string
.text
, job
->username
);
1821 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1822 strcmp(attr
->values
[0].string
.text
, "none") &&
1823 (attr
->num_values
== 1 ||
1824 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1825 strcmp(attr
->values
[1].string
.text
, "none"))))
1827 if (attr
->num_values
== 1)
1828 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1829 "CLASSIFICATION OVERRIDDEN "
1830 "job-sheets=\"%s\", "
1831 "job-originating-user-name=\"%s\"",
1832 attr
->values
[0].string
.text
, job
->username
);
1834 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1835 "CLASSIFICATION OVERRIDDEN "
1836 "job-sheets=\"%s,%s\",fffff "
1837 "job-originating-user-name=\"%s\"",
1838 attr
->values
[0].string
.text
,
1839 attr
->values
[1].string
.text
, job
->username
);
1842 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1843 (attr
->num_values
== 1 ||
1844 strcmp(attr
->values
[1].string
.text
, Classification
)))
1847 * Force the banner to have the classification on it...
1850 if (attr
->num_values
> 1 &&
1851 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1853 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1854 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1858 if (attr
->num_values
== 1 ||
1859 strcmp(attr
->values
[0].string
.text
, "none"))
1860 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1862 if (attr
->num_values
> 1 &&
1863 strcmp(attr
->values
[1].string
.text
, "none"))
1864 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1867 if (attr
->num_values
> 1)
1868 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1869 "CLASSIFICATION FORCED "
1870 "job-sheets=\"%s,%s\", "
1871 "job-originating-user-name=\"%s\"",
1872 attr
->values
[0].string
.text
,
1873 attr
->values
[1].string
.text
, job
->username
);
1875 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1876 "CLASSIFICATION FORCED "
1877 "job-sheets=\"%s\", "
1878 "job-originating-user-name=\"%s\"",
1879 Classification
, job
->username
);
1884 * See if we need to add the starting sheet...
1887 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1889 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1890 attr
->values
[0].string
.text
);
1892 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1894 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1895 "Aborting job because the start banner could not be "
1900 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1903 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1904 IPP_TAG_ZERO
)) != NULL
)
1908 * Fill in the response info...
1911 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1912 LocalPort
, job
->id
);
1914 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1917 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1919 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1921 add_job_state_reasons(con
, job
);
1923 con
->response
->request
.status
.status_code
= IPP_OK
;
1926 * Add any job subscriptions...
1929 add_job_subscriptions(con
, job
);
1932 * Set all but the first two attributes to the job attributes group...
1935 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1936 attr
->group_tag
= IPP_TAG_JOB
;
1939 * Fire the "job created" event...
1942 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1945 * Return the new job...
1953 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1954 * upon the job and printer state...
1958 add_job_state_reasons(
1959 cupsd_client_t
*con
, /* I - Client connection */
1960 cupsd_job_t
*job
) /* I - Job info */
1962 cupsd_printer_t
*dest
; /* Destination printer */
1965 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1966 con
, con
->http
.fd
, job
? job
->id
: 0);
1968 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1970 case IPP_JOB_PENDING
:
1971 dest
= cupsdFindDest(job
->dest
);
1973 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1974 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1975 "job-state-reasons", NULL
, "printer-stopped");
1977 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1978 "job-state-reasons", NULL
, "none");
1982 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1983 IPP_TAG_KEYWORD
) != NULL
||
1984 ippFindAttribute(job
->attrs
, "job-hold-until",
1985 IPP_TAG_NAME
) != NULL
)
1986 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1987 "job-state-reasons", NULL
, "job-hold-until-specified");
1989 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1990 "job-state-reasons", NULL
, "job-incoming");
1993 case IPP_JOB_PROCESSING
:
1994 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1995 "job-state-reasons", NULL
, "job-printing");
1998 case IPP_JOB_STOPPED
:
1999 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2000 "job-state-reasons", NULL
, "job-stopped");
2003 case IPP_JOB_CANCELED
:
2004 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2005 "job-state-reasons", NULL
, "job-canceled-by-user");
2008 case IPP_JOB_ABORTED
:
2009 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2010 "job-state-reasons", NULL
, "aborted-by-system");
2013 case IPP_JOB_COMPLETED
:
2014 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2015 "job-state-reasons", NULL
, "job-completed-successfully");
2022 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2026 add_job_subscriptions(
2027 cupsd_client_t
*con
, /* I - Client connection */
2028 cupsd_job_t
*job
) /* I - Newly created job */
2030 int i
; /* Looping var */
2031 ipp_attribute_t
*prev
, /* Previous attribute */
2032 *next
, /* Next attribute */
2033 *attr
; /* Current attribute */
2034 cupsd_subscription_t
*sub
; /* Subscription object */
2035 const char *recipient
, /* notify-recipient-uri */
2036 *pullmethod
; /* notify-pull-method */
2037 ipp_attribute_t
*user_data
; /* notify-user-data */
2038 int interval
; /* notify-time-interval */
2039 unsigned mask
; /* notify-events */
2043 * Find the first subscription group attribute; return if we have
2047 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2048 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2055 * Process the subscription attributes in the request...
2064 mask
= CUPSD_EVENT_NONE
;
2066 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2068 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2069 attr
->value_tag
== IPP_TAG_URI
)
2072 * Validate the recipient scheme against the ServerBin/notifier
2076 char notifier
[1024], /* Notifier filename */
2077 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2078 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2079 host
[HTTP_MAX_URI
], /* Host portion of URI */
2080 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2081 int port
; /* Port portion of URI */
2084 recipient
= attr
->values
[0].string
.text
;
2086 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2087 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2088 host
, sizeof(host
), &port
,
2089 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2091 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2092 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
2093 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2094 "notify-status-code", IPP_URI_SCHEME
);
2098 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2100 if (access(notifier
, X_OK
))
2102 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2103 _("notify-recipient-uri URI \"%s\" uses unknown "
2104 "scheme"), recipient
);
2105 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2106 "notify-status-code", IPP_URI_SCHEME
);
2110 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2112 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2113 _("notify-recipient-uri URI \"%s\" is already used"),
2115 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2116 "notify-status-code", IPP_ATTRIBUTES
);
2120 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2121 attr
->value_tag
== IPP_TAG_KEYWORD
)
2123 pullmethod
= attr
->values
[0].string
.text
;
2125 if (strcmp(pullmethod
, "ippget"))
2127 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2128 _("Bad notify-pull-method \"%s\""), pullmethod
);
2129 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2130 "notify-status-code", IPP_ATTRIBUTES
);
2134 else if (!strcmp(attr
->name
, "notify-charset") &&
2135 attr
->value_tag
== IPP_TAG_CHARSET
&&
2136 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2137 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2139 send_ipp_status(con
, IPP_CHARSET
,
2140 _("Character set \"%s\" not supported"),
2141 attr
->values
[0].string
.text
);
2144 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2145 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2146 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2148 send_ipp_status(con
, IPP_CHARSET
,
2149 _("Language \"%s\" not supported"),
2150 attr
->values
[0].string
.text
);
2153 else if (!strcmp(attr
->name
, "notify-user-data") &&
2154 attr
->value_tag
== IPP_TAG_STRING
)
2156 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2158 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2159 _("The notify-user-data value is too large "
2160 "(%d > 63 octets)"),
2161 attr
->values
[0].unknown
.length
);
2167 else if (!strcmp(attr
->name
, "notify-events") &&
2168 attr
->value_tag
== IPP_TAG_KEYWORD
)
2170 for (i
= 0; i
< attr
->num_values
; i
++)
2171 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2173 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2175 send_ipp_status(con
, IPP_BAD_REQUEST
,
2176 _("The notify-lease-duration attribute cannot be "
2177 "used with job subscriptions."));
2180 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2181 attr
->value_tag
== IPP_TAG_INTEGER
)
2182 interval
= attr
->values
[0].integer
;
2187 if (!recipient
&& !pullmethod
)
2190 if (mask
== CUPSD_EVENT_NONE
)
2191 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2193 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2194 recipient
, 0)) != NULL
)
2196 sub
->interval
= interval
;
2198 cupsdSetString(&sub
->owner
, job
->username
);
2202 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2203 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2204 sub
->user_data_len
);
2207 ippAddSeparator(con
->response
);
2208 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2209 "notify-subscription-id", sub
->id
);
2216 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2219 * Remove all of the subscription attributes from the job request...
2221 * TODO: Optimize this since subscription groups have to come at the
2222 * end of the request...
2225 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2229 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2230 attr
->group_tag
== IPP_TAG_ZERO
)
2233 * Free and remove this attribute...
2241 job
->attrs
->attrs
= next
;
2247 job
->attrs
->last
= prev
;
2248 job
->attrs
->current
= prev
;
2253 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2255 * See RFC 4122 for the definition of UUIDs and the format.
2259 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2260 cupsd_job_t
*job
) /* I - Job */
2262 char uuid
[1024]; /* job-uuid string */
2263 _cups_md5_state_t md5state
; /* MD5 state */
2264 unsigned char md5sum
[16]; /* MD5 digest/sum */
2268 * First see if the job already has a job-uuid attribute; if so, return...
2271 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2275 * No job-uuid attribute, so build a version 3 UUID with the local job
2276 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2277 * the ServerName, server name and port that the client connected to,
2278 * and local job ID...
2281 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2282 con
->serverport
, job
->id
);
2284 _cupsMD5Init(&md5state
);
2285 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2286 _cupsMD5Finish(&md5state
, md5sum
);
2289 * Format the UUID URI using the MD5 sum and job ID.
2292 snprintf(uuid
, sizeof(uuid
),
2293 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2294 "%02x%02x%02x%02x%02x%02x",
2295 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2296 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2297 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2298 md5sum
[14], md5sum
[15]);
2300 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2305 * 'add_printer()' - Add a printer to the system.
2309 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2310 ipp_attribute_t
*uri
) /* I - URI of printer */
2312 http_status_t status
; /* Policy status */
2313 int i
; /* Looping var */
2314 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2315 username
[HTTP_MAX_URI
], /* Username portion of URI */
2316 host
[HTTP_MAX_URI
], /* Host portion of URI */
2317 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2318 int port
; /* Port portion of URI */
2319 cupsd_printer_t
*printer
; /* Printer/class */
2320 ipp_attribute_t
*attr
; /* Printer attribute */
2321 cups_file_t
*fp
; /* Script/PPD file */
2322 char line
[1024]; /* Line from file... */
2323 char srcfile
[1024], /* Source Script/PPD file */
2324 dstfile
[1024]; /* Destination Script/PPD file */
2325 int modify
; /* Non-zero if we are modifying */
2326 char newname
[IPP_MAX_NAME
]; /* New printer name */
2327 int changed_driver
, /* Changed the PPD/interface script? */
2328 need_restart_job
, /* Need to restart job? */
2329 set_device_uri
, /* Did we set the device URI? */
2330 set_port_monitor
; /* Did we set the port monitor? */
2333 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2334 con
->http
.fd
, uri
->values
[0].string
.text
);
2337 * Do we have a valid URI?
2340 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2341 sizeof(scheme
), username
, sizeof(username
), host
,
2342 sizeof(host
), &port
, resource
, sizeof(resource
));
2344 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2347 * No, return an error...
2350 send_ipp_status(con
, IPP_BAD_REQUEST
,
2351 _("The printer-uri must be of the form "
2352 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2357 * Do we have a valid printer name?
2360 if (!validate_name(resource
+ 10))
2363 * No, return an error...
2366 send_ipp_status(con
, IPP_BAD_REQUEST
,
2367 _("The printer-uri \"%s\" contains invalid characters."),
2368 uri
->values
[0].string
.text
);
2373 * See if the printer already exists; if not, create a new printer...
2376 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2379 * Printer doesn't exist; see if we have a class of the same name...
2382 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2383 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2386 * Yes, return an error...
2389 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2390 _("A class named \"%s\" already exists"),
2396 * No, check the default policy then add the printer...
2399 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2401 send_http_error(con
, status
, NULL
);
2405 printer
= cupsdAddPrinter(resource
+ 10);
2408 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2411 * Check the default policy, then rename the implicit printer to
2412 * "AnyPrinter" or delete it...
2415 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2417 send_http_error(con
, status
, NULL
);
2421 if (ImplicitAnyClasses
)
2423 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2424 cupsdRenamePrinter(printer
, newname
);
2427 cupsdDeletePrinter(printer
, 1);
2430 * Add the printer as a new local printer...
2433 printer
= cupsdAddPrinter(resource
+ 10);
2436 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2439 * Check the default policy, then rename the remote printer to
2440 * "Printer@server"...
2443 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2445 send_http_error(con
, status
, NULL
);
2449 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2451 cupsdRenamePrinter(printer
, newname
);
2454 * Add the printer as a new local printer...
2457 printer
= cupsdAddPrinter(resource
+ 10);
2460 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2463 send_http_error(con
, status
, printer
);
2470 * Look for attributes and copy them over as needed...
2474 need_restart_job
= 0;
2476 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2477 IPP_TAG_TEXT
)) != NULL
)
2478 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2480 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2481 IPP_TAG_TEXT
)) != NULL
)
2482 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2486 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2487 IPP_TAG_URI
)) != NULL
)
2490 * Do we have a valid device URI?
2493 http_uri_status_t uri_status
; /* URI separation status */
2494 char old_device_uri
[1024];
2495 /* Old device URI */
2498 need_restart_job
= 1;
2500 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2501 attr
->values
[0].string
.text
,
2502 scheme
, sizeof(scheme
),
2503 username
, sizeof(username
),
2504 host
, sizeof(host
), &port
,
2505 resource
, sizeof(resource
));
2507 if (uri_status
< HTTP_URI_OK
)
2509 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\""),
2510 attr
->values
[0].string
.text
);
2511 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2512 "add_printer: httpSeparateURI returned %d", uri_status
);
2516 if (!strcmp(scheme
, "file"))
2519 * See if the administrator has enabled file devices...
2522 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2525 * File devices are disabled and the URL is not file:/dev/null...
2528 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2529 _("File device URIs have been disabled! "
2530 "To enable, see the FileDevice directive in "
2531 "\"%s/cupsd.conf\"."),
2539 * See if the backend exists and is executable...
2542 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2543 if (access(srcfile
, X_OK
))
2546 * Could not find device in list!
2549 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\""),
2555 if (printer
->sanitized_device_uri
)
2556 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2557 sizeof(old_device_uri
));
2559 old_device_uri
[0] = '\0';
2561 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2563 cupsdLogMessage(CUPSD_LOG_INFO
,
2564 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2565 printer
->name
, printer
->sanitized_device_uri
,
2571 set_port_monitor
= 0;
2573 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2574 IPP_TAG_NAME
)) != NULL
)
2576 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2579 need_restart_job
= 1;
2581 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2585 for (i
= 0; i
< supported
->num_values
; i
++)
2586 if (!strcmp(supported
->values
[i
].string
.text
,
2587 attr
->values
[0].string
.text
))
2591 if (!supported
|| i
>= supported
->num_values
)
2593 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\""),
2594 attr
->values
[0].string
.text
);
2598 cupsdLogMessage(CUPSD_LOG_INFO
,
2599 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2600 printer
->name
, attr
->values
[0].string
.text
,
2601 printer
->port_monitor
? printer
->port_monitor
: "none");
2603 if (strcmp(attr
->values
[0].string
.text
, "none"))
2604 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2606 cupsdClearString(&printer
->port_monitor
);
2608 set_port_monitor
= 1;
2611 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2612 IPP_TAG_BOOLEAN
)) != NULL
)
2614 cupsdLogMessage(CUPSD_LOG_INFO
,
2615 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2616 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2618 printer
->accepting
= attr
->values
[0].boolean
;
2619 cupsdAddPrinterHistory(printer
);
2622 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2623 IPP_TAG_BOOLEAN
)) != NULL
)
2625 if (printer
->shared
&& !attr
->values
[0].boolean
)
2626 cupsdDeregisterPrinter(printer
, 1);
2628 cupsdLogMessage(CUPSD_LOG_INFO
,
2629 "Setting %s printer-is-shared to %d (was %d.)",
2630 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2632 printer
->shared
= attr
->values
[0].boolean
;
2635 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2636 IPP_TAG_ENUM
)) != NULL
)
2638 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2639 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2641 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d"),
2642 attr
->values
[0].integer
);
2646 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2647 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2649 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2650 cupsdStopPrinter(printer
, 0);
2653 need_restart_job
= 1;
2654 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2658 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2659 IPP_TAG_TEXT
)) != NULL
)
2661 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2662 sizeof(printer
->state_message
));
2663 cupsdAddPrinterHistory(printer
);
2666 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2667 IPP_TAG_KEYWORD
)) != NULL
)
2669 if (attr
->num_values
>
2670 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2672 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2673 _("Too many printer-state-reasons values (%d > %d)"),
2675 (int)(sizeof(printer
->reasons
) /
2676 sizeof(printer
->reasons
[0])));
2680 for (i
= 0; i
< printer
->num_reasons
; i
++)
2681 _cupsStrFree(printer
->reasons
[i
]);
2683 printer
->num_reasons
= 0;
2684 for (i
= 0; i
< attr
->num_values
; i
++)
2686 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2689 printer
->reasons
[printer
->num_reasons
] =
2690 _cupsStrRetain(attr
->values
[i
].string
.text
);
2691 printer
->num_reasons
++;
2693 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2694 printer
->state
!= IPP_PRINTER_STOPPED
)
2696 cupsdLogMessage(CUPSD_LOG_INFO
,
2697 "Setting %s printer-state to %d (was %d.)",
2698 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2699 cupsdStopPrinter(printer
, 0);
2703 if (PrintcapFormat
== PRINTCAP_PLIST
)
2704 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2707 set_printer_defaults(con
, printer
);
2709 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2710 IPP_TAG_KEYWORD
)) != NULL
)
2711 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2714 * See if we have all required attributes...
2717 if (!printer
->device_uri
)
2718 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2721 * See if we have an interface script or PPD file attached to the request...
2726 need_restart_job
= 1;
2729 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2731 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2734 * Yes; get the first line from it...
2738 cupsFileGets(fp
, line
, sizeof(line
));
2742 * Then see what kind of file it is...
2745 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2748 if (!strncmp(line
, "*PPD-Adobe", 10))
2751 * The new file is a PPD file, so remove any old interface script
2752 * that might be lying around...
2760 * This must be an interface script, so move the file over to the
2761 * interfaces directory and make it executable...
2764 if (copy_file(srcfile
, dstfile
))
2766 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2767 _("Unable to copy interface script - %s"),
2772 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2773 "Copied interface script successfully");
2774 chmod(dstfile
, 0755);
2777 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2780 if (!strncmp(line
, "*PPD-Adobe", 10))
2783 * The new file is a PPD file, so move the file over to the
2784 * ppd directory and make it readable by all...
2787 if (copy_file(srcfile
, dstfile
))
2789 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2790 _("Unable to copy PPD file - %s"),
2795 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2796 "Copied PPD file successfully");
2797 chmod(dstfile
, 0644);
2802 * This must be an interface script, so remove any old PPD file that
2803 * may be lying around...
2810 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2811 IPP_TAG_NAME
)) != NULL
)
2813 need_restart_job
= 1;
2816 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2819 * Raw driver, remove any existing PPD or interface script files.
2822 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2826 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2836 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2840 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2843 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2845 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file"));
2849 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2850 "Copied PPD file successfully");
2851 chmod(dstfile
, 0644);
2858 * If we changed the PPD/interface script, then remove the printer's cache
2862 char cache_name
[1024]; /* Cache filename for printer attrs */
2864 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp", CacheDir
,
2870 * (Re)register color profiles...
2875 apple_unregister_profiles(printer
);
2876 apple_register_profiles(printer
);
2878 #endif /* __APPLE__ */
2882 * If we set the device URI but not the port monitor, check which port
2883 * monitor to use by default...
2886 if (set_device_uri
&& !set_port_monitor
)
2888 ppd_file_t
*ppd
; /* PPD file */
2889 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2892 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2893 sizeof(scheme
), username
, sizeof(username
), host
,
2894 sizeof(host
), &port
, resource
, sizeof(resource
));
2896 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2898 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2900 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2902 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2903 if (!strcmp(scheme
, ppdattr
->spec
))
2905 cupsdLogMessage(CUPSD_LOG_INFO
,
2906 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2907 printer
->name
, ppdattr
->value
,
2908 printer
->port_monitor
? printer
->port_monitor
2911 if (strcmp(ppdattr
->value
, "none"))
2912 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2914 cupsdClearString(&printer
->port_monitor
);
2924 * Update the printer attributes and return...
2927 cupsdSetPrinterAttrs(printer
);
2928 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2930 if (need_restart_job
&& printer
->job
)
2933 * Restart the current job...
2936 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2937 "Job restarted because the printer was modified.");
2940 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2944 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2945 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2948 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2949 printer
->name
, get_username(con
));
2953 cupsdAddPrinterHistory(printer
);
2955 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2956 "New printer \"%s\" added by \"%s\".", printer
->name
,
2959 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2960 printer
->name
, get_username(con
));
2963 con
->response
->request
.status
.status_code
= IPP_OK
;
2968 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2969 * based upon the printer state...
2973 add_printer_state_reasons(
2974 cupsd_client_t
*con
, /* I - Client connection */
2975 cupsd_printer_t
*p
) /* I - Printer info */
2977 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2978 "add_printer_state_reasons(%p[%d], %p[%s])",
2979 con
, con
->http
.fd
, p
, p
->name
);
2981 if (p
->num_reasons
== 0)
2982 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2983 "printer-state-reasons", NULL
, "none");
2985 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2986 "printer-state-reasons", p
->num_reasons
, NULL
,
2987 (const char * const *)p
->reasons
);
2992 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2993 * the specified printer or class.
2997 add_queued_job_count(
2998 cupsd_client_t
*con
, /* I - Client connection */
2999 cupsd_printer_t
*p
) /* I - Printer or class */
3001 int count
; /* Number of jobs on destination */
3004 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3005 con
, con
->http
.fd
, p
, p
->name
);
3007 count
= cupsdGetPrinterJobCount(p
->name
);
3009 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3010 "queued-job-count", count
);
3016 * 'apple_init_profile()' - Initialize a color profile.
3021 ppd_file_t
*ppd
, /* I - PPD file */
3022 cups_array_t
*languages
, /* I - Languages in the PPD file */
3023 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3024 unsigned id
, /* I - Profile ID */
3025 const char *name
, /* I - Profile name */
3026 const char *text
, /* I - Profile UI text */
3027 const char *iccfile
) /* I - ICC filename */
3029 char url
[1024]; /* URL for profile filename */
3030 CFMutableDictionaryRef dict
; /* Dictionary for name */
3031 char *language
; /* Current language */
3032 ppd_attr_t
*attr
; /* Profile attribute */
3033 CFStringRef cflang
, /* Language string */
3034 cftext
; /* Localized text */
3038 * Build the profile name dictionary...
3041 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3042 &kCFTypeDictionaryKeyCallBacks
,
3043 &kCFTypeDictionaryValueCallBacks
);
3045 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3046 kCFStringEncodingUTF8
);
3050 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
3057 * Find localized names for the color profiles...
3060 cupsArraySave(ppd
->sorted_attrs
);
3062 for (language
= (char *)cupsArrayFirst(languages
);
3064 language
= (char *)cupsArrayNext(languages
))
3068 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3070 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3073 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3075 if (attr
&& attr
->text
[0])
3077 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3078 kCFStringEncodingUTF8
);
3079 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3080 kCFStringEncodingUTF8
);
3082 if (cflang
&& cftext
)
3083 CFDictionarySetValue(dict
, cflang
, cftext
);
3093 cupsArrayRestore(ppd
->sorted_attrs
);
3097 * Fill in the profile data...
3101 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3104 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3105 profile
->profileID
= id
;
3106 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3107 profile
->profileName
= dict
;
3110 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3111 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3116 * 'apple_register_profiles()' - Register color profiles for a printer.
3120 apple_register_profiles(
3121 cupsd_printer_t
*p
) /* I - Printer */
3123 int i
; /* Looping var */
3124 char ppdfile
[1024], /* PPD filename */
3125 iccfile
[1024], /* ICC filename */
3126 selector
[PPD_MAX_NAME
];
3127 /* Profile selection string */
3128 ppd_file_t
*ppd
; /* PPD file */
3129 ppd_attr_t
*attr
, /* Profile attributes */
3130 *profileid_attr
,/* cupsProfileID attribute */
3131 *q1_attr
, /* ColorModel (or other) qualifier */
3132 *q2_attr
, /* MediaType (or other) qualifier */
3133 *q3_attr
; /* Resolution (or other) qualifier */
3134 char q_keyword
[PPD_MAX_NAME
];
3135 /* Qualifier keyword */
3136 const char *q1_choice
, /* ColorModel (or other) choice */
3137 *q2_choice
, /* MediaType (or other) choice */
3138 *q3_choice
; /* Resolution (or other) choice */
3139 const char *profile_key
; /* Profile keyword */
3140 ppd_option_t
*cm_option
; /* Color model option */
3141 ppd_choice_t
*cm_choice
; /* Color model choice */
3142 int num_profiles
; /* Number of profiles */
3143 CMError error
; /* Last error */
3144 unsigned device_id
, /* Printer device ID */
3145 profile_id
, /* Profile ID */
3146 default_profile_id
= 0;
3147 /* Default profile ID */
3148 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3149 CFStringRef printer_name
; /* Printer name string */
3150 CMDeviceScope scope
= /* Scope of the registration */
3152 kCFPreferencesAnyUser
,
3153 kCFPreferencesCurrentHost
3155 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3156 CMDeviceProfileInfo
*profile
; /* Current profile */
3157 cups_array_t
*languages
; /* Languages array */
3161 * Make sure ColorSync is available...
3164 if (CMRegisterColorDevice
== NULL
)
3168 * Try opening the PPD file for this printer...
3171 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3172 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3176 * See if we have any profiles...
3179 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3180 profile_key
= "APTiogaProfile";
3183 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3184 profile_key
= "cupsICCProfile";
3187 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3188 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3190 if (attr
->value
[0] != '/')
3191 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3194 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3196 if (access(iccfile
, 0))
3204 * If we have profiles, add them...
3207 if (num_profiles
> 0)
3209 if (profile_key
[0] == 'A')
3212 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3216 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3218 default_profile_id
= atoi(attr
->value
);
3220 q1_choice
= q2_choice
= q3_choice
= NULL
;
3225 * For CUPS PPDs, figure out the default profile selector values...
3228 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3229 attr
->value
&& attr
->value
[0])
3231 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3232 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3234 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3235 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3237 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3238 q1_choice
= q1_attr
->value
;
3242 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3243 attr
->value
&& attr
->value
[0])
3245 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3246 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3249 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3251 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3252 q2_choice
= q2_attr
->value
;
3256 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3257 attr
->value
&& attr
->value
[0])
3259 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3260 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3263 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3265 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3266 q3_choice
= q3_attr
->value
;
3272 * Build the array of profiles...
3274 * Note: This calloc actually requests slightly more memory than needed.
3277 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3279 cupsdLogMessage(CUPSD_LOG_ERROR
,
3280 "Unable to allocate memory for %d profiles",
3286 profiles
->profileCount
= num_profiles
;
3287 languages
= _ppdGetLanguages(ppd
);
3289 for (profile
= profiles
->profiles
,
3290 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3292 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3293 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3296 * Add this profile...
3299 if (attr
->value
[0] != '/')
3300 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3303 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3305 if (access(iccfile
, 0))
3308 if (profile_key
[0] == 'c')
3310 cupsArraySave(ppd
->sorted_attrs
);
3312 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3313 attr
->spec
)) != NULL
&&
3314 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3315 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3317 profile_id
= _ppdHashName(attr
->spec
);
3319 cupsArrayRestore(ppd
->sorted_attrs
);
3322 profile_id
= atoi(attr
->spec
);
3324 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3325 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3330 * See if this is the default profile...
3333 if (!default_profile_id
)
3339 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3340 q1_choice
, q2_choice
, q3_choice
);
3341 if (!strcmp(selector
, attr
->spec
))
3342 default_profile_id
= profile_id
;
3345 if (!default_profile_id
)
3347 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3349 if (!strcmp(selector
, attr
->spec
))
3350 default_profile_id
= profile_id
;
3354 if (!default_profile_id
&& q3_choice
)
3356 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3358 if (!strcmp(selector
, attr
->spec
))
3359 default_profile_id
= profile_id
;
3362 if (!default_profile_id
)
3364 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3365 if (!strcmp(selector
, attr
->spec
))
3366 default_profile_id
= profile_id
;
3371 _ppdFreeLanguages(languages
);
3373 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3376 * Extract profiles from ColorModel option...
3379 const char *profile_name
; /* Name of generic profile */
3382 num_profiles
= cm_option
->num_choices
;
3384 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3386 cupsdLogMessage(CUPSD_LOG_ERROR
,
3387 "Unable to allocate memory for %d profiles",
3393 profiles
->profileCount
= num_profiles
;
3395 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3396 cm_choice
= cm_option
->choices
;
3398 i
--, cm_choice
++, profile
++)
3400 if (!strcmp(cm_choice
->choice
, "Gray") ||
3401 !strcmp(cm_choice
->choice
, "Black"))
3402 profile_name
= "Gray";
3403 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3404 !strcmp(cm_choice
->choice
, "CMY"))
3405 profile_name
= "RGB";
3406 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3407 !strcmp(cm_choice
->choice
, "KCMY"))
3408 profile_name
= "CMYK";
3410 profile_name
= "DeviceN";
3412 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3413 profile_id
= _ppdHashName(selector
);
3415 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3416 cm_choice
->text
, NULL
);
3418 if (cm_choice
->marked
)
3419 default_profile_id
= profile_id
;
3425 * Use the default colorspace...
3428 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3430 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3432 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3434 cupsdLogMessage(CUPSD_LOG_ERROR
,
3435 "Unable to allocate memory for %d profiles",
3441 profiles
->profileCount
= num_profiles
;
3443 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3444 "Gray", "Gray", NULL
);
3446 switch (ppd
->colorspace
)
3450 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3451 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3455 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3456 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3464 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3465 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3471 if (num_profiles
> 0)
3474 * Make sure we have a default profile ID...
3477 if (!default_profile_id
)
3478 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3481 * Get the device ID hash and pathelogical name dictionary.
3484 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3487 device_id
= _ppdHashName(p
->name
);
3488 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3489 &kCFTypeDictionaryKeyCallBacks
,
3490 &kCFTypeDictionaryValueCallBacks
);
3491 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3492 p
->name
, kCFStringEncodingUTF8
);
3494 if (device_name
&& printer_name
)
3496 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3499 * Register the device with ColorSync...
3502 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3503 device_name
, &scope
);
3506 * Register the profiles...
3510 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3511 default_profile_id
, profiles
);
3521 cupsdLogMessage(CUPSD_LOG_ERROR
,
3522 "Unable to register ICC color profiles for \"%s\" - %d",
3523 p
->name
, (int)error
);
3525 for (profile
= profiles
->profiles
;
3527 profile
++, num_profiles
--)
3528 CFRelease(profile
->profileName
);
3533 CFRelease(printer_name
);
3536 CFRelease(device_name
);
3544 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3549 apple_unregister_profiles(
3550 cupsd_printer_t
*p
) /* I - Printer */
3553 * Make sure ColorSync is available...
3556 if (CMUnregisterColorDevice
!= NULL
)
3557 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3559 #endif /* __APPLE__ */
3562 * 'apply_printer_defaults()' - Apply printer default options to a job.
3566 apply_printer_defaults(
3567 cupsd_printer_t
*printer
, /* I - Printer */
3568 cupsd_job_t
*job
) /* I - Job */
3570 int i
, /* Looping var */
3571 num_options
; /* Number of default options */
3572 cups_option_t
*options
, /* Default options */
3573 *option
; /* Current option */
3577 * Collect all of the default options and add the missing ones to the
3581 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3582 option
= printer
->options
;
3585 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3587 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3592 * Encode these options as attributes in the job object...
3595 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3596 cupsFreeOptions(num_options
, options
);
3601 * 'authenticate_job()' - Set job authentication info.
3605 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3606 ipp_attribute_t
*uri
) /* I - Job URI */
3608 ipp_attribute_t
*attr
, /* job-id attribute */
3609 *auth_info
; /* auth-info attribute */
3610 int jobid
; /* Job ID */
3611 cupsd_job_t
*job
; /* Current job */
3612 char scheme
[HTTP_MAX_URI
],
3613 /* Method portion of URI */
3614 username
[HTTP_MAX_URI
],
3615 /* Username portion of URI */
3617 /* Host portion of URI */
3618 resource
[HTTP_MAX_URI
];
3619 /* Resource portion of URI */
3620 int port
; /* Port portion of URI */
3623 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3624 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3627 * Start with "everything is OK" status...
3630 con
->response
->request
.status
.status_code
= IPP_OK
;
3633 * See if we have a job URI or a printer URI...
3636 if (!strcmp(uri
->name
, "printer-uri"))
3639 * Got a printer URI; see if we also have a job-id attribute...
3642 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3643 IPP_TAG_INTEGER
)) == NULL
)
3645 send_ipp_status(con
, IPP_BAD_REQUEST
,
3646 _("Got a printer-uri attribute but no job-id"));
3650 jobid
= attr
->values
[0].integer
;
3655 * Got a job URI; parse it to get the job ID...
3658 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3659 sizeof(scheme
), username
, sizeof(username
), host
,
3660 sizeof(host
), &port
, resource
, sizeof(resource
));
3662 if (strncmp(resource
, "/jobs/", 6))
3668 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\""),
3669 uri
->values
[0].string
.text
);
3673 jobid
= atoi(resource
+ 6);
3677 * See if the job exists...
3680 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3683 * Nope - return a "not found" error...
3686 send_ipp_status(con
, IPP_NOT_FOUND
,
3687 _("Job #%d does not exist"), jobid
);
3692 * See if the job has been completed...
3695 if (job
->state_value
!= IPP_JOB_HELD
)
3698 * Return a "not-possible" error...
3701 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3702 _("Job #%d is not held for authentication"),
3708 * See if we have already authenticated...
3711 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3713 if (!con
->username
[0] && !auth_info
)
3715 cupsd_printer_t
*printer
; /* Job destination */
3719 * No auth data. If we need to authenticate via Kerberos, send a
3720 * HTTP auth challenge, otherwise just return an IPP error...
3723 printer
= cupsdFindDest(job
->dest
);
3725 if (printer
&& printer
->num_auth_info_required
> 0 &&
3726 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3727 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3729 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3730 _("No authentication information provided"));
3735 * See if the job is owned by the requesting user...
3738 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3740 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3741 cupsdFindDest(job
->dest
));
3746 * Save the authentication information for this job...
3749 save_auth_info(con
, job
, auth_info
);
3752 * Reset the job-hold-until value to "no-hold"...
3755 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3756 IPP_TAG_KEYWORD
)) == NULL
)
3757 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3761 attr
->value_tag
= IPP_TAG_KEYWORD
;
3762 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3766 * Release the job and return...
3769 cupsdReleaseJob(job
);
3771 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3776 * 'cancel_all_jobs()' - Cancel all print jobs.
3780 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3781 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3783 http_status_t status
; /* Policy status */
3784 cups_ptype_t dtype
; /* Destination type */
3785 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3786 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3787 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3788 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3789 int port
; /* Port portion of URI */
3790 ipp_attribute_t
*attr
; /* Attribute in request */
3791 const char *username
; /* Username */
3792 cupsd_jobaction_t purge
; /* Purge? */
3793 cupsd_printer_t
*printer
; /* Printer */
3796 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3797 con
->http
.fd
, uri
->values
[0].string
.text
);
3800 * See if we have a printer URI...
3803 if (strcmp(uri
->name
, "printer-uri"))
3805 send_ipp_status(con
, IPP_BAD_REQUEST
,
3806 _("The printer-uri attribute is required"));
3811 * Get the username (if any) for the jobs we want to cancel (only if
3812 * "my-jobs" is specified...
3815 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3816 IPP_TAG_BOOLEAN
)) != NULL
&&
3817 attr
->values
[0].boolean
)
3819 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3820 IPP_TAG_NAME
)) != NULL
)
3821 username
= attr
->values
[0].string
.text
;
3824 send_ipp_status(con
, IPP_BAD_REQUEST
,
3825 _("Missing requesting-user-name attribute"));
3833 * Look for the "purge-jobs" attribute...
3836 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3837 IPP_TAG_BOOLEAN
)) != NULL
)
3838 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3840 purge
= CUPSD_JOB_PURGE
;
3843 * And if the destination is valid...
3846 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3852 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3853 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3854 hostname
, sizeof(hostname
), &port
,
3855 resource
, sizeof(resource
));
3857 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3858 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3860 send_ipp_status(con
, IPP_NOT_FOUND
,
3861 _("The printer or class was not found."));
3869 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3871 send_http_error(con
, status
, NULL
);
3876 * Cancel all jobs on all printers...
3879 cupsdCancelJobs(NULL
, username
, purge
);
3881 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3882 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3891 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3894 send_http_error(con
, status
, printer
);
3899 * Cancel all of the jobs on the named printer...
3902 cupsdCancelJobs(printer
->name
, username
, purge
);
3904 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3906 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3910 con
->response
->request
.status
.status_code
= IPP_OK
;
3915 * 'cancel_job()' - Cancel a print job.
3919 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3920 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3922 ipp_attribute_t
*attr
; /* Current attribute */
3923 int jobid
; /* Job ID */
3924 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3925 username
[HTTP_MAX_URI
], /* Username portion of URI */
3926 host
[HTTP_MAX_URI
], /* Host portion of URI */
3927 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3928 int port
; /* Port portion of URI */
3929 cupsd_job_t
*job
; /* Job information */
3930 cups_ptype_t dtype
; /* Destination type (printer/class) */
3931 cupsd_printer_t
*printer
; /* Printer data */
3932 cupsd_jobaction_t purge
; /* Purge the job? */
3935 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3936 con
->http
.fd
, uri
->values
[0].string
.text
);
3939 * See if we have a job URI or a printer URI...
3942 if (!strcmp(uri
->name
, "printer-uri"))
3945 * Got a printer URI; see if we also have a job-id attribute...
3948 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3949 IPP_TAG_INTEGER
)) == NULL
)
3951 send_ipp_status(con
, IPP_BAD_REQUEST
,
3952 _("Got a printer-uri attribute but no job-id"));
3956 if ((jobid
= attr
->values
[0].integer
) == 0)
3959 * Find the current job on the specified printer...
3962 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3968 send_ipp_status(con
, IPP_NOT_FOUND
,
3969 _("The printer or class was not found."));
3974 * See if there are any pending jobs...
3977 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3979 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3980 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3981 !strcasecmp(job
->dest
, printer
->name
))
3989 * No, try stopped jobs...
3992 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3994 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3995 if (job
->state_value
== IPP_JOB_STOPPED
&&
3996 !strcasecmp(job
->dest
, printer
->name
))
4003 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s"),
4013 * Got a job URI; parse it to get the job ID...
4016 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4017 sizeof(scheme
), username
, sizeof(username
), host
,
4018 sizeof(host
), &port
, resource
, sizeof(resource
));
4020 if (strncmp(resource
, "/jobs/", 6))
4026 send_ipp_status(con
, IPP_BAD_REQUEST
,
4027 _("Bad job-uri attribute \"%s\""),
4028 uri
->values
[0].string
.text
);
4032 jobid
= atoi(resource
+ 6);
4036 * Look for the "purge-job" attribute...
4039 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4040 IPP_TAG_BOOLEAN
)) != NULL
)
4041 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4043 purge
= CUPSD_JOB_DEFAULT
;
4046 * See if the job exists...
4049 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4052 * Nope - return a "not found" error...
4055 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
4060 * See if the job is owned by the requesting user...
4063 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4065 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4066 cupsdFindDest(job
->dest
));
4071 * See if the job is already completed, canceled, or aborted; if so,
4072 * we can't cancel...
4075 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4077 switch (job
->state_value
)
4079 case IPP_JOB_CANCELED
:
4080 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4081 _("Job #%d is already canceled - can\'t cancel."),
4085 case IPP_JOB_ABORTED
:
4086 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4087 _("Job #%d is already aborted - can\'t cancel."),
4092 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4093 _("Job #%d is already completed - can\'t cancel."),
4102 * Cancel the job and return...
4105 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4106 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4107 "Job canceled by \"%s\"",
4111 if (purge
== CUPSD_JOB_PURGE
)
4112 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4115 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4118 con
->response
->request
.status
.status_code
= IPP_OK
;
4123 * 'cancel_subscription()' - Cancel a subscription.
4127 cancel_subscription(
4128 cupsd_client_t
*con
, /* I - Client connection */
4129 int sub_id
) /* I - Subscription ID */
4131 http_status_t status
; /* Policy status */
4132 cupsd_subscription_t
*sub
; /* Subscription */
4135 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4136 "cancel_subscription(con=%p[%d], sub_id=%d)",
4137 con
, con
->http
.fd
, sub_id
);
4140 * Is the subscription ID valid?
4143 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4146 * Bad subscription ID...
4149 send_ipp_status(con
, IPP_NOT_FOUND
,
4150 _("notify-subscription-id %d no good"), sub_id
);
4158 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4160 con
, sub
->owner
)) != HTTP_OK
)
4162 send_http_error(con
, status
, sub
->dest
);
4167 * Cancel the subscription...
4170 cupsdDeleteSubscription(sub
, 1);
4172 con
->response
->request
.status
.status_code
= IPP_OK
;
4177 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4180 static int /* O - 1 if OK, 0 if not */
4181 check_rss_recipient(
4182 const char *recipient
) /* I - Recipient URI */
4184 cupsd_subscription_t
*sub
; /* Current subscription */
4187 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4189 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4193 * Compare the URIs up to the first ?...
4196 const char *r1
, *r2
;
4198 for (r1
= recipient
, r2
= sub
->recipient
;
4199 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4211 * 'check_quotas()' - Check quotas for a printer and user.
4214 static int /* O - 1 if OK, 0 if not */
4215 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4216 cupsd_printer_t
*p
) /* I - Printer or class */
4218 int i
; /* Looping var */
4219 char username
[33]; /* Username */
4220 cupsd_quota_t
*q
; /* Quota data */
4221 #ifdef HAVE_MBR_UID_TO_UUID
4223 * Use Apple membership APIs which require that all names represent
4224 * valid user account or group records accessible by the server.
4227 uuid_t usr_uuid
; /* UUID for job requesting user */
4228 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4229 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4230 int mbr_err
; /* Error from membership function */
4231 int is_member
; /* Is this user a member? */
4234 * Use standard POSIX APIs for checking users and groups...
4237 struct passwd
*pw
; /* User password data */
4238 #endif /* HAVE_MBR_UID_TO_UUID */
4241 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4242 con
, con
->http
.fd
, p
, p
->name
);
4245 * Figure out who is printing...
4248 strlcpy(username
, get_username(con
), sizeof(username
));
4251 * Check global active job limits for printers and users...
4254 if (MaxJobsPerPrinter
)
4257 * Check if there are too many pending jobs on this printer...
4260 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4262 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4271 * Check if there are too many pending jobs for this user...
4274 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4276 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4283 * Check against users...
4286 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4291 #ifdef HAVE_MBR_UID_TO_UUID
4293 * Get UUID for job requesting user...
4296 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4302 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4303 "check_quotas: UUID lookup failed for user \"%s\"",
4305 cupsdLogMessage(CUPSD_LOG_INFO
,
4306 "Denying user \"%s\" access to printer \"%s\" "
4307 "(unknown user)...",
4313 * Get UID and GID of requesting user...
4316 pw
= getpwnam(username
);
4318 #endif /* HAVE_MBR_UID_TO_UUID */
4320 for (i
= 0; i
< p
->num_users
; i
++)
4321 if (p
->users
[i
][0] == '@')
4324 * Check group membership...
4327 #ifdef HAVE_MBR_UID_TO_UUID
4328 if (p
->users
[i
][1] == '#')
4330 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4331 uuid_clear(grp_uuid
);
4333 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4337 * Invalid ACL entries are ignored for matching; just record a
4338 * warning in the log...
4341 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4342 "check_quotas: UUID lookup failed for ACL entry "
4343 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4344 cupsdLogMessage(CUPSD_LOG_WARN
,
4345 "Access control entry \"%s\" not a valid group name; "
4346 "entry ignored", p
->users
[i
]);
4349 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4353 * At this point, there should be no errors, but check anyways...
4356 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4357 "check_quotas: group \"%s\" membership check "
4358 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4363 * Stop if we found a match...
4370 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4372 #endif /* HAVE_MBR_UID_TO_UUID */
4374 #ifdef HAVE_MBR_UID_TO_UUID
4377 if (p
->users
[i
][0] == '#')
4379 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4380 uuid_clear(usr2_uuid
);
4382 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4386 * Invalid ACL entries are ignored for matching; just record a
4387 * warning in the log...
4390 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4391 "check_quotas: UUID lookup failed for ACL entry "
4392 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4393 cupsdLogMessage(CUPSD_LOG_WARN
,
4394 "Access control entry \"%s\" not a valid user name; "
4395 "entry ignored", p
->users
[i
]);
4398 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4402 else if (!strcasecmp(username
, p
->users
[i
]))
4404 #endif /* HAVE_MBR_UID_TO_UUID */
4406 if ((i
< p
->num_users
) == p
->deny_users
)
4408 cupsdLogMessage(CUPSD_LOG_INFO
,
4409 "Denying user \"%s\" access to printer \"%s\"...",
4420 if (AppleQuotas
&& (q
= cupsdFindQuota(p
, username
)) != NULL
)
4423 * TODO: Define these special page count values as constants!
4426 if (q
->page_count
== -4) /* special case: unlimited user */
4428 cupsdLogMessage(CUPSD_LOG_INFO
,
4429 "User \"%s\" request approved for printer %s (%s): "
4431 username
, p
->name
, p
->info
);
4432 q
->page_count
= 0; /* allow user to print */
4435 else if (q
->page_count
== -3) /* quota exceeded */
4437 cupsdLogMessage(CUPSD_LOG_INFO
,
4438 "User \"%s\" request denied for printer %s (%s): "
4439 "quota limit exceeded.",
4440 username
, p
->name
, p
->info
);
4441 q
->page_count
= 2; /* force quota exceeded failure */
4444 else if (q
->page_count
== -2) /* quota disabled for user */
4446 cupsdLogMessage(CUPSD_LOG_INFO
,
4447 "User \"%s\" request denied for printer %s (%s): "
4448 "printing disabled for user.",
4449 username
, p
->name
, p
->info
);
4450 q
->page_count
= 2; /* force quota exceeded failure */
4453 else if (q
->page_count
== -1) /* quota access error */
4455 cupsdLogMessage(CUPSD_LOG_INFO
,
4456 "User \"%s\" request denied for printer %s (%s): "
4457 "unable to determine quota limit.",
4458 username
, p
->name
, p
->info
);
4459 q
->page_count
= 2; /* force quota exceeded failure */
4462 else if (q
->page_count
< 0) /* user not found or other error */
4464 cupsdLogMessage(CUPSD_LOG_INFO
,
4465 "User \"%s\" request denied for printer %s (%s): "
4466 "user disabled / missing quota.",
4467 username
, p
->name
, p
->info
);
4468 q
->page_count
= 2; /* force quota exceeded failure */
4471 else /* page within user limits */
4473 q
->page_count
= 0; /* allow user to print */
4478 #endif /* __APPLE__ */
4479 if (p
->k_limit
|| p
->page_limit
)
4481 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4483 cupsdLogMessage(CUPSD_LOG_ERROR
,
4484 "Unable to allocate quota data for user \"%s\"",
4489 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4490 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4492 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4499 * If we have gotten this far, we're done!
4507 * 'copy_attribute()' - Copy a single attribute.
4510 static ipp_attribute_t
* /* O - New attribute */
4512 ipp_t
*to
, /* O - Destination request/response */
4513 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4514 int quickcopy
) /* I - Do a quick copy? */
4516 int i
; /* Looping var */
4517 ipp_attribute_t
*toattr
; /* Destination attribute */
4520 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4521 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4522 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4525 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4528 toattr
= ippAddSeparator(to
);
4531 case IPP_TAG_INTEGER
:
4533 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4534 attr
->name
, attr
->num_values
, NULL
);
4536 for (i
= 0; i
< attr
->num_values
; i
++)
4537 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4540 case IPP_TAG_BOOLEAN
:
4541 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4542 attr
->num_values
, NULL
);
4544 for (i
= 0; i
< attr
->num_values
; i
++)
4545 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4548 case IPP_TAG_STRING
:
4551 case IPP_TAG_KEYWORD
:
4553 case IPP_TAG_URISCHEME
:
4554 case IPP_TAG_CHARSET
:
4555 case IPP_TAG_LANGUAGE
:
4556 case IPP_TAG_MIMETYPE
:
4557 toattr
= ippAddStrings(to
, attr
->group_tag
,
4558 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4559 attr
->name
, attr
->num_values
, NULL
, NULL
);
4563 for (i
= 0; i
< attr
->num_values
; i
++)
4564 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4566 else if (attr
->value_tag
& IPP_TAG_COPY
)
4568 for (i
= 0; i
< attr
->num_values
; i
++)
4569 toattr
->values
[i
].string
.text
=
4570 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4574 for (i
= 0; i
< attr
->num_values
; i
++)
4575 toattr
->values
[i
].string
.text
=
4576 _cupsStrRetain(attr
->values
[i
].string
.text
);
4581 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4582 attr
->values
[0].date
);
4585 case IPP_TAG_RESOLUTION
:
4586 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4587 attr
->num_values
, IPP_RES_PER_INCH
,
4590 for (i
= 0; i
< attr
->num_values
; i
++)
4592 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4593 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4594 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4598 case IPP_TAG_RANGE
:
4599 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4600 attr
->num_values
, NULL
, NULL
);
4602 for (i
= 0; i
< attr
->num_values
; i
++)
4604 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4605 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4609 case IPP_TAG_TEXTLANG
:
4610 case IPP_TAG_NAMELANG
:
4611 toattr
= ippAddStrings(to
, attr
->group_tag
,
4612 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4613 attr
->name
, attr
->num_values
, NULL
, NULL
);
4617 for (i
= 0; i
< attr
->num_values
; i
++)
4619 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4620 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4623 else if (attr
->value_tag
& IPP_TAG_COPY
)
4625 for (i
= 0; i
< attr
->num_values
; i
++)
4628 toattr
->values
[i
].string
.charset
=
4629 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4631 toattr
->values
[i
].string
.charset
=
4632 toattr
->values
[0].string
.charset
;
4634 toattr
->values
[i
].string
.text
=
4635 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4640 for (i
= 0; i
< attr
->num_values
; i
++)
4643 toattr
->values
[i
].string
.charset
=
4644 _cupsStrRetain(attr
->values
[i
].string
.charset
);
4646 toattr
->values
[i
].string
.charset
=
4647 toattr
->values
[0].string
.charset
;
4649 toattr
->values
[i
].string
.text
=
4650 _cupsStrRetain(attr
->values
[i
].string
.text
);
4655 case IPP_TAG_BEGIN_COLLECTION
:
4656 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4657 attr
->num_values
, NULL
);
4659 for (i
= 0; i
< attr
->num_values
; i
++)
4661 toattr
->values
[i
].collection
= ippNew();
4662 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
4663 NULL
, IPP_TAG_ZERO
, 0);
4668 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4669 attr
->name
, attr
->num_values
, NULL
);
4671 for (i
= 0; i
< attr
->num_values
; i
++)
4673 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4675 if (toattr
->values
[i
].unknown
.length
> 0)
4677 if ((toattr
->values
[i
].unknown
.data
=
4678 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4679 toattr
->values
[i
].unknown
.length
= 0;
4681 memcpy(toattr
->values
[i
].unknown
.data
,
4682 attr
->values
[i
].unknown
.data
,
4683 toattr
->values
[i
].unknown
.length
);
4686 break; /* anti-compiler-warning-code */
4694 * 'copy_attrs()' - Copy attributes from one request to another.
4698 copy_attrs(ipp_t
*to
, /* I - Destination request */
4699 ipp_t
*from
, /* I - Source request */
4700 cups_array_t
*ra
, /* I - Requested attributes */
4701 ipp_tag_t group
, /* I - Group to copy */
4702 int quickcopy
) /* I - Do a quick copy? */
4704 ipp_attribute_t
*fromattr
; /* Source attribute */
4707 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4708 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4709 to
, from
, ra
, group
, quickcopy
);
4714 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4717 * Filter attributes as needed...
4720 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4721 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4724 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4727 * Don't send collection attributes by default to IPP/1.x clients
4728 * since many do not support collections...
4731 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4732 !ra
&& to
->request
.status
.version
[0] == 1)
4735 copy_attribute(to
, fromattr
, quickcopy
);
4742 * 'copy_banner()' - Copy a banner file to the requests directory for the
4746 static int /* O - Size of banner file in kbytes */
4747 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4748 cupsd_job_t
*job
, /* I - Job information */
4749 const char *name
) /* I - Name of banner */
4751 int i
; /* Looping var */
4752 int kbytes
; /* Size of banner file in kbytes */
4753 char filename
[1024]; /* Job filename */
4754 cupsd_banner_t
*banner
; /* Pointer to banner */
4755 cups_file_t
*in
; /* Input file */
4756 cups_file_t
*out
; /* Output file */
4757 int ch
; /* Character from file */
4758 char attrname
[255], /* Name of attribute */
4759 *s
; /* Pointer into name */
4760 ipp_attribute_t
*attr
; /* Attribute */
4763 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4764 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4765 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4766 name
? name
: "(null)");
4769 * Find the banner; return if not found or "none"...
4772 if (!name
|| !strcmp(name
, "none") ||
4773 (banner
= cupsdFindBanner(name
)) == NULL
)
4777 * Open the banner and job files...
4780 if (add_file(con
, job
, banner
->filetype
, 0))
4783 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4785 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4787 cupsdLogMessage(CUPSD_LOG_ERROR
,
4788 "Unable to create banner job file %s - %s",
4789 filename
, strerror(errno
));
4794 fchmod(cupsFileNumber(out
), 0640);
4795 fchown(cupsFileNumber(out
), RunUser
, Group
);
4798 * Try the localized banner file under the subdirectory...
4801 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4803 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4806 * Convert ll-cc to ll_CC...
4810 attrname
[3] = toupper(attrname
[3] & 255);
4811 attrname
[4] = toupper(attrname
[4] & 255);
4814 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4817 if (access(filename
, 0) && strlen(attrname
) > 2)
4820 * Wasn't able to find "ll_CC" locale file; try the non-national
4821 * localization banner directory.
4826 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4830 if (access(filename
, 0))
4833 * Use the non-localized banner file.
4836 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4839 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4843 cupsdLogMessage(CUPSD_LOG_ERROR
,
4844 "Unable to open banner template file %s - %s",
4845 filename
, strerror(errno
));
4851 * Parse the file to the end...
4854 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4858 * Get an attribute name...
4861 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4862 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4864 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4874 * Ignore { followed by stuff that is not an attribute name...
4877 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4882 * See if it is defined...
4885 if (attrname
[0] == '?')
4890 if (!strcmp(s
, "printer-name"))
4892 cupsFilePuts(out
, job
->dest
);
4895 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4898 * See if we have a leading question mark...
4901 if (attrname
[0] != '?')
4904 * Nope, write to file as-is; probably a PostScript procedure...
4907 cupsFilePrintf(out
, "{%s}", attrname
);
4914 * Output value(s)...
4917 for (i
= 0; i
< attr
->num_values
; i
++)
4920 cupsFilePutChar(out
, ',');
4922 switch (attr
->value_tag
)
4924 case IPP_TAG_INTEGER
:
4926 if (!strncmp(s
, "time-at-", 8))
4928 struct timeval tv
= { attr
->values
[i
].integer
, 0 };
4929 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4932 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4935 case IPP_TAG_BOOLEAN
:
4936 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4939 case IPP_TAG_NOVALUE
:
4940 cupsFilePuts(out
, "novalue");
4943 case IPP_TAG_RANGE
:
4944 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4945 attr
->values
[i
].range
.upper
);
4948 case IPP_TAG_RESOLUTION
:
4949 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4950 attr
->values
[i
].resolution
.yres
,
4951 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4956 case IPP_TAG_STRING
:
4959 case IPP_TAG_KEYWORD
:
4960 case IPP_TAG_CHARSET
:
4961 case IPP_TAG_LANGUAGE
:
4962 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
4965 * Need to quote strings for PS banners...
4970 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4972 if (*p
== '(' || *p
== ')' || *p
== '\\')
4974 cupsFilePutChar(out
, '\\');
4975 cupsFilePutChar(out
, *p
);
4977 else if (*p
< 32 || *p
> 126)
4978 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4980 cupsFilePutChar(out
, *p
);
4984 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4988 break; /* anti-compiler-warning-code */
4992 else if (ch
== '\\') /* Quoted char */
4994 ch
= cupsFileGetChar(in
);
4996 if (ch
!= '{') /* Only do special handling for \{ */
4997 cupsFilePutChar(out
, '\\');
4999 cupsFilePutChar(out
, ch
);
5002 cupsFilePutChar(out
, ch
);
5006 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5008 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5009 IPP_TAG_INTEGER
)) != NULL
)
5010 attr
->values
[0].integer
+= kbytes
;
5019 * 'copy_file()' - Copy a PPD file or interface script...
5022 static int /* O - 0 = success, -1 = error */
5023 copy_file(const char *from
, /* I - Source file */
5024 const char *to
) /* I - Destination file */
5026 cups_file_t
*src
, /* Source file */
5027 *dst
; /* Destination file */
5028 int bytes
; /* Bytes to read/write */
5029 char buffer
[2048]; /* Copy buffer */
5032 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5035 * Open the source and destination file for a copy...
5038 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5041 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5048 * Copy the source file to the destination...
5051 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5052 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5060 * Close both files and return...
5065 return (cupsFileClose(dst
));
5070 * 'copy_model()' - Copy a PPD model file, substituting default values
5074 static int /* O - 0 = success, -1 = error */
5075 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5076 const char *from
, /* I - Source file */
5077 const char *to
) /* I - Destination file */
5079 fd_set input
; /* select() input set */
5080 struct timeval timeout
; /* select() timeout */
5081 int maxfd
; /* Max file descriptor for select() */
5082 char tempfile
[1024]; /* Temporary PPD file */
5083 int tempfd
; /* Temporary PPD file descriptor */
5084 int temppid
; /* Process ID of cups-driverd */
5085 int temppipe
[2]; /* Temporary pipes */
5086 char *argv
[4], /* Command-line arguments */
5087 *envp
[MAX_ENV
]; /* Environment */
5088 cups_file_t
*src
, /* Source file */
5089 *dst
; /* Destination file */
5090 ppd_file_t
*ppd
; /* PPD file */
5091 int bytes
, /* Bytes from pipe */
5092 total
; /* Total bytes from pipe */
5093 char buffer
[2048]; /* Copy buffer */
5094 int i
; /* Looping var */
5095 char option
[PPD_MAX_NAME
], /* Option name */
5096 choice
[PPD_MAX_NAME
]; /* Choice name */
5097 int num_defaults
; /* Number of default options */
5098 cups_option_t
*defaults
; /* Default options */
5099 char cups_protocol
[PPD_MAX_LINE
];
5100 /* cupsProtocol attribute */
5103 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5104 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5108 * Run cups-driverd to get the PPD file...
5111 argv
[0] = "cups-driverd";
5113 argv
[2] = (char *)from
;
5116 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5118 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5119 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5120 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5124 cupsdOpenPipe(temppipe
);
5126 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5127 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5129 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5130 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5141 * Wait up to 30 seconds for the PPD file to be copied...
5146 if (temppipe
[0] > CGIPipes
[0])
5147 maxfd
= temppipe
[0] + 1;
5149 maxfd
= CGIPipes
[0] + 1;
5154 * See if we have data ready...
5158 FD_SET(temppipe
[0], &input
);
5159 FD_SET(CGIPipes
[0], &input
);
5161 timeout
.tv_sec
= 30;
5162 timeout
.tv_usec
= 0;
5164 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5174 * We have timed out...
5180 if (FD_ISSET(temppipe
[0], &input
))
5183 * Read the PPD file from the pipe, and write it to the PPD file.
5186 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5188 if (write(tempfd
, buffer
, bytes
) < bytes
)
5197 if (FD_ISSET(CGIPipes
[0], &input
))
5207 * No data from cups-deviced...
5210 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5216 * Read the source file and see what page sizes are supported...
5219 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5226 * Open the destination (if possible) and set the default options...
5231 cups_protocol
[0] = '\0';
5233 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5236 * Read all of the default lines from the old PPD...
5239 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5240 if (!strncmp(buffer
, "*Default", 8))
5243 * Add the default option...
5246 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5247 choice
, sizeof(choice
)))
5249 ppd_option_t
*ppdo
; /* PPD option */
5253 * Only add the default if the default hasn't already been
5254 * set and the choice exists in the new PPD...
5257 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5258 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5259 ppdFindChoice(ppdo
, choice
))
5260 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5264 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5265 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5269 else if (ppdPageSize(ppd
, DefaultPaperSize
))
5272 * Add the default media sizes...
5275 num_defaults
= cupsAddOption("PageSize", DefaultPaperSize
,
5276 num_defaults
, &defaults
);
5277 num_defaults
= cupsAddOption("PageRegion", DefaultPaperSize
,
5278 num_defaults
, &defaults
);
5279 num_defaults
= cupsAddOption("PaperDimension", DefaultPaperSize
,
5280 num_defaults
, &defaults
);
5281 num_defaults
= cupsAddOption("ImageableArea", DefaultPaperSize
,
5282 num_defaults
, &defaults
);
5288 * Open the source file for a copy...
5291 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5293 cupsFreeOptions(num_defaults
, defaults
);
5299 * Open the destination file for a copy...
5302 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5304 cupsFreeOptions(num_defaults
, defaults
);
5311 * Copy the source file to the destination...
5314 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5316 if (!strncmp(buffer
, "*Default", 8))
5319 * Check for an previous default option choice...
5322 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5323 choice
, sizeof(choice
)))
5325 const char *val
; /* Default option value */
5328 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5331 * Substitute the previous choice...
5334 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5339 cupsFilePrintf(dst
, "%s\n", buffer
);
5342 if (cups_protocol
[0])
5343 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5345 cupsFreeOptions(num_defaults
, defaults
);
5348 * Close both files and return...
5355 return (cupsFileClose(dst
));
5360 * 'copy_job_attrs()' - Copy job attributes.
5364 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5365 cupsd_job_t
*job
, /* I - Job */
5366 cups_array_t
*ra
) /* I - Requested attributes array */
5368 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5372 * Send the requested attributes for each job...
5375 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5376 con
->servername
, con
->serverport
, "/jobs/%d",
5379 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5380 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5381 "document-count", job
->num_files
);
5383 if (!ra
|| cupsArrayFind(ra
, "job-media-progress"))
5384 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5385 "job-media-progress", job
->progress
);
5387 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5388 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5389 "job-more-info", NULL
, job_uri
);
5391 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5392 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5393 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5394 job
->num_files
> 0);
5396 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5397 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5398 "job-printer-up-time", time(NULL
));
5400 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5401 add_job_state_reasons(con
, job
);
5403 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5404 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5405 "job-uri", NULL
, job_uri
);
5407 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5412 * 'copy_printer_attrs()' - Copy printer attributes.
5417 cupsd_client_t
*con
, /* I - Client connection */
5418 cupsd_printer_t
*printer
, /* I - Printer */
5419 cups_array_t
*ra
) /* I - Requested attributes array */
5421 char printer_uri
[HTTP_MAX_URI
];
5423 time_t curtime
; /* Current time */
5424 int i
; /* Looping var */
5425 ipp_attribute_t
*history
; /* History collection */
5429 * Copy the printer attributes to the response using requested-attributes
5430 * and document-format attributes that may be provided by the client.
5433 curtime
= time(NULL
);
5436 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
5437 printer
->recoverable
)
5438 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5439 "com.apple.print.recoverable-message", NULL
,
5440 printer
->recoverable
);
5441 #endif /* __APPLE__ */
5443 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5444 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5445 "marker-change-time", printer
->marker_time
);
5447 if (printer
->num_printers
> 0 &&
5448 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5450 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5451 cupsd_printer_t
*p2
; /* Printer in class */
5452 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5455 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5456 IPP_TAG_URI
, "member-uris",
5457 printer
->num_printers
, NULL
,
5460 for (i
= 0; i
< printer
->num_printers
; i
++)
5462 p2
= printer
->printers
[i
];
5464 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5465 IPP_TAG_URI
)) != NULL
)
5466 member_uris
->values
[i
].string
.text
=
5467 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5470 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5471 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5473 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5474 "/classes/%s" : "/printers/%s", p2
->name
);
5475 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5481 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5482 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5483 "printer-alert", NULL
, printer
->alert
);
5485 if (printer
->alert_description
&&
5486 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5487 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5488 "printer-alert-description", NULL
,
5489 printer
->alert_description
);
5491 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5492 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5493 ippTimeToDate(curtime
));
5496 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5498 if (printer
->reg_name
)
5499 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5500 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5502 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5503 "printer-dns-sd-name", 0);
5505 #endif /* HAVE_DNSSD */
5507 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5508 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5509 "printer-error-policy", NULL
, printer
->error_policy
);
5511 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
5513 static const char * const errors
[] =/* printer-error-policy-supported values */
5516 "retry-current-job",
5521 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
5522 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5523 "printer-error-policy-supported", NULL
, "retry-current-job");
5525 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5526 "printer-error-policy-supported",
5527 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
5530 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5531 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5532 printer
->accepting
);
5534 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5535 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5538 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5539 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5541 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5542 "http", NULL
, con
->servername
, con
->serverport
,
5543 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5544 "/classes/%s" : "/printers/%s", printer
->name
);
5545 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5546 "printer-more-info", NULL
, printer_uri
);
5549 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5550 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5551 "printer-op-policy", NULL
, printer
->op_policy
);
5553 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5554 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5557 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5558 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5559 "printer-state-change-time", printer
->state_time
);
5561 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5562 cupsArrayFind(ra
, "printer-state-history"))
5565 * Printer history is only sent if specifically requested, so that
5566 * older CUPS/IPP clients won't barf on the collection attributes.
5569 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5570 "printer-state-history",
5571 printer
->num_history
, NULL
);
5573 for (i
= 0; i
< printer
->num_history
; i
++)
5574 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5575 NULL
, IPP_TAG_ZERO
, 0);
5578 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5579 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5580 "printer-state-message", NULL
, printer
->state_message
);
5582 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5583 add_printer_state_reasons(con
, printer
);
5585 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5587 int type
; /* printer-type value */
5591 * Add the CUPS-specific printer-type attribute...
5594 type
= printer
->type
;
5596 if (printer
== DefaultPrinter
)
5597 type
|= CUPS_PRINTER_DEFAULT
;
5599 if (!printer
->accepting
)
5600 type
|= CUPS_PRINTER_REJECTING
;
5602 if (!printer
->shared
)
5603 type
|= CUPS_PRINTER_NOT_SHARED
;
5605 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5609 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5610 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5611 "printer-up-time", curtime
);
5613 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5614 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5616 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5617 "ipp", NULL
, con
->servername
, con
->serverport
,
5618 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5619 "/classes/%s" : "/printers/%s", printer
->name
);
5620 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5621 "printer-uri-supported", NULL
, printer_uri
);
5622 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5626 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5627 add_queued_job_count(con
, printer
);
5629 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5630 if (printer
->ppd_attrs
)
5631 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0);
5632 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5637 * 'copy_subscription_attrs()' - Copy subscription attributes.
5641 copy_subscription_attrs(
5642 cupsd_client_t
*con
, /* I - Client connection */
5643 cupsd_subscription_t
*sub
, /* I - Subscription */
5644 cups_array_t
*ra
) /* I - Requested attributes array */
5646 ipp_attribute_t
*attr
; /* Current attribute */
5647 char printer_uri
[HTTP_MAX_URI
];
5649 int count
; /* Number of events */
5650 unsigned mask
; /* Current event mask */
5651 const char *name
; /* Current event name */
5655 * Copy the subscription attributes to the response using the
5656 * requested-attributes attribute that may be provided by the client.
5659 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5661 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5664 * Simple event list...
5667 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5668 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5669 "notify-events", NULL
, name
);
5674 * Complex event list...
5677 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5678 if (sub
->mask
& mask
)
5681 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5682 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5683 "notify-events", count
, NULL
, NULL
);
5685 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5686 if (sub
->mask
& mask
)
5688 attr
->values
[count
].string
.text
=
5689 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5696 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5697 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5698 "notify-job-id", sub
->job
->id
);
5700 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5701 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5702 "notify-lease-duration", sub
->lease
);
5704 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5706 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5707 "ipp", NULL
, con
->servername
, con
->serverport
,
5708 "/printers/%s", sub
->dest
->name
);
5709 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5710 "notify-printer-uri", NULL
, printer_uri
);
5713 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5714 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5715 "notify-recipient-uri", NULL
, sub
->recipient
);
5716 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5717 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5718 "notify-pull-method", NULL
, "ippget");
5720 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5721 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5722 "notify-subscriber-user-name", NULL
, sub
->owner
);
5724 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5725 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5726 "notify-subscription-id", sub
->id
);
5728 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5729 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5730 "notify-time-interval", sub
->interval
);
5732 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5733 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5734 sub
->user_data
, sub
->user_data_len
);
5739 * 'create_job()' - Print a file to a printer or class.
5743 create_job(cupsd_client_t
*con
, /* I - Client connection */
5744 ipp_attribute_t
*uri
) /* I - Printer URI */
5746 cupsd_printer_t
*printer
; /* Printer */
5747 cupsd_job_t
*job
; /* New job */
5750 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5751 con
->http
.fd
, uri
->values
[0].string
.text
);
5754 * Is the destination valid?
5757 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5763 send_ipp_status(con
, IPP_NOT_FOUND
,
5764 _("The printer or class was not found."));
5769 * Create the job object...
5772 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5775 job
->pending_timeout
= 1;
5778 * Save and log the job...
5781 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5782 job
->dest
, job
->username
);
5787 * 'create_requested_array()' - Create an array for the requested-attributes.
5790 static cups_array_t
* /* O - Array of attributes or NULL */
5791 create_requested_array(ipp_t
*request
) /* I - IPP request */
5793 int i
; /* Looping var */
5794 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5795 cups_array_t
*ra
; /* Requested attributes array */
5796 char *value
; /* Current value */
5800 * Get the requested-attributes attribute, and return NULL if we don't
5804 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5805 IPP_TAG_KEYWORD
)) == NULL
)
5809 * If the attribute contains a single "all" keyword, return NULL...
5812 if (requested
->num_values
== 1 &&
5813 !strcmp(requested
->values
[0].string
.text
, "all"))
5817 * Create an array using "strcmp" as the comparison function...
5820 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5822 for (i
= 0; i
< requested
->num_values
; i
++)
5824 value
= requested
->values
[i
].string
.text
;
5826 if (!strcmp(value
, "job-template"))
5828 cupsArrayAdd(ra
, "copies");
5829 cupsArrayAdd(ra
, "copies-default");
5830 cupsArrayAdd(ra
, "copies-supported");
5831 cupsArrayAdd(ra
, "finishings");
5832 cupsArrayAdd(ra
, "finishings-default");
5833 cupsArrayAdd(ra
, "finishings-supported");
5834 cupsArrayAdd(ra
, "job-hold-until");
5835 cupsArrayAdd(ra
, "job-hold-until-default");
5836 cupsArrayAdd(ra
, "job-hold-until-supported");
5837 cupsArrayAdd(ra
, "job-priority");
5838 cupsArrayAdd(ra
, "job-priority-default");
5839 cupsArrayAdd(ra
, "job-priority-supported");
5840 cupsArrayAdd(ra
, "job-sheets");
5841 cupsArrayAdd(ra
, "job-sheets-default");
5842 cupsArrayAdd(ra
, "job-sheets-supported");
5843 cupsArrayAdd(ra
, "media");
5844 cupsArrayAdd(ra
, "media-default");
5845 cupsArrayAdd(ra
, "media-supported");
5846 cupsArrayAdd(ra
, "multiple-document-handling");
5847 cupsArrayAdd(ra
, "multiple-document-handling-default");
5848 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5849 cupsArrayAdd(ra
, "number-up");
5850 cupsArrayAdd(ra
, "number-up-default");
5851 cupsArrayAdd(ra
, "number-up-supported");
5852 cupsArrayAdd(ra
, "orientation-requested");
5853 cupsArrayAdd(ra
, "orientation-requested-default");
5854 cupsArrayAdd(ra
, "orientation-requested-supported");
5855 cupsArrayAdd(ra
, "page-ranges");
5856 cupsArrayAdd(ra
, "page-ranges-supported");
5857 cupsArrayAdd(ra
, "printer-resolution");
5858 cupsArrayAdd(ra
, "printer-resolution-default");
5859 cupsArrayAdd(ra
, "printer-resolution-supported");
5860 cupsArrayAdd(ra
, "print-quality");
5861 cupsArrayAdd(ra
, "print-quality-default");
5862 cupsArrayAdd(ra
, "print-quality-supported");
5863 cupsArrayAdd(ra
, "sides");
5864 cupsArrayAdd(ra
, "sides-default");
5865 cupsArrayAdd(ra
, "sides-supported");
5867 else if (!strcmp(value
, "job-description"))
5869 cupsArrayAdd(ra
, "date-time-at-completed");
5870 cupsArrayAdd(ra
, "date-time-at-creation");
5871 cupsArrayAdd(ra
, "date-time-at-processing");
5872 cupsArrayAdd(ra
, "job-detailed-status-message");
5873 cupsArrayAdd(ra
, "job-document-access-errors");
5874 cupsArrayAdd(ra
, "job-id");
5875 cupsArrayAdd(ra
, "job-impressions");
5876 cupsArrayAdd(ra
, "job-impressions-completed");
5877 cupsArrayAdd(ra
, "job-k-octets");
5878 cupsArrayAdd(ra
, "job-k-octets-processed");
5879 cupsArrayAdd(ra
, "job-media-progress");
5880 cupsArrayAdd(ra
, "job-media-sheets");
5881 cupsArrayAdd(ra
, "job-media-sheets-completed");
5882 cupsArrayAdd(ra
, "job-message-from-operator");
5883 cupsArrayAdd(ra
, "job-more-info");
5884 cupsArrayAdd(ra
, "job-name");
5885 cupsArrayAdd(ra
, "job-originating-user-name");
5886 cupsArrayAdd(ra
, "job-printer-up-time");
5887 cupsArrayAdd(ra
, "job-printer-uri");
5888 cupsArrayAdd(ra
, "job-state");
5889 cupsArrayAdd(ra
, "job-state-message");
5890 cupsArrayAdd(ra
, "job-state-reasons");
5891 cupsArrayAdd(ra
, "job-uri");
5892 cupsArrayAdd(ra
, "number-of-documents");
5893 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5894 cupsArrayAdd(ra
, "output-device-assigned");
5895 cupsArrayAdd(ra
, "time-at-completed");
5896 cupsArrayAdd(ra
, "time-at-creation");
5897 cupsArrayAdd(ra
, "time-at-processing");
5899 else if (!strcmp(value
, "printer-description"))
5901 cupsArrayAdd(ra
, "charset-configured");
5902 cupsArrayAdd(ra
, "charset-supported");
5903 cupsArrayAdd(ra
, "color-supported");
5904 cupsArrayAdd(ra
, "compression-supported");
5905 cupsArrayAdd(ra
, "document-format-default");
5906 cupsArrayAdd(ra
, "document-format-supported");
5907 cupsArrayAdd(ra
, "generated-natural-language-supported");
5908 cupsArrayAdd(ra
, "ipp-versions-supported");
5909 cupsArrayAdd(ra
, "job-impressions-supported");
5910 cupsArrayAdd(ra
, "job-k-octets-supported");
5911 cupsArrayAdd(ra
, "job-media-sheets-supported");
5912 cupsArrayAdd(ra
, "job-settable-attributes-supported");
5913 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5914 cupsArrayAdd(ra
, "multiple-operation-time-out");
5915 cupsArrayAdd(ra
, "natural-language-configured");
5916 cupsArrayAdd(ra
, "notify-attributes-supported");
5917 cupsArrayAdd(ra
, "notify-lease-duration-default");
5918 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5919 cupsArrayAdd(ra
, "notify-max-events-supported");
5920 cupsArrayAdd(ra
, "notify-events-default");
5921 cupsArrayAdd(ra
, "notify-events-supported");
5922 cupsArrayAdd(ra
, "notify-pull-method-supported");
5923 cupsArrayAdd(ra
, "notify-schemes-supported");
5924 cupsArrayAdd(ra
, "operations-supported");
5925 cupsArrayAdd(ra
, "pages-per-minute");
5926 cupsArrayAdd(ra
, "pages-per-minute-color");
5927 cupsArrayAdd(ra
, "pdl-override-supported");
5928 cupsArrayAdd(ra
, "printer-alert");
5929 cupsArrayAdd(ra
, "printer-alert-description");
5930 cupsArrayAdd(ra
, "printer-commands");
5931 cupsArrayAdd(ra
, "printer-current-time");
5932 cupsArrayAdd(ra
, "printer-driver-installer");
5933 cupsArrayAdd(ra
, "printer-dns-sd-name");
5934 cupsArrayAdd(ra
, "printer-info");
5935 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5936 cupsArrayAdd(ra
, "printer-location");
5937 cupsArrayAdd(ra
, "printer-make-and-model");
5938 cupsArrayAdd(ra
, "printer-message-from-operator");
5939 cupsArrayAdd(ra
, "printer-more-info");
5940 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5941 cupsArrayAdd(ra
, "printer-name");
5942 cupsArrayAdd(ra
, "printer-state");
5943 cupsArrayAdd(ra
, "printer-state-message");
5944 cupsArrayAdd(ra
, "printer-state-reasons");
5945 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
5946 cupsArrayAdd(ra
, "printer-type");
5947 cupsArrayAdd(ra
, "printer-up-time");
5948 cupsArrayAdd(ra
, "printer-uri-supported");
5949 cupsArrayAdd(ra
, "queued-job-count");
5950 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5951 cupsArrayAdd(ra
, "uri-authentication-supported");
5952 cupsArrayAdd(ra
, "uri-security-supported");
5954 else if (!strcmp(value
, "printer-defaults"))
5956 char *name
; /* Option name */
5959 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5961 name
= (char *)cupsArrayNext(CommonDefaults
))
5962 cupsArrayAdd(ra
, name
);
5964 else if (!strcmp(value
, "subscription-template"))
5966 cupsArrayAdd(ra
, "notify-attributes");
5967 cupsArrayAdd(ra
, "notify-charset");
5968 cupsArrayAdd(ra
, "notify-events");
5969 cupsArrayAdd(ra
, "notify-lease-duration");
5970 cupsArrayAdd(ra
, "notify-natural-language");
5971 cupsArrayAdd(ra
, "notify-pull-method");
5972 cupsArrayAdd(ra
, "notify-recipient-uri");
5973 cupsArrayAdd(ra
, "notify-time-interval");
5974 cupsArrayAdd(ra
, "notify-user-data");
5977 cupsArrayAdd(ra
, value
);
5985 * 'create_subscription()' - Create a notification subscription.
5989 create_subscription(
5990 cupsd_client_t
*con
, /* I - Client connection */
5991 ipp_attribute_t
*uri
) /* I - Printer URI */
5993 http_status_t status
; /* Policy status */
5994 int i
; /* Looping var */
5995 ipp_attribute_t
*attr
; /* Current attribute */
5996 cups_ptype_t dtype
; /* Destination type (printer/class) */
5997 char scheme
[HTTP_MAX_URI
],
5998 /* Scheme portion of URI */
5999 userpass
[HTTP_MAX_URI
],
6000 /* Username portion of URI */
6002 /* Host portion of URI */
6003 resource
[HTTP_MAX_URI
];
6004 /* Resource portion of URI */
6005 int port
; /* Port portion of URI */
6006 cupsd_printer_t
*printer
; /* Printer/class */
6007 cupsd_job_t
*job
; /* Job */
6008 int jobid
; /* Job ID */
6009 cupsd_subscription_t
*sub
; /* Subscription object */
6010 const char *username
, /* requesting-user-name or
6011 authenticated username */
6012 *recipient
, /* notify-recipient-uri */
6013 *pullmethod
; /* notify-pull-method */
6014 ipp_attribute_t
*user_data
; /* notify-user-data */
6015 int interval
, /* notify-time-interval */
6016 lease
; /* notify-lease-duration */
6017 unsigned mask
; /* notify-events */
6018 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6019 *notify_lease
; /* notify-lease-duration(-default) */
6023 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6025 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6026 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6027 attr
->value_tag
, attr
->name
);
6029 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6034 * Is the destination valid?
6037 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6038 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6039 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6041 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6042 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6043 sizeof(host
), &port
, resource
, sizeof(resource
));
6045 if (!strcmp(resource
, "/"))
6047 dtype
= (cups_ptype_t
)0;
6050 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6052 dtype
= (cups_ptype_t
)0;
6055 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6057 dtype
= CUPS_PRINTER_CLASS
;
6060 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6066 send_ipp_status(con
, IPP_NOT_FOUND
,
6067 _("The printer or class was not found."));
6077 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6080 send_http_error(con
, status
, printer
);
6084 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6086 send_http_error(con
, status
, NULL
);
6091 * Get the user that is requesting the subscription...
6094 username
= get_username(con
);
6097 * Find the first subscription group attribute; return if we have
6101 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6102 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6107 send_ipp_status(con
, IPP_BAD_REQUEST
,
6108 _("No subscription attributes in request"));
6113 * Process the subscription attributes in the request...
6116 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6124 lease
= DefaultLeaseDuration
;
6126 mask
= CUPSD_EVENT_NONE
;
6130 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6132 notify_lease
= ippFindAttribute(printer
->attrs
,
6133 "notify-lease-duration-default",
6137 lease
= notify_lease
->values
[0].integer
;
6141 notify_events
= NULL
;
6142 notify_lease
= NULL
;
6145 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6147 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6148 attr
->value_tag
== IPP_TAG_URI
)
6151 * Validate the recipient scheme against the ServerBin/notifier
6155 char notifier
[1024]; /* Notifier filename */
6158 recipient
= attr
->values
[0].string
.text
;
6160 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6161 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6162 host
, sizeof(host
), &port
,
6163 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6165 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6166 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
6167 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6168 "notify-status-code", IPP_URI_SCHEME
);
6172 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6174 if (access(notifier
, X_OK
))
6176 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6177 _("notify-recipient-uri URI \"%s\" uses unknown "
6178 "scheme"), recipient
);
6179 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6180 "notify-status-code", IPP_URI_SCHEME
);
6184 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6186 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6187 _("notify-recipient-uri URI \"%s\" is already used"),
6189 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6190 "notify-status-code", IPP_ATTRIBUTES
);
6194 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6195 attr
->value_tag
== IPP_TAG_KEYWORD
)
6197 pullmethod
= attr
->values
[0].string
.text
;
6199 if (strcmp(pullmethod
, "ippget"))
6201 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6202 _("Bad notify-pull-method \"%s\""), pullmethod
);
6203 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6204 "notify-status-code", IPP_ATTRIBUTES
);
6208 else if (!strcmp(attr
->name
, "notify-charset") &&
6209 attr
->value_tag
== IPP_TAG_CHARSET
&&
6210 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6211 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6213 send_ipp_status(con
, IPP_CHARSET
,
6214 _("Character set \"%s\" not supported"),
6215 attr
->values
[0].string
.text
);
6218 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6219 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6220 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6222 send_ipp_status(con
, IPP_CHARSET
,
6223 _("Language \"%s\" not supported"),
6224 attr
->values
[0].string
.text
);
6227 else if (!strcmp(attr
->name
, "notify-user-data") &&
6228 attr
->value_tag
== IPP_TAG_STRING
)
6230 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6232 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6233 _("The notify-user-data value is too large "
6234 "(%d > 63 octets)"),
6235 attr
->values
[0].unknown
.length
);
6241 else if (!strcmp(attr
->name
, "notify-events") &&
6242 attr
->value_tag
== IPP_TAG_KEYWORD
)
6243 notify_events
= attr
;
6244 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6245 attr
->value_tag
== IPP_TAG_INTEGER
)
6246 lease
= attr
->values
[0].integer
;
6247 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6248 attr
->value_tag
== IPP_TAG_INTEGER
)
6249 interval
= attr
->values
[0].integer
;
6250 else if (!strcmp(attr
->name
, "notify-job-id") &&
6251 attr
->value_tag
== IPP_TAG_INTEGER
)
6252 jobid
= attr
->values
[0].integer
;
6259 for (i
= 0; i
< notify_events
->num_values
; i
++)
6260 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6264 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6266 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6267 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6268 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6270 if (!recipient
&& !pullmethod
)
6273 if (mask
== CUPSD_EVENT_NONE
)
6276 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6278 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6281 send_ipp_status(con
, IPP_BAD_REQUEST
,
6282 _("notify-events not specified"));
6287 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6289 cupsdLogMessage(CUPSD_LOG_INFO
,
6290 "create_subscription: Limiting notify-lease-duration to "
6293 lease
= MaxLeaseDuration
;
6298 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6300 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found"), jobid
);
6307 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6309 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6310 _("There are too many subscriptions."));
6315 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6318 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6319 "Added subscription %d for printer \"%s\"",
6320 sub
->id
, printer
->name
);
6322 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6325 sub
->interval
= interval
;
6327 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6329 cupsdSetString(&sub
->owner
, username
);
6333 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6334 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6335 sub
->user_data_len
);
6338 ippAddSeparator(con
->response
);
6339 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6340 "notify-subscription-id", sub
->id
);
6342 con
->response
->request
.status
.status_code
= IPP_OK
;
6348 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6353 * 'delete_printer()' - Remove a printer or class from the system.
6357 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6358 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6360 http_status_t status
; /* Policy status */
6361 cups_ptype_t dtype
; /* Destination type (printer/class) */
6362 cupsd_printer_t
*printer
; /* Printer/class */
6363 char filename
[1024]; /* Script/PPD filename */
6366 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6367 con
->http
.fd
, uri
->values
[0].string
.text
);
6370 * Do we have a valid URI?
6373 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6379 send_ipp_status(con
, IPP_NOT_FOUND
,
6380 _("The printer or class was not found."));
6388 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6390 send_http_error(con
, status
, NULL
);
6395 * Remove old jobs...
6398 cupsdCancelJobs(printer
->name
, NULL
, 1);
6401 * Remove old subscriptions and send a "deleted printer" event...
6404 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6405 "%s \"%s\" deleted by \"%s\".",
6406 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6407 printer
->name
, get_username(con
));
6409 cupsdExpireSubscriptions(printer
, NULL
);
6412 * Remove any old PPD or script files...
6415 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6419 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6423 snprintf(filename
, sizeof(filename
), "%s/%s.ipp", CacheDir
, printer
->name
);
6428 * Unregister color profiles...
6431 apple_unregister_profiles(printer
);
6432 #endif /* __APPLE__ */
6434 if (dtype
& CUPS_PRINTER_CLASS
)
6436 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6437 printer
->name
, get_username(con
));
6439 cupsdDeletePrinter(printer
, 0);
6440 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6444 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6445 printer
->name
, get_username(con
));
6447 cupsdDeletePrinter(printer
, 0);
6448 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6451 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6454 * Return with no errors...
6457 con
->response
->request
.status
.status_code
= IPP_OK
;
6462 * 'get_default()' - Get the default destination.
6466 get_default(cupsd_client_t
*con
) /* I - Client connection */
6468 http_status_t status
; /* Policy status */
6469 cups_array_t
*ra
; /* Requested attributes array */
6472 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6478 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6480 send_http_error(con
, status
, NULL
);
6486 ra
= create_requested_array(con
->request
);
6488 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6490 cupsArrayDelete(ra
);
6492 con
->response
->request
.status
.status_code
= IPP_OK
;
6495 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6500 * 'get_devices()' - Get the list of available devices on the local system.
6504 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6506 http_status_t status
; /* Policy status */
6507 ipp_attribute_t
*limit
, /* limit attribute */
6508 *timeout
, /* timeout attribute */
6509 *requested
, /* requested-attributes attribute */
6510 *exclude
, /* exclude-schemes attribute */
6511 *include
; /* include-schemes attribute */
6512 char command
[1024], /* cups-deviced command */
6513 options
[2048], /* Options to pass to command */
6515 /* String for requested attributes */
6517 /* String for excluded schemes */
6519 /* String for included schemes */
6522 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6528 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6530 send_http_error(con
, status
, NULL
);
6535 * Run cups-deviced command with the given options...
6538 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6539 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6540 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6542 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6543 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6546 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6548 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6551 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6553 exclude_str
[0] = '\0';
6556 url_encode_attr(include
, include_str
, sizeof(include_str
));
6558 include_str
[0] = '\0';
6560 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6561 snprintf(options
, sizeof(options
),
6562 "%d+%d+%d+%d+%s%s%s%s%s",
6563 con
->request
->request
.op
.request_id
,
6564 limit
? limit
->values
[0].integer
: 0,
6565 timeout
? timeout
->values
[0].integer
: 15,
6568 exclude_str
[0] ? "%20" : "", exclude_str
,
6569 include_str
[0] ? "%20" : "", include_str
);
6571 if (cupsdSendCommand(con
, command
, options
, 1))
6574 * Command started successfully, don't send an IPP response here...
6577 ippDelete(con
->response
);
6578 con
->response
= NULL
;
6583 * Command failed, return "internal error" so the user knows something
6587 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6588 _("cups-deviced failed to execute."));
6594 * 'get_document()' - Get a copy of a job file.
6598 get_document(cupsd_client_t
*con
, /* I - Client connection */
6599 ipp_attribute_t
*uri
) /* I - Job URI */
6601 http_status_t status
; /* Policy status */
6602 ipp_attribute_t
*attr
; /* Current attribute */
6603 int jobid
; /* Job ID */
6604 int docnum
; /* Document number */
6605 cupsd_job_t
*job
; /* Current job */
6606 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6607 username
[HTTP_MAX_URI
], /* Username portion of URI */
6608 host
[HTTP_MAX_URI
], /* Host portion of URI */
6609 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6610 int port
; /* Port portion of URI */
6611 char filename
[1024], /* Filename for document */
6612 format
[1024]; /* Format for document */
6615 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6616 con
->http
.fd
, uri
->values
[0].string
.text
);
6619 * See if we have a job URI or a printer URI...
6622 if (!strcmp(uri
->name
, "printer-uri"))
6625 * Got a printer URI; see if we also have a job-id attribute...
6628 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6629 IPP_TAG_INTEGER
)) == NULL
)
6631 send_ipp_status(con
, IPP_BAD_REQUEST
,
6632 _("Got a printer-uri attribute but no job-id"));
6636 jobid
= attr
->values
[0].integer
;
6641 * Got a job URI; parse it to get the job ID...
6644 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6645 sizeof(scheme
), username
, sizeof(username
), host
,
6646 sizeof(host
), &port
, resource
, sizeof(resource
));
6648 if (strncmp(resource
, "/jobs/", 6))
6654 send_ipp_status(con
, IPP_BAD_REQUEST
,
6655 _("Bad job-uri attribute \"%s\""),
6656 uri
->values
[0].string
.text
);
6660 jobid
= atoi(resource
+ 6);
6664 * See if the job exists...
6667 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6670 * Nope - return a "not found" error...
6673 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
6681 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6683 send_http_error(con
, status
, NULL
);
6688 * Get the document number...
6691 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6692 IPP_TAG_INTEGER
)) == NULL
)
6694 send_ipp_status(con
, IPP_BAD_REQUEST
,
6695 _("Missing document-number attribute"));
6699 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6700 attr
->num_values
> 1)
6702 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6707 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6709 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6711 cupsdLogMessage(CUPSD_LOG_ERROR
,
6712 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6714 send_ipp_status(con
, IPP_NOT_FOUND
,
6715 _("Unable to open document %d in job %d"), docnum
, jobid
);
6719 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6723 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6724 job
->filetypes
[docnum
- 1]->type
);
6726 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6728 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6730 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6731 IPP_TAG_NAME
)) != NULL
)
6732 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6733 NULL
, attr
->values
[0].string
.text
);
6738 * 'get_job_attrs()' - Get job attributes.
6742 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6743 ipp_attribute_t
*uri
) /* I - Job URI */
6745 http_status_t status
; /* Policy status */
6746 ipp_attribute_t
*attr
; /* Current attribute */
6747 int jobid
; /* Job ID */
6748 cupsd_job_t
*job
; /* Current job */
6749 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6750 username
[HTTP_MAX_URI
], /* Username portion of URI */
6751 host
[HTTP_MAX_URI
], /* Host portion of URI */
6752 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6753 int port
; /* Port portion of URI */
6754 cups_array_t
*ra
; /* Requested attributes array */
6757 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6758 con
->http
.fd
, uri
->values
[0].string
.text
);
6761 * See if we have a job URI or a printer URI...
6764 if (!strcmp(uri
->name
, "printer-uri"))
6767 * Got a printer URI; see if we also have a job-id attribute...
6770 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6771 IPP_TAG_INTEGER
)) == NULL
)
6773 send_ipp_status(con
, IPP_BAD_REQUEST
,
6774 _("Got a printer-uri attribute but no job-id"));
6778 jobid
= attr
->values
[0].integer
;
6783 * Got a job URI; parse it to get the job ID...
6786 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6787 sizeof(scheme
), username
, sizeof(username
), host
,
6788 sizeof(host
), &port
, resource
, sizeof(resource
));
6790 if (strncmp(resource
, "/jobs/", 6))
6796 send_ipp_status(con
, IPP_BAD_REQUEST
,
6797 _("Bad job-uri attribute \"%s\""),
6798 uri
->values
[0].string
.text
);
6802 jobid
= atoi(resource
+ 6);
6806 * See if the job exists...
6809 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6812 * Nope - return a "not found" error...
6815 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
6823 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6825 send_http_error(con
, status
, NULL
);
6830 * Copy attributes...
6835 ra
= create_requested_array(con
->request
);
6836 copy_job_attrs(con
, job
, ra
);
6837 cupsArrayDelete(ra
);
6839 con
->response
->request
.status
.status_code
= IPP_OK
;
6844 * 'get_jobs()' - Get a list of jobs for the specified printer.
6848 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6849 ipp_attribute_t
*uri
) /* I - Printer URI */
6851 http_status_t status
; /* Policy status */
6852 ipp_attribute_t
*attr
; /* Current attribute */
6853 const char *dest
; /* Destination */
6854 cups_ptype_t dtype
; /* Destination type (printer/class) */
6855 cups_ptype_t dmask
; /* Destination type mask */
6856 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6857 username
[HTTP_MAX_URI
], /* Username portion of URI */
6858 host
[HTTP_MAX_URI
], /* Host portion of URI */
6859 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6860 int port
; /* Port portion of URI */
6861 int completed
; /* Completed jobs? */
6862 int first_job_id
; /* First job ID */
6863 int limit
; /* Maximum number of jobs to return */
6864 int count
; /* Number of jobs that match */
6865 cupsd_job_t
*job
; /* Current job pointer */
6866 cupsd_printer_t
*printer
; /* Printer */
6867 cups_array_t
*list
; /* Which job list... */
6868 cups_array_t
*ra
; /* Requested attributes array */
6871 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6872 uri
->values
[0].string
.text
);
6875 * Is the destination valid?
6878 if (strcmp(uri
->name
, "printer-uri"))
6880 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request"));
6884 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6885 sizeof(scheme
), username
, sizeof(username
), host
,
6886 sizeof(host
), &port
, resource
, sizeof(resource
));
6888 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6891 dtype
= (cups_ptype_t
)0;
6892 dmask
= (cups_ptype_t
)0;
6895 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6898 dtype
= (cups_ptype_t
)0;
6899 dmask
= CUPS_PRINTER_CLASS
;
6902 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6905 dtype
= CUPS_PRINTER_CLASS
;
6906 dmask
= CUPS_PRINTER_CLASS
;
6909 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6916 send_ipp_status(con
, IPP_NOT_FOUND
,
6917 _("The printer or class was not found."));
6922 dtype
&= CUPS_PRINTER_CLASS
;
6923 dmask
= CUPS_PRINTER_CLASS
;
6932 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6935 send_http_error(con
, status
, printer
);
6939 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6941 send_http_error(con
, status
, NULL
);
6946 * See if the "which-jobs" attribute have been specified...
6949 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6950 IPP_TAG_KEYWORD
)) != NULL
&&
6951 !strcmp(attr
->values
[0].string
.text
, "completed"))
6956 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
6961 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "processing"))
6964 list
= PrintingJobs
;
6973 * See if they want to limit the number of jobs reported...
6976 if ((attr
= ippFindAttribute(con
->request
, "limit",
6977 IPP_TAG_INTEGER
)) != NULL
)
6978 limit
= attr
->values
[0].integer
;
6982 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6983 IPP_TAG_INTEGER
)) != NULL
)
6984 first_job_id
= attr
->values
[0].integer
;
6989 * See if we only want to see jobs for a specific user...
6992 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6993 IPP_TAG_BOOLEAN
)) != NULL
&&
6994 attr
->values
[0].boolean
)
6995 strlcpy(username
, get_username(con
), sizeof(username
));
6999 ra
= create_requested_array(con
->request
);
7002 * OK, build a list of jobs for this printer...
7005 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7006 (limit
<= 0 || count
< limit
) && job
;
7007 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7010 * Filter out jobs that don't match...
7013 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7014 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7015 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7016 job
->username
, job
->state_value
, job
->attrs
);
7018 if (!job
->dest
|| !job
->username
)
7021 if (!job
->dest
|| !job
->username
)
7024 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7025 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7027 if ((job
->dtype
& dmask
) != dtype
&&
7028 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7030 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
7033 if (job
->id
< first_job_id
)
7040 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7045 if (username
[0] && strcasecmp(username
, job
->username
))
7049 ippAddSeparator(con
->response
);
7053 copy_job_attrs(con
, job
, ra
);
7056 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7058 cupsArrayDelete(ra
);
7060 con
->response
->request
.status
.status_code
= IPP_OK
;
7065 * 'get_notifications()' - Get events for a subscription.
7069 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7071 int i
, j
; /* Looping vars */
7072 http_status_t status
; /* Policy status */
7073 cupsd_subscription_t
*sub
; /* Subscription */
7074 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7075 *sequences
; /* notify-sequence-numbers */
7076 int min_seq
; /* Minimum sequence number */
7077 int interval
; /* Poll interval */
7080 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7084 * Get subscription attributes...
7087 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7089 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7094 send_ipp_status(con
, IPP_BAD_REQUEST
,
7095 _("Missing notify-subscription-ids attribute"));
7100 * Are the subscription IDs valid?
7103 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7105 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7108 * Bad subscription ID...
7111 send_ipp_status(con
, IPP_NOT_FOUND
,
7112 _("notify-subscription-id %d no good"),
7113 ids
->values
[i
].integer
);
7121 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7123 con
, sub
->owner
)) != HTTP_OK
)
7125 send_http_error(con
, status
, sub
->dest
);
7130 * Check the subscription type and update the interval accordingly.
7133 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7136 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7138 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7144 * Tell the client to poll again in N seconds...
7148 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7149 "notify-get-interval", interval
);
7151 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7152 "printer-up-time", time(NULL
));
7155 * Copy the subscription event attributes to the response.
7158 con
->response
->request
.status
.status_code
=
7159 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7161 for (i
= 0; i
< ids
->num_values
; i
++)
7164 * Get the subscription and sequence number...
7167 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7169 if (sequences
&& i
< sequences
->num_values
)
7170 min_seq
= sequences
->values
[i
].integer
;
7175 * If we don't have any new events, nothing to do here...
7178 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7182 * Otherwise copy all of the new events...
7185 if (sub
->first_event_id
> min_seq
)
7188 j
= min_seq
- sub
->first_event_id
;
7190 for (; j
< sub
->num_events
; j
++)
7192 ippAddSeparator(con
->response
);
7194 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7195 IPP_TAG_EVENT_NOTIFICATION
, 0);
7202 * 'get_ppd()' - Get a named PPD from the local system.
7206 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7207 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7209 http_status_t status
; /* Policy status */
7210 cupsd_printer_t
*dest
; /* Destination */
7211 cups_ptype_t dtype
; /* Destination type */
7214 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7215 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7217 if (!strcmp(uri
->name
, "ppd-name"))
7220 * Return a PPD file from cups-driverd...
7223 char command
[1024], /* cups-driverd command */
7224 options
[1024], /* Options to pass to command */
7225 ppd_name
[1024]; /* ppd-name */
7232 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7234 send_http_error(con
, status
, NULL
);
7239 * Run cups-driverd command with the given options...
7242 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7243 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7244 snprintf(options
, sizeof(options
), "get+%d+%s",
7245 con
->request
->request
.op
.request_id
, ppd_name
);
7247 if (cupsdSendCommand(con
, command
, options
, 0))
7250 * Command started successfully, don't send an IPP response here...
7253 ippDelete(con
->response
);
7254 con
->response
= NULL
;
7259 * Command failed, return "internal error" so the user knows something
7263 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7264 _("cups-driverd failed to execute."));
7267 else if (!strcmp(uri
->name
, "printer-uri") &&
7268 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7270 int i
; /* Looping var */
7271 char filename
[1024]; /* PPD filename */
7278 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7280 send_http_error(con
, status
, dest
);
7285 * See if we need the PPD for a class or remote printer...
7288 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7291 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7293 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7294 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7295 "printer-uri", NULL
, dest
->uri
);
7298 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7300 for (i
= 0; i
< dest
->num_printers
; i
++)
7301 if (!(dest
->printers
[i
]->type
&
7302 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7304 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7305 dest
->printers
[i
]->name
);
7307 if (!access(filename
, 0))
7311 if (i
< dest
->num_printers
)
7312 dest
= dest
->printers
[i
];
7315 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7316 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7317 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7323 * Found the printer with the PPD file, now see if there is one...
7326 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7328 send_ipp_status(con
, IPP_NOT_FOUND
,
7329 _("The PPD file \"%s\" could not be opened: %s"),
7330 uri
->values
[0].string
.text
, strerror(errno
));
7334 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7338 con
->response
->request
.status
.status_code
= IPP_OK
;
7341 send_ipp_status(con
, IPP_NOT_FOUND
,
7342 _("The PPD file \"%s\" could not be found."),
7343 uri
->values
[0].string
.text
);
7348 * 'get_ppds()' - Get the list of PPD files on the local system.
7352 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7354 http_status_t status
; /* Policy status */
7355 ipp_attribute_t
*limit
, /* Limit attribute */
7356 *device
, /* ppd-device-id attribute */
7357 *language
, /* ppd-natural-language attribute */
7358 *make
, /* ppd-make attribute */
7359 *model
, /* ppd-make-and-model attribute */
7360 *model_number
, /* ppd-model-number attribute */
7361 *product
, /* ppd-product attribute */
7362 *psversion
, /* ppd-psverion attribute */
7363 *type
, /* ppd-type attribute */
7364 *requested
, /* requested-attributes attribute */
7365 *exclude
, /* exclude-schemes attribute */
7366 *include
; /* include-schemes attribute */
7367 char command
[1024], /* cups-driverd command */
7368 options
[4096], /* Options to pass to command */
7369 device_str
[256],/* Escaped ppd-device-id string */
7371 /* Escaped ppd-natural-language */
7372 make_str
[256], /* Escaped ppd-make string */
7373 model_str
[256], /* Escaped ppd-make-and-model string */
7374 model_number_str
[256],
7375 /* ppd-model-number string */
7377 /* Escaped ppd-product string */
7379 /* Escaped ppd-psversion string */
7380 type_str
[256], /* Escaped ppd-type string */
7382 /* String for requested attributes */
7384 /* String for excluded schemes */
7386 /* String for included schemes */
7389 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7395 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7397 send_http_error(con
, status
, NULL
);
7402 * Run cups-driverd command with the given options...
7405 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7406 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7407 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7409 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7410 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7412 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7414 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7415 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7416 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7417 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7419 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7421 include
= ippFindAttribute(con
->request
, "include-schemes",
7425 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7427 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7430 url_encode_attr(device
, device_str
, sizeof(device_str
));
7432 device_str
[0] = '\0';
7435 url_encode_attr(language
, language_str
, sizeof(language_str
));
7437 language_str
[0] = '\0';
7440 url_encode_attr(make
, make_str
, sizeof(make_str
));
7445 url_encode_attr(model
, model_str
, sizeof(model_str
));
7447 model_str
[0] = '\0';
7450 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7451 model_number
->values
[0].integer
);
7453 model_number_str
[0] = '\0';
7456 url_encode_attr(product
, product_str
, sizeof(product_str
));
7458 product_str
[0] = '\0';
7461 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7463 psversion_str
[0] = '\0';
7466 url_encode_attr(type
, type_str
, sizeof(type_str
));
7471 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7473 exclude_str
[0] = '\0';
7476 url_encode_attr(include
, include_str
, sizeof(include_str
));
7478 include_str
[0] = '\0';
7480 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7481 snprintf(options
, sizeof(options
),
7482 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7483 con
->request
->request
.op
.request_id
,
7484 limit
? limit
->values
[0].integer
: 0,
7486 device
? "%20" : "", device_str
,
7487 language
? "%20" : "", language_str
,
7488 make
? "%20" : "", make_str
,
7489 model
? "%20" : "", model_str
,
7490 model_number
? "%20" : "", model_number_str
,
7491 product
? "%20" : "", product_str
,
7492 psversion
? "%20" : "", psversion_str
,
7493 type
? "%20" : "", type_str
,
7494 exclude_str
[0] ? "%20" : "", exclude_str
,
7495 include_str
[0] ? "%20" : "", include_str
);
7497 if (cupsdSendCommand(con
, command
, options
, 0))
7500 * Command started successfully, don't send an IPP response here...
7503 ippDelete(con
->response
);
7504 con
->response
= NULL
;
7509 * Command failed, return "internal error" so the user knows something
7513 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7514 _("cups-driverd failed to execute."));
7520 * 'get_printer_attrs()' - Get printer attributes.
7524 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7525 ipp_attribute_t
*uri
) /* I - Printer URI */
7527 http_status_t status
; /* Policy status */
7528 cups_ptype_t dtype
; /* Destination type (printer/class) */
7529 cupsd_printer_t
*printer
; /* Printer/class */
7530 cups_array_t
*ra
; /* Requested attributes array */
7533 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7534 con
->http
.fd
, uri
->values
[0].string
.text
);
7537 * Is the destination valid?
7540 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7546 send_ipp_status(con
, IPP_NOT_FOUND
,
7547 _("The printer or class was not found."));
7555 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7557 send_http_error(con
, status
, printer
);
7562 * Send the attributes...
7565 ra
= create_requested_array(con
->request
);
7567 copy_printer_attrs(con
, printer
, ra
);
7569 cupsArrayDelete(ra
);
7571 con
->response
->request
.status
.status_code
= IPP_OK
;
7576 * 'get_printer_supported()' - Get printer supported values.
7580 get_printer_supported(
7581 cupsd_client_t
*con
, /* I - Client connection */
7582 ipp_attribute_t
*uri
) /* I - Printer URI */
7584 http_status_t status
; /* Policy status */
7585 cups_ptype_t dtype
; /* Destination type (printer/class) */
7586 cupsd_printer_t
*printer
; /* Printer/class */
7589 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7590 con
->http
.fd
, uri
->values
[0].string
.text
);
7593 * Is the destination valid?
7596 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7602 send_ipp_status(con
, IPP_NOT_FOUND
,
7603 _("The printer or class was not found."));
7611 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7613 send_http_error(con
, status
, printer
);
7618 * Return a list of attributes that can be set via Set-Printer-Attributes.
7621 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7623 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7624 "printer-location", 0);
7626 con
->response
->request
.status
.status_code
= IPP_OK
;
7631 * 'get_printers()' - Get a list of printers or classes.
7635 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7636 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7638 http_status_t status
; /* Policy status */
7639 ipp_attribute_t
*attr
; /* Current attribute */
7640 int limit
; /* Max number of printers to return */
7641 int count
; /* Number of printers that match */
7642 cupsd_printer_t
*printer
; /* Current printer pointer */
7643 int printer_type
, /* printer-type attribute */
7644 printer_mask
; /* printer-type-mask attribute */
7645 char *location
; /* Location string */
7646 const char *username
; /* Current user */
7647 char *first_printer_name
; /* first-printer-name attribute */
7648 cups_array_t
*ra
; /* Requested attributes array */
7649 int local
; /* Local connection? */
7652 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7653 con
->http
.fd
, type
);
7659 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7661 send_http_error(con
, status
, NULL
);
7666 * Check for printers...
7669 if (!Printers
|| !cupsArrayCount(Printers
))
7671 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7676 * See if they want to limit the number of printers reported...
7679 if ((attr
= ippFindAttribute(con
->request
, "limit",
7680 IPP_TAG_INTEGER
)) != NULL
)
7681 limit
= attr
->values
[0].integer
;
7685 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7686 IPP_TAG_NAME
)) != NULL
)
7687 first_printer_name
= attr
->values
[0].string
.text
;
7689 first_printer_name
= NULL
;
7692 * Support filtering...
7695 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7696 IPP_TAG_ENUM
)) != NULL
)
7697 printer_type
= attr
->values
[0].integer
;
7701 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7702 IPP_TAG_ENUM
)) != NULL
)
7703 printer_mask
= attr
->values
[0].integer
;
7707 local
= httpAddrLocalhost(&(con
->clientaddr
));
7709 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7710 IPP_TAG_TEXT
)) != NULL
)
7711 location
= attr
->values
[0].string
.text
;
7715 if (con
->username
[0])
7716 username
= con
->username
;
7717 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7718 IPP_TAG_NAME
)) != NULL
)
7719 username
= attr
->values
[0].string
.text
;
7723 ra
= create_requested_array(con
->request
);
7726 * OK, build a list of printers for this printer...
7729 if (first_printer_name
)
7731 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7732 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7735 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7738 count
< limit
&& printer
;
7739 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7741 if (!local
&& !printer
->shared
)
7744 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7745 (printer
->type
& printer_mask
) == printer_type
&&
7747 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
7750 * If HideImplicitMembers is enabled, see if this printer or class
7751 * is a member of an implicit class...
7754 if (ImplicitClasses
&& HideImplicitMembers
&&
7755 printer
->in_implicit_class
)
7759 * If a username is specified, see if it is allowed or denied
7763 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
7767 * Add the group separator as needed...
7771 ippAddSeparator(con
->response
);
7776 * Send the attributes...
7779 copy_printer_attrs(con
, printer
, ra
);
7783 cupsArrayDelete(ra
);
7785 con
->response
->request
.status
.status_code
= IPP_OK
;
7790 * 'get_subscription_attrs()' - Get subscription attributes.
7794 get_subscription_attrs(
7795 cupsd_client_t
*con
, /* I - Client connection */
7796 int sub_id
) /* I - Subscription ID */
7798 http_status_t status
; /* Policy status */
7799 cupsd_subscription_t
*sub
; /* Subscription */
7800 cups_array_t
*ra
; /* Requested attributes array */
7803 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7804 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7805 con
, con
->http
.fd
, sub_id
);
7808 * Is the subscription ID valid?
7811 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7814 * Bad subscription ID...
7817 send_ipp_status(con
, IPP_NOT_FOUND
,
7818 _("notify-subscription-id %d no good"), sub_id
);
7826 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7828 con
, sub
->owner
)) != HTTP_OK
)
7830 send_http_error(con
, status
, sub
->dest
);
7835 * Copy the subscription attributes to the response using the
7836 * requested-attributes attribute that may be provided by the client.
7839 ra
= create_requested_array(con
->request
);
7841 copy_subscription_attrs(con
, sub
, ra
);
7843 cupsArrayDelete(ra
);
7845 con
->response
->request
.status
.status_code
= IPP_OK
;
7850 * 'get_subscriptions()' - Get subscriptions.
7854 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7855 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7857 http_status_t status
; /* Policy status */
7858 int count
; /* Number of subscriptions */
7859 int limit
; /* Limit */
7860 cupsd_subscription_t
*sub
; /* Subscription */
7861 cups_array_t
*ra
; /* Requested attributes array */
7862 ipp_attribute_t
*attr
; /* Attribute */
7863 cups_ptype_t dtype
; /* Destination type (printer/class) */
7864 char scheme
[HTTP_MAX_URI
],
7865 /* Scheme portion of URI */
7866 username
[HTTP_MAX_URI
],
7867 /* Username portion of URI */
7869 /* Host portion of URI */
7870 resource
[HTTP_MAX_URI
];
7871 /* Resource portion of URI */
7872 int port
; /* Port portion of URI */
7873 cupsd_job_t
*job
; /* Job pointer */
7874 cupsd_printer_t
*printer
; /* Printer */
7877 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7878 "get_subscriptions(con=%p[%d], uri=%s)",
7879 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7882 * Is the destination valid?
7885 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7886 sizeof(scheme
), username
, sizeof(username
), host
,
7887 sizeof(host
), &port
, resource
, sizeof(resource
));
7889 if (!strcmp(resource
, "/") ||
7890 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7891 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7892 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7897 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7900 job
= cupsdFindJob(atoi(resource
+ 6));
7904 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist"),
7909 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7915 send_ipp_status(con
, IPP_NOT_FOUND
,
7916 _("The printer or class was not found."));
7919 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7920 IPP_TAG_INTEGER
)) != NULL
)
7922 job
= cupsdFindJob(attr
->values
[0].integer
);
7926 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
7927 attr
->values
[0].integer
);
7938 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
7940 con
, NULL
)) != HTTP_OK
)
7942 send_http_error(con
, status
, printer
);
7947 * Copy the subscription attributes to the response using the
7948 * requested-attributes attribute that may be provided by the client.
7951 ra
= create_requested_array(con
->request
);
7953 if ((attr
= ippFindAttribute(con
->request
, "limit",
7954 IPP_TAG_INTEGER
)) != NULL
)
7955 limit
= attr
->values
[0].integer
;
7960 * See if we only want to see subscriptions for a specific user...
7963 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7964 IPP_TAG_BOOLEAN
)) != NULL
&&
7965 attr
->values
[0].boolean
)
7966 strlcpy(username
, get_username(con
), sizeof(username
));
7970 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7972 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7973 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7974 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
7976 ippAddSeparator(con
->response
);
7977 copy_subscription_attrs(con
, sub
, ra
);
7980 if (limit
&& count
>= limit
)
7984 cupsArrayDelete(ra
);
7987 con
->response
->request
.status
.status_code
= IPP_OK
;
7989 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7994 * 'get_username()' - Get the username associated with a request.
7997 static const char * /* O - Username */
7998 get_username(cupsd_client_t
*con
) /* I - Connection */
8000 ipp_attribute_t
*attr
; /* Attribute */
8003 if (con
->username
[0])
8004 return (con
->username
);
8005 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8006 IPP_TAG_NAME
)) != NULL
)
8007 return (attr
->values
[0].string
.text
);
8009 return ("anonymous");
8014 * 'hold_job()' - Hold a print job.
8018 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8019 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8021 ipp_attribute_t
*attr
; /* Current job-hold-until */
8022 const char *when
; /* New value */
8023 int jobid
; /* Job ID */
8024 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8025 username
[HTTP_MAX_URI
], /* Username portion of URI */
8026 host
[HTTP_MAX_URI
], /* Host portion of URI */
8027 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8028 int port
; /* Port portion of URI */
8029 cupsd_job_t
*job
; /* Job information */
8032 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8033 uri
->values
[0].string
.text
);
8036 * See if we have a job URI or a printer URI...
8039 if (!strcmp(uri
->name
, "printer-uri"))
8042 * Got a printer URI; see if we also have a job-id attribute...
8045 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8046 IPP_TAG_INTEGER
)) == NULL
)
8048 send_ipp_status(con
, IPP_BAD_REQUEST
,
8049 _("Got a printer-uri attribute but no job-id"));
8053 jobid
= attr
->values
[0].integer
;
8058 * Got a job URI; parse it to get the job ID...
8061 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8062 sizeof(scheme
), username
, sizeof(username
), host
,
8063 sizeof(host
), &port
, resource
, sizeof(resource
));
8065 if (strncmp(resource
, "/jobs/", 6))
8071 send_ipp_status(con
, IPP_BAD_REQUEST
,
8072 _("Bad job-uri attribute \"%s\""),
8073 uri
->values
[0].string
.text
);
8077 jobid
= atoi(resource
+ 6);
8081 * See if the job exists...
8084 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8087 * Nope - return a "not found" error...
8090 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
8095 * See if the job is owned by the requesting user...
8098 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8100 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8101 cupsdFindDest(job
->dest
));
8106 * Hold the job and return...
8109 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8110 IPP_TAG_KEYWORD
)) == NULL
)
8111 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8115 when
= attr
->values
[0].string
.text
;
8117 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8118 "Job job-hold-until value changed by user.");
8121 when
= "indefinite";
8123 cupsdSetJobHoldUntil(job
, when
, 1);
8124 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8127 con
->response
->request
.status
.status_code
= IPP_OK
;
8132 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8136 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8137 ipp_attribute_t
*uri
) /* I - Printer URI */
8139 http_status_t status
; /* Policy status */
8140 cups_ptype_t dtype
; /* Destination type (printer/class) */
8141 cupsd_printer_t
*printer
; /* Printer data */
8144 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8145 con
->http
.fd
, uri
->values
[0].string
.text
);
8148 * Is the destination valid?
8151 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8157 send_ipp_status(con
, IPP_NOT_FOUND
,
8158 _("The printer or class was not found."));
8166 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8168 send_http_error(con
, status
, printer
);
8173 * Hold pending/new jobs sent to the printer...
8176 printer
->holding_new_jobs
= 1;
8178 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8179 cupsdAddPrinterHistory(printer
);
8181 if (dtype
& CUPS_PRINTER_CLASS
)
8182 cupsdLogMessage(CUPSD_LOG_INFO
,
8183 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8184 printer
->name
, get_username(con
));
8186 cupsdLogMessage(CUPSD_LOG_INFO
,
8187 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8188 printer
->name
, get_username(con
));
8191 * Everything was ok, so return OK status...
8194 con
->response
->request
.status
.status_code
= IPP_OK
;
8199 * 'move_job()' - Move a job to a new destination.
8203 move_job(cupsd_client_t
*con
, /* I - Client connection */
8204 ipp_attribute_t
*uri
) /* I - Job URI */
8206 http_status_t status
; /* Policy status */
8207 ipp_attribute_t
*attr
; /* Current attribute */
8208 int jobid
; /* Job ID */
8209 cupsd_job_t
*job
; /* Current job */
8210 const char *src
; /* Source printer/class */
8211 cups_ptype_t stype
, /* Source type (printer or class) */
8212 dtype
; /* Destination type (printer/class) */
8213 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8214 username
[HTTP_MAX_URI
], /* Username portion of URI */
8215 host
[HTTP_MAX_URI
], /* Host portion of URI */
8216 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8217 int port
; /* Port portion of URI */
8218 cupsd_printer_t
*sprinter
, /* Source printer */
8219 *dprinter
; /* Destination printer */
8222 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8223 uri
->values
[0].string
.text
);
8226 * Get the new printer or class...
8229 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8230 IPP_TAG_URI
)) == NULL
)
8233 * Need job-printer-uri...
8236 send_ipp_status(con
, IPP_BAD_REQUEST
,
8237 _("job-printer-uri attribute missing"));
8241 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8247 send_ipp_status(con
, IPP_NOT_FOUND
,
8248 _("The printer or class was not found."));
8253 * See if we have a job URI or a printer URI...
8256 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8257 sizeof(scheme
), username
, sizeof(username
), host
,
8258 sizeof(host
), &port
, resource
, sizeof(resource
));
8260 if (!strcmp(uri
->name
, "printer-uri"))
8263 * Got a printer URI; see if we also have a job-id attribute...
8266 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8267 IPP_TAG_INTEGER
)) == NULL
)
8273 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8274 &sprinter
)) == NULL
)
8280 send_ipp_status(con
, IPP_NOT_FOUND
,
8281 _("The printer or class was not found."));
8290 * Otherwise, just move a single job...
8293 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8296 * Nope - return a "not found" error...
8299 send_ipp_status(con
, IPP_NOT_FOUND
,
8300 _("Job #%d does not exist"), attr
->values
[0].integer
);
8306 * Job found, initialize source pointers...
8317 * Got a job URI; parse it to get the job ID...
8320 if (strncmp(resource
, "/jobs/", 6))
8326 send_ipp_status(con
, IPP_BAD_REQUEST
,
8327 _("Bad job-uri attribute \"%s\""),
8328 uri
->values
[0].string
.text
);
8333 * See if the job exists...
8336 jobid
= atoi(resource
+ 6);
8338 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8341 * Nope - return a "not found" error...
8344 send_ipp_status(con
, IPP_NOT_FOUND
,
8345 _("Job #%d does not exist"), jobid
);
8351 * Job found, initialize source pointers...
8360 * Check the policy of the destination printer...
8363 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8364 job
? job
->username
: NULL
)) != HTTP_OK
)
8366 send_http_error(con
, status
, dprinter
);
8371 * Now move the job or jobs...
8377 * See if the job has been completed...
8380 if (job
->state_value
> IPP_JOB_STOPPED
)
8383 * Return a "not-possible" error...
8386 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8387 _("Job #%d is finished and cannot be altered"),
8393 * See if the job is owned by the requesting user...
8396 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8398 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8399 cupsdFindDest(job
->dest
));
8404 * Move the job to a different printer or class...
8407 cupsdMoveJob(job
, dprinter
);
8412 * Got the source printer, now look through the jobs...
8415 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8417 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8420 * See if the job is pointing at the source printer or has not been
8424 if (strcasecmp(job
->dest
, src
) ||
8425 job
->state_value
> IPP_JOB_STOPPED
)
8429 * See if the job can be moved by the requesting user...
8432 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8436 * Move the job to a different printer or class...
8439 cupsdMoveJob(job
, dprinter
);
8444 * Start jobs if possible...
8450 * Return with "everything is OK" status...
8453 con
->response
->request
.status
.status_code
= IPP_OK
;
8458 * 'ppd_parse_line()' - Parse a PPD default line.
8461 static int /* O - 0 on success, -1 on failure */
8462 ppd_parse_line(const char *line
, /* I - Line */
8463 char *option
, /* O - Option name */
8464 int olen
, /* I - Size of option name */
8465 char *choice
, /* O - Choice name */
8466 int clen
) /* I - Size of choice name */
8469 * Verify this is a default option line...
8472 if (strncmp(line
, "*Default", 8))
8476 * Read the option name...
8479 for (line
+= 8, olen
--;
8480 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8491 * Skip everything else up to the colon (:)...
8494 while (*line
&& *line
!= ':')
8503 * Now grab the option choice, skipping leading whitespace...
8506 while (isspace(*line
& 255))
8510 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8521 * Return with no errors...
8529 * 'print_job()' - Print a file to a printer or class.
8533 print_job(cupsd_client_t
*con
, /* I - Client connection */
8534 ipp_attribute_t
*uri
) /* I - Printer URI */
8536 ipp_attribute_t
*attr
; /* Current attribute */
8537 ipp_attribute_t
*format
; /* Document-format attribute */
8538 const char *default_format
; /* document-format-default value */
8539 cupsd_job_t
*job
; /* New job */
8540 char filename
[1024]; /* Job filename */
8541 mime_type_t
*filetype
; /* Type of file */
8542 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8543 type
[MIME_MAX_TYPE
], /* Subtype of file */
8544 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8545 /* Textual name of mime type */
8546 cupsd_printer_t
*printer
; /* Printer data */
8547 struct stat fileinfo
; /* File information */
8548 int kbytes
; /* Size of file */
8549 int compression
; /* Document compression */
8552 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8553 uri
->values
[0].string
.text
);
8556 * Validate print file attributes, for now just document-format and
8557 * compression (CUPS only supports "none" and "gzip")...
8560 compression
= CUPS_FILE_NONE
;
8562 if ((attr
= ippFindAttribute(con
->request
, "compression",
8563 IPP_TAG_KEYWORD
)) != NULL
)
8565 if (strcmp(attr
->values
[0].string
.text
, "none")
8567 && strcmp(attr
->values
[0].string
.text
, "gzip")
8568 #endif /* HAVE_LIBZ */
8571 send_ipp_status(con
, IPP_ATTRIBUTES
,
8572 _("Unsupported compression \"%s\""),
8573 attr
->values
[0].string
.text
);
8574 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8575 "compression", NULL
, attr
->values
[0].string
.text
);
8580 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8581 compression
= CUPS_FILE_GZIP
;
8582 #endif /* HAVE_LIBZ */
8586 * Do we have a file to print?
8591 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
8596 * Is the destination valid?
8599 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8605 send_ipp_status(con
, IPP_NOT_FOUND
,
8606 _("The printer or class was not found."));
8611 * Is it a format we support?
8614 if ((format
= ippFindAttribute(con
->request
, "document-format",
8615 IPP_TAG_MIMETYPE
)) != NULL
)
8618 * Grab format from client...
8621 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8624 send_ipp_status(con
, IPP_BAD_REQUEST
,
8625 _("Could not scan type \"%s\""),
8626 format
->values
[0].string
.text
);
8630 else if ((default_format
= cupsGetOption("document-format",
8631 printer
->num_options
,
8632 printer
->options
)) != NULL
)
8635 * Use default document format...
8638 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8640 send_ipp_status(con
, IPP_BAD_REQUEST
,
8641 _("Could not scan type \"%s\""),
8652 strcpy(super
, "application");
8653 strcpy(type
, "octet-stream");
8656 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8659 * Auto-type the file...
8662 ipp_attribute_t
*doc_name
; /* document-name attribute */
8665 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8667 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8668 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8669 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8673 filetype
= mimeType(MimeDatabase
, super
, type
);
8675 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8676 filetype
->super
, filetype
->type
);
8679 filetype
= mimeType(MimeDatabase
, super
, type
);
8683 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8686 * Replace the document-format attribute value with the auto-typed or
8690 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8695 _cupsStrFree(format
->values
[0].string
.text
);
8697 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8700 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8701 "document-format", NULL
, mimetype
);
8705 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8706 _("Unsupported format \'%s/%s\'"), super
, type
);
8707 cupsdLogMessage(CUPSD_LOG_INFO
,
8708 "Hint: Do you have the raw file printing rules enabled?");
8711 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8712 "document-format", NULL
, format
->values
[0].string
.text
);
8718 * Read any embedded job ticket info from PS files...
8721 if (!strcasecmp(filetype
->super
, "application") &&
8722 (!strcasecmp(filetype
->type
, "postscript") ||
8723 !strcasecmp(filetype
->type
, "pdf")))
8724 read_job_ticket(con
);
8727 * Create the job object...
8730 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8734 * Update quota data...
8737 if (stat(con
->filename
, &fileinfo
))
8740 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8742 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8744 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8745 IPP_TAG_INTEGER
)) != NULL
)
8746 attr
->values
[0].integer
+= kbytes
;
8749 * Add the job file...
8752 if (add_file(con
, job
, filetype
, compression
))
8755 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8757 rename(con
->filename
, filename
);
8758 cupsdClearString(&con
->filename
);
8761 * See if we need to add the ending sheet...
8764 if (cupsdTimeoutJob(job
))
8768 * Log and save the job...
8771 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8772 "File of type %s/%s queued by \"%s\".",
8773 filetype
->super
, filetype
->type
, job
->username
);
8774 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8775 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8776 job
->dest
, job
->username
);
8779 * Start the job if possible...
8787 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8789 * This function only gets called when printing a single PDF or PostScript
8790 * file using the Print-Job operation. It doesn't work for Create-Job +
8791 * Send-File, since the job attributes need to be set at job creation
8792 * time for banners to work. The embedded job ticket stuff is here
8793 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8794 * options and IPP attributes which otherwise would be lost.
8796 * The format of a job ticket is simple:
8798 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8800 * %cupsJobTicket: attr1=value1
8801 * %cupsJobTicket: attr2=value2
8803 * %cupsJobTicket: attrN=valueN
8805 * Job ticket lines must appear immediately after the first line that
8806 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8807 * stops looking for job ticket info when it finds a line that does not begin
8808 * with "%cupsJobTicket:".
8810 * The maximum length of a job ticket line, including the prefix, is
8811 * 255 characters to conform with the Adobe DSC.
8813 * Read-only attributes are rejected with a notice to the error log in
8814 * case a malicious user tries anything. Since the job ticket is read
8815 * prior to attribute validation in print_job(), job ticket attributes
8816 * will go through the same validation as IPP attributes...
8820 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8822 cups_file_t
*fp
; /* File to read from */
8823 char line
[256]; /* Line data */
8824 int num_options
; /* Number of options */
8825 cups_option_t
*options
; /* Options */
8826 ipp_t
*ticket
; /* New attributes */
8827 ipp_attribute_t
*attr
, /* Current attribute */
8828 *attr2
, /* Job attribute */
8829 *prev2
; /* Previous job attribute */
8833 * First open the print file...
8836 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8838 cupsdLogMessage(CUPSD_LOG_ERROR
,
8839 "Unable to open print file for job ticket - %s",
8845 * Skip the first line...
8848 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8850 cupsdLogMessage(CUPSD_LOG_ERROR
,
8851 "Unable to read from print file for job ticket - %s",
8857 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8860 * Not a DSC-compliant file, so no job ticket info will be available...
8868 * Read job ticket info from the file...
8874 while (cupsFileGets(fp
, line
, sizeof(line
)))
8877 * Stop at the first non-ticket line...
8880 if (strncmp(line
, "%cupsJobTicket:", 15))
8884 * Add the options to the option array...
8887 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8891 * Done with the file; see if we have any options...
8896 if (num_options
== 0)
8900 * OK, convert the options to an attribute list, and apply them to
8905 cupsEncodeOptions(ticket
, num_options
, options
);
8908 * See what the user wants to change.
8911 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8913 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8916 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8917 !strcmp(attr
->name
, "job-originating-user-name") ||
8918 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8919 !strcmp(attr
->name
, "job-k-octets") ||
8920 !strcmp(attr
->name
, "job-id") ||
8921 !strncmp(attr
->name
, "job-state", 9) ||
8922 !strncmp(attr
->name
, "time-at-", 8))
8923 continue; /* Read-only attrs */
8925 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8926 IPP_TAG_ZERO
)) != NULL
)
8929 * Some other value; first free the old value...
8932 if (con
->request
->attrs
== attr2
)
8934 con
->request
->attrs
= attr2
->next
;
8939 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8940 if (prev2
->next
== attr2
)
8942 prev2
->next
= attr2
->next
;
8947 if (con
->request
->last
== attr2
)
8948 con
->request
->last
= prev2
;
8950 _ippFreeAttr(attr2
);
8954 * Add new option by copying it...
8957 copy_attribute(con
->request
, attr
, 0);
8961 * Then free the attribute list and option array...
8965 cupsFreeOptions(num_options
, options
);
8970 * 'reject_jobs()' - Reject print jobs to a printer.
8974 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8975 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8977 http_status_t status
; /* Policy status */
8978 cups_ptype_t dtype
; /* Destination type (printer/class) */
8979 cupsd_printer_t
*printer
; /* Printer data */
8980 ipp_attribute_t
*attr
; /* printer-state-message text */
8983 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8984 con
->http
.fd
, uri
->values
[0].string
.text
);
8987 * Is the destination valid?
8990 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8996 send_ipp_status(con
, IPP_NOT_FOUND
,
8997 _("The printer or class was not found."));
9005 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9007 send_http_error(con
, status
, printer
);
9012 * Reject jobs sent to the printer...
9015 printer
->accepting
= 0;
9017 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9018 IPP_TAG_TEXT
)) == NULL
)
9019 strcpy(printer
->state_message
, "Rejecting Jobs");
9021 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9022 sizeof(printer
->state_message
));
9024 cupsdAddPrinterHistory(printer
);
9026 if (dtype
& CUPS_PRINTER_CLASS
)
9028 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9030 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9031 printer
->name
, get_username(con
));
9035 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9037 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9038 printer
->name
, get_username(con
));
9042 * Everything was ok, so return OK status...
9045 con
->response
->request
.status
.status_code
= IPP_OK
;
9050 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9054 release_held_new_jobs(
9055 cupsd_client_t
*con
, /* I - Connection */
9056 ipp_attribute_t
*uri
) /* I - Printer URI */
9058 http_status_t status
; /* Policy status */
9059 cups_ptype_t dtype
; /* Destination type (printer/class) */
9060 cupsd_printer_t
*printer
; /* Printer data */
9063 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9064 con
->http
.fd
, uri
->values
[0].string
.text
);
9067 * Is the destination valid?
9070 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9076 send_ipp_status(con
, IPP_NOT_FOUND
,
9077 _("The printer or class was not found."));
9085 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9087 send_http_error(con
, status
, printer
);
9092 * Hold pending/new jobs sent to the printer...
9095 printer
->holding_new_jobs
= 0;
9097 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9098 cupsdAddPrinterHistory(printer
);
9100 if (dtype
& CUPS_PRINTER_CLASS
)
9101 cupsdLogMessage(CUPSD_LOG_INFO
,
9102 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9103 printer
->name
, get_username(con
));
9105 cupsdLogMessage(CUPSD_LOG_INFO
,
9106 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9107 printer
->name
, get_username(con
));
9110 * Everything was ok, so return OK status...
9113 con
->response
->request
.status
.status_code
= IPP_OK
;
9118 * 'release_job()' - Release a held print job.
9122 release_job(cupsd_client_t
*con
, /* I - Client connection */
9123 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9125 ipp_attribute_t
*attr
; /* Current attribute */
9126 int jobid
; /* Job ID */
9127 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9128 username
[HTTP_MAX_URI
], /* Username portion of URI */
9129 host
[HTTP_MAX_URI
], /* Host portion of URI */
9130 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9131 int port
; /* Port portion of URI */
9132 cupsd_job_t
*job
; /* Job information */
9135 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9136 con
->http
.fd
, uri
->values
[0].string
.text
);
9139 * See if we have a job URI or a printer URI...
9142 if (!strcmp(uri
->name
, "printer-uri"))
9145 * Got a printer URI; see if we also have a job-id attribute...
9148 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9149 IPP_TAG_INTEGER
)) == NULL
)
9151 send_ipp_status(con
, IPP_BAD_REQUEST
,
9152 _("Got a printer-uri attribute but no job-id"));
9156 jobid
= attr
->values
[0].integer
;
9161 * Got a job URI; parse it to get the job ID...
9164 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9165 sizeof(scheme
), username
, sizeof(username
), host
,
9166 sizeof(host
), &port
, resource
, sizeof(resource
));
9168 if (strncmp(resource
, "/jobs/", 6))
9174 send_ipp_status(con
, IPP_BAD_REQUEST
,
9175 _("Bad job-uri attribute \"%s\""),
9176 uri
->values
[0].string
.text
);
9180 jobid
= atoi(resource
+ 6);
9184 * See if the job exists...
9187 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9190 * Nope - return a "not found" error...
9193 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9198 * See if job is "held"...
9201 if (job
->state_value
!= IPP_JOB_HELD
)
9204 * Nope - return a "not possible" error...
9207 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held"), jobid
);
9212 * See if the job is owned by the requesting user...
9215 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9217 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9218 cupsdFindDest(job
->dest
));
9223 * Reset the job-hold-until value to "no-hold"...
9226 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9227 IPP_TAG_KEYWORD
)) == NULL
)
9228 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9232 _cupsStrFree(attr
->values
[0].string
.text
);
9234 attr
->value_tag
= IPP_TAG_KEYWORD
;
9235 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9237 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9238 "Job job-hold-until value changed by user.");
9242 * Release the job and return...
9245 cupsdReleaseJob(job
);
9247 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9248 "Job released by user.");
9250 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9252 con
->response
->request
.status
.status_code
= IPP_OK
;
9259 * 'renew_subscription()' - Renew an existing subscription...
9264 cupsd_client_t
*con
, /* I - Client connection */
9265 int sub_id
) /* I - Subscription ID */
9267 http_status_t status
; /* Policy status */
9268 cupsd_subscription_t
*sub
; /* Subscription */
9269 ipp_attribute_t
*lease
; /* notify-lease-duration */
9272 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9273 "renew_subscription(con=%p[%d], sub_id=%d)",
9274 con
, con
->http
.fd
, sub_id
);
9277 * Is the subscription ID valid?
9280 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9283 * Bad subscription ID...
9286 send_ipp_status(con
, IPP_NOT_FOUND
,
9287 _("notify-subscription-id %d no good"), sub_id
);
9294 * Job subscriptions cannot be renewed...
9297 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9298 _("Job subscriptions cannot be renewed"));
9306 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9308 con
, sub
->owner
)) != HTTP_OK
)
9310 send_http_error(con
, status
, sub
->dest
);
9315 * Renew the subscription...
9318 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9321 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9323 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9325 cupsdLogMessage(CUPSD_LOG_INFO
,
9326 "renew_subscription: Limiting notify-lease-duration to "
9329 sub
->lease
= MaxLeaseDuration
;
9332 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9334 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9336 con
->response
->request
.status
.status_code
= IPP_OK
;
9338 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9339 "notify-lease-duration", sub
->lease
);
9344 * 'restart_job()' - Restart an old print job.
9348 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9349 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9351 ipp_attribute_t
*attr
; /* Current attribute */
9352 int jobid
; /* Job ID */
9353 cupsd_job_t
*job
; /* Job information */
9354 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9355 username
[HTTP_MAX_URI
], /* Username portion of URI */
9356 host
[HTTP_MAX_URI
], /* Host portion of URI */
9357 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9358 int port
; /* Port portion of URI */
9361 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9362 con
->http
.fd
, uri
->values
[0].string
.text
);
9365 * See if we have a job URI or a printer URI...
9368 if (!strcmp(uri
->name
, "printer-uri"))
9371 * Got a printer URI; see if we also have a job-id attribute...
9374 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9375 IPP_TAG_INTEGER
)) == NULL
)
9377 send_ipp_status(con
, IPP_BAD_REQUEST
,
9378 _("Got a printer-uri attribute but no job-id"));
9382 jobid
= attr
->values
[0].integer
;
9387 * Got a job URI; parse it to get the job ID...
9390 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9391 sizeof(scheme
), username
, sizeof(username
), host
,
9392 sizeof(host
), &port
, resource
, sizeof(resource
));
9394 if (strncmp(resource
, "/jobs/", 6))
9400 send_ipp_status(con
, IPP_BAD_REQUEST
,
9401 _("Bad job-uri attribute \"%s\""),
9402 uri
->values
[0].string
.text
);
9406 jobid
= atoi(resource
+ 6);
9410 * See if the job exists...
9413 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9416 * Nope - return a "not found" error...
9419 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9424 * See if job is in any of the "completed" states...
9427 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9430 * Nope - return a "not possible" error...
9433 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete"),
9439 * See if we have retained the job files...
9444 if (!job
->attrs
|| job
->num_files
== 0)
9447 * Nope - return a "not possible" error...
9450 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9451 _("Job #%d cannot be restarted - no files"), jobid
);
9456 * See if the job is owned by the requesting user...
9459 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9461 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9462 cupsdFindDest(job
->dest
));
9467 * See if the job-hold-until attribute is specified...
9470 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9471 IPP_TAG_KEYWORD
)) == NULL
)
9472 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9474 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9477 * Return the job to a held state...
9480 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9481 "Restarted by \"%s\" with job-hold-until=%s.",
9482 username
, attr
->values
[0].string
.text
);
9483 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9485 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9486 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9487 attr
->values
[0].string
.text
);
9492 * Restart the job...
9495 cupsdRestartJob(job
);
9499 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9501 con
->response
->request
.status
.status_code
= IPP_OK
;
9506 * 'save_auth_info()' - Save authentication information for a job.
9511 cupsd_client_t
*con
, /* I - Client connection */
9512 cupsd_job_t
*job
, /* I - Job */
9513 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9515 int i
; /* Looping var */
9516 char filename
[1024]; /* Job authentication filename */
9517 cups_file_t
*fp
; /* Job authentication file */
9518 char line
[2048]; /* Line for file */
9519 cupsd_printer_t
*dest
; /* Destination printer/class */
9523 * This function saves the in-memory authentication information for
9524 * a job so that it can be used to authenticate with a remote host.
9525 * The information is stored in a file that is readable only by the
9526 * root user. The fields are Base-64 encoded, each on a separate line,
9527 * followed by random number (up to 1024) of newlines to limit the
9528 * amount of information that is exposed.
9530 * Because of the potential for exposing of authentication information,
9531 * this functionality is only enabled when running cupsd as root.
9533 * This caching only works for the Basic and BasicDigest authentication
9534 * types. Digest authentication cannot be cached this way, and in
9535 * the future Kerberos authentication may make all of this obsolete.
9537 * Authentication information is saved whenever an authenticated
9538 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9541 * This information is deleted after a job is completed or canceled,
9542 * so reprints may require subsequent re-authentication.
9548 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9552 * Create the authentication file and change permissions...
9555 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9556 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9558 cupsdLogMessage(CUPSD_LOG_ERROR
,
9559 "Unable to save authentication info to \"%s\" - %s",
9560 filename
, strerror(errno
));
9564 fchown(cupsFileNumber(fp
), 0, 0);
9565 fchmod(cupsFileNumber(fp
), 0400);
9567 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9570 * Write 1 to 3 auth values...
9573 cupsdClearString(&job
->auth_username
);
9574 cupsdClearString(&job
->auth_domain
);
9575 cupsdClearString(&job
->auth_password
);
9577 for (i
= 0; i
< auth_info
->num_values
; i
++)
9579 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9580 strlen(auth_info
->values
[i
].string
.text
));
9581 cupsFilePrintf(fp
, "%s\n", line
);
9583 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9584 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9585 auth_info
->values
[i
].string
.text
);
9586 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9587 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9588 auth_info
->values
[i
].string
.text
);
9589 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9590 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9591 auth_info
->values
[i
].string
.text
);
9594 else if (con
->username
[0])
9597 * Write the authenticated username...
9600 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9601 cupsFilePrintf(fp
, "%s\n", line
);
9603 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9604 cupsdClearString(&job
->auth_domain
);
9607 * Write the authenticated password...
9610 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9611 cupsFilePrintf(fp
, "%s\n", line
);
9613 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
9617 * Write a random number of newlines to the end of the file...
9620 for (i
= (rand() % 1024); i
>= 0; i
--)
9621 cupsFilePutChar(fp
, '\n');
9624 * Close the file and return...
9629 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9630 # ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
9631 if (con
->have_gss
&&
9632 (con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
|| con
->gss_creds
))
9634 if (con
->have_gss
&& con
->gss_creds
)
9635 # endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
9636 save_krb5_creds(con
, job
);
9637 else if (job
->ccname
)
9638 cupsdClearString(&(job
->ccname
));
9639 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9643 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9645 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
9649 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
9650 cupsd_job_t
*job
) /* I - Job */
9653 * Get the credentials...
9656 job
->ccache
= cupsdCopyKrb5Creds(con
);
9659 * Add the KRB5CCNAME environment variable to the job so that the
9660 * backend can use the credentials when printing.
9665 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
9666 krb5_cc_get_name(KerberosContext
, job
->ccache
));
9668 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
9671 cupsdClearString(&(job
->ccname
));
9673 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9677 * 'send_document()' - Send a file to a printer or class.
9681 send_document(cupsd_client_t
*con
, /* I - Client connection */
9682 ipp_attribute_t
*uri
) /* I - Printer URI */
9684 ipp_attribute_t
*attr
; /* Current attribute */
9685 ipp_attribute_t
*format
; /* Request's document-format attribute */
9686 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9687 const char *default_format
;/* document-format-default value */
9688 int jobid
; /* Job ID number */
9689 cupsd_job_t
*job
; /* Current job */
9690 char job_uri
[HTTP_MAX_URI
],
9692 scheme
[HTTP_MAX_URI
],
9693 /* Method portion of URI */
9694 username
[HTTP_MAX_URI
],
9695 /* Username portion of URI */
9697 /* Host portion of URI */
9698 resource
[HTTP_MAX_URI
];
9699 /* Resource portion of URI */
9700 int port
; /* Port portion of URI */
9701 mime_type_t
*filetype
; /* Type of file */
9702 char super
[MIME_MAX_SUPER
],
9703 /* Supertype of file */
9704 type
[MIME_MAX_TYPE
],
9705 /* Subtype of file */
9706 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9707 /* Textual name of mime type */
9708 char filename
[1024]; /* Job filename */
9709 cupsd_printer_t
*printer
; /* Current printer */
9710 struct stat fileinfo
; /* File information */
9711 int kbytes
; /* Size of file */
9712 int compression
; /* Type of compression */
9713 int start_job
; /* Start the job? */
9716 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9717 con
->http
.fd
, uri
->values
[0].string
.text
);
9720 * See if we have a job URI or a printer URI...
9723 if (!strcmp(uri
->name
, "printer-uri"))
9726 * Got a printer URI; see if we also have a job-id attribute...
9729 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9730 IPP_TAG_INTEGER
)) == NULL
)
9732 send_ipp_status(con
, IPP_BAD_REQUEST
,
9733 _("Got a printer-uri attribute but no job-id"));
9737 jobid
= attr
->values
[0].integer
;
9742 * Got a job URI; parse it to get the job ID...
9745 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9746 sizeof(scheme
), username
, sizeof(username
), host
,
9747 sizeof(host
), &port
, resource
, sizeof(resource
));
9749 if (strncmp(resource
, "/jobs/", 6))
9755 send_ipp_status(con
, IPP_BAD_REQUEST
,
9756 _("Bad job-uri attribute \"%s\""),
9757 uri
->values
[0].string
.text
);
9761 jobid
= atoi(resource
+ 6);
9765 * See if the job exists...
9768 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9771 * Nope - return a "not found" error...
9774 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9778 printer
= cupsdFindDest(job
->dest
);
9781 * See if the job is owned by the requesting user...
9784 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9786 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9787 cupsdFindDest(job
->dest
));
9792 * OK, see if the client is sending the document compressed - CUPS
9793 * only supports "none" and "gzip".
9796 compression
= CUPS_FILE_NONE
;
9798 if ((attr
= ippFindAttribute(con
->request
, "compression",
9799 IPP_TAG_KEYWORD
)) != NULL
)
9801 if (strcmp(attr
->values
[0].string
.text
, "none")
9803 && strcmp(attr
->values
[0].string
.text
, "gzip")
9804 #endif /* HAVE_LIBZ */
9807 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\""),
9808 attr
->values
[0].string
.text
);
9809 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9810 "compression", NULL
, attr
->values
[0].string
.text
);
9815 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9816 compression
= CUPS_FILE_GZIP
;
9817 #endif /* HAVE_LIBZ */
9821 * Do we have a file to print?
9826 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
9831 * Is it a format we support?
9834 if ((format
= ippFindAttribute(con
->request
, "document-format",
9835 IPP_TAG_MIMETYPE
)) != NULL
)
9838 * Grab format from client...
9841 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9844 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
9845 format
->values
[0].string
.text
);
9849 else if ((default_format
= cupsGetOption("document-format",
9850 printer
->num_options
,
9851 printer
->options
)) != NULL
)
9854 * Use default document format...
9857 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9859 send_ipp_status(con
, IPP_BAD_REQUEST
,
9860 _("Could not scan type \"%s\""),
9868 * No document format attribute? Auto-type it!
9871 strcpy(super
, "application");
9872 strcpy(type
, "octet-stream");
9875 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9878 * Auto-type the file...
9881 ipp_attribute_t
*doc_name
; /* document-name attribute */
9884 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9886 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9887 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9888 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9892 filetype
= mimeType(MimeDatabase
, super
, type
);
9894 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9895 filetype
->super
, filetype
->type
);
9898 filetype
= mimeType(MimeDatabase
, super
, type
);
9903 * Replace the document-format attribute value with the auto-typed or
9907 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9910 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9911 IPP_TAG_MIMETYPE
)) != NULL
)
9913 _cupsStrFree(jformat
->values
[0].string
.text
);
9915 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9918 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9919 "document-format", NULL
, mimetype
);
9923 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9924 _("Unsupported format \'%s/%s\'"), super
, type
);
9925 cupsdLogMessage(CUPSD_LOG_INFO
,
9926 "Hint: Do you have the raw file printing rules enabled?");
9929 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9930 "document-format", NULL
, format
->values
[0].string
.text
);
9935 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9937 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9940 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9941 _("Unsupported format \'%s\'"), mimetype
);
9943 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9944 "document-format", NULL
, mimetype
);
9950 * Add the file to the job...
9955 if (add_file(con
, job
, filetype
, compression
))
9958 if (stat(con
->filename
, &fileinfo
))
9961 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9963 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9965 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9966 IPP_TAG_INTEGER
)) != NULL
)
9967 attr
->values
[0].integer
+= kbytes
;
9969 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9971 rename(con
->filename
, filename
);
9973 cupsdClearString(&con
->filename
);
9975 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9976 filetype
->super
, filetype
->type
, job
->username
);
9979 * Start the job if this is the last document...
9982 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9983 IPP_TAG_BOOLEAN
)) != NULL
&&
9984 attr
->values
[0].boolean
)
9987 * See if we need to add the ending sheet...
9990 if (cupsdTimeoutJob(job
))
9993 if (job
->state_value
== IPP_JOB_STOPPED
)
9995 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9996 job
->state_value
= IPP_JOB_PENDING
;
9998 else if (job
->state_value
== IPP_JOB_HELD
)
10000 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10001 IPP_TAG_KEYWORD
)) == NULL
)
10002 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10004 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10006 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10007 job
->state_value
= IPP_JOB_PENDING
;
10012 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10018 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10019 IPP_TAG_KEYWORD
)) == NULL
)
10020 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10022 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10024 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10025 job
->state_value
= IPP_JOB_HELD
;
10026 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10029 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10036 * Fill in the response info...
10039 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10042 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10045 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10047 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10049 add_job_state_reasons(con
, job
);
10051 con
->response
->request
.status
.status_code
= IPP_OK
;
10054 * Start the job if necessary...
10063 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10068 cupsd_client_t
*con
, /* I - Client connection */
10069 http_status_t status
, /* I - HTTP status code */
10070 cupsd_printer_t
*printer
) /* I - Printer, if any */
10072 ipp_attribute_t
*uri
; /* Request URI, if any */
10075 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10076 IPP_TAG_URI
)) == NULL
)
10077 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10079 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10080 "Returning HTTP %s for %s (%s) from %s",
10081 httpStatus(status
),
10082 ippOpString(con
->request
->request
.op
.operation_id
),
10083 uri
? uri
->values
[0].string
.text
: "no URI",
10084 con
->http
.hostname
);
10088 int auth_type
; /* Type of authentication required */
10091 auth_type
= CUPSD_AUTH_NONE
;
10093 if (status
== HTTP_UNAUTHORIZED
&&
10094 printer
->num_auth_info_required
> 0 &&
10095 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10097 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10098 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10099 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10102 * Creating and authenticating jobs requires Kerberos...
10105 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10110 * Use policy/location-defined authentication requirements...
10113 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10114 cupsd_location_t
*auth
; /* Pointer to authentication element */
10117 if (printer
->type
& CUPS_PRINTER_CLASS
)
10118 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10120 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10122 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10123 auth
->type
== CUPSD_AUTH_NONE
)
10124 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10126 con
->request
->request
.op
.operation_id
:
10131 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10132 auth_type
= DefaultAuthType
;
10134 auth_type
= auth
->type
;
10138 cupsdSendError(con
, status
, auth_type
);
10141 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10143 ippDelete(con
->response
);
10144 con
->response
= NULL
;
10151 * 'send_ipp_status()' - Send a status back to the IPP client.
10155 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10156 ipp_status_t status
, /* I - IPP status code */
10157 const char *message
,/* I - Status message */
10158 ...) /* I - Additional args as needed */
10160 va_list ap
; /* Pointer to additional args */
10161 char formatted
[1024]; /* Formatted errror message */
10164 va_start(ap
, message
);
10165 vsnprintf(formatted
, sizeof(formatted
),
10166 _cupsLangString(con
->language
, message
), ap
);
10169 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10170 ippOpString(con
->request
->request
.op
.operation_id
),
10171 ippErrorString(status
), formatted
);
10173 con
->response
->request
.status
.status_code
= status
;
10175 if (ippFindAttribute(con
->response
, "attributes-charset",
10176 IPP_TAG_ZERO
) == NULL
)
10177 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10178 "attributes-charset", NULL
, DefaultCharset
);
10180 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10181 IPP_TAG_ZERO
) == NULL
)
10182 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10183 "attributes-natural-language", NULL
, DefaultLanguage
);
10185 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10186 "status-message", NULL
, formatted
);
10191 * 'set_default()' - Set the default destination...
10195 set_default(cupsd_client_t
*con
, /* I - Client connection */
10196 ipp_attribute_t
*uri
) /* I - Printer URI */
10198 http_status_t status
; /* Policy status */
10199 cups_ptype_t dtype
; /* Destination type (printer/class) */
10200 cupsd_printer_t
*printer
, /* Printer */
10201 *oldprinter
; /* Old default printer */
10204 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10205 con
->http
.fd
, uri
->values
[0].string
.text
);
10208 * Is the destination valid?
10211 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10217 send_ipp_status(con
, IPP_NOT_FOUND
,
10218 _("The printer or class was not found."));
10226 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10228 send_http_error(con
, status
, NULL
);
10233 * Set it as the default...
10236 oldprinter
= DefaultPrinter
;
10237 DefaultPrinter
= printer
;
10240 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10241 "%s is no longer the default printer.", oldprinter
->name
);
10243 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10244 "%s is now the default printer.", printer
->name
);
10246 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10247 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10249 cupsdLogMessage(CUPSD_LOG_INFO
,
10250 "Default destination set to \"%s\" by \"%s\".",
10251 printer
->name
, get_username(con
));
10254 * Everything was ok, so return OK status...
10257 con
->response
->request
.status
.status_code
= IPP_OK
;
10262 * 'set_job_attrs()' - Set job attributes.
10266 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10267 ipp_attribute_t
*uri
) /* I - Job URI */
10269 ipp_attribute_t
*attr
, /* Current attribute */
10270 *attr2
; /* Job attribute */
10271 int jobid
; /* Job ID */
10272 cupsd_job_t
*job
; /* Current job */
10273 char scheme
[HTTP_MAX_URI
],
10274 /* Method portion of URI */
10275 username
[HTTP_MAX_URI
],
10276 /* Username portion of URI */
10277 host
[HTTP_MAX_URI
],
10278 /* Host portion of URI */
10279 resource
[HTTP_MAX_URI
];
10280 /* Resource portion of URI */
10281 int port
; /* Port portion of URI */
10282 int event
; /* Events? */
10283 int check_jobs
; /* Check jobs? */
10286 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10287 con
->http
.fd
, uri
->values
[0].string
.text
);
10290 * Start with "everything is OK" status...
10293 con
->response
->request
.status
.status_code
= IPP_OK
;
10296 * See if we have a job URI or a printer URI...
10299 if (!strcmp(uri
->name
, "printer-uri"))
10302 * Got a printer URI; see if we also have a job-id attribute...
10305 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10306 IPP_TAG_INTEGER
)) == NULL
)
10308 send_ipp_status(con
, IPP_BAD_REQUEST
,
10309 _("Got a printer-uri attribute but no job-id"));
10313 jobid
= attr
->values
[0].integer
;
10318 * Got a job URI; parse it to get the job ID...
10321 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10322 sizeof(scheme
), username
, sizeof(username
), host
,
10323 sizeof(host
), &port
, resource
, sizeof(resource
));
10325 if (strncmp(resource
, "/jobs/", 6))
10331 send_ipp_status(con
, IPP_BAD_REQUEST
,
10332 _("Bad job-uri attribute \"%s\""),
10333 uri
->values
[0].string
.text
);
10337 jobid
= atoi(resource
+ 6);
10341 * See if the job exists...
10344 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10347 * Nope - return a "not found" error...
10350 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10355 * See if the job has been completed...
10358 if (job
->state_value
> IPP_JOB_STOPPED
)
10361 * Return a "not-possible" error...
10364 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10365 _("Job #%d is finished and cannot be altered"), jobid
);
10370 * See if the job is owned by the requesting user...
10373 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10375 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10376 cupsdFindDest(job
->dest
));
10381 * See what the user wants to change.
10389 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10391 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10394 if (!strcmp(attr
->name
, "attributes-charset") ||
10395 !strcmp(attr
->name
, "attributes-natural-language") ||
10396 !strcmp(attr
->name
, "document-compression") ||
10397 !strcmp(attr
->name
, "document-format") ||
10398 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10399 !strcmp(attr
->name
, "job-document-access-errors") ||
10400 !strcmp(attr
->name
, "job-id") ||
10401 !strcmp(attr
->name
, "job-impressions-completed") ||
10402 !strcmp(attr
->name
, "job-k-octets") ||
10403 !strcmp(attr
->name
, "job-originating-host-name") ||
10404 !strcmp(attr
->name
, "job-originating-user-name") ||
10405 !strcmp(attr
->name
, "job-printer-up-time") ||
10406 !strcmp(attr
->name
, "job-printer-uri") ||
10407 !strcmp(attr
->name
, "job-sheets") ||
10408 !strcmp(attr
->name
, "job-state-message") ||
10409 !strcmp(attr
->name
, "job-state-reasons") ||
10410 !strcmp(attr
->name
, "job-uri") ||
10411 !strcmp(attr
->name
, "number-of-documents") ||
10412 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10413 !strcmp(attr
->name
, "output-device-assigned") ||
10414 !strncmp(attr
->name
, "date-time-at-", 13) ||
10415 !strncmp(attr
->name
, "job-k-octets", 12) ||
10416 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10417 !strncmp(attr
->name
, "time-at-", 8))
10423 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10424 _("%s cannot be changed."), attr
->name
);
10426 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10427 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10432 if (!strcmp(attr
->name
, "job-priority"))
10435 * Change the job priority...
10438 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10440 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value"));
10442 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10443 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10445 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10447 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10448 _("Job is completed and cannot be changed."));
10451 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10453 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10454 attr
->values
[0].integer
);
10455 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10458 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10459 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10462 else if (!strcmp(attr
->name
, "job-state"))
10465 * Change the job state...
10468 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10470 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value"));
10472 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10473 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10477 switch (attr
->values
[0].integer
)
10479 case IPP_JOB_PENDING
:
10480 case IPP_JOB_HELD
:
10481 if (job
->state_value
> IPP_JOB_HELD
)
10483 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10484 _("Job state cannot be changed."));
10487 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10489 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10490 attr
->values
[0].integer
);
10491 cupsdSetJobState(job
, attr
->values
[0].integer
,
10493 "Job state changed by \"%s\"", username
);
10498 case IPP_JOB_PROCESSING
:
10499 case IPP_JOB_STOPPED
:
10500 if (job
->state_value
!= attr
->values
[0].integer
)
10502 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10503 _("Job state cannot be changed."));
10508 case IPP_JOB_CANCELED
:
10509 case IPP_JOB_ABORTED
:
10510 case IPP_JOB_COMPLETED
:
10511 if (job
->state_value
> IPP_JOB_PROCESSING
)
10513 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10514 _("Job state cannot be changed."));
10517 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10519 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10520 attr
->values
[0].integer
);
10521 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10523 "Job state changed by \"%s\"", username
);
10530 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10532 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10533 IPP_TAG_ZERO
)) != NULL
)
10536 * Some other value; first free the old value...
10539 if (job
->attrs
->prev
)
10540 job
->attrs
->prev
->next
= attr2
->next
;
10542 job
->attrs
->attrs
= attr2
->next
;
10544 if (job
->attrs
->last
== attr2
)
10545 job
->attrs
->last
= job
->attrs
->prev
;
10547 _ippFreeAttr(attr2
);
10550 * Then copy the attribute...
10553 copy_attribute(job
->attrs
, attr
, 0);
10556 * See if the job-name or job-hold-until is being changed.
10559 if (!strcmp(attr
->name
, "job-hold-until"))
10561 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10562 attr
->values
[0].string
.text
);
10563 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10565 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10567 cupsdReleaseJob(job
);
10571 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10572 "Job held by \"%s\".", username
);
10574 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10577 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10580 * Delete the attribute...
10583 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10584 IPP_TAG_ZERO
)) != NULL
)
10586 if (job
->attrs
->prev
)
10587 job
->attrs
->prev
->next
= attr2
->next
;
10589 job
->attrs
->attrs
= attr2
->next
;
10591 if (attr2
== job
->attrs
->last
)
10592 job
->attrs
->last
= job
->attrs
->prev
;
10594 _ippFreeAttr(attr2
);
10596 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10602 * Add new option by copying it...
10605 copy_attribute(job
->attrs
, attr
, 0);
10607 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10616 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10619 * Send events as needed...
10622 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10623 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10624 cupsdFindDest(job
->dest
), job
,
10625 "Job priority changed by user.");
10627 if (event
& CUPSD_EVENT_JOB_STATE
)
10628 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10629 job
->state_value
== IPP_JOB_HELD
?
10630 "Job held by user." : "Job restarted by user.");
10632 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10633 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10634 "Job options changed by user.");
10637 * Start jobs if possible...
10646 * 'set_printer_attrs()' - Set printer attributes.
10650 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10651 ipp_attribute_t
*uri
) /* I - Printer */
10653 http_status_t status
; /* Policy status */
10654 cups_ptype_t dtype
; /* Destination type (printer/class) */
10655 cupsd_printer_t
*printer
; /* Printer/class */
10656 ipp_attribute_t
*attr
; /* Printer attribute */
10657 int changed
= 0; /* Was anything changed? */
10660 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10661 con
->http
.fd
, uri
->values
[0].string
.text
);
10664 * Is the destination valid?
10667 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10673 send_ipp_status(con
, IPP_NOT_FOUND
,
10674 _("The printer or class was not found."));
10682 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10684 send_http_error(con
, status
, printer
);
10689 * Return a list of attributes that can be set via Set-Printer-Attributes.
10692 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10693 IPP_TAG_TEXT
)) != NULL
)
10695 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10699 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10700 IPP_TAG_TEXT
)) != NULL
)
10702 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10707 * Update the printer attributes and return...
10712 cupsdSetPrinterAttrs(printer
);
10713 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10715 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10716 "Printer \"%s\" description or location changed by \"%s\".",
10717 printer
->name
, get_username(con
));
10719 cupsdLogMessage(CUPSD_LOG_INFO
,
10720 "Printer \"%s\" description or location changed by \"%s\".",
10721 printer
->name
, get_username(con
));
10724 con
->response
->request
.status
.status_code
= IPP_OK
;
10729 * 'set_printer_defaults()' - Set printer default options from a request.
10733 set_printer_defaults(
10734 cupsd_client_t
*con
, /* I - Client connection */
10735 cupsd_printer_t
*printer
) /* I - Printer */
10737 int i
; /* Looping var */
10738 ipp_attribute_t
*attr
; /* Current attribute */
10739 int namelen
; /* Length of attribute name */
10740 char name
[256], /* New attribute name */
10741 value
[256]; /* String version of integer attrs */
10744 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10747 * Skip non-printer attributes...
10750 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10753 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10755 if (!strcmp(attr
->name
, "job-sheets-default"))
10758 * Only allow keywords and names...
10761 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10765 * Only allow job-sheets-default to be set when running without a
10766 * system high classification level...
10769 if (Classification
)
10772 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10774 if (attr
->num_values
> 1)
10775 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10777 cupsdSetString(&printer
->job_sheets
[1], "none");
10779 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10781 cupsdFreePrinterUsers(printer
);
10783 printer
->deny_users
= 0;
10785 if (attr
->value_tag
== IPP_TAG_NAME
&&
10786 (attr
->num_values
> 1 ||
10787 strcmp(attr
->values
[0].string
.text
, "all")))
10789 for (i
= 0; i
< attr
->num_values
; i
++)
10790 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10793 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10795 cupsdFreePrinterUsers(printer
);
10797 printer
->deny_users
= 1;
10799 if (attr
->value_tag
== IPP_TAG_NAME
&&
10800 (attr
->num_values
> 1 ||
10801 strcmp(attr
->values
[0].string
.text
, "none")))
10803 for (i
= 0; i
< attr
->num_values
; i
++)
10804 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10807 else if (!strcmp(attr
->name
, "job-quota-period"))
10809 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10812 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10813 attr
->values
[0].integer
);
10814 cupsdFreeQuotas(printer
);
10816 printer
->quota_period
= attr
->values
[0].integer
;
10818 else if (!strcmp(attr
->name
, "job-k-limit"))
10820 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10823 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10824 attr
->values
[0].integer
);
10825 cupsdFreeQuotas(printer
);
10827 printer
->k_limit
= attr
->values
[0].integer
;
10829 else if (!strcmp(attr
->name
, "job-page-limit"))
10831 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10834 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10835 attr
->values
[0].integer
);
10836 cupsdFreeQuotas(printer
);
10838 printer
->page_limit
= attr
->values
[0].integer
;
10840 else if (!strcmp(attr
->name
, "printer-op-policy"))
10842 cupsd_policy_t
*p
; /* Policy */
10845 if (attr
->value_tag
!= IPP_TAG_NAME
)
10848 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10850 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10851 "Setting printer-op-policy to \"%s\"...",
10852 attr
->values
[0].string
.text
);
10853 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10854 printer
->op_policy_ptr
= p
;
10858 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10859 _("Unknown printer-op-policy \"%s\"."),
10860 attr
->values
[0].string
.text
);
10864 else if (!strcmp(attr
->name
, "printer-error-policy"))
10866 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10869 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10870 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
10871 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10872 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10873 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10875 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10876 _("Unknown printer-error-policy \"%s\"."),
10877 attr
->values
[0].string
.text
);
10881 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10882 "Setting printer-error-policy to \"%s\"...",
10883 attr
->values
[0].string
.text
);
10884 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10888 * Skip any other non-default attributes...
10891 namelen
= strlen(attr
->name
);
10892 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10893 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10897 * OK, anything else must be a user-defined default...
10900 strlcpy(name
, attr
->name
, sizeof(name
));
10901 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10903 switch (attr
->value_tag
)
10905 case IPP_TAG_DELETEATTR
:
10906 printer
->num_options
= cupsRemoveOption(name
,
10907 printer
->num_options
,
10908 &(printer
->options
));
10909 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10910 "Deleting %s", attr
->name
);
10913 case IPP_TAG_NAME
:
10914 case IPP_TAG_KEYWORD
:
10916 printer
->num_options
= cupsAddOption(name
,
10917 attr
->values
[0].string
.text
,
10918 printer
->num_options
,
10919 &(printer
->options
));
10920 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10921 "Setting %s to \"%s\"...", attr
->name
,
10922 attr
->values
[0].string
.text
);
10925 case IPP_TAG_BOOLEAN
:
10926 printer
->num_options
= cupsAddOption(name
,
10927 attr
->values
[0].boolean
?
10929 printer
->num_options
,
10930 &(printer
->options
));
10931 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10932 "Setting %s to %s...", attr
->name
,
10933 attr
->values
[0].boolean
? "true" : "false");
10936 case IPP_TAG_INTEGER
:
10937 case IPP_TAG_ENUM
:
10938 sprintf(value
, "%d", attr
->values
[0].integer
);
10939 printer
->num_options
= cupsAddOption(name
, value
,
10940 printer
->num_options
,
10941 &(printer
->options
));
10942 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10943 "Setting %s to %s...", attr
->name
, value
);
10946 case IPP_TAG_RANGE
:
10947 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10948 attr
->values
[0].range
.upper
);
10949 printer
->num_options
= cupsAddOption(name
, value
,
10950 printer
->num_options
,
10951 &(printer
->options
));
10952 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10953 "Setting %s to %s...", attr
->name
, value
);
10956 case IPP_TAG_RESOLUTION
:
10957 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10958 attr
->values
[0].resolution
.yres
,
10959 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10961 printer
->num_options
= cupsAddOption(name
, value
,
10962 printer
->num_options
,
10963 &(printer
->options
));
10964 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10965 "Setting %s to %s...", attr
->name
, value
);
10969 /* Do nothing for other values */
10977 * 'start_printer()' - Start a printer.
10981 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10982 ipp_attribute_t
*uri
) /* I - Printer URI */
10984 http_status_t status
; /* Policy status */
10985 cups_ptype_t dtype
; /* Destination type (printer/class) */
10986 cupsd_printer_t
*printer
; /* Printer data */
10989 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10990 con
->http
.fd
, uri
->values
[0].string
.text
);
10993 * Is the destination valid?
10996 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11002 send_ipp_status(con
, IPP_NOT_FOUND
,
11003 _("The printer or class was not found."));
11011 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11013 send_http_error(con
, status
, printer
);
11018 * Start the printer...
11021 printer
->state_message
[0] = '\0';
11023 cupsdStartPrinter(printer
, 1);
11025 if (dtype
& CUPS_PRINTER_CLASS
)
11026 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11027 printer
->name
, get_username(con
));
11029 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11030 printer
->name
, get_username(con
));
11035 * Everything was ok, so return OK status...
11038 con
->response
->request
.status
.status_code
= IPP_OK
;
11043 * 'stop_printer()' - Stop a printer.
11047 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11048 ipp_attribute_t
*uri
) /* I - Printer URI */
11050 http_status_t status
; /* Policy status */
11051 cups_ptype_t dtype
; /* Destination type (printer/class) */
11052 cupsd_printer_t
*printer
; /* Printer data */
11053 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11056 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11057 con
->http
.fd
, uri
->values
[0].string
.text
);
11060 * Is the destination valid?
11063 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11069 send_ipp_status(con
, IPP_NOT_FOUND
,
11070 _("The printer or class was not found."));
11078 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11080 send_http_error(con
, status
, printer
);
11085 * Stop the printer...
11088 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11089 IPP_TAG_TEXT
)) == NULL
)
11090 strcpy(printer
->state_message
, "Paused");
11093 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11094 sizeof(printer
->state_message
));
11097 cupsdStopPrinter(printer
, 1);
11099 if (dtype
& CUPS_PRINTER_CLASS
)
11100 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11101 printer
->name
, get_username(con
));
11103 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11104 printer
->name
, get_username(con
));
11107 * Everything was ok, so return OK status...
11110 con
->response
->request
.status
.status_code
= IPP_OK
;
11115 * 'url_encode_attr()' - URL-encode a string attribute.
11119 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11120 char *buffer
,/* I - String buffer */
11121 int bufsize
)/* I - Size of buffer */
11123 int i
; /* Looping var */
11124 char *bufptr
, /* Pointer into buffer */
11125 *bufend
; /* End of buffer */
11128 strlcpy(buffer
, attr
->name
, bufsize
);
11129 bufptr
= buffer
+ strlen(buffer
);
11130 bufend
= buffer
+ bufsize
- 1;
11132 for (i
= 0; i
< attr
->num_values
; i
++)
11134 if (bufptr
>= bufend
)
11142 if (bufptr
>= bufend
)
11147 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11148 bufptr
, bufend
- bufptr
+ 1);
11150 if (bufptr
>= bufend
)
11161 * 'url_encode_string()' - URL-encode a string.
11164 static char * /* O - End of string */
11165 url_encode_string(const char *s
, /* I - String */
11166 char *buffer
, /* I - String buffer */
11167 int bufsize
) /* I - Size of buffer */
11169 char *bufptr
, /* Pointer into buffer */
11170 *bufend
; /* End of buffer */
11171 static const char *hex
= "0123456789ABCDEF";
11176 bufend
= buffer
+ bufsize
- 1;
11178 while (*s
&& bufptr
< bufend
)
11180 if (*s
== ' ' || *s
== '%' || *s
== '+')
11182 if (bufptr
>= (bufend
- 2))
11186 *bufptr
++ = hex
[(*s
>> 4) & 15];
11187 *bufptr
++ = hex
[*s
& 15];
11191 else if (*s
== '\'' || *s
== '\\')
11193 if (bufptr
>= (bufend
- 1))
11210 * 'user_allowed()' - See if a user is allowed to print to a queue.
11213 static int /* O - 0 if not allowed, 1 if allowed */
11214 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11215 const char *username
) /* I - Username */
11217 int i
; /* Looping var */
11218 struct passwd
*pw
; /* User password data */
11219 char baseuser
[256], /* Base username */
11220 *baseptr
; /* Pointer to "@" in base username */
11223 if (p
->num_users
== 0)
11226 if (!strcmp(username
, "root"))
11229 if (strchr(username
, '@'))
11232 * Strip @REALM for username check...
11235 strlcpy(baseuser
, username
, sizeof(baseuser
));
11237 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11240 username
= baseuser
;
11243 pw
= getpwnam(username
);
11246 for (i
= 0; i
< p
->num_users
; i
++)
11248 if (p
->users
[i
][0] == '@')
11251 * Check group membership...
11254 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
11257 else if (p
->users
[i
][0] == '#')
11263 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
11266 else if (!strcasecmp(username
, p
->users
[i
]))
11270 return ((i
< p
->num_users
) != p
->deny_users
);
11275 * 'validate_job()' - Validate printer options and destination.
11279 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11280 ipp_attribute_t
*uri
) /* I - Printer URI */
11282 http_status_t status
; /* Policy status */
11283 ipp_attribute_t
*attr
; /* Current attribute */
11284 ipp_attribute_t
*format
; /* Document-format attribute */
11285 cups_ptype_t dtype
; /* Destination type (printer/class) */
11286 char super
[MIME_MAX_SUPER
],
11287 /* Supertype of file */
11288 type
[MIME_MAX_TYPE
];
11289 /* Subtype of file */
11290 cupsd_printer_t
*printer
; /* Printer */
11293 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11294 con
->http
.fd
, uri
->values
[0].string
.text
);
11297 * OK, see if the client is sending the document compressed - CUPS
11298 * doesn't support compression yet...
11301 if ((attr
= ippFindAttribute(con
->request
, "compression",
11302 IPP_TAG_KEYWORD
)) != NULL
&&
11303 !strcmp(attr
->values
[0].string
.text
, "none"))
11305 send_ipp_status(con
, IPP_ATTRIBUTES
,
11306 _("Unsupported compression attribute %s"),
11307 attr
->values
[0].string
.text
);
11308 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11309 "compression", NULL
, attr
->values
[0].string
.text
);
11314 * Is it a format we support?
11317 if ((format
= ippFindAttribute(con
->request
, "document-format",
11318 IPP_TAG_MIMETYPE
)) != NULL
)
11320 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11323 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
11324 format
->values
[0].string
.text
);
11328 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11329 !mimeType(MimeDatabase
, super
, type
))
11331 cupsdLogMessage(CUPSD_LOG_INFO
,
11332 "Hint: Do you have the raw file printing rules enabled?");
11333 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11334 _("Unsupported format \"%s\""),
11335 format
->values
[0].string
.text
);
11336 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11337 "document-format", NULL
, format
->values
[0].string
.text
);
11343 * Is the destination valid?
11346 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11352 send_ipp_status(con
, IPP_NOT_FOUND
,
11353 _("The printer or class was not found."));
11361 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11363 send_http_error(con
, status
, printer
);
11368 * Everything was ok, so return OK status...
11371 con
->response
->request
.status
.status_code
= IPP_OK
;
11376 * 'validate_name()' - Make sure the printer name only contains valid chars.
11379 static int /* O - 0 if name is no good, 1 if good */
11380 validate_name(const char *name
) /* I - Name to check */
11382 const char *ptr
; /* Pointer into name */
11386 * Scan the whole name...
11389 for (ptr
= name
; *ptr
; ptr
++)
11390 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11394 * All the characters are good; validate the length, too...
11397 return ((ptr
- name
) < 128);
11402 * 'validate_user()' - Validate the user for the request.
11405 static int /* O - 1 if permitted, 0 otherwise */
11406 validate_user(cupsd_job_t
*job
, /* I - Job */
11407 cupsd_client_t
*con
, /* I - Client connection */
11408 const char *owner
, /* I - Owner of job/resource */
11409 char *username
, /* O - Authenticated username */
11410 int userlen
) /* I - Length of username */
11412 cupsd_printer_t
*printer
; /* Printer for job */
11415 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11416 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11418 job
->id
, con
? con
->http
.fd
: 0,
11419 owner
? owner
: "(null)", username
, userlen
);
11422 * Validate input...
11425 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11429 * Get the best authenticated username that is available.
11432 strlcpy(username
, get_username(con
), userlen
);
11435 * Check the username against the owner...
11438 printer
= cupsdFindDest(job
->dest
);
11440 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11441 con
, owner
) == HTTP_OK
);
11446 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".