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 need_restart_job
; /* Need to restart job? */
2328 int set_device_uri
, /* Did we set the device URI? */
2329 set_port_monitor
; /* Did we set the port monitor? */
2332 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2333 con
->http
.fd
, uri
->values
[0].string
.text
);
2336 * Do we have a valid URI?
2339 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2340 sizeof(scheme
), username
, sizeof(username
), host
,
2341 sizeof(host
), &port
, resource
, sizeof(resource
));
2343 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2346 * No, return an error...
2349 send_ipp_status(con
, IPP_BAD_REQUEST
,
2350 _("The printer-uri must be of the form "
2351 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2356 * Do we have a valid printer name?
2359 if (!validate_name(resource
+ 10))
2362 * No, return an error...
2365 send_ipp_status(con
, IPP_BAD_REQUEST
,
2366 _("The printer-uri \"%s\" contains invalid characters."),
2367 uri
->values
[0].string
.text
);
2372 * See if the printer already exists; if not, create a new printer...
2375 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2378 * Printer doesn't exist; see if we have a class of the same name...
2381 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2382 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2385 * Yes, return an error...
2388 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2389 _("A class named \"%s\" already exists!"),
2395 * No, check the default policy then add the printer...
2398 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2400 send_http_error(con
, status
, NULL
);
2404 printer
= cupsdAddPrinter(resource
+ 10);
2407 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2410 * Check the default policy, then rename the implicit printer to
2411 * "AnyPrinter" or delete it...
2414 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2416 send_http_error(con
, status
, NULL
);
2420 if (ImplicitAnyClasses
)
2422 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2423 cupsdRenamePrinter(printer
, newname
);
2426 cupsdDeletePrinter(printer
, 1);
2429 * Add the printer as a new local printer...
2432 printer
= cupsdAddPrinter(resource
+ 10);
2435 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2438 * Check the default policy, then rename the remote printer to
2439 * "Printer@server"...
2442 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2444 send_http_error(con
, status
, NULL
);
2448 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2450 cupsdRenamePrinter(printer
, newname
);
2453 * Add the printer as a new local printer...
2456 printer
= cupsdAddPrinter(resource
+ 10);
2459 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2462 send_http_error(con
, status
, printer
);
2469 * Look for attributes and copy them over as needed...
2472 need_restart_job
= 0;
2474 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2475 IPP_TAG_TEXT
)) != NULL
)
2476 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2478 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2479 IPP_TAG_TEXT
)) != NULL
)
2480 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2484 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2485 IPP_TAG_URI
)) != NULL
)
2488 * Do we have a valid device URI?
2491 http_uri_status_t uri_status
; /* URI separation status */
2492 char old_device_uri
[1024];
2493 /* Old device URI */
2496 need_restart_job
= 1;
2498 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2499 attr
->values
[0].string
.text
,
2500 scheme
, sizeof(scheme
),
2501 username
, sizeof(username
),
2502 host
, sizeof(host
), &port
,
2503 resource
, sizeof(resource
));
2505 if (uri_status
< HTTP_URI_OK
)
2507 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"!"),
2508 attr
->values
[0].string
.text
);
2509 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2510 "add_printer: httpSeparateURI returned %d", uri_status
);
2514 if (!strcmp(scheme
, "file"))
2517 * See if the administrator has enabled file devices...
2520 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2523 * File devices are disabled and the URL is not file:/dev/null...
2526 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2527 _("File device URIs have been disabled! "
2528 "To enable, see the FileDevice directive in "
2529 "\"%s/cupsd.conf\"."),
2537 * See if the backend exists and is executable...
2540 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2541 if (access(srcfile
, X_OK
))
2544 * Could not find device in list!
2547 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\"!"),
2553 if (printer
->sanitized_device_uri
)
2554 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2555 sizeof(old_device_uri
));
2557 old_device_uri
[0] = '\0';
2559 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2561 cupsdLogMessage(CUPSD_LOG_INFO
,
2562 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2563 printer
->name
, printer
->sanitized_device_uri
,
2569 set_port_monitor
= 0;
2571 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2572 IPP_TAG_NAME
)) != NULL
)
2574 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2577 need_restart_job
= 1;
2579 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2583 for (i
= 0; i
< supported
->num_values
; i
++)
2584 if (!strcmp(supported
->values
[i
].string
.text
,
2585 attr
->values
[0].string
.text
))
2589 if (!supported
|| i
>= supported
->num_values
)
2591 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"!"),
2592 attr
->values
[0].string
.text
);
2596 cupsdLogMessage(CUPSD_LOG_INFO
,
2597 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2598 printer
->name
, attr
->values
[0].string
.text
,
2599 printer
->port_monitor
? printer
->port_monitor
: "none");
2601 if (strcmp(attr
->values
[0].string
.text
, "none"))
2602 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2604 cupsdClearString(&printer
->port_monitor
);
2606 set_port_monitor
= 1;
2609 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2610 IPP_TAG_BOOLEAN
)) != NULL
)
2612 cupsdLogMessage(CUPSD_LOG_INFO
,
2613 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2614 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2616 printer
->accepting
= attr
->values
[0].boolean
;
2617 cupsdAddPrinterHistory(printer
);
2620 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2621 IPP_TAG_BOOLEAN
)) != NULL
)
2623 if (printer
->shared
&& !attr
->values
[0].boolean
)
2624 cupsdDeregisterPrinter(printer
, 1);
2626 cupsdLogMessage(CUPSD_LOG_INFO
,
2627 "Setting %s printer-is-shared to %d (was %d.)",
2628 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2630 printer
->shared
= attr
->values
[0].boolean
;
2633 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2634 IPP_TAG_ENUM
)) != NULL
)
2636 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2637 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2639 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d!"),
2640 attr
->values
[0].integer
);
2644 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2645 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2647 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2648 cupsdStopPrinter(printer
, 0);
2651 need_restart_job
= 1;
2652 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2656 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2657 IPP_TAG_TEXT
)) != NULL
)
2659 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2660 sizeof(printer
->state_message
));
2661 cupsdAddPrinterHistory(printer
);
2664 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2665 IPP_TAG_KEYWORD
)) != NULL
)
2667 if (attr
->num_values
>
2668 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2670 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2671 _("Too many printer-state-reasons values (%d > %d)!"),
2673 (int)(sizeof(printer
->reasons
) /
2674 sizeof(printer
->reasons
[0])));
2678 for (i
= 0; i
< printer
->num_reasons
; i
++)
2679 _cupsStrFree(printer
->reasons
[i
]);
2681 printer
->num_reasons
= 0;
2682 for (i
= 0; i
< attr
->num_values
; i
++)
2684 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2687 printer
->reasons
[printer
->num_reasons
] =
2688 _cupsStrRetain(attr
->values
[i
].string
.text
);
2689 printer
->num_reasons
++;
2691 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2692 printer
->state
!= IPP_PRINTER_STOPPED
)
2694 cupsdLogMessage(CUPSD_LOG_INFO
,
2695 "Setting %s printer-state to %d (was %d.)",
2696 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2697 cupsdStopPrinter(printer
, 0);
2701 if (PrintcapFormat
== PRINTCAP_PLIST
)
2702 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2705 set_printer_defaults(con
, printer
);
2707 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2708 IPP_TAG_KEYWORD
)) != NULL
)
2709 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2712 * See if we have all required attributes...
2715 if (!printer
->device_uri
)
2716 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2719 * See if we have an interface script or PPD file attached to the request...
2724 need_restart_job
= 1;
2726 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2728 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2731 * Yes; get the first line from it...
2735 cupsFileGets(fp
, line
, sizeof(line
));
2739 * Then see what kind of file it is...
2742 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2745 if (!strncmp(line
, "*PPD-Adobe", 10))
2748 * The new file is a PPD file, so remove any old interface script
2749 * that might be lying around...
2757 * This must be an interface script, so move the file over to the
2758 * interfaces directory and make it executable...
2761 if (copy_file(srcfile
, dstfile
))
2763 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2764 _("Unable to copy interface script - %s!"),
2769 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2770 "Copied interface script successfully!");
2771 chmod(dstfile
, 0755);
2774 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2777 if (!strncmp(line
, "*PPD-Adobe", 10))
2780 * The new file is a PPD file, so move the file over to the
2781 * ppd directory and make it readable by all...
2784 if (copy_file(srcfile
, dstfile
))
2786 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2787 _("Unable to copy PPD file - %s!"),
2792 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2793 "Copied PPD file successfully!");
2794 chmod(dstfile
, 0644);
2798 * (Re)register color profiles...
2803 apple_unregister_profiles(printer
);
2804 apple_register_profiles(printer
);
2806 #endif /* __APPLE__ */
2811 * This must be an interface script, so remove any old PPD file that
2812 * may be lying around...
2819 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2820 IPP_TAG_NAME
)) != NULL
)
2822 need_restart_job
= 1;
2824 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2827 * Raw driver, remove any existing PPD or interface script files.
2830 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2834 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2844 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2848 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2851 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2853 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file!"));
2857 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2858 "Copied PPD file successfully!");
2859 chmod(dstfile
, 0644);
2863 * (Re)register color profiles...
2868 apple_unregister_profiles(printer
);
2869 apple_register_profiles(printer
);
2871 #endif /* __APPLE__ */
2876 * If we set the device URI but not the port monitor, check which port
2877 * monitor to use by default...
2880 if (set_device_uri
&& !set_port_monitor
)
2882 ppd_file_t
*ppd
; /* PPD file */
2883 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2886 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2887 sizeof(scheme
), username
, sizeof(username
), host
,
2888 sizeof(host
), &port
, resource
, sizeof(resource
));
2890 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2892 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2894 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2896 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2897 if (!strcmp(scheme
, ppdattr
->spec
))
2899 cupsdLogMessage(CUPSD_LOG_INFO
,
2900 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2901 printer
->name
, ppdattr
->value
,
2902 printer
->port_monitor
? printer
->port_monitor
2905 if (strcmp(ppdattr
->value
, "none"))
2906 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2908 cupsdClearString(&printer
->port_monitor
);
2918 * Update the printer attributes and return...
2921 cupsdSetPrinterAttrs(printer
);
2922 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2924 if (need_restart_job
&& printer
->job
)
2927 * Restart the current job...
2930 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2931 "Job restarted because the printer was modified.");
2934 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2938 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2939 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2942 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2943 printer
->name
, get_username(con
));
2947 cupsdAddPrinterHistory(printer
);
2949 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2950 "New printer \"%s\" added by \"%s\".", printer
->name
,
2953 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2954 printer
->name
, get_username(con
));
2957 con
->response
->request
.status
.status_code
= IPP_OK
;
2962 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2963 * based upon the printer state...
2967 add_printer_state_reasons(
2968 cupsd_client_t
*con
, /* I - Client connection */
2969 cupsd_printer_t
*p
) /* I - Printer info */
2971 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2972 "add_printer_state_reasons(%p[%d], %p[%s])",
2973 con
, con
->http
.fd
, p
, p
->name
);
2975 if (p
->num_reasons
== 0)
2976 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2977 "printer-state-reasons", NULL
, "none");
2979 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2980 "printer-state-reasons", p
->num_reasons
, NULL
,
2981 (const char * const *)p
->reasons
);
2986 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2987 * the specified printer or class.
2991 add_queued_job_count(
2992 cupsd_client_t
*con
, /* I - Client connection */
2993 cupsd_printer_t
*p
) /* I - Printer or class */
2995 int count
; /* Number of jobs on destination */
2998 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2999 con
, con
->http
.fd
, p
, p
->name
);
3001 count
= cupsdGetPrinterJobCount(p
->name
);
3003 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3004 "queued-job-count", count
);
3010 * 'apple_init_profile()' - Initialize a color profile.
3015 ppd_file_t
*ppd
, /* I - PPD file */
3016 cups_array_t
*languages
, /* I - Languages in the PPD file */
3017 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3018 unsigned id
, /* I - Profile ID */
3019 const char *name
, /* I - Profile name */
3020 const char *text
, /* I - Profile UI text */
3021 const char *iccfile
) /* I - ICC filename */
3023 char url
[1024]; /* URL for profile filename */
3024 CFMutableDictionaryRef dict
; /* Dictionary for name */
3025 char *language
; /* Current language */
3026 ppd_attr_t
*attr
; /* Profile attribute */
3027 CFStringRef cflang
, /* Language string */
3028 cftext
; /* Localized text */
3032 * Build the profile name dictionary...
3035 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3036 &kCFTypeDictionaryKeyCallBacks
,
3037 &kCFTypeDictionaryValueCallBacks
);
3039 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3040 kCFStringEncodingUTF8
);
3044 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
3051 * Find localized names for the color profiles...
3054 cupsArraySave(ppd
->sorted_attrs
);
3056 for (language
= (char *)cupsArrayFirst(languages
);
3058 language
= (char *)cupsArrayNext(languages
))
3062 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3064 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3067 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3069 if (attr
&& attr
->text
[0])
3071 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3072 kCFStringEncodingUTF8
);
3073 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3074 kCFStringEncodingUTF8
);
3076 if (cflang
&& cftext
)
3077 CFDictionarySetValue(dict
, cflang
, cftext
);
3087 cupsArrayRestore(ppd
->sorted_attrs
);
3091 * Fill in the profile data...
3095 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3098 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3099 profile
->profileID
= id
;
3100 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3101 profile
->profileName
= dict
;
3104 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3105 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3110 * 'apple_register_profiles()' - Register color profiles for a printer.
3114 apple_register_profiles(
3115 cupsd_printer_t
*p
) /* I - Printer */
3117 int i
; /* Looping var */
3118 char ppdfile
[1024], /* PPD filename */
3119 iccfile
[1024], /* ICC filename */
3120 selector
[PPD_MAX_NAME
];
3121 /* Profile selection string */
3122 ppd_file_t
*ppd
; /* PPD file */
3123 ppd_attr_t
*attr
, /* Profile attributes */
3124 *profileid_attr
,/* cupsProfileID attribute */
3125 *q1_attr
, /* ColorModel (or other) qualifier */
3126 *q2_attr
, /* MediaType (or other) qualifier */
3127 *q3_attr
; /* Resolution (or other) qualifier */
3128 char q_keyword
[PPD_MAX_NAME
];
3129 /* Qualifier keyword */
3130 const char *q1_choice
, /* ColorModel (or other) choice */
3131 *q2_choice
, /* MediaType (or other) choice */
3132 *q3_choice
; /* Resolution (or other) choice */
3133 const char *profile_key
; /* Profile keyword */
3134 ppd_option_t
*cm_option
; /* Color model option */
3135 ppd_choice_t
*cm_choice
; /* Color model choice */
3136 int num_profiles
; /* Number of profiles */
3137 CMError error
; /* Last error */
3138 unsigned device_id
, /* Printer device ID */
3139 profile_id
, /* Profile ID */
3140 default_profile_id
= 0;
3141 /* Default profile ID */
3142 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3143 CFStringRef printer_name
; /* Printer name string */
3144 CMDeviceScope scope
= /* Scope of the registration */
3146 kCFPreferencesAnyUser
,
3147 kCFPreferencesCurrentHost
3149 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3150 CMDeviceProfileInfo
*profile
; /* Current profile */
3151 cups_array_t
*languages
; /* Languages array */
3155 * Make sure ColorSync is available...
3158 if (CMRegisterColorDevice
== NULL
)
3162 * Try opening the PPD file for this printer...
3165 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3166 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3170 * See if we have any profiles...
3173 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3174 profile_key
= "APTiogaProfile";
3177 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3178 profile_key
= "cupsICCProfile";
3181 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3182 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3184 if (attr
->value
[0] != '/')
3185 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3188 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3190 if (access(iccfile
, 0))
3198 * If we have profiles, add them...
3201 if (num_profiles
> 0)
3203 if (profile_key
[0] == 'A')
3206 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3210 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3212 default_profile_id
= atoi(attr
->value
);
3214 q1_choice
= q2_choice
= q3_choice
= NULL
;
3219 * For CUPS PPDs, figure out the default profile selector values...
3222 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3223 attr
->value
&& attr
->value
[0])
3225 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3226 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3228 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3229 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3231 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3232 q1_choice
= q1_attr
->value
;
3236 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3237 attr
->value
&& attr
->value
[0])
3239 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3240 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3243 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3245 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3246 q2_choice
= q2_attr
->value
;
3250 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3251 attr
->value
&& attr
->value
[0])
3253 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3254 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3257 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3259 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3260 q3_choice
= q3_attr
->value
;
3266 * Build the array of profiles...
3268 * Note: This calloc actually requests slightly more memory than needed.
3271 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3273 cupsdLogMessage(CUPSD_LOG_ERROR
,
3274 "Unable to allocate memory for %d profiles!",
3280 profiles
->profileCount
= num_profiles
;
3281 languages
= _ppdGetLanguages(ppd
);
3283 for (profile
= profiles
->profiles
,
3284 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3286 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3287 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3290 * Add this profile...
3293 if (attr
->value
[0] != '/')
3294 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3297 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3299 if (access(iccfile
, 0))
3302 if (profile_key
[0] == 'c')
3304 cupsArraySave(ppd
->sorted_attrs
);
3306 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3307 attr
->spec
)) != NULL
&&
3308 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3309 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3311 profile_id
= _ppdHashName(attr
->spec
);
3313 cupsArrayRestore(ppd
->sorted_attrs
);
3316 profile_id
= atoi(attr
->spec
);
3318 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3319 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3324 * See if this is the default profile...
3327 if (!default_profile_id
)
3333 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3334 q1_choice
, q2_choice
, q3_choice
);
3335 if (!strcmp(selector
, attr
->spec
))
3336 default_profile_id
= profile_id
;
3339 if (!default_profile_id
)
3341 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3343 if (!strcmp(selector
, attr
->spec
))
3344 default_profile_id
= profile_id
;
3348 if (!default_profile_id
&& q3_choice
)
3350 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3352 if (!strcmp(selector
, attr
->spec
))
3353 default_profile_id
= profile_id
;
3356 if (!default_profile_id
)
3358 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3359 if (!strcmp(selector
, attr
->spec
))
3360 default_profile_id
= profile_id
;
3365 _ppdFreeLanguages(languages
);
3367 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3370 * Extract profiles from ColorModel option...
3373 const char *profile_name
; /* Name of generic profile */
3376 num_profiles
= cm_option
->num_choices
;
3378 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3380 cupsdLogMessage(CUPSD_LOG_ERROR
,
3381 "Unable to allocate memory for %d profiles!",
3387 profiles
->profileCount
= num_profiles
;
3389 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3390 cm_choice
= cm_option
->choices
;
3392 i
--, cm_choice
++, profile
++)
3394 if (!strcmp(cm_choice
->choice
, "Gray") ||
3395 !strcmp(cm_choice
->choice
, "Black"))
3396 profile_name
= "Gray";
3397 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3398 !strcmp(cm_choice
->choice
, "CMY"))
3399 profile_name
= "RGB";
3400 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3401 !strcmp(cm_choice
->choice
, "KCMY"))
3402 profile_name
= "CMYK";
3404 profile_name
= "DeviceN";
3406 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3407 profile_id
= _ppdHashName(selector
);
3409 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3410 cm_choice
->text
, NULL
);
3412 if (cm_choice
->marked
)
3413 default_profile_id
= profile_id
;
3419 * Use the default colorspace...
3422 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3424 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3426 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3428 cupsdLogMessage(CUPSD_LOG_ERROR
,
3429 "Unable to allocate memory for %d profiles!",
3435 profiles
->profileCount
= num_profiles
;
3437 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3438 "Gray", "Gray", NULL
);
3440 switch (ppd
->colorspace
)
3444 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3445 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3449 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3450 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3458 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3459 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3465 if (num_profiles
> 0)
3468 * Make sure we have a default profile ID...
3471 if (!default_profile_id
)
3472 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3475 * Get the device ID hash and pathelogical name dictionary.
3478 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3481 device_id
= _ppdHashName(p
->name
);
3482 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3483 &kCFTypeDictionaryKeyCallBacks
,
3484 &kCFTypeDictionaryValueCallBacks
);
3485 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3486 p
->name
, kCFStringEncodingUTF8
);
3488 if (device_name
&& printer_name
)
3490 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3493 * Register the device with ColorSync...
3496 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3497 device_name
, &scope
);
3500 * Register the profiles...
3504 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3505 default_profile_id
, profiles
);
3515 cupsdLogMessage(CUPSD_LOG_ERROR
,
3516 "Unable to register ICC color profiles for \"%s\" - %d",
3517 p
->name
, (int)error
);
3519 for (profile
= profiles
->profiles
;
3521 profile
++, num_profiles
--)
3522 CFRelease(profile
->profileName
);
3527 CFRelease(printer_name
);
3530 CFRelease(device_name
);
3538 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3543 apple_unregister_profiles(
3544 cupsd_printer_t
*p
) /* I - Printer */
3547 * Make sure ColorSync is available...
3550 if (CMUnregisterColorDevice
!= NULL
)
3551 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3553 #endif /* __APPLE__ */
3556 * 'apply_printer_defaults()' - Apply printer default options to a job.
3560 apply_printer_defaults(
3561 cupsd_printer_t
*printer
, /* I - Printer */
3562 cupsd_job_t
*job
) /* I - Job */
3564 int i
, /* Looping var */
3565 num_options
; /* Number of default options */
3566 cups_option_t
*options
, /* Default options */
3567 *option
; /* Current option */
3571 * Collect all of the default options and add the missing ones to the
3575 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3576 option
= printer
->options
;
3579 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3581 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3586 * Encode these options as attributes in the job object...
3589 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3590 cupsFreeOptions(num_options
, options
);
3595 * 'authenticate_job()' - Set job authentication info.
3599 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3600 ipp_attribute_t
*uri
) /* I - Job URI */
3602 ipp_attribute_t
*attr
, /* job-id attribute */
3603 *auth_info
; /* auth-info attribute */
3604 int jobid
; /* Job ID */
3605 cupsd_job_t
*job
; /* Current job */
3606 char scheme
[HTTP_MAX_URI
],
3607 /* Method portion of URI */
3608 username
[HTTP_MAX_URI
],
3609 /* Username portion of URI */
3611 /* Host portion of URI */
3612 resource
[HTTP_MAX_URI
];
3613 /* Resource portion of URI */
3614 int port
; /* Port portion of URI */
3617 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3618 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3621 * Start with "everything is OK" status...
3624 con
->response
->request
.status
.status_code
= IPP_OK
;
3627 * See if we have a job URI or a printer URI...
3630 if (!strcmp(uri
->name
, "printer-uri"))
3633 * Got a printer URI; see if we also have a job-id attribute...
3636 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3637 IPP_TAG_INTEGER
)) == NULL
)
3639 send_ipp_status(con
, IPP_BAD_REQUEST
,
3640 _("Got a printer-uri attribute but no job-id!"));
3644 jobid
= attr
->values
[0].integer
;
3649 * Got a job URI; parse it to get the job ID...
3652 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3653 sizeof(scheme
), username
, sizeof(username
), host
,
3654 sizeof(host
), &port
, resource
, sizeof(resource
));
3656 if (strncmp(resource
, "/jobs/", 6))
3662 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
3663 uri
->values
[0].string
.text
);
3667 jobid
= atoi(resource
+ 6);
3671 * See if the job exists...
3674 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3677 * Nope - return a "not found" error...
3680 send_ipp_status(con
, IPP_NOT_FOUND
,
3681 _("Job #%d does not exist!"), jobid
);
3686 * See if the job has been completed...
3689 if (job
->state_value
!= IPP_JOB_HELD
)
3692 * Return a "not-possible" error...
3695 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3696 _("Job #%d is not held for authentication!"),
3702 * See if we have already authenticated...
3705 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3707 if (!con
->username
[0] && !auth_info
)
3709 cupsd_printer_t
*printer
; /* Job destination */
3713 * No auth data. If we need to authenticate via Kerberos, send a
3714 * HTTP auth challenge, otherwise just return an IPP error...
3717 printer
= cupsdFindDest(job
->dest
);
3719 if (printer
&& printer
->num_auth_info_required
> 0 &&
3720 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3721 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3723 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3724 _("No authentication information provided!"));
3729 * See if the job is owned by the requesting user...
3732 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3734 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3735 cupsdFindDest(job
->dest
));
3740 * Save the authentication information for this job...
3743 save_auth_info(con
, job
, auth_info
);
3746 * Reset the job-hold-until value to "no-hold"...
3749 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3750 IPP_TAG_KEYWORD
)) == NULL
)
3751 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3755 attr
->value_tag
= IPP_TAG_KEYWORD
;
3756 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3760 * Release the job and return...
3763 cupsdReleaseJob(job
);
3765 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3770 * 'cancel_all_jobs()' - Cancel all print jobs.
3774 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3775 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3777 http_status_t status
; /* Policy status */
3778 cups_ptype_t dtype
; /* Destination type */
3779 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3780 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3781 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3782 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3783 int port
; /* Port portion of URI */
3784 ipp_attribute_t
*attr
; /* Attribute in request */
3785 const char *username
; /* Username */
3786 cupsd_jobaction_t purge
; /* Purge? */
3787 cupsd_printer_t
*printer
; /* Printer */
3790 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3791 con
->http
.fd
, uri
->values
[0].string
.text
);
3794 * See if we have a printer URI...
3797 if (strcmp(uri
->name
, "printer-uri"))
3799 send_ipp_status(con
, IPP_BAD_REQUEST
,
3800 _("The printer-uri attribute is required!"));
3805 * Get the username (if any) for the jobs we want to cancel (only if
3806 * "my-jobs" is specified...
3809 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3810 IPP_TAG_BOOLEAN
)) != NULL
&&
3811 attr
->values
[0].boolean
)
3813 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3814 IPP_TAG_NAME
)) != NULL
)
3815 username
= attr
->values
[0].string
.text
;
3818 send_ipp_status(con
, IPP_BAD_REQUEST
,
3819 _("Missing requesting-user-name attribute!"));
3827 * Look for the "purge-jobs" attribute...
3830 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3831 IPP_TAG_BOOLEAN
)) != NULL
)
3832 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3834 purge
= CUPSD_JOB_PURGE
;
3837 * And if the destination is valid...
3840 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3846 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3847 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3848 hostname
, sizeof(hostname
), &port
,
3849 resource
, sizeof(resource
));
3851 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3852 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3854 send_ipp_status(con
, IPP_NOT_FOUND
,
3855 _("The printer or class was not found."));
3863 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3865 send_http_error(con
, status
, NULL
);
3870 * Cancel all jobs on all printers...
3873 cupsdCancelJobs(NULL
, username
, purge
);
3875 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3876 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3885 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3888 send_http_error(con
, status
, printer
);
3893 * Cancel all of the jobs on the named printer...
3896 cupsdCancelJobs(printer
->name
, username
, purge
);
3898 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3900 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3904 con
->response
->request
.status
.status_code
= IPP_OK
;
3909 * 'cancel_job()' - Cancel a print job.
3913 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3914 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3916 ipp_attribute_t
*attr
; /* Current attribute */
3917 int jobid
; /* Job ID */
3918 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3919 username
[HTTP_MAX_URI
], /* Username portion of URI */
3920 host
[HTTP_MAX_URI
], /* Host portion of URI */
3921 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3922 int port
; /* Port portion of URI */
3923 cupsd_job_t
*job
; /* Job information */
3924 cups_ptype_t dtype
; /* Destination type (printer/class) */
3925 cupsd_printer_t
*printer
; /* Printer data */
3926 cupsd_jobaction_t purge
; /* Purge the job? */
3929 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3930 con
->http
.fd
, uri
->values
[0].string
.text
);
3933 * See if we have a job URI or a printer URI...
3936 if (!strcmp(uri
->name
, "printer-uri"))
3939 * Got a printer URI; see if we also have a job-id attribute...
3942 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3943 IPP_TAG_INTEGER
)) == NULL
)
3945 send_ipp_status(con
, IPP_BAD_REQUEST
,
3946 _("Got a printer-uri attribute but no job-id!"));
3950 if ((jobid
= attr
->values
[0].integer
) == 0)
3953 * Find the current job on the specified printer...
3956 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3962 send_ipp_status(con
, IPP_NOT_FOUND
,
3963 _("The printer or class was not found."));
3968 * See if there are any pending jobs...
3971 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3973 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3974 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3975 !strcasecmp(job
->dest
, printer
->name
))
3983 * No, try stopped jobs...
3986 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3988 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3989 if (job
->state_value
== IPP_JOB_STOPPED
&&
3990 !strcasecmp(job
->dest
, printer
->name
))
3997 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s!"),
4007 * Got a job URI; parse it to get the job ID...
4010 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4011 sizeof(scheme
), username
, sizeof(username
), host
,
4012 sizeof(host
), &port
, resource
, sizeof(resource
));
4014 if (strncmp(resource
, "/jobs/", 6))
4020 send_ipp_status(con
, IPP_BAD_REQUEST
,
4021 _("Bad job-uri attribute \"%s\"!"),
4022 uri
->values
[0].string
.text
);
4026 jobid
= atoi(resource
+ 6);
4030 * Look for the "purge-job" attribute...
4033 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4034 IPP_TAG_BOOLEAN
)) != NULL
)
4035 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4037 purge
= CUPSD_JOB_DEFAULT
;
4040 * See if the job exists...
4043 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4046 * Nope - return a "not found" error...
4049 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
4054 * See if the job is owned by the requesting user...
4057 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4059 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4060 cupsdFindDest(job
->dest
));
4065 * See if the job is already completed, canceled, or aborted; if so,
4066 * we can't cancel...
4069 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4071 switch (job
->state_value
)
4073 case IPP_JOB_CANCELED
:
4074 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4075 _("Job #%d is already canceled - can\'t cancel."),
4079 case IPP_JOB_ABORTED
:
4080 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4081 _("Job #%d is already aborted - can\'t cancel."),
4086 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4087 _("Job #%d is already completed - can\'t cancel."),
4096 * Cancel the job and return...
4099 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4100 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4101 "Job canceled by \"%s\"",
4105 if (purge
== CUPSD_JOB_PURGE
)
4106 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4109 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4112 con
->response
->request
.status
.status_code
= IPP_OK
;
4117 * 'cancel_subscription()' - Cancel a subscription.
4121 cancel_subscription(
4122 cupsd_client_t
*con
, /* I - Client connection */
4123 int sub_id
) /* I - Subscription ID */
4125 http_status_t status
; /* Policy status */
4126 cupsd_subscription_t
*sub
; /* Subscription */
4129 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4130 "cancel_subscription(con=%p[%d], sub_id=%d)",
4131 con
, con
->http
.fd
, sub_id
);
4134 * Is the subscription ID valid?
4137 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4140 * Bad subscription ID...
4143 send_ipp_status(con
, IPP_NOT_FOUND
,
4144 _("notify-subscription-id %d no good!"), sub_id
);
4152 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4154 con
, sub
->owner
)) != HTTP_OK
)
4156 send_http_error(con
, status
, sub
->dest
);
4161 * Cancel the subscription...
4164 cupsdDeleteSubscription(sub
, 1);
4166 con
->response
->request
.status
.status_code
= IPP_OK
;
4171 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4174 static int /* O - 1 if OK, 0 if not */
4175 check_rss_recipient(
4176 const char *recipient
) /* I - Recipient URI */
4178 cupsd_subscription_t
*sub
; /* Current subscription */
4181 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4183 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4187 * Compare the URIs up to the first ?...
4190 const char *r1
, *r2
;
4192 for (r1
= recipient
, r2
= sub
->recipient
;
4193 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4205 * 'check_quotas()' - Check quotas for a printer and user.
4208 static int /* O - 1 if OK, 0 if not */
4209 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4210 cupsd_printer_t
*p
) /* I - Printer or class */
4212 int i
; /* Looping var */
4213 char username
[33]; /* Username */
4214 cupsd_quota_t
*q
; /* Quota data */
4215 #ifdef HAVE_MBR_UID_TO_UUID
4217 * Use Apple membership APIs which require that all names represent
4218 * valid user account or group records accessible by the server.
4221 uuid_t usr_uuid
; /* UUID for job requesting user */
4222 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4223 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4224 int mbr_err
; /* Error from membership function */
4225 int is_member
; /* Is this user a member? */
4228 * Use standard POSIX APIs for checking users and groups...
4231 struct passwd
*pw
; /* User password data */
4232 #endif /* HAVE_MBR_UID_TO_UUID */
4235 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4236 con
, con
->http
.fd
, p
, p
->name
);
4239 * Figure out who is printing...
4242 strlcpy(username
, get_username(con
), sizeof(username
));
4245 * Check global active job limits for printers and users...
4248 if (MaxJobsPerPrinter
)
4251 * Check if there are too many pending jobs on this printer...
4254 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4256 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4265 * Check if there are too many pending jobs for this user...
4268 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4270 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4277 * Check against users...
4280 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4285 #ifdef HAVE_MBR_UID_TO_UUID
4287 * Get UUID for job requesting user...
4290 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4296 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4297 "check_quotas: UUID lookup failed for user \"%s\"",
4299 cupsdLogMessage(CUPSD_LOG_INFO
,
4300 "Denying user \"%s\" access to printer \"%s\" "
4301 "(unknown user)...",
4307 * Get UID and GID of requesting user...
4310 pw
= getpwnam(username
);
4312 #endif /* HAVE_MBR_UID_TO_UUID */
4314 for (i
= 0; i
< p
->num_users
; i
++)
4315 if (p
->users
[i
][0] == '@')
4318 * Check group membership...
4321 #ifdef HAVE_MBR_UID_TO_UUID
4322 if (p
->users
[i
][1] == '#')
4324 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4325 uuid_clear(grp_uuid
);
4327 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4331 * Invalid ACL entries are ignored for matching; just record a
4332 * warning in the log...
4335 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4336 "check_quotas: UUID lookup failed for ACL entry "
4337 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4338 cupsdLogMessage(CUPSD_LOG_WARN
,
4339 "Access control entry \"%s\" not a valid group name; "
4340 "entry ignored", p
->users
[i
]);
4343 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4347 * At this point, there should be no errors, but check anyways...
4350 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4351 "check_quotas: group \"%s\" membership check "
4352 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4357 * Stop if we found a match...
4364 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4366 #endif /* HAVE_MBR_UID_TO_UUID */
4368 #ifdef HAVE_MBR_UID_TO_UUID
4371 if (p
->users
[i
][0] == '#')
4373 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4374 uuid_clear(usr2_uuid
);
4376 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4380 * Invalid ACL entries are ignored for matching; just record a
4381 * warning in the log...
4384 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4385 "check_quotas: UUID lookup failed for ACL entry "
4386 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4387 cupsdLogMessage(CUPSD_LOG_WARN
,
4388 "Access control entry \"%s\" not a valid user name; "
4389 "entry ignored", p
->users
[i
]);
4392 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4396 else if (!strcasecmp(username
, p
->users
[i
]))
4398 #endif /* HAVE_MBR_UID_TO_UUID */
4400 if ((i
< p
->num_users
) == p
->deny_users
)
4402 cupsdLogMessage(CUPSD_LOG_INFO
,
4403 "Denying user \"%s\" access to printer \"%s\"...",
4414 if (AppleQuotas
&& (q
= cupsdFindQuota(p
, username
)) != NULL
)
4417 * TODO: Define these special page count values as constants!
4420 if (q
->page_count
== -4) /* special case: unlimited user */
4422 cupsdLogMessage(CUPSD_LOG_INFO
,
4423 "User \"%s\" request approved for printer %s (%s): "
4425 username
, p
->name
, p
->info
);
4426 q
->page_count
= 0; /* allow user to print */
4429 else if (q
->page_count
== -3) /* quota exceeded */
4431 cupsdLogMessage(CUPSD_LOG_INFO
,
4432 "User \"%s\" request denied for printer %s (%s): "
4433 "quota limit exceeded.",
4434 username
, p
->name
, p
->info
);
4435 q
->page_count
= 2; /* force quota exceeded failure */
4438 else if (q
->page_count
== -2) /* quota disabled for user */
4440 cupsdLogMessage(CUPSD_LOG_INFO
,
4441 "User \"%s\" request denied for printer %s (%s): "
4442 "printing disabled for user.",
4443 username
, p
->name
, p
->info
);
4444 q
->page_count
= 2; /* force quota exceeded failure */
4447 else if (q
->page_count
== -1) /* quota access error */
4449 cupsdLogMessage(CUPSD_LOG_INFO
,
4450 "User \"%s\" request denied for printer %s (%s): "
4451 "unable to determine quota limit.",
4452 username
, p
->name
, p
->info
);
4453 q
->page_count
= 2; /* force quota exceeded failure */
4456 else if (q
->page_count
< 0) /* user not found or other error */
4458 cupsdLogMessage(CUPSD_LOG_INFO
,
4459 "User \"%s\" request denied for printer %s (%s): "
4460 "user disabled / missing quota.",
4461 username
, p
->name
, p
->info
);
4462 q
->page_count
= 2; /* force quota exceeded failure */
4465 else /* page within user limits */
4467 q
->page_count
= 0; /* allow user to print */
4472 #endif /* __APPLE__ */
4473 if (p
->k_limit
|| p
->page_limit
)
4475 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4477 cupsdLogMessage(CUPSD_LOG_ERROR
,
4478 "Unable to allocate quota data for user \"%s\"!",
4483 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4484 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4486 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4493 * If we have gotten this far, we're done!
4501 * 'copy_attribute()' - Copy a single attribute.
4504 static ipp_attribute_t
* /* O - New attribute */
4506 ipp_t
*to
, /* O - Destination request/response */
4507 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4508 int quickcopy
) /* I - Do a quick copy? */
4510 int i
; /* Looping var */
4511 ipp_attribute_t
*toattr
; /* Destination attribute */
4514 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4515 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4516 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4519 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4522 toattr
= ippAddSeparator(to
);
4525 case IPP_TAG_INTEGER
:
4527 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4528 attr
->name
, attr
->num_values
, NULL
);
4530 for (i
= 0; i
< attr
->num_values
; i
++)
4531 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4534 case IPP_TAG_BOOLEAN
:
4535 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4536 attr
->num_values
, NULL
);
4538 for (i
= 0; i
< attr
->num_values
; i
++)
4539 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4542 case IPP_TAG_STRING
:
4545 case IPP_TAG_KEYWORD
:
4547 case IPP_TAG_URISCHEME
:
4548 case IPP_TAG_CHARSET
:
4549 case IPP_TAG_LANGUAGE
:
4550 case IPP_TAG_MIMETYPE
:
4551 toattr
= ippAddStrings(to
, attr
->group_tag
,
4552 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4553 attr
->name
, attr
->num_values
, NULL
, NULL
);
4557 for (i
= 0; i
< attr
->num_values
; i
++)
4558 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4560 else if (attr
->value_tag
& IPP_TAG_COPY
)
4562 for (i
= 0; i
< attr
->num_values
; i
++)
4563 toattr
->values
[i
].string
.text
=
4564 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4568 for (i
= 0; i
< attr
->num_values
; i
++)
4569 toattr
->values
[i
].string
.text
=
4570 _cupsStrRetain(attr
->values
[i
].string
.text
);
4575 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4576 attr
->values
[0].date
);
4579 case IPP_TAG_RESOLUTION
:
4580 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4581 attr
->num_values
, IPP_RES_PER_INCH
,
4584 for (i
= 0; i
< attr
->num_values
; i
++)
4586 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4587 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4588 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4592 case IPP_TAG_RANGE
:
4593 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4594 attr
->num_values
, NULL
, NULL
);
4596 for (i
= 0; i
< attr
->num_values
; i
++)
4598 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4599 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4603 case IPP_TAG_TEXTLANG
:
4604 case IPP_TAG_NAMELANG
:
4605 toattr
= ippAddStrings(to
, attr
->group_tag
,
4606 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4607 attr
->name
, attr
->num_values
, NULL
, NULL
);
4611 for (i
= 0; i
< attr
->num_values
; i
++)
4613 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4614 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4617 else if (attr
->value_tag
& IPP_TAG_COPY
)
4619 for (i
= 0; i
< attr
->num_values
; i
++)
4622 toattr
->values
[i
].string
.charset
=
4623 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4625 toattr
->values
[i
].string
.charset
=
4626 toattr
->values
[0].string
.charset
;
4628 toattr
->values
[i
].string
.text
=
4629 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4634 for (i
= 0; i
< attr
->num_values
; i
++)
4637 toattr
->values
[i
].string
.charset
=
4638 _cupsStrRetain(attr
->values
[i
].string
.charset
);
4640 toattr
->values
[i
].string
.charset
=
4641 toattr
->values
[0].string
.charset
;
4643 toattr
->values
[i
].string
.text
=
4644 _cupsStrRetain(attr
->values
[i
].string
.text
);
4649 case IPP_TAG_BEGIN_COLLECTION
:
4650 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4651 attr
->num_values
, NULL
);
4653 for (i
= 0; i
< attr
->num_values
; i
++)
4655 toattr
->values
[i
].collection
= ippNew();
4656 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
4657 NULL
, IPP_TAG_ZERO
, 0);
4662 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4663 attr
->name
, attr
->num_values
, NULL
);
4665 for (i
= 0; i
< attr
->num_values
; i
++)
4667 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4669 if (toattr
->values
[i
].unknown
.length
> 0)
4671 if ((toattr
->values
[i
].unknown
.data
=
4672 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4673 toattr
->values
[i
].unknown
.length
= 0;
4675 memcpy(toattr
->values
[i
].unknown
.data
,
4676 attr
->values
[i
].unknown
.data
,
4677 toattr
->values
[i
].unknown
.length
);
4680 break; /* anti-compiler-warning-code */
4688 * 'copy_attrs()' - Copy attributes from one request to another.
4692 copy_attrs(ipp_t
*to
, /* I - Destination request */
4693 ipp_t
*from
, /* I - Source request */
4694 cups_array_t
*ra
, /* I - Requested attributes */
4695 ipp_tag_t group
, /* I - Group to copy */
4696 int quickcopy
) /* I - Do a quick copy? */
4698 ipp_attribute_t
*fromattr
; /* Source attribute */
4701 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4702 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4703 to
, from
, ra
, group
, quickcopy
);
4708 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4711 * Filter attributes as needed...
4714 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4715 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4718 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4721 * Don't send collection attributes by default to IPP/1.x clients
4722 * since many do not support collections...
4725 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4726 !ra
&& to
->request
.status
.version
[0] == 1)
4729 copy_attribute(to
, fromattr
, quickcopy
);
4736 * 'copy_banner()' - Copy a banner file to the requests directory for the
4740 static int /* O - Size of banner file in kbytes */
4741 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4742 cupsd_job_t
*job
, /* I - Job information */
4743 const char *name
) /* I - Name of banner */
4745 int i
; /* Looping var */
4746 int kbytes
; /* Size of banner file in kbytes */
4747 char filename
[1024]; /* Job filename */
4748 cupsd_banner_t
*banner
; /* Pointer to banner */
4749 cups_file_t
*in
; /* Input file */
4750 cups_file_t
*out
; /* Output file */
4751 int ch
; /* Character from file */
4752 char attrname
[255], /* Name of attribute */
4753 *s
; /* Pointer into name */
4754 ipp_attribute_t
*attr
; /* Attribute */
4757 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4758 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4759 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4760 name
? name
: "(null)");
4763 * Find the banner; return if not found or "none"...
4766 if (!name
|| !strcmp(name
, "none") ||
4767 (banner
= cupsdFindBanner(name
)) == NULL
)
4771 * Open the banner and job files...
4774 if (add_file(con
, job
, banner
->filetype
, 0))
4777 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4779 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4781 cupsdLogMessage(CUPSD_LOG_ERROR
,
4782 "Unable to create banner job file %s - %s",
4783 filename
, strerror(errno
));
4788 fchmod(cupsFileNumber(out
), 0640);
4789 fchown(cupsFileNumber(out
), RunUser
, Group
);
4792 * Try the localized banner file under the subdirectory...
4795 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4797 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4800 * Convert ll-cc to ll_CC...
4804 attrname
[3] = toupper(attrname
[3] & 255);
4805 attrname
[4] = toupper(attrname
[4] & 255);
4808 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4811 if (access(filename
, 0) && strlen(attrname
) > 2)
4814 * Wasn't able to find "ll_CC" locale file; try the non-national
4815 * localization banner directory.
4820 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4824 if (access(filename
, 0))
4827 * Use the non-localized banner file.
4830 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4833 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4837 cupsdLogMessage(CUPSD_LOG_ERROR
,
4838 "Unable to open banner template file %s - %s",
4839 filename
, strerror(errno
));
4845 * Parse the file to the end...
4848 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4852 * Get an attribute name...
4855 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4856 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4858 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4868 * Ignore { followed by stuff that is not an attribute name...
4871 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4876 * See if it is defined...
4879 if (attrname
[0] == '?')
4884 if (!strcmp(s
, "printer-name"))
4886 cupsFilePuts(out
, job
->dest
);
4889 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4892 * See if we have a leading question mark...
4895 if (attrname
[0] != '?')
4898 * Nope, write to file as-is; probably a PostScript procedure...
4901 cupsFilePrintf(out
, "{%s}", attrname
);
4908 * Output value(s)...
4911 for (i
= 0; i
< attr
->num_values
; i
++)
4914 cupsFilePutChar(out
, ',');
4916 switch (attr
->value_tag
)
4918 case IPP_TAG_INTEGER
:
4920 if (!strncmp(s
, "time-at-", 8))
4922 struct timeval tv
= { attr
->values
[i
].integer
, 0 };
4923 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4926 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4929 case IPP_TAG_BOOLEAN
:
4930 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4933 case IPP_TAG_NOVALUE
:
4934 cupsFilePuts(out
, "novalue");
4937 case IPP_TAG_RANGE
:
4938 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4939 attr
->values
[i
].range
.upper
);
4942 case IPP_TAG_RESOLUTION
:
4943 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4944 attr
->values
[i
].resolution
.yres
,
4945 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4950 case IPP_TAG_STRING
:
4953 case IPP_TAG_KEYWORD
:
4954 case IPP_TAG_CHARSET
:
4955 case IPP_TAG_LANGUAGE
:
4956 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
4959 * Need to quote strings for PS banners...
4964 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4966 if (*p
== '(' || *p
== ')' || *p
== '\\')
4968 cupsFilePutChar(out
, '\\');
4969 cupsFilePutChar(out
, *p
);
4971 else if (*p
< 32 || *p
> 126)
4972 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4974 cupsFilePutChar(out
, *p
);
4978 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4982 break; /* anti-compiler-warning-code */
4986 else if (ch
== '\\') /* Quoted char */
4988 ch
= cupsFileGetChar(in
);
4990 if (ch
!= '{') /* Only do special handling for \{ */
4991 cupsFilePutChar(out
, '\\');
4993 cupsFilePutChar(out
, ch
);
4996 cupsFilePutChar(out
, ch
);
5000 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5002 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5003 IPP_TAG_INTEGER
)) != NULL
)
5004 attr
->values
[0].integer
+= kbytes
;
5013 * 'copy_file()' - Copy a PPD file or interface script...
5016 static int /* O - 0 = success, -1 = error */
5017 copy_file(const char *from
, /* I - Source file */
5018 const char *to
) /* I - Destination file */
5020 cups_file_t
*src
, /* Source file */
5021 *dst
; /* Destination file */
5022 int bytes
; /* Bytes to read/write */
5023 char buffer
[2048]; /* Copy buffer */
5026 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5029 * Open the source and destination file for a copy...
5032 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5035 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5042 * Copy the source file to the destination...
5045 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5046 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5054 * Close both files and return...
5059 return (cupsFileClose(dst
));
5064 * 'copy_model()' - Copy a PPD model file, substituting default values
5068 static int /* O - 0 = success, -1 = error */
5069 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5070 const char *from
, /* I - Source file */
5071 const char *to
) /* I - Destination file */
5073 fd_set input
; /* select() input set */
5074 struct timeval timeout
; /* select() timeout */
5075 int maxfd
; /* Max file descriptor for select() */
5076 char tempfile
[1024]; /* Temporary PPD file */
5077 int tempfd
; /* Temporary PPD file descriptor */
5078 int temppid
; /* Process ID of cups-driverd */
5079 int temppipe
[2]; /* Temporary pipes */
5080 char *argv
[4], /* Command-line arguments */
5081 *envp
[MAX_ENV
]; /* Environment */
5082 cups_file_t
*src
, /* Source file */
5083 *dst
; /* Destination file */
5084 ppd_file_t
*ppd
; /* PPD file */
5085 int bytes
, /* Bytes from pipe */
5086 total
; /* Total bytes from pipe */
5087 char buffer
[2048]; /* Copy buffer */
5088 int i
; /* Looping var */
5089 char option
[PPD_MAX_NAME
], /* Option name */
5090 choice
[PPD_MAX_NAME
]; /* Choice name */
5091 int num_defaults
; /* Number of default options */
5092 cups_option_t
*defaults
; /* Default options */
5093 char cups_protocol
[PPD_MAX_LINE
];
5094 /* cupsProtocol attribute */
5097 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5098 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5102 * Run cups-driverd to get the PPD file...
5105 argv
[0] = "cups-driverd";
5107 argv
[2] = (char *)from
;
5110 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5112 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5113 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5114 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5118 cupsdOpenPipe(temppipe
);
5120 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5121 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5123 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5124 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5135 * Wait up to 30 seconds for the PPD file to be copied...
5140 if (temppipe
[0] > CGIPipes
[0])
5141 maxfd
= temppipe
[0] + 1;
5143 maxfd
= CGIPipes
[0] + 1;
5148 * See if we have data ready...
5152 FD_SET(temppipe
[0], &input
);
5153 FD_SET(CGIPipes
[0], &input
);
5155 timeout
.tv_sec
= 30;
5156 timeout
.tv_usec
= 0;
5158 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5168 * We have timed out...
5174 if (FD_ISSET(temppipe
[0], &input
))
5177 * Read the PPD file from the pipe, and write it to the PPD file.
5180 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5182 if (write(tempfd
, buffer
, bytes
) < bytes
)
5191 if (FD_ISSET(CGIPipes
[0], &input
))
5201 * No data from cups-deviced...
5204 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
5210 * Read the source file and see what page sizes are supported...
5213 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5220 * Open the destination (if possible) and set the default options...
5225 cups_protocol
[0] = '\0';
5227 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5230 * Read all of the default lines from the old PPD...
5233 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5234 if (!strncmp(buffer
, "*Default", 8))
5237 * Add the default option...
5240 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5241 choice
, sizeof(choice
)))
5243 ppd_option_t
*ppdo
; /* PPD option */
5247 * Only add the default if the default hasn't already been
5248 * set and the choice exists in the new PPD...
5251 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5252 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5253 ppdFindChoice(ppdo
, choice
))
5254 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5258 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5259 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5263 else if (ppdPageSize(ppd
, DefaultPaperSize
))
5266 * Add the default media sizes...
5269 num_defaults
= cupsAddOption("PageSize", DefaultPaperSize
,
5270 num_defaults
, &defaults
);
5271 num_defaults
= cupsAddOption("PageRegion", DefaultPaperSize
,
5272 num_defaults
, &defaults
);
5273 num_defaults
= cupsAddOption("PaperDimension", DefaultPaperSize
,
5274 num_defaults
, &defaults
);
5275 num_defaults
= cupsAddOption("ImageableArea", DefaultPaperSize
,
5276 num_defaults
, &defaults
);
5282 * Open the source file for a copy...
5285 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5287 cupsFreeOptions(num_defaults
, defaults
);
5293 * Open the destination file for a copy...
5296 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5298 cupsFreeOptions(num_defaults
, defaults
);
5305 * Copy the source file to the destination...
5308 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5310 if (!strncmp(buffer
, "*Default", 8))
5313 * Check for an previous default option choice...
5316 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5317 choice
, sizeof(choice
)))
5319 const char *val
; /* Default option value */
5322 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5325 * Substitute the previous choice...
5328 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5333 cupsFilePrintf(dst
, "%s\n", buffer
);
5336 if (cups_protocol
[0])
5337 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5339 cupsFreeOptions(num_defaults
, defaults
);
5342 * Close both files and return...
5349 return (cupsFileClose(dst
));
5354 * 'copy_job_attrs()' - Copy job attributes.
5358 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5359 cupsd_job_t
*job
, /* I - Job */
5360 cups_array_t
*ra
) /* I - Requested attributes array */
5362 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5366 * Send the requested attributes for each job...
5369 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5370 con
->servername
, con
->serverport
, "/jobs/%d",
5373 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5374 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5375 "document-count", job
->num_files
);
5377 if (!ra
|| cupsArrayFind(ra
, "job-media-progress"))
5378 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5379 "job-media-progress", job
->progress
);
5381 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5382 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5383 "job-more-info", NULL
, job_uri
);
5385 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5386 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5387 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5388 job
->num_files
> 0);
5390 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5391 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5392 "job-printer-up-time", time(NULL
));
5394 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5395 add_job_state_reasons(con
, job
);
5397 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5398 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5399 "job-uri", NULL
, job_uri
);
5401 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5406 * 'copy_printer_attrs()' - Copy printer attributes.
5411 cupsd_client_t
*con
, /* I - Client connection */
5412 cupsd_printer_t
*printer
, /* I - Printer */
5413 cups_array_t
*ra
) /* I - Requested attributes array */
5415 char printer_uri
[HTTP_MAX_URI
];
5417 time_t curtime
; /* Current time */
5418 int i
; /* Looping var */
5419 ipp_attribute_t
*history
; /* History collection */
5423 * Copy the printer attributes to the response using requested-attributes
5424 * and document-format attributes that may be provided by the client.
5427 curtime
= time(NULL
);
5430 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
5431 printer
->recoverable
)
5432 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5433 "com.apple.print.recoverable-message", NULL
,
5434 printer
->recoverable
);
5435 #endif /* __APPLE__ */
5437 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5438 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5439 "marker-change-time", printer
->marker_time
);
5441 if (printer
->num_printers
> 0 &&
5442 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5444 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5445 cupsd_printer_t
*p2
; /* Printer in class */
5446 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5449 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5450 IPP_TAG_URI
, "member-uris",
5451 printer
->num_printers
, NULL
,
5454 for (i
= 0; i
< printer
->num_printers
; i
++)
5456 p2
= printer
->printers
[i
];
5458 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5459 IPP_TAG_URI
)) != NULL
)
5460 member_uris
->values
[i
].string
.text
=
5461 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5464 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5465 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5467 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5468 "/classes/%s" : "/printers/%s", p2
->name
);
5469 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5475 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5476 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5477 "printer-alert", NULL
, printer
->alert
);
5479 if (printer
->alert_description
&&
5480 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5481 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5482 "printer-alert-description", NULL
,
5483 printer
->alert_description
);
5485 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5486 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5487 ippTimeToDate(curtime
));
5490 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5492 if (printer
->reg_name
)
5493 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5494 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5496 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5497 "printer-dns-sd-name", 0);
5499 #endif /* HAVE_DNSSD */
5501 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5502 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5503 "printer-error-policy", NULL
, printer
->error_policy
);
5505 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
5507 static const char * const errors
[] =/* printer-error-policy-supported values */
5510 "retry-current-job",
5515 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
5516 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5517 "printer-error-policy-supported", NULL
, "retry-current-job");
5519 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5520 "printer-error-policy-supported",
5521 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
5524 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5525 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5526 printer
->accepting
);
5528 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5529 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5532 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5533 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5535 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5536 "http", NULL
, con
->servername
, con
->serverport
,
5537 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5538 "/classes/%s" : "/printers/%s", printer
->name
);
5539 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5540 "printer-more-info", NULL
, printer_uri
);
5543 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5544 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5545 "printer-op-policy", NULL
, printer
->op_policy
);
5547 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5548 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5551 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5552 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5553 "printer-state-change-time", printer
->state_time
);
5555 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5556 cupsArrayFind(ra
, "printer-state-history"))
5559 * Printer history is only sent if specifically requested, so that
5560 * older CUPS/IPP clients won't barf on the collection attributes.
5563 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5564 "printer-state-history",
5565 printer
->num_history
, NULL
);
5567 for (i
= 0; i
< printer
->num_history
; i
++)
5568 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5569 NULL
, IPP_TAG_ZERO
, 0);
5572 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5573 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5574 "printer-state-message", NULL
, printer
->state_message
);
5576 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5577 add_printer_state_reasons(con
, printer
);
5579 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5581 int type
; /* printer-type value */
5585 * Add the CUPS-specific printer-type attribute...
5588 type
= printer
->type
;
5590 if (printer
== DefaultPrinter
)
5591 type
|= CUPS_PRINTER_DEFAULT
;
5593 if (!printer
->accepting
)
5594 type
|= CUPS_PRINTER_REJECTING
;
5596 if (!printer
->shared
)
5597 type
|= CUPS_PRINTER_NOT_SHARED
;
5599 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5603 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5604 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5605 "printer-up-time", curtime
);
5607 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5608 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5610 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5611 "ipp", NULL
, con
->servername
, con
->serverport
,
5612 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5613 "/classes/%s" : "/printers/%s", printer
->name
);
5614 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5615 "printer-uri-supported", NULL
, printer_uri
);
5616 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5620 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5621 add_queued_job_count(con
, printer
);
5623 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5624 if (printer
->ppd_attrs
)
5625 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0);
5626 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5631 * 'copy_subscription_attrs()' - Copy subscription attributes.
5635 copy_subscription_attrs(
5636 cupsd_client_t
*con
, /* I - Client connection */
5637 cupsd_subscription_t
*sub
, /* I - Subscription */
5638 cups_array_t
*ra
) /* I - Requested attributes array */
5640 ipp_attribute_t
*attr
; /* Current attribute */
5641 char printer_uri
[HTTP_MAX_URI
];
5643 int count
; /* Number of events */
5644 unsigned mask
; /* Current event mask */
5645 const char *name
; /* Current event name */
5649 * Copy the subscription attributes to the response using the
5650 * requested-attributes attribute that may be provided by the client.
5653 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5655 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5658 * Simple event list...
5661 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5662 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5663 "notify-events", NULL
, name
);
5668 * Complex event list...
5671 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5672 if (sub
->mask
& mask
)
5675 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5676 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5677 "notify-events", count
, NULL
, NULL
);
5679 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5680 if (sub
->mask
& mask
)
5682 attr
->values
[count
].string
.text
=
5683 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5690 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5691 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5692 "notify-job-id", sub
->job
->id
);
5694 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5695 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5696 "notify-lease-duration", sub
->lease
);
5698 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5700 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5701 "ipp", NULL
, con
->servername
, con
->serverport
,
5702 "/printers/%s", sub
->dest
->name
);
5703 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5704 "notify-printer-uri", NULL
, printer_uri
);
5707 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5708 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5709 "notify-recipient-uri", NULL
, sub
->recipient
);
5710 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5711 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5712 "notify-pull-method", NULL
, "ippget");
5714 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5715 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5716 "notify-subscriber-user-name", NULL
, sub
->owner
);
5718 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5719 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5720 "notify-subscription-id", sub
->id
);
5722 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5723 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5724 "notify-time-interval", sub
->interval
);
5726 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5727 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5728 sub
->user_data
, sub
->user_data_len
);
5733 * 'create_job()' - Print a file to a printer or class.
5737 create_job(cupsd_client_t
*con
, /* I - Client connection */
5738 ipp_attribute_t
*uri
) /* I - Printer URI */
5740 cupsd_printer_t
*printer
; /* Printer */
5741 cupsd_job_t
*job
; /* New job */
5744 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5745 con
->http
.fd
, uri
->values
[0].string
.text
);
5748 * Is the destination valid?
5751 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5757 send_ipp_status(con
, IPP_NOT_FOUND
,
5758 _("The printer or class was not found."));
5763 * Create the job object...
5766 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5769 job
->pending_timeout
= 1;
5772 * Save and log the job...
5775 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5776 job
->dest
, job
->username
);
5781 * 'create_requested_array()' - Create an array for the requested-attributes.
5784 static cups_array_t
* /* O - Array of attributes or NULL */
5785 create_requested_array(ipp_t
*request
) /* I - IPP request */
5787 int i
; /* Looping var */
5788 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5789 cups_array_t
*ra
; /* Requested attributes array */
5790 char *value
; /* Current value */
5794 * Get the requested-attributes attribute, and return NULL if we don't
5798 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5799 IPP_TAG_KEYWORD
)) == NULL
)
5803 * If the attribute contains a single "all" keyword, return NULL...
5806 if (requested
->num_values
== 1 &&
5807 !strcmp(requested
->values
[0].string
.text
, "all"))
5811 * Create an array using "strcmp" as the comparison function...
5814 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5816 for (i
= 0; i
< requested
->num_values
; i
++)
5818 value
= requested
->values
[i
].string
.text
;
5820 if (!strcmp(value
, "job-template"))
5822 cupsArrayAdd(ra
, "copies");
5823 cupsArrayAdd(ra
, "copies-default");
5824 cupsArrayAdd(ra
, "copies-supported");
5825 cupsArrayAdd(ra
, "finishings");
5826 cupsArrayAdd(ra
, "finishings-default");
5827 cupsArrayAdd(ra
, "finishings-supported");
5828 cupsArrayAdd(ra
, "job-hold-until");
5829 cupsArrayAdd(ra
, "job-hold-until-default");
5830 cupsArrayAdd(ra
, "job-hold-until-supported");
5831 cupsArrayAdd(ra
, "job-priority");
5832 cupsArrayAdd(ra
, "job-priority-default");
5833 cupsArrayAdd(ra
, "job-priority-supported");
5834 cupsArrayAdd(ra
, "job-sheets");
5835 cupsArrayAdd(ra
, "job-sheets-default");
5836 cupsArrayAdd(ra
, "job-sheets-supported");
5837 cupsArrayAdd(ra
, "media");
5838 cupsArrayAdd(ra
, "media-default");
5839 cupsArrayAdd(ra
, "media-supported");
5840 cupsArrayAdd(ra
, "multiple-document-handling");
5841 cupsArrayAdd(ra
, "multiple-document-handling-default");
5842 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5843 cupsArrayAdd(ra
, "number-up");
5844 cupsArrayAdd(ra
, "number-up-default");
5845 cupsArrayAdd(ra
, "number-up-supported");
5846 cupsArrayAdd(ra
, "orientation-requested");
5847 cupsArrayAdd(ra
, "orientation-requested-default");
5848 cupsArrayAdd(ra
, "orientation-requested-supported");
5849 cupsArrayAdd(ra
, "page-ranges");
5850 cupsArrayAdd(ra
, "page-ranges-supported");
5851 cupsArrayAdd(ra
, "printer-resolution");
5852 cupsArrayAdd(ra
, "printer-resolution-default");
5853 cupsArrayAdd(ra
, "printer-resolution-supported");
5854 cupsArrayAdd(ra
, "print-quality");
5855 cupsArrayAdd(ra
, "print-quality-default");
5856 cupsArrayAdd(ra
, "print-quality-supported");
5857 cupsArrayAdd(ra
, "sides");
5858 cupsArrayAdd(ra
, "sides-default");
5859 cupsArrayAdd(ra
, "sides-supported");
5861 else if (!strcmp(value
, "job-description"))
5863 cupsArrayAdd(ra
, "date-time-at-completed");
5864 cupsArrayAdd(ra
, "date-time-at-creation");
5865 cupsArrayAdd(ra
, "date-time-at-processing");
5866 cupsArrayAdd(ra
, "job-detailed-status-message");
5867 cupsArrayAdd(ra
, "job-document-access-errors");
5868 cupsArrayAdd(ra
, "job-id");
5869 cupsArrayAdd(ra
, "job-impressions");
5870 cupsArrayAdd(ra
, "job-impressions-completed");
5871 cupsArrayAdd(ra
, "job-k-octets");
5872 cupsArrayAdd(ra
, "job-k-octets-processed");
5873 cupsArrayAdd(ra
, "job-media-progress");
5874 cupsArrayAdd(ra
, "job-media-sheets");
5875 cupsArrayAdd(ra
, "job-media-sheets-completed");
5876 cupsArrayAdd(ra
, "job-message-from-operator");
5877 cupsArrayAdd(ra
, "job-more-info");
5878 cupsArrayAdd(ra
, "job-name");
5879 cupsArrayAdd(ra
, "job-originating-user-name");
5880 cupsArrayAdd(ra
, "job-printer-up-time");
5881 cupsArrayAdd(ra
, "job-printer-uri");
5882 cupsArrayAdd(ra
, "job-state");
5883 cupsArrayAdd(ra
, "job-state-message");
5884 cupsArrayAdd(ra
, "job-state-reasons");
5885 cupsArrayAdd(ra
, "job-uri");
5886 cupsArrayAdd(ra
, "number-of-documents");
5887 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5888 cupsArrayAdd(ra
, "output-device-assigned");
5889 cupsArrayAdd(ra
, "time-at-completed");
5890 cupsArrayAdd(ra
, "time-at-creation");
5891 cupsArrayAdd(ra
, "time-at-processing");
5893 else if (!strcmp(value
, "printer-description"))
5895 cupsArrayAdd(ra
, "charset-configured");
5896 cupsArrayAdd(ra
, "charset-supported");
5897 cupsArrayAdd(ra
, "color-supported");
5898 cupsArrayAdd(ra
, "compression-supported");
5899 cupsArrayAdd(ra
, "document-format-default");
5900 cupsArrayAdd(ra
, "document-format-supported");
5901 cupsArrayAdd(ra
, "generated-natural-language-supported");
5902 cupsArrayAdd(ra
, "ipp-versions-supported");
5903 cupsArrayAdd(ra
, "job-impressions-supported");
5904 cupsArrayAdd(ra
, "job-k-octets-supported");
5905 cupsArrayAdd(ra
, "job-media-sheets-supported");
5906 cupsArrayAdd(ra
, "job-settable-attributes-supported");
5907 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5908 cupsArrayAdd(ra
, "multiple-operation-time-out");
5909 cupsArrayAdd(ra
, "natural-language-configured");
5910 cupsArrayAdd(ra
, "notify-attributes-supported");
5911 cupsArrayAdd(ra
, "notify-lease-duration-default");
5912 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5913 cupsArrayAdd(ra
, "notify-max-events-supported");
5914 cupsArrayAdd(ra
, "notify-events-default");
5915 cupsArrayAdd(ra
, "notify-events-supported");
5916 cupsArrayAdd(ra
, "notify-pull-method-supported");
5917 cupsArrayAdd(ra
, "notify-schemes-supported");
5918 cupsArrayAdd(ra
, "operations-supported");
5919 cupsArrayAdd(ra
, "pages-per-minute");
5920 cupsArrayAdd(ra
, "pages-per-minute-color");
5921 cupsArrayAdd(ra
, "pdl-override-supported");
5922 cupsArrayAdd(ra
, "printer-alert");
5923 cupsArrayAdd(ra
, "printer-alert-description");
5924 cupsArrayAdd(ra
, "printer-commands");
5925 cupsArrayAdd(ra
, "printer-current-time");
5926 cupsArrayAdd(ra
, "printer-driver-installer");
5927 cupsArrayAdd(ra
, "printer-dns-sd-name");
5928 cupsArrayAdd(ra
, "printer-info");
5929 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5930 cupsArrayAdd(ra
, "printer-location");
5931 cupsArrayAdd(ra
, "printer-make-and-model");
5932 cupsArrayAdd(ra
, "printer-message-from-operator");
5933 cupsArrayAdd(ra
, "printer-more-info");
5934 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5935 cupsArrayAdd(ra
, "printer-name");
5936 cupsArrayAdd(ra
, "printer-state");
5937 cupsArrayAdd(ra
, "printer-state-message");
5938 cupsArrayAdd(ra
, "printer-state-reasons");
5939 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
5940 cupsArrayAdd(ra
, "printer-type");
5941 cupsArrayAdd(ra
, "printer-up-time");
5942 cupsArrayAdd(ra
, "printer-uri-supported");
5943 cupsArrayAdd(ra
, "queued-job-count");
5944 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5945 cupsArrayAdd(ra
, "uri-authentication-supported");
5946 cupsArrayAdd(ra
, "uri-security-supported");
5948 else if (!strcmp(value
, "printer-defaults"))
5950 char *name
; /* Option name */
5953 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5955 name
= (char *)cupsArrayNext(CommonDefaults
))
5956 cupsArrayAdd(ra
, name
);
5958 else if (!strcmp(value
, "subscription-template"))
5960 cupsArrayAdd(ra
, "notify-attributes");
5961 cupsArrayAdd(ra
, "notify-charset");
5962 cupsArrayAdd(ra
, "notify-events");
5963 cupsArrayAdd(ra
, "notify-lease-duration");
5964 cupsArrayAdd(ra
, "notify-natural-language");
5965 cupsArrayAdd(ra
, "notify-pull-method");
5966 cupsArrayAdd(ra
, "notify-recipient-uri");
5967 cupsArrayAdd(ra
, "notify-time-interval");
5968 cupsArrayAdd(ra
, "notify-user-data");
5971 cupsArrayAdd(ra
, value
);
5979 * 'create_subscription()' - Create a notification subscription.
5983 create_subscription(
5984 cupsd_client_t
*con
, /* I - Client connection */
5985 ipp_attribute_t
*uri
) /* I - Printer URI */
5987 http_status_t status
; /* Policy status */
5988 int i
; /* Looping var */
5989 ipp_attribute_t
*attr
; /* Current attribute */
5990 cups_ptype_t dtype
; /* Destination type (printer/class) */
5991 char scheme
[HTTP_MAX_URI
],
5992 /* Scheme portion of URI */
5993 userpass
[HTTP_MAX_URI
],
5994 /* Username portion of URI */
5996 /* Host portion of URI */
5997 resource
[HTTP_MAX_URI
];
5998 /* Resource portion of URI */
5999 int port
; /* Port portion of URI */
6000 cupsd_printer_t
*printer
; /* Printer/class */
6001 cupsd_job_t
*job
; /* Job */
6002 int jobid
; /* Job ID */
6003 cupsd_subscription_t
*sub
; /* Subscription object */
6004 const char *username
, /* requesting-user-name or
6005 authenticated username */
6006 *recipient
, /* notify-recipient-uri */
6007 *pullmethod
; /* notify-pull-method */
6008 ipp_attribute_t
*user_data
; /* notify-user-data */
6009 int interval
, /* notify-time-interval */
6010 lease
; /* notify-lease-duration */
6011 unsigned mask
; /* notify-events */
6012 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6013 *notify_lease
; /* notify-lease-duration(-default) */
6017 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6019 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6020 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6021 attr
->value_tag
, attr
->name
);
6023 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6028 * Is the destination valid?
6031 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6032 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6033 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6035 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6036 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6037 sizeof(host
), &port
, resource
, sizeof(resource
));
6039 if (!strcmp(resource
, "/"))
6041 dtype
= (cups_ptype_t
)0;
6044 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6046 dtype
= (cups_ptype_t
)0;
6049 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6051 dtype
= CUPS_PRINTER_CLASS
;
6054 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6060 send_ipp_status(con
, IPP_NOT_FOUND
,
6061 _("The printer or class was not found."));
6071 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6074 send_http_error(con
, status
, printer
);
6078 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6080 send_http_error(con
, status
, NULL
);
6085 * Get the user that is requesting the subscription...
6088 username
= get_username(con
);
6091 * Find the first subscription group attribute; return if we have
6095 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6096 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6101 send_ipp_status(con
, IPP_BAD_REQUEST
,
6102 _("No subscription attributes in request!"));
6107 * Process the subscription attributes in the request...
6110 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6118 lease
= DefaultLeaseDuration
;
6120 mask
= CUPSD_EVENT_NONE
;
6124 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6126 notify_lease
= ippFindAttribute(printer
->attrs
,
6127 "notify-lease-duration-default",
6131 lease
= notify_lease
->values
[0].integer
;
6135 notify_events
= NULL
;
6136 notify_lease
= NULL
;
6139 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6141 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6142 attr
->value_tag
== IPP_TAG_URI
)
6145 * Validate the recipient scheme against the ServerBin/notifier
6149 char notifier
[1024]; /* Notifier filename */
6152 recipient
= attr
->values
[0].string
.text
;
6154 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6155 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6156 host
, sizeof(host
), &port
,
6157 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6159 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6160 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
6161 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6162 "notify-status-code", IPP_URI_SCHEME
);
6166 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6168 if (access(notifier
, X_OK
))
6170 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6171 _("notify-recipient-uri URI \"%s\" uses unknown "
6172 "scheme!"), recipient
);
6173 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6174 "notify-status-code", IPP_URI_SCHEME
);
6178 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6180 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6181 _("notify-recipient-uri URI \"%s\" is already used!"),
6183 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6184 "notify-status-code", IPP_ATTRIBUTES
);
6188 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6189 attr
->value_tag
== IPP_TAG_KEYWORD
)
6191 pullmethod
= attr
->values
[0].string
.text
;
6193 if (strcmp(pullmethod
, "ippget"))
6195 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6196 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
6197 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6198 "notify-status-code", IPP_ATTRIBUTES
);
6202 else if (!strcmp(attr
->name
, "notify-charset") &&
6203 attr
->value_tag
== IPP_TAG_CHARSET
&&
6204 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6205 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6207 send_ipp_status(con
, IPP_CHARSET
,
6208 _("Character set \"%s\" not supported!"),
6209 attr
->values
[0].string
.text
);
6212 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6213 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6214 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6216 send_ipp_status(con
, IPP_CHARSET
,
6217 _("Language \"%s\" not supported!"),
6218 attr
->values
[0].string
.text
);
6221 else if (!strcmp(attr
->name
, "notify-user-data") &&
6222 attr
->value_tag
== IPP_TAG_STRING
)
6224 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6226 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6227 _("The notify-user-data value is too large "
6228 "(%d > 63 octets)!"),
6229 attr
->values
[0].unknown
.length
);
6235 else if (!strcmp(attr
->name
, "notify-events") &&
6236 attr
->value_tag
== IPP_TAG_KEYWORD
)
6237 notify_events
= attr
;
6238 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6239 attr
->value_tag
== IPP_TAG_INTEGER
)
6240 lease
= attr
->values
[0].integer
;
6241 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6242 attr
->value_tag
== IPP_TAG_INTEGER
)
6243 interval
= attr
->values
[0].integer
;
6244 else if (!strcmp(attr
->name
, "notify-job-id") &&
6245 attr
->value_tag
== IPP_TAG_INTEGER
)
6246 jobid
= attr
->values
[0].integer
;
6253 for (i
= 0; i
< notify_events
->num_values
; i
++)
6254 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6258 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6260 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6261 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6262 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6264 if (!recipient
&& !pullmethod
)
6267 if (mask
== CUPSD_EVENT_NONE
)
6270 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6272 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6275 send_ipp_status(con
, IPP_BAD_REQUEST
,
6276 _("notify-events not specified!"));
6281 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6283 cupsdLogMessage(CUPSD_LOG_INFO
,
6284 "create_subscription: Limiting notify-lease-duration to "
6287 lease
= MaxLeaseDuration
;
6292 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6294 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
6301 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6303 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6304 _("There are too many subscriptions."));
6309 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6312 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6313 "Added subscription %d for printer \"%s\"",
6314 sub
->id
, printer
->name
);
6316 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6319 sub
->interval
= interval
;
6321 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6323 cupsdSetString(&sub
->owner
, username
);
6327 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6328 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6329 sub
->user_data_len
);
6332 ippAddSeparator(con
->response
);
6333 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6334 "notify-subscription-id", sub
->id
);
6336 con
->response
->request
.status
.status_code
= IPP_OK
;
6342 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6347 * 'delete_printer()' - Remove a printer or class from the system.
6351 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6352 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6354 http_status_t status
; /* Policy status */
6355 cups_ptype_t dtype
; /* Destination type (printer/class) */
6356 cupsd_printer_t
*printer
; /* Printer/class */
6357 char filename
[1024]; /* Script/PPD filename */
6360 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6361 con
->http
.fd
, uri
->values
[0].string
.text
);
6364 * Do we have a valid URI?
6367 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6373 send_ipp_status(con
, IPP_NOT_FOUND
,
6374 _("The printer or class was not found."));
6382 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6384 send_http_error(con
, status
, NULL
);
6389 * Remove old jobs...
6392 cupsdCancelJobs(printer
->name
, NULL
, 1);
6395 * Remove old subscriptions and send a "deleted printer" event...
6398 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6399 "%s \"%s\" deleted by \"%s\".",
6400 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6401 printer
->name
, get_username(con
));
6403 cupsdExpireSubscriptions(printer
, NULL
);
6406 * Remove any old PPD or script files...
6409 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6413 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6417 snprintf(filename
, sizeof(filename
), "%s/%s.ipp", CacheDir
, printer
->name
);
6422 * Unregister color profiles...
6425 apple_unregister_profiles(printer
);
6426 #endif /* __APPLE__ */
6428 if (dtype
& CUPS_PRINTER_CLASS
)
6430 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6431 printer
->name
, get_username(con
));
6433 cupsdDeletePrinter(printer
, 0);
6434 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6438 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6439 printer
->name
, get_username(con
));
6441 cupsdDeletePrinter(printer
, 0);
6442 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6445 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6448 * Return with no errors...
6451 con
->response
->request
.status
.status_code
= IPP_OK
;
6456 * 'get_default()' - Get the default destination.
6460 get_default(cupsd_client_t
*con
) /* I - Client connection */
6462 http_status_t status
; /* Policy status */
6463 cups_array_t
*ra
; /* Requested attributes array */
6466 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6472 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6474 send_http_error(con
, status
, NULL
);
6480 ra
= create_requested_array(con
->request
);
6482 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6484 cupsArrayDelete(ra
);
6486 con
->response
->request
.status
.status_code
= IPP_OK
;
6489 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6494 * 'get_devices()' - Get the list of available devices on the local system.
6498 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6500 http_status_t status
; /* Policy status */
6501 ipp_attribute_t
*limit
, /* limit attribute */
6502 *timeout
, /* timeout attribute */
6503 *requested
, /* requested-attributes attribute */
6504 *exclude
, /* exclude-schemes attribute */
6505 *include
; /* include-schemes attribute */
6506 char command
[1024], /* cups-deviced command */
6507 options
[2048], /* Options to pass to command */
6509 /* String for requested attributes */
6511 /* String for excluded schemes */
6513 /* String for included schemes */
6516 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6522 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6524 send_http_error(con
, status
, NULL
);
6529 * Run cups-deviced command with the given options...
6532 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6533 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6534 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6536 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6537 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6540 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6542 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6545 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6547 exclude_str
[0] = '\0';
6550 url_encode_attr(include
, include_str
, sizeof(include_str
));
6552 include_str
[0] = '\0';
6554 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6555 snprintf(options
, sizeof(options
),
6556 "%d+%d+%d+%d+%s%s%s%s%s",
6557 con
->request
->request
.op
.request_id
,
6558 limit
? limit
->values
[0].integer
: 0,
6559 timeout
? timeout
->values
[0].integer
: 15,
6562 exclude_str
[0] ? "%20" : "", exclude_str
,
6563 include_str
[0] ? "%20" : "", include_str
);
6565 if (cupsdSendCommand(con
, command
, options
, 1))
6568 * Command started successfully, don't send an IPP response here...
6571 ippDelete(con
->response
);
6572 con
->response
= NULL
;
6577 * Command failed, return "internal error" so the user knows something
6581 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6582 _("cups-deviced failed to execute."));
6588 * 'get_document()' - Get a copy of a job file.
6592 get_document(cupsd_client_t
*con
, /* I - Client connection */
6593 ipp_attribute_t
*uri
) /* I - Job URI */
6595 http_status_t status
; /* Policy status */
6596 ipp_attribute_t
*attr
; /* Current attribute */
6597 int jobid
; /* Job ID */
6598 int docnum
; /* Document number */
6599 cupsd_job_t
*job
; /* Current job */
6600 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6601 username
[HTTP_MAX_URI
], /* Username portion of URI */
6602 host
[HTTP_MAX_URI
], /* Host portion of URI */
6603 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6604 int port
; /* Port portion of URI */
6605 char filename
[1024], /* Filename for document */
6606 format
[1024]; /* Format for document */
6609 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6610 con
->http
.fd
, uri
->values
[0].string
.text
);
6613 * See if we have a job URI or a printer URI...
6616 if (!strcmp(uri
->name
, "printer-uri"))
6619 * Got a printer URI; see if we also have a job-id attribute...
6622 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6623 IPP_TAG_INTEGER
)) == NULL
)
6625 send_ipp_status(con
, IPP_BAD_REQUEST
,
6626 _("Got a printer-uri attribute but no job-id!"));
6630 jobid
= attr
->values
[0].integer
;
6635 * Got a job URI; parse it to get the job ID...
6638 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6639 sizeof(scheme
), username
, sizeof(username
), host
,
6640 sizeof(host
), &port
, resource
, sizeof(resource
));
6642 if (strncmp(resource
, "/jobs/", 6))
6648 send_ipp_status(con
, IPP_BAD_REQUEST
,
6649 _("Bad job-uri attribute \"%s\"!"),
6650 uri
->values
[0].string
.text
);
6654 jobid
= atoi(resource
+ 6);
6658 * See if the job exists...
6661 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6664 * Nope - return a "not found" error...
6667 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6675 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6677 send_http_error(con
, status
, NULL
);
6682 * Get the document number...
6685 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6686 IPP_TAG_INTEGER
)) == NULL
)
6688 send_ipp_status(con
, IPP_BAD_REQUEST
,
6689 _("Missing document-number attribute!"));
6693 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6694 attr
->num_values
> 1)
6696 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6701 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6703 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6705 cupsdLogMessage(CUPSD_LOG_ERROR
,
6706 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6708 send_ipp_status(con
, IPP_NOT_FOUND
,
6709 _("Unable to open document %d in job %d!"), docnum
, jobid
);
6713 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6717 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6718 job
->filetypes
[docnum
- 1]->type
);
6720 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6722 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6724 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6725 IPP_TAG_NAME
)) != NULL
)
6726 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6727 NULL
, attr
->values
[0].string
.text
);
6732 * 'get_job_attrs()' - Get job attributes.
6736 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6737 ipp_attribute_t
*uri
) /* I - Job URI */
6739 http_status_t status
; /* Policy status */
6740 ipp_attribute_t
*attr
; /* Current attribute */
6741 int jobid
; /* Job ID */
6742 cupsd_job_t
*job
; /* Current job */
6743 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6744 username
[HTTP_MAX_URI
], /* Username portion of URI */
6745 host
[HTTP_MAX_URI
], /* Host portion of URI */
6746 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6747 int port
; /* Port portion of URI */
6748 cups_array_t
*ra
; /* Requested attributes array */
6751 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6752 con
->http
.fd
, uri
->values
[0].string
.text
);
6755 * See if we have a job URI or a printer URI...
6758 if (!strcmp(uri
->name
, "printer-uri"))
6761 * Got a printer URI; see if we also have a job-id attribute...
6764 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6765 IPP_TAG_INTEGER
)) == NULL
)
6767 send_ipp_status(con
, IPP_BAD_REQUEST
,
6768 _("Got a printer-uri attribute but no job-id!"));
6772 jobid
= attr
->values
[0].integer
;
6777 * Got a job URI; parse it to get the job ID...
6780 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6781 sizeof(scheme
), username
, sizeof(username
), host
,
6782 sizeof(host
), &port
, resource
, sizeof(resource
));
6784 if (strncmp(resource
, "/jobs/", 6))
6790 send_ipp_status(con
, IPP_BAD_REQUEST
,
6791 _("Bad job-uri attribute \"%s\"!"),
6792 uri
->values
[0].string
.text
);
6796 jobid
= atoi(resource
+ 6);
6800 * See if the job exists...
6803 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6806 * Nope - return a "not found" error...
6809 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6817 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6819 send_http_error(con
, status
, NULL
);
6824 * Copy attributes...
6829 ra
= create_requested_array(con
->request
);
6830 copy_job_attrs(con
, job
, ra
);
6831 cupsArrayDelete(ra
);
6833 con
->response
->request
.status
.status_code
= IPP_OK
;
6838 * 'get_jobs()' - Get a list of jobs for the specified printer.
6842 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6843 ipp_attribute_t
*uri
) /* I - Printer URI */
6845 http_status_t status
; /* Policy status */
6846 ipp_attribute_t
*attr
; /* Current attribute */
6847 const char *dest
; /* Destination */
6848 cups_ptype_t dtype
; /* Destination type (printer/class) */
6849 cups_ptype_t dmask
; /* Destination type mask */
6850 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6851 username
[HTTP_MAX_URI
], /* Username portion of URI */
6852 host
[HTTP_MAX_URI
], /* Host portion of URI */
6853 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6854 int port
; /* Port portion of URI */
6855 int completed
; /* Completed jobs? */
6856 int first_job_id
; /* First job ID */
6857 int limit
; /* Maximum number of jobs to return */
6858 int count
; /* Number of jobs that match */
6859 cupsd_job_t
*job
; /* Current job pointer */
6860 cupsd_printer_t
*printer
; /* Printer */
6861 cups_array_t
*list
; /* Which job list... */
6862 cups_array_t
*ra
; /* Requested attributes array */
6865 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6866 uri
->values
[0].string
.text
);
6869 * Is the destination valid?
6872 if (strcmp(uri
->name
, "printer-uri"))
6874 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request!"));
6878 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6879 sizeof(scheme
), username
, sizeof(username
), host
,
6880 sizeof(host
), &port
, resource
, sizeof(resource
));
6882 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6885 dtype
= (cups_ptype_t
)0;
6886 dmask
= (cups_ptype_t
)0;
6889 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6892 dtype
= (cups_ptype_t
)0;
6893 dmask
= CUPS_PRINTER_CLASS
;
6896 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6899 dtype
= CUPS_PRINTER_CLASS
;
6900 dmask
= CUPS_PRINTER_CLASS
;
6903 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6910 send_ipp_status(con
, IPP_NOT_FOUND
,
6911 _("The printer or class was not found."));
6916 dtype
&= CUPS_PRINTER_CLASS
;
6917 dmask
= CUPS_PRINTER_CLASS
;
6926 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6929 send_http_error(con
, status
, printer
);
6933 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6935 send_http_error(con
, status
, NULL
);
6940 * See if the "which-jobs" attribute have been specified...
6943 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6944 IPP_TAG_KEYWORD
)) != NULL
&&
6945 !strcmp(attr
->values
[0].string
.text
, "completed"))
6950 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
6955 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "processing"))
6958 list
= PrintingJobs
;
6967 * See if they want to limit the number of jobs reported...
6970 if ((attr
= ippFindAttribute(con
->request
, "limit",
6971 IPP_TAG_INTEGER
)) != NULL
)
6972 limit
= attr
->values
[0].integer
;
6976 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6977 IPP_TAG_INTEGER
)) != NULL
)
6978 first_job_id
= attr
->values
[0].integer
;
6983 * See if we only want to see jobs for a specific user...
6986 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6987 IPP_TAG_BOOLEAN
)) != NULL
&&
6988 attr
->values
[0].boolean
)
6989 strlcpy(username
, get_username(con
), sizeof(username
));
6993 ra
= create_requested_array(con
->request
);
6996 * OK, build a list of jobs for this printer...
6999 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7000 (limit
<= 0 || count
< limit
) && job
;
7001 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7004 * Filter out jobs that don't match...
7007 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7008 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7009 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7010 job
->username
, job
->state_value
, job
->attrs
);
7012 if (!job
->dest
|| !job
->username
)
7015 if (!job
->dest
|| !job
->username
)
7018 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7019 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7021 if ((job
->dtype
& dmask
) != dtype
&&
7022 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7024 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
7027 if (job
->id
< first_job_id
)
7034 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d!",
7039 if (username
[0] && strcasecmp(username
, job
->username
))
7043 ippAddSeparator(con
->response
);
7047 copy_job_attrs(con
, job
, ra
);
7050 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7052 cupsArrayDelete(ra
);
7054 con
->response
->request
.status
.status_code
= IPP_OK
;
7059 * 'get_notifications()' - Get events for a subscription.
7063 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7065 int i
, j
; /* Looping vars */
7066 http_status_t status
; /* Policy status */
7067 cupsd_subscription_t
*sub
; /* Subscription */
7068 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7069 *sequences
; /* notify-sequence-numbers */
7070 int min_seq
; /* Minimum sequence number */
7071 int interval
; /* Poll interval */
7074 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7078 * Get subscription attributes...
7081 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7083 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7088 send_ipp_status(con
, IPP_BAD_REQUEST
,
7089 _("Missing notify-subscription-ids attribute!"));
7094 * Are the subscription IDs valid?
7097 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7099 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7102 * Bad subscription ID...
7105 send_ipp_status(con
, IPP_NOT_FOUND
,
7106 _("notify-subscription-id %d no good!"),
7107 ids
->values
[i
].integer
);
7115 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7117 con
, sub
->owner
)) != HTTP_OK
)
7119 send_http_error(con
, status
, sub
->dest
);
7124 * Check the subscription type and update the interval accordingly.
7127 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7130 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7132 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7138 * Tell the client to poll again in N seconds...
7142 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7143 "notify-get-interval", interval
);
7145 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7146 "printer-up-time", time(NULL
));
7149 * Copy the subscription event attributes to the response.
7152 con
->response
->request
.status
.status_code
=
7153 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7155 for (i
= 0; i
< ids
->num_values
; i
++)
7158 * Get the subscription and sequence number...
7161 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7163 if (sequences
&& i
< sequences
->num_values
)
7164 min_seq
= sequences
->values
[i
].integer
;
7169 * If we don't have any new events, nothing to do here...
7172 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7176 * Otherwise copy all of the new events...
7179 if (sub
->first_event_id
> min_seq
)
7182 j
= min_seq
- sub
->first_event_id
;
7184 for (; j
< sub
->num_events
; j
++)
7186 ippAddSeparator(con
->response
);
7188 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7189 IPP_TAG_EVENT_NOTIFICATION
, 0);
7196 * 'get_ppd()' - Get a named PPD from the local system.
7200 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7201 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7203 http_status_t status
; /* Policy status */
7204 cupsd_printer_t
*dest
; /* Destination */
7205 cups_ptype_t dtype
; /* Destination type */
7208 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7209 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7211 if (!strcmp(uri
->name
, "ppd-name"))
7214 * Return a PPD file from cups-driverd...
7217 char command
[1024], /* cups-driverd command */
7218 options
[1024], /* Options to pass to command */
7219 ppd_name
[1024]; /* ppd-name */
7226 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7228 send_http_error(con
, status
, NULL
);
7233 * Run cups-driverd command with the given options...
7236 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7237 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7238 snprintf(options
, sizeof(options
), "get+%d+%s",
7239 con
->request
->request
.op
.request_id
, ppd_name
);
7241 if (cupsdSendCommand(con
, command
, options
, 0))
7244 * Command started successfully, don't send an IPP response here...
7247 ippDelete(con
->response
);
7248 con
->response
= NULL
;
7253 * Command failed, return "internal error" so the user knows something
7257 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7258 _("cups-driverd failed to execute."));
7261 else if (!strcmp(uri
->name
, "printer-uri") &&
7262 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7264 int i
; /* Looping var */
7265 char filename
[1024]; /* PPD filename */
7272 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7274 send_http_error(con
, status
, dest
);
7279 * See if we need the PPD for a class or remote printer...
7282 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7285 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7287 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7288 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7289 "printer-uri", NULL
, dest
->uri
);
7292 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7294 for (i
= 0; i
< dest
->num_printers
; i
++)
7295 if (!(dest
->printers
[i
]->type
&
7296 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7298 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7299 dest
->printers
[i
]->name
);
7301 if (!access(filename
, 0))
7305 if (i
< dest
->num_printers
)
7306 dest
= dest
->printers
[i
];
7309 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7310 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7311 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7317 * Found the printer with the PPD file, now see if there is one...
7320 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7322 send_ipp_status(con
, IPP_NOT_FOUND
,
7323 _("The PPD file \"%s\" could not be opened: %s"),
7324 uri
->values
[0].string
.text
, strerror(errno
));
7328 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7332 con
->response
->request
.status
.status_code
= IPP_OK
;
7335 send_ipp_status(con
, IPP_NOT_FOUND
,
7336 _("The PPD file \"%s\" could not be found."),
7337 uri
->values
[0].string
.text
);
7342 * 'get_ppds()' - Get the list of PPD files on the local system.
7346 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7348 http_status_t status
; /* Policy status */
7349 ipp_attribute_t
*limit
, /* Limit attribute */
7350 *device
, /* ppd-device-id attribute */
7351 *language
, /* ppd-natural-language attribute */
7352 *make
, /* ppd-make attribute */
7353 *model
, /* ppd-make-and-model attribute */
7354 *model_number
, /* ppd-model-number attribute */
7355 *product
, /* ppd-product attribute */
7356 *psversion
, /* ppd-psverion attribute */
7357 *type
, /* ppd-type attribute */
7358 *requested
, /* requested-attributes attribute */
7359 *exclude
, /* exclude-schemes attribute */
7360 *include
; /* include-schemes attribute */
7361 char command
[1024], /* cups-driverd command */
7362 options
[4096], /* Options to pass to command */
7363 device_str
[256],/* Escaped ppd-device-id string */
7365 /* Escaped ppd-natural-language */
7366 make_str
[256], /* Escaped ppd-make string */
7367 model_str
[256], /* Escaped ppd-make-and-model string */
7368 model_number_str
[256],
7369 /* ppd-model-number string */
7371 /* Escaped ppd-product string */
7373 /* Escaped ppd-psversion string */
7374 type_str
[256], /* Escaped ppd-type string */
7376 /* String for requested attributes */
7378 /* String for excluded schemes */
7380 /* String for included schemes */
7383 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7389 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7391 send_http_error(con
, status
, NULL
);
7396 * Run cups-driverd command with the given options...
7399 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7400 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7401 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7403 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7404 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7406 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7408 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7409 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7410 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7411 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7413 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7415 include
= ippFindAttribute(con
->request
, "include-schemes",
7419 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7421 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7424 url_encode_attr(device
, device_str
, sizeof(device_str
));
7426 device_str
[0] = '\0';
7429 url_encode_attr(language
, language_str
, sizeof(language_str
));
7431 language_str
[0] = '\0';
7434 url_encode_attr(make
, make_str
, sizeof(make_str
));
7439 url_encode_attr(model
, model_str
, sizeof(model_str
));
7441 model_str
[0] = '\0';
7444 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7445 model_number
->values
[0].integer
);
7447 model_number_str
[0] = '\0';
7450 url_encode_attr(product
, product_str
, sizeof(product_str
));
7452 product_str
[0] = '\0';
7455 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7457 psversion_str
[0] = '\0';
7460 url_encode_attr(type
, type_str
, sizeof(type_str
));
7465 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7467 exclude_str
[0] = '\0';
7470 url_encode_attr(include
, include_str
, sizeof(include_str
));
7472 include_str
[0] = '\0';
7474 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7475 snprintf(options
, sizeof(options
),
7476 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7477 con
->request
->request
.op
.request_id
,
7478 limit
? limit
->values
[0].integer
: 0,
7480 device
? "%20" : "", device_str
,
7481 language
? "%20" : "", language_str
,
7482 make
? "%20" : "", make_str
,
7483 model
? "%20" : "", model_str
,
7484 model_number
? "%20" : "", model_number_str
,
7485 product
? "%20" : "", product_str
,
7486 psversion
? "%20" : "", psversion_str
,
7487 type
? "%20" : "", type_str
,
7488 exclude_str
[0] ? "%20" : "", exclude_str
,
7489 include_str
[0] ? "%20" : "", include_str
);
7491 if (cupsdSendCommand(con
, command
, options
, 0))
7494 * Command started successfully, don't send an IPP response here...
7497 ippDelete(con
->response
);
7498 con
->response
= NULL
;
7503 * Command failed, return "internal error" so the user knows something
7507 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7508 _("cups-driverd failed to execute."));
7514 * 'get_printer_attrs()' - Get printer attributes.
7518 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7519 ipp_attribute_t
*uri
) /* I - Printer URI */
7521 http_status_t status
; /* Policy status */
7522 cups_ptype_t dtype
; /* Destination type (printer/class) */
7523 cupsd_printer_t
*printer
; /* Printer/class */
7524 cups_array_t
*ra
; /* Requested attributes array */
7527 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7528 con
->http
.fd
, uri
->values
[0].string
.text
);
7531 * Is the destination valid?
7534 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7540 send_ipp_status(con
, IPP_NOT_FOUND
,
7541 _("The printer or class was not found."));
7549 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7551 send_http_error(con
, status
, printer
);
7556 * Send the attributes...
7559 ra
= create_requested_array(con
->request
);
7561 copy_printer_attrs(con
, printer
, ra
);
7563 cupsArrayDelete(ra
);
7565 con
->response
->request
.status
.status_code
= IPP_OK
;
7570 * 'get_printer_supported()' - Get printer supported values.
7574 get_printer_supported(
7575 cupsd_client_t
*con
, /* I - Client connection */
7576 ipp_attribute_t
*uri
) /* I - Printer URI */
7578 http_status_t status
; /* Policy status */
7579 cups_ptype_t dtype
; /* Destination type (printer/class) */
7580 cupsd_printer_t
*printer
; /* Printer/class */
7583 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7584 con
->http
.fd
, uri
->values
[0].string
.text
);
7587 * Is the destination valid?
7590 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7596 send_ipp_status(con
, IPP_NOT_FOUND
,
7597 _("The printer or class was not found."));
7605 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7607 send_http_error(con
, status
, printer
);
7612 * Return a list of attributes that can be set via Set-Printer-Attributes.
7615 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7617 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7618 "printer-location", 0);
7620 con
->response
->request
.status
.status_code
= IPP_OK
;
7625 * 'get_printers()' - Get a list of printers or classes.
7629 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7630 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7632 http_status_t status
; /* Policy status */
7633 ipp_attribute_t
*attr
; /* Current attribute */
7634 int limit
; /* Max number of printers to return */
7635 int count
; /* Number of printers that match */
7636 cupsd_printer_t
*printer
; /* Current printer pointer */
7637 int printer_type
, /* printer-type attribute */
7638 printer_mask
; /* printer-type-mask attribute */
7639 char *location
; /* Location string */
7640 const char *username
; /* Current user */
7641 char *first_printer_name
; /* first-printer-name attribute */
7642 cups_array_t
*ra
; /* Requested attributes array */
7643 int local
; /* Local connection? */
7646 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7647 con
->http
.fd
, type
);
7653 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7655 send_http_error(con
, status
, NULL
);
7660 * Check for printers...
7663 if (!Printers
|| !cupsArrayCount(Printers
))
7665 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7670 * See if they want to limit the number of printers reported...
7673 if ((attr
= ippFindAttribute(con
->request
, "limit",
7674 IPP_TAG_INTEGER
)) != NULL
)
7675 limit
= attr
->values
[0].integer
;
7679 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7680 IPP_TAG_NAME
)) != NULL
)
7681 first_printer_name
= attr
->values
[0].string
.text
;
7683 first_printer_name
= NULL
;
7686 * Support filtering...
7689 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7690 IPP_TAG_ENUM
)) != NULL
)
7691 printer_type
= attr
->values
[0].integer
;
7695 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7696 IPP_TAG_ENUM
)) != NULL
)
7697 printer_mask
= attr
->values
[0].integer
;
7701 local
= httpAddrLocalhost(&(con
->clientaddr
));
7703 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7704 IPP_TAG_TEXT
)) != NULL
)
7705 location
= attr
->values
[0].string
.text
;
7709 if (con
->username
[0])
7710 username
= con
->username
;
7711 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7712 IPP_TAG_NAME
)) != NULL
)
7713 username
= attr
->values
[0].string
.text
;
7717 ra
= create_requested_array(con
->request
);
7720 * OK, build a list of printers for this printer...
7723 if (first_printer_name
)
7725 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7726 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7729 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7732 count
< limit
&& printer
;
7733 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7735 if (!local
&& !printer
->shared
)
7738 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7739 (printer
->type
& printer_mask
) == printer_type
&&
7741 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
7744 * If HideImplicitMembers is enabled, see if this printer or class
7745 * is a member of an implicit class...
7748 if (ImplicitClasses
&& HideImplicitMembers
&&
7749 printer
->in_implicit_class
)
7753 * If a username is specified, see if it is allowed or denied
7757 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
7761 * Add the group separator as needed...
7765 ippAddSeparator(con
->response
);
7770 * Send the attributes...
7773 copy_printer_attrs(con
, printer
, ra
);
7777 cupsArrayDelete(ra
);
7779 con
->response
->request
.status
.status_code
= IPP_OK
;
7784 * 'get_subscription_attrs()' - Get subscription attributes.
7788 get_subscription_attrs(
7789 cupsd_client_t
*con
, /* I - Client connection */
7790 int sub_id
) /* I - Subscription ID */
7792 http_status_t status
; /* Policy status */
7793 cupsd_subscription_t
*sub
; /* Subscription */
7794 cups_array_t
*ra
; /* Requested attributes array */
7797 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7798 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7799 con
, con
->http
.fd
, sub_id
);
7802 * Is the subscription ID valid?
7805 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7808 * Bad subscription ID...
7811 send_ipp_status(con
, IPP_NOT_FOUND
,
7812 _("notify-subscription-id %d no good!"), sub_id
);
7820 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7822 con
, sub
->owner
)) != HTTP_OK
)
7824 send_http_error(con
, status
, sub
->dest
);
7829 * Copy the subscription attributes to the response using the
7830 * requested-attributes attribute that may be provided by the client.
7833 ra
= create_requested_array(con
->request
);
7835 copy_subscription_attrs(con
, sub
, ra
);
7837 cupsArrayDelete(ra
);
7839 con
->response
->request
.status
.status_code
= IPP_OK
;
7844 * 'get_subscriptions()' - Get subscriptions.
7848 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7849 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7851 http_status_t status
; /* Policy status */
7852 int count
; /* Number of subscriptions */
7853 int limit
; /* Limit */
7854 cupsd_subscription_t
*sub
; /* Subscription */
7855 cups_array_t
*ra
; /* Requested attributes array */
7856 ipp_attribute_t
*attr
; /* Attribute */
7857 cups_ptype_t dtype
; /* Destination type (printer/class) */
7858 char scheme
[HTTP_MAX_URI
],
7859 /* Scheme portion of URI */
7860 username
[HTTP_MAX_URI
],
7861 /* Username portion of URI */
7863 /* Host portion of URI */
7864 resource
[HTTP_MAX_URI
];
7865 /* Resource portion of URI */
7866 int port
; /* Port portion of URI */
7867 cupsd_job_t
*job
; /* Job pointer */
7868 cupsd_printer_t
*printer
; /* Printer */
7871 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7872 "get_subscriptions(con=%p[%d], uri=%s)",
7873 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7876 * Is the destination valid?
7879 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7880 sizeof(scheme
), username
, sizeof(username
), host
,
7881 sizeof(host
), &port
, resource
, sizeof(resource
));
7883 if (!strcmp(resource
, "/") ||
7884 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7885 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7886 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7891 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7894 job
= cupsdFindJob(atoi(resource
+ 6));
7898 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
7903 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7909 send_ipp_status(con
, IPP_NOT_FOUND
,
7910 _("The printer or class was not found."));
7913 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7914 IPP_TAG_INTEGER
)) != NULL
)
7916 job
= cupsdFindJob(attr
->values
[0].integer
);
7920 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
7921 attr
->values
[0].integer
);
7932 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
7934 con
, NULL
)) != HTTP_OK
)
7936 send_http_error(con
, status
, printer
);
7941 * Copy the subscription attributes to the response using the
7942 * requested-attributes attribute that may be provided by the client.
7945 ra
= create_requested_array(con
->request
);
7947 if ((attr
= ippFindAttribute(con
->request
, "limit",
7948 IPP_TAG_INTEGER
)) != NULL
)
7949 limit
= attr
->values
[0].integer
;
7954 * See if we only want to see subscriptions for a specific user...
7957 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7958 IPP_TAG_BOOLEAN
)) != NULL
&&
7959 attr
->values
[0].boolean
)
7960 strlcpy(username
, get_username(con
), sizeof(username
));
7964 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7966 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7967 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7968 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
7970 ippAddSeparator(con
->response
);
7971 copy_subscription_attrs(con
, sub
, ra
);
7974 if (limit
&& count
>= limit
)
7978 cupsArrayDelete(ra
);
7981 con
->response
->request
.status
.status_code
= IPP_OK
;
7983 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7988 * 'get_username()' - Get the username associated with a request.
7991 static const char * /* O - Username */
7992 get_username(cupsd_client_t
*con
) /* I - Connection */
7994 ipp_attribute_t
*attr
; /* Attribute */
7997 if (con
->username
[0])
7998 return (con
->username
);
7999 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8000 IPP_TAG_NAME
)) != NULL
)
8001 return (attr
->values
[0].string
.text
);
8003 return ("anonymous");
8008 * 'hold_job()' - Hold a print job.
8012 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8013 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8015 ipp_attribute_t
*attr
; /* Current job-hold-until */
8016 const char *when
; /* New value */
8017 int jobid
; /* Job ID */
8018 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8019 username
[HTTP_MAX_URI
], /* Username portion of URI */
8020 host
[HTTP_MAX_URI
], /* Host portion of URI */
8021 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8022 int port
; /* Port portion of URI */
8023 cupsd_job_t
*job
; /* Job information */
8026 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8027 uri
->values
[0].string
.text
);
8030 * See if we have a job URI or a printer URI...
8033 if (!strcmp(uri
->name
, "printer-uri"))
8036 * Got a printer URI; see if we also have a job-id attribute...
8039 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8040 IPP_TAG_INTEGER
)) == NULL
)
8042 send_ipp_status(con
, IPP_BAD_REQUEST
,
8043 _("Got a printer-uri attribute but no job-id!"));
8047 jobid
= attr
->values
[0].integer
;
8052 * Got a job URI; parse it to get the job ID...
8055 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8056 sizeof(scheme
), username
, sizeof(username
), host
,
8057 sizeof(host
), &port
, resource
, sizeof(resource
));
8059 if (strncmp(resource
, "/jobs/", 6))
8065 send_ipp_status(con
, IPP_BAD_REQUEST
,
8066 _("Bad job-uri attribute \"%s\"!"),
8067 uri
->values
[0].string
.text
);
8071 jobid
= atoi(resource
+ 6);
8075 * See if the job exists...
8078 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8081 * Nope - return a "not found" error...
8084 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8089 * See if the job is owned by the requesting user...
8092 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8094 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8095 cupsdFindDest(job
->dest
));
8100 * Hold the job and return...
8103 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8104 IPP_TAG_KEYWORD
)) == NULL
)
8105 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8109 when
= attr
->values
[0].string
.text
;
8111 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8112 "Job job-hold-until value changed by user.");
8115 when
= "indefinite";
8117 cupsdSetJobHoldUntil(job
, when
, 1);
8118 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8121 con
->response
->request
.status
.status_code
= IPP_OK
;
8126 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8130 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8131 ipp_attribute_t
*uri
) /* I - Printer URI */
8133 http_status_t status
; /* Policy status */
8134 cups_ptype_t dtype
; /* Destination type (printer/class) */
8135 cupsd_printer_t
*printer
; /* Printer data */
8138 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8139 con
->http
.fd
, uri
->values
[0].string
.text
);
8142 * Is the destination valid?
8145 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8151 send_ipp_status(con
, IPP_NOT_FOUND
,
8152 _("The printer or class was not found."));
8160 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8162 send_http_error(con
, status
, printer
);
8167 * Hold pending/new jobs sent to the printer...
8170 printer
->holding_new_jobs
= 1;
8172 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8173 cupsdAddPrinterHistory(printer
);
8175 if (dtype
& CUPS_PRINTER_CLASS
)
8176 cupsdLogMessage(CUPSD_LOG_INFO
,
8177 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8178 printer
->name
, get_username(con
));
8180 cupsdLogMessage(CUPSD_LOG_INFO
,
8181 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8182 printer
->name
, get_username(con
));
8185 * Everything was ok, so return OK status...
8188 con
->response
->request
.status
.status_code
= IPP_OK
;
8193 * 'move_job()' - Move a job to a new destination.
8197 move_job(cupsd_client_t
*con
, /* I - Client connection */
8198 ipp_attribute_t
*uri
) /* I - Job URI */
8200 http_status_t status
; /* Policy status */
8201 ipp_attribute_t
*attr
; /* Current attribute */
8202 int jobid
; /* Job ID */
8203 cupsd_job_t
*job
; /* Current job */
8204 const char *src
; /* Source printer/class */
8205 cups_ptype_t stype
, /* Source type (printer or class) */
8206 dtype
; /* Destination type (printer/class) */
8207 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8208 username
[HTTP_MAX_URI
], /* Username portion of URI */
8209 host
[HTTP_MAX_URI
], /* Host portion of URI */
8210 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8211 int port
; /* Port portion of URI */
8212 cupsd_printer_t
*sprinter
, /* Source printer */
8213 *dprinter
; /* Destination printer */
8216 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8217 uri
->values
[0].string
.text
);
8220 * Get the new printer or class...
8223 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8224 IPP_TAG_URI
)) == NULL
)
8227 * Need job-printer-uri...
8230 send_ipp_status(con
, IPP_BAD_REQUEST
,
8231 _("job-printer-uri attribute missing!"));
8235 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8241 send_ipp_status(con
, IPP_NOT_FOUND
,
8242 _("The printer or class was not found."));
8247 * See if we have a job URI or a printer URI...
8250 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8251 sizeof(scheme
), username
, sizeof(username
), host
,
8252 sizeof(host
), &port
, resource
, sizeof(resource
));
8254 if (!strcmp(uri
->name
, "printer-uri"))
8257 * Got a printer URI; see if we also have a job-id attribute...
8260 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8261 IPP_TAG_INTEGER
)) == NULL
)
8267 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8268 &sprinter
)) == NULL
)
8274 send_ipp_status(con
, IPP_NOT_FOUND
,
8275 _("The printer or class was not found."));
8284 * Otherwise, just move a single job...
8287 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8290 * Nope - return a "not found" error...
8293 send_ipp_status(con
, IPP_NOT_FOUND
,
8294 _("Job #%d does not exist!"), attr
->values
[0].integer
);
8300 * Job found, initialize source pointers...
8311 * Got a job URI; parse it to get the job ID...
8314 if (strncmp(resource
, "/jobs/", 6))
8320 send_ipp_status(con
, IPP_BAD_REQUEST
,
8321 _("Bad job-uri attribute \"%s\"!"),
8322 uri
->values
[0].string
.text
);
8327 * See if the job exists...
8330 jobid
= atoi(resource
+ 6);
8332 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8335 * Nope - return a "not found" error...
8338 send_ipp_status(con
, IPP_NOT_FOUND
,
8339 _("Job #%d does not exist!"), jobid
);
8345 * Job found, initialize source pointers...
8354 * Check the policy of the destination printer...
8357 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8358 job
? job
->username
: NULL
)) != HTTP_OK
)
8360 send_http_error(con
, status
, dprinter
);
8365 * Now move the job or jobs...
8371 * See if the job has been completed...
8374 if (job
->state_value
> IPP_JOB_STOPPED
)
8377 * Return a "not-possible" error...
8380 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8381 _("Job #%d is finished and cannot be altered!"),
8387 * See if the job is owned by the requesting user...
8390 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8392 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8393 cupsdFindDest(job
->dest
));
8398 * Move the job to a different printer or class...
8401 cupsdMoveJob(job
, dprinter
);
8406 * Got the source printer, now look through the jobs...
8409 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8411 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8414 * See if the job is pointing at the source printer or has not been
8418 if (strcasecmp(job
->dest
, src
) ||
8419 job
->state_value
> IPP_JOB_STOPPED
)
8423 * See if the job can be moved by the requesting user...
8426 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8430 * Move the job to a different printer or class...
8433 cupsdMoveJob(job
, dprinter
);
8438 * Start jobs if possible...
8444 * Return with "everything is OK" status...
8447 con
->response
->request
.status
.status_code
= IPP_OK
;
8452 * 'ppd_parse_line()' - Parse a PPD default line.
8455 static int /* O - 0 on success, -1 on failure */
8456 ppd_parse_line(const char *line
, /* I - Line */
8457 char *option
, /* O - Option name */
8458 int olen
, /* I - Size of option name */
8459 char *choice
, /* O - Choice name */
8460 int clen
) /* I - Size of choice name */
8463 * Verify this is a default option line...
8466 if (strncmp(line
, "*Default", 8))
8470 * Read the option name...
8473 for (line
+= 8, olen
--;
8474 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8485 * Skip everything else up to the colon (:)...
8488 while (*line
&& *line
!= ':')
8497 * Now grab the option choice, skipping leading whitespace...
8500 while (isspace(*line
& 255))
8504 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8515 * Return with no errors...
8523 * 'print_job()' - Print a file to a printer or class.
8527 print_job(cupsd_client_t
*con
, /* I - Client connection */
8528 ipp_attribute_t
*uri
) /* I - Printer URI */
8530 ipp_attribute_t
*attr
; /* Current attribute */
8531 ipp_attribute_t
*format
; /* Document-format attribute */
8532 const char *default_format
; /* document-format-default value */
8533 cupsd_job_t
*job
; /* New job */
8534 char filename
[1024]; /* Job filename */
8535 mime_type_t
*filetype
; /* Type of file */
8536 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8537 type
[MIME_MAX_TYPE
], /* Subtype of file */
8538 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8539 /* Textual name of mime type */
8540 cupsd_printer_t
*printer
; /* Printer data */
8541 struct stat fileinfo
; /* File information */
8542 int kbytes
; /* Size of file */
8543 int compression
; /* Document compression */
8546 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8547 uri
->values
[0].string
.text
);
8550 * Validate print file attributes, for now just document-format and
8551 * compression (CUPS only supports "none" and "gzip")...
8554 compression
= CUPS_FILE_NONE
;
8556 if ((attr
= ippFindAttribute(con
->request
, "compression",
8557 IPP_TAG_KEYWORD
)) != NULL
)
8559 if (strcmp(attr
->values
[0].string
.text
, "none")
8561 && strcmp(attr
->values
[0].string
.text
, "gzip")
8562 #endif /* HAVE_LIBZ */
8565 send_ipp_status(con
, IPP_ATTRIBUTES
,
8566 _("Unsupported compression \"%s\"!"),
8567 attr
->values
[0].string
.text
);
8568 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8569 "compression", NULL
, attr
->values
[0].string
.text
);
8574 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8575 compression
= CUPS_FILE_GZIP
;
8576 #endif /* HAVE_LIBZ */
8580 * Do we have a file to print?
8585 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8590 * Is the destination valid?
8593 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8599 send_ipp_status(con
, IPP_NOT_FOUND
,
8600 _("The printer or class was not found."));
8605 * Is it a format we support?
8608 if ((format
= ippFindAttribute(con
->request
, "document-format",
8609 IPP_TAG_MIMETYPE
)) != NULL
)
8612 * Grab format from client...
8615 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8618 send_ipp_status(con
, IPP_BAD_REQUEST
,
8619 _("Could not scan type \"%s\"!"),
8620 format
->values
[0].string
.text
);
8624 else if ((default_format
= cupsGetOption("document-format",
8625 printer
->num_options
,
8626 printer
->options
)) != NULL
)
8629 * Use default document format...
8632 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8634 send_ipp_status(con
, IPP_BAD_REQUEST
,
8635 _("Could not scan type \"%s\"!"),
8646 strcpy(super
, "application");
8647 strcpy(type
, "octet-stream");
8650 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8653 * Auto-type the file...
8656 ipp_attribute_t
*doc_name
; /* document-name attribute */
8659 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8661 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8662 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8663 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8667 filetype
= mimeType(MimeDatabase
, super
, type
);
8669 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8670 filetype
->super
, filetype
->type
);
8673 filetype
= mimeType(MimeDatabase
, super
, type
);
8677 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8680 * Replace the document-format attribute value with the auto-typed or
8684 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8689 _cupsStrFree(format
->values
[0].string
.text
);
8691 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8694 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8695 "document-format", NULL
, mimetype
);
8699 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8700 _("Unsupported format \'%s/%s\'!"), super
, type
);
8701 cupsdLogMessage(CUPSD_LOG_INFO
,
8702 "Hint: Do you have the raw file printing rules enabled?");
8705 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8706 "document-format", NULL
, format
->values
[0].string
.text
);
8712 * Read any embedded job ticket info from PS files...
8715 if (!strcasecmp(filetype
->super
, "application") &&
8716 (!strcasecmp(filetype
->type
, "postscript") ||
8717 !strcasecmp(filetype
->type
, "pdf")))
8718 read_job_ticket(con
);
8721 * Create the job object...
8724 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8728 * Update quota data...
8731 if (stat(con
->filename
, &fileinfo
))
8734 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8736 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8738 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8739 IPP_TAG_INTEGER
)) != NULL
)
8740 attr
->values
[0].integer
+= kbytes
;
8743 * Add the job file...
8746 if (add_file(con
, job
, filetype
, compression
))
8749 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8751 rename(con
->filename
, filename
);
8752 cupsdClearString(&con
->filename
);
8755 * See if we need to add the ending sheet...
8758 if (cupsdTimeoutJob(job
))
8762 * Log and save the job...
8765 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8766 "File of type %s/%s queued by \"%s\".",
8767 filetype
->super
, filetype
->type
, job
->username
);
8768 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8769 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8770 job
->dest
, job
->username
);
8773 * Start the job if possible...
8781 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8783 * This function only gets called when printing a single PDF or PostScript
8784 * file using the Print-Job operation. It doesn't work for Create-Job +
8785 * Send-File, since the job attributes need to be set at job creation
8786 * time for banners to work. The embedded job ticket stuff is here
8787 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8788 * options and IPP attributes which otherwise would be lost.
8790 * The format of a job ticket is simple:
8792 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8794 * %cupsJobTicket: attr1=value1
8795 * %cupsJobTicket: attr2=value2
8797 * %cupsJobTicket: attrN=valueN
8799 * Job ticket lines must appear immediately after the first line that
8800 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8801 * stops looking for job ticket info when it finds a line that does not begin
8802 * with "%cupsJobTicket:".
8804 * The maximum length of a job ticket line, including the prefix, is
8805 * 255 characters to conform with the Adobe DSC.
8807 * Read-only attributes are rejected with a notice to the error log in
8808 * case a malicious user tries anything. Since the job ticket is read
8809 * prior to attribute validation in print_job(), job ticket attributes
8810 * will go through the same validation as IPP attributes...
8814 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8816 cups_file_t
*fp
; /* File to read from */
8817 char line
[256]; /* Line data */
8818 int num_options
; /* Number of options */
8819 cups_option_t
*options
; /* Options */
8820 ipp_t
*ticket
; /* New attributes */
8821 ipp_attribute_t
*attr
, /* Current attribute */
8822 *attr2
, /* Job attribute */
8823 *prev2
; /* Previous job attribute */
8827 * First open the print file...
8830 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8832 cupsdLogMessage(CUPSD_LOG_ERROR
,
8833 "Unable to open print file for job ticket - %s",
8839 * Skip the first line...
8842 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8844 cupsdLogMessage(CUPSD_LOG_ERROR
,
8845 "Unable to read from print file for job ticket - %s",
8851 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8854 * Not a DSC-compliant file, so no job ticket info will be available...
8862 * Read job ticket info from the file...
8868 while (cupsFileGets(fp
, line
, sizeof(line
)))
8871 * Stop at the first non-ticket line...
8874 if (strncmp(line
, "%cupsJobTicket:", 15))
8878 * Add the options to the option array...
8881 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8885 * Done with the file; see if we have any options...
8890 if (num_options
== 0)
8894 * OK, convert the options to an attribute list, and apply them to
8899 cupsEncodeOptions(ticket
, num_options
, options
);
8902 * See what the user wants to change.
8905 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8907 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8910 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8911 !strcmp(attr
->name
, "job-originating-user-name") ||
8912 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8913 !strcmp(attr
->name
, "job-k-octets") ||
8914 !strcmp(attr
->name
, "job-id") ||
8915 !strncmp(attr
->name
, "job-state", 9) ||
8916 !strncmp(attr
->name
, "time-at-", 8))
8917 continue; /* Read-only attrs */
8919 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8920 IPP_TAG_ZERO
)) != NULL
)
8923 * Some other value; first free the old value...
8926 if (con
->request
->attrs
== attr2
)
8928 con
->request
->attrs
= attr2
->next
;
8933 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8934 if (prev2
->next
== attr2
)
8936 prev2
->next
= attr2
->next
;
8941 if (con
->request
->last
== attr2
)
8942 con
->request
->last
= prev2
;
8944 _ippFreeAttr(attr2
);
8948 * Add new option by copying it...
8951 copy_attribute(con
->request
, attr
, 0);
8955 * Then free the attribute list and option array...
8959 cupsFreeOptions(num_options
, options
);
8964 * 'reject_jobs()' - Reject print jobs to a printer.
8968 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8969 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8971 http_status_t status
; /* Policy status */
8972 cups_ptype_t dtype
; /* Destination type (printer/class) */
8973 cupsd_printer_t
*printer
; /* Printer data */
8974 ipp_attribute_t
*attr
; /* printer-state-message text */
8977 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8978 con
->http
.fd
, uri
->values
[0].string
.text
);
8981 * Is the destination valid?
8984 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8990 send_ipp_status(con
, IPP_NOT_FOUND
,
8991 _("The printer or class was not found."));
8999 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9001 send_http_error(con
, status
, printer
);
9006 * Reject jobs sent to the printer...
9009 printer
->accepting
= 0;
9011 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9012 IPP_TAG_TEXT
)) == NULL
)
9013 strcpy(printer
->state_message
, "Rejecting Jobs");
9015 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9016 sizeof(printer
->state_message
));
9018 cupsdAddPrinterHistory(printer
);
9020 if (dtype
& CUPS_PRINTER_CLASS
)
9022 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9024 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9025 printer
->name
, get_username(con
));
9029 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9031 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9032 printer
->name
, get_username(con
));
9036 * Everything was ok, so return OK status...
9039 con
->response
->request
.status
.status_code
= IPP_OK
;
9044 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9048 release_held_new_jobs(
9049 cupsd_client_t
*con
, /* I - Connection */
9050 ipp_attribute_t
*uri
) /* I - Printer URI */
9052 http_status_t status
; /* Policy status */
9053 cups_ptype_t dtype
; /* Destination type (printer/class) */
9054 cupsd_printer_t
*printer
; /* Printer data */
9057 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9058 con
->http
.fd
, uri
->values
[0].string
.text
);
9061 * Is the destination valid?
9064 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9070 send_ipp_status(con
, IPP_NOT_FOUND
,
9071 _("The printer or class was not found."));
9079 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9081 send_http_error(con
, status
, printer
);
9086 * Hold pending/new jobs sent to the printer...
9089 printer
->holding_new_jobs
= 0;
9091 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9092 cupsdAddPrinterHistory(printer
);
9094 if (dtype
& CUPS_PRINTER_CLASS
)
9095 cupsdLogMessage(CUPSD_LOG_INFO
,
9096 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9097 printer
->name
, get_username(con
));
9099 cupsdLogMessage(CUPSD_LOG_INFO
,
9100 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9101 printer
->name
, get_username(con
));
9104 * Everything was ok, so return OK status...
9107 con
->response
->request
.status
.status_code
= IPP_OK
;
9112 * 'release_job()' - Release a held print job.
9116 release_job(cupsd_client_t
*con
, /* I - Client connection */
9117 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9119 ipp_attribute_t
*attr
; /* Current attribute */
9120 int jobid
; /* Job ID */
9121 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9122 username
[HTTP_MAX_URI
], /* Username portion of URI */
9123 host
[HTTP_MAX_URI
], /* Host portion of URI */
9124 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9125 int port
; /* Port portion of URI */
9126 cupsd_job_t
*job
; /* Job information */
9129 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9130 con
->http
.fd
, uri
->values
[0].string
.text
);
9133 * See if we have a job URI or a printer URI...
9136 if (!strcmp(uri
->name
, "printer-uri"))
9139 * Got a printer URI; see if we also have a job-id attribute...
9142 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9143 IPP_TAG_INTEGER
)) == NULL
)
9145 send_ipp_status(con
, IPP_BAD_REQUEST
,
9146 _("Got a printer-uri attribute but no job-id!"));
9150 jobid
= attr
->values
[0].integer
;
9155 * Got a job URI; parse it to get the job ID...
9158 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9159 sizeof(scheme
), username
, sizeof(username
), host
,
9160 sizeof(host
), &port
, resource
, sizeof(resource
));
9162 if (strncmp(resource
, "/jobs/", 6))
9168 send_ipp_status(con
, IPP_BAD_REQUEST
,
9169 _("Bad job-uri attribute \"%s\"!"),
9170 uri
->values
[0].string
.text
);
9174 jobid
= atoi(resource
+ 6);
9178 * See if the job exists...
9181 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9184 * Nope - return a "not found" error...
9187 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9192 * See if job is "held"...
9195 if (job
->state_value
!= IPP_JOB_HELD
)
9198 * Nope - return a "not possible" error...
9201 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
9206 * See if the job is owned by the requesting user...
9209 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9211 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9212 cupsdFindDest(job
->dest
));
9217 * Reset the job-hold-until value to "no-hold"...
9220 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9221 IPP_TAG_KEYWORD
)) == NULL
)
9222 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9226 _cupsStrFree(attr
->values
[0].string
.text
);
9228 attr
->value_tag
= IPP_TAG_KEYWORD
;
9229 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9231 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9232 "Job job-hold-until value changed by user.");
9236 * Release the job and return...
9239 cupsdReleaseJob(job
);
9241 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9242 "Job released by user.");
9244 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9246 con
->response
->request
.status
.status_code
= IPP_OK
;
9253 * 'renew_subscription()' - Renew an existing subscription...
9258 cupsd_client_t
*con
, /* I - Client connection */
9259 int sub_id
) /* I - Subscription ID */
9261 http_status_t status
; /* Policy status */
9262 cupsd_subscription_t
*sub
; /* Subscription */
9263 ipp_attribute_t
*lease
; /* notify-lease-duration */
9266 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9267 "renew_subscription(con=%p[%d], sub_id=%d)",
9268 con
, con
->http
.fd
, sub_id
);
9271 * Is the subscription ID valid?
9274 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9277 * Bad subscription ID...
9280 send_ipp_status(con
, IPP_NOT_FOUND
,
9281 _("notify-subscription-id %d no good!"), sub_id
);
9288 * Job subscriptions cannot be renewed...
9291 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9292 _("Job subscriptions cannot be renewed!"));
9300 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9302 con
, sub
->owner
)) != HTTP_OK
)
9304 send_http_error(con
, status
, sub
->dest
);
9309 * Renew the subscription...
9312 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9315 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9317 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9319 cupsdLogMessage(CUPSD_LOG_INFO
,
9320 "renew_subscription: Limiting notify-lease-duration to "
9323 sub
->lease
= MaxLeaseDuration
;
9326 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9328 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9330 con
->response
->request
.status
.status_code
= IPP_OK
;
9332 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9333 "notify-lease-duration", sub
->lease
);
9338 * 'restart_job()' - Restart an old print job.
9342 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9343 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9345 ipp_attribute_t
*attr
; /* Current attribute */
9346 int jobid
; /* Job ID */
9347 cupsd_job_t
*job
; /* Job information */
9348 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9349 username
[HTTP_MAX_URI
], /* Username portion of URI */
9350 host
[HTTP_MAX_URI
], /* Host portion of URI */
9351 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9352 int port
; /* Port portion of URI */
9355 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9356 con
->http
.fd
, uri
->values
[0].string
.text
);
9359 * See if we have a job URI or a printer URI...
9362 if (!strcmp(uri
->name
, "printer-uri"))
9365 * Got a printer URI; see if we also have a job-id attribute...
9368 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9369 IPP_TAG_INTEGER
)) == NULL
)
9371 send_ipp_status(con
, IPP_BAD_REQUEST
,
9372 _("Got a printer-uri attribute but no job-id!"));
9376 jobid
= attr
->values
[0].integer
;
9381 * Got a job URI; parse it to get the job ID...
9384 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9385 sizeof(scheme
), username
, sizeof(username
), host
,
9386 sizeof(host
), &port
, resource
, sizeof(resource
));
9388 if (strncmp(resource
, "/jobs/", 6))
9394 send_ipp_status(con
, IPP_BAD_REQUEST
,
9395 _("Bad job-uri attribute \"%s\"!"),
9396 uri
->values
[0].string
.text
);
9400 jobid
= atoi(resource
+ 6);
9404 * See if the job exists...
9407 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9410 * Nope - return a "not found" error...
9413 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9418 * See if job is in any of the "completed" states...
9421 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9424 * Nope - return a "not possible" error...
9427 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
9433 * See if we have retained the job files...
9438 if (!job
->attrs
|| job
->num_files
== 0)
9441 * Nope - return a "not possible" error...
9444 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9445 _("Job #%d cannot be restarted - no files!"), jobid
);
9450 * See if the job is owned by the requesting user...
9453 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9455 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9456 cupsdFindDest(job
->dest
));
9461 * See if the job-hold-until attribute is specified...
9464 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9465 IPP_TAG_KEYWORD
)) == NULL
)
9466 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9468 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9471 * Return the job to a held state...
9474 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9475 "Restarted by \"%s\" with job-hold-until=%s.",
9476 username
, attr
->values
[0].string
.text
);
9477 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9479 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9480 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9481 attr
->values
[0].string
.text
);
9486 * Restart the job...
9489 cupsdRestartJob(job
);
9493 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9495 con
->response
->request
.status
.status_code
= IPP_OK
;
9500 * 'save_auth_info()' - Save authentication information for a job.
9505 cupsd_client_t
*con
, /* I - Client connection */
9506 cupsd_job_t
*job
, /* I - Job */
9507 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9509 int i
; /* Looping var */
9510 char filename
[1024]; /* Job authentication filename */
9511 cups_file_t
*fp
; /* Job authentication file */
9512 char line
[2048]; /* Line for file */
9513 cupsd_printer_t
*dest
; /* Destination printer/class */
9517 * This function saves the in-memory authentication information for
9518 * a job so that it can be used to authenticate with a remote host.
9519 * The information is stored in a file that is readable only by the
9520 * root user. The fields are Base-64 encoded, each on a separate line,
9521 * followed by random number (up to 1024) of newlines to limit the
9522 * amount of information that is exposed.
9524 * Because of the potential for exposing of authentication information,
9525 * this functionality is only enabled when running cupsd as root.
9527 * This caching only works for the Basic and BasicDigest authentication
9528 * types. Digest authentication cannot be cached this way, and in
9529 * the future Kerberos authentication may make all of this obsolete.
9531 * Authentication information is saved whenever an authenticated
9532 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9535 * This information is deleted after a job is completed or canceled,
9536 * so reprints may require subsequent re-authentication.
9542 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9546 * Create the authentication file and change permissions...
9549 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9550 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9552 cupsdLogMessage(CUPSD_LOG_ERROR
,
9553 "Unable to save authentication info to \"%s\" - %s",
9554 filename
, strerror(errno
));
9558 fchown(cupsFileNumber(fp
), 0, 0);
9559 fchmod(cupsFileNumber(fp
), 0400);
9561 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9564 * Write 1 to 3 auth values...
9567 cupsdClearString(&job
->auth_username
);
9568 cupsdClearString(&job
->auth_domain
);
9569 cupsdClearString(&job
->auth_password
);
9571 for (i
= 0; i
< auth_info
->num_values
; i
++)
9573 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9574 strlen(auth_info
->values
[i
].string
.text
));
9575 cupsFilePrintf(fp
, "%s\n", line
);
9577 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9578 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9579 auth_info
->values
[i
].string
.text
);
9580 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9581 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9582 auth_info
->values
[i
].string
.text
);
9583 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9584 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9585 auth_info
->values
[i
].string
.text
);
9588 else if (con
->username
[0])
9591 * Write the authenticated username...
9594 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9595 cupsFilePrintf(fp
, "%s\n", line
);
9597 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9598 cupsdClearString(&job
->auth_domain
);
9601 * Write the authenticated password...
9604 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9605 cupsFilePrintf(fp
, "%s\n", line
);
9607 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
9611 * Write a random number of newlines to the end of the file...
9614 for (i
= (rand() % 1024); i
>= 0; i
--)
9615 cupsFilePutChar(fp
, '\n');
9618 * Close the file and return...
9623 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9624 # ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
9625 if (con
->have_gss
&&
9626 (con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
|| con
->gss_creds
))
9628 if (con
->have_gss
&& con
->gss_creds
)
9629 # endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
9630 save_krb5_creds(con
, job
);
9631 else if (job
->ccname
)
9632 cupsdClearString(&(job
->ccname
));
9633 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9637 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9639 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
9643 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
9644 cupsd_job_t
*job
) /* I - Job */
9647 * Get the credentials...
9650 job
->ccache
= cupsdCopyKrb5Creds(con
);
9653 * Add the KRB5CCNAME environment variable to the job so that the
9654 * backend can use the credentials when printing.
9659 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
9660 krb5_cc_get_name(KerberosContext
, job
->ccache
));
9662 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
9665 cupsdClearString(&(job
->ccname
));
9667 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9671 * 'send_document()' - Send a file to a printer or class.
9675 send_document(cupsd_client_t
*con
, /* I - Client connection */
9676 ipp_attribute_t
*uri
) /* I - Printer URI */
9678 ipp_attribute_t
*attr
; /* Current attribute */
9679 ipp_attribute_t
*format
; /* Request's document-format attribute */
9680 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9681 const char *default_format
;/* document-format-default value */
9682 int jobid
; /* Job ID number */
9683 cupsd_job_t
*job
; /* Current job */
9684 char job_uri
[HTTP_MAX_URI
],
9686 scheme
[HTTP_MAX_URI
],
9687 /* Method portion of URI */
9688 username
[HTTP_MAX_URI
],
9689 /* Username portion of URI */
9691 /* Host portion of URI */
9692 resource
[HTTP_MAX_URI
];
9693 /* Resource portion of URI */
9694 int port
; /* Port portion of URI */
9695 mime_type_t
*filetype
; /* Type of file */
9696 char super
[MIME_MAX_SUPER
],
9697 /* Supertype of file */
9698 type
[MIME_MAX_TYPE
],
9699 /* Subtype of file */
9700 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9701 /* Textual name of mime type */
9702 char filename
[1024]; /* Job filename */
9703 cupsd_printer_t
*printer
; /* Current printer */
9704 struct stat fileinfo
; /* File information */
9705 int kbytes
; /* Size of file */
9706 int compression
; /* Type of compression */
9707 int start_job
; /* Start the job? */
9710 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9711 con
->http
.fd
, uri
->values
[0].string
.text
);
9714 * See if we have a job URI or a printer URI...
9717 if (!strcmp(uri
->name
, "printer-uri"))
9720 * Got a printer URI; see if we also have a job-id attribute...
9723 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9724 IPP_TAG_INTEGER
)) == NULL
)
9726 send_ipp_status(con
, IPP_BAD_REQUEST
,
9727 _("Got a printer-uri attribute but no job-id!"));
9731 jobid
= attr
->values
[0].integer
;
9736 * Got a job URI; parse it to get the job ID...
9739 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9740 sizeof(scheme
), username
, sizeof(username
), host
,
9741 sizeof(host
), &port
, resource
, sizeof(resource
));
9743 if (strncmp(resource
, "/jobs/", 6))
9749 send_ipp_status(con
, IPP_BAD_REQUEST
,
9750 _("Bad job-uri attribute \"%s\"!"),
9751 uri
->values
[0].string
.text
);
9755 jobid
= atoi(resource
+ 6);
9759 * See if the job exists...
9762 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9765 * Nope - return a "not found" error...
9768 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9772 printer
= cupsdFindDest(job
->dest
);
9775 * See if the job is owned by the requesting user...
9778 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9780 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9781 cupsdFindDest(job
->dest
));
9786 * OK, see if the client is sending the document compressed - CUPS
9787 * only supports "none" and "gzip".
9790 compression
= CUPS_FILE_NONE
;
9792 if ((attr
= ippFindAttribute(con
->request
, "compression",
9793 IPP_TAG_KEYWORD
)) != NULL
)
9795 if (strcmp(attr
->values
[0].string
.text
, "none")
9797 && strcmp(attr
->values
[0].string
.text
, "gzip")
9798 #endif /* HAVE_LIBZ */
9801 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
9802 attr
->values
[0].string
.text
);
9803 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9804 "compression", NULL
, attr
->values
[0].string
.text
);
9809 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9810 compression
= CUPS_FILE_GZIP
;
9811 #endif /* HAVE_LIBZ */
9815 * Do we have a file to print?
9820 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
9825 * Is it a format we support?
9828 if ((format
= ippFindAttribute(con
->request
, "document-format",
9829 IPP_TAG_MIMETYPE
)) != NULL
)
9832 * Grab format from client...
9835 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9838 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9839 format
->values
[0].string
.text
);
9843 else if ((default_format
= cupsGetOption("document-format",
9844 printer
->num_options
,
9845 printer
->options
)) != NULL
)
9848 * Use default document format...
9851 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9853 send_ipp_status(con
, IPP_BAD_REQUEST
,
9854 _("Could not scan type \"%s\"!"),
9862 * No document format attribute? Auto-type it!
9865 strcpy(super
, "application");
9866 strcpy(type
, "octet-stream");
9869 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9872 * Auto-type the file...
9875 ipp_attribute_t
*doc_name
; /* document-name attribute */
9878 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9880 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9881 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9882 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9886 filetype
= mimeType(MimeDatabase
, super
, type
);
9888 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9889 filetype
->super
, filetype
->type
);
9892 filetype
= mimeType(MimeDatabase
, super
, type
);
9897 * Replace the document-format attribute value with the auto-typed or
9901 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9904 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9905 IPP_TAG_MIMETYPE
)) != NULL
)
9907 _cupsStrFree(jformat
->values
[0].string
.text
);
9909 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9912 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9913 "document-format", NULL
, mimetype
);
9917 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9918 _("Unsupported format \'%s/%s\'!"), super
, type
);
9919 cupsdLogMessage(CUPSD_LOG_INFO
,
9920 "Hint: Do you have the raw file printing rules enabled?");
9923 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9924 "document-format", NULL
, format
->values
[0].string
.text
);
9929 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9931 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9934 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9935 _("Unsupported format \'%s\'!"), mimetype
);
9937 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9938 "document-format", NULL
, mimetype
);
9944 * Add the file to the job...
9949 if (add_file(con
, job
, filetype
, compression
))
9952 if (stat(con
->filename
, &fileinfo
))
9955 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9957 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9959 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9960 IPP_TAG_INTEGER
)) != NULL
)
9961 attr
->values
[0].integer
+= kbytes
;
9963 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9965 rename(con
->filename
, filename
);
9967 cupsdClearString(&con
->filename
);
9969 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9970 filetype
->super
, filetype
->type
, job
->username
);
9973 * Start the job if this is the last document...
9976 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9977 IPP_TAG_BOOLEAN
)) != NULL
&&
9978 attr
->values
[0].boolean
)
9981 * See if we need to add the ending sheet...
9984 if (cupsdTimeoutJob(job
))
9987 if (job
->state_value
== IPP_JOB_STOPPED
)
9989 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9990 job
->state_value
= IPP_JOB_PENDING
;
9992 else if (job
->state_value
== IPP_JOB_HELD
)
9994 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9995 IPP_TAG_KEYWORD
)) == NULL
)
9996 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9998 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10000 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10001 job
->state_value
= IPP_JOB_PENDING
;
10006 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10012 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10013 IPP_TAG_KEYWORD
)) == NULL
)
10014 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10016 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10018 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10019 job
->state_value
= IPP_JOB_HELD
;
10020 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10023 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10030 * Fill in the response info...
10033 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10036 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10039 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10041 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10043 add_job_state_reasons(con
, job
);
10045 con
->response
->request
.status
.status_code
= IPP_OK
;
10048 * Start the job if necessary...
10057 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10062 cupsd_client_t
*con
, /* I - Client connection */
10063 http_status_t status
, /* I - HTTP status code */
10064 cupsd_printer_t
*printer
) /* I - Printer, if any */
10066 ipp_attribute_t
*uri
; /* Request URI, if any */
10069 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10070 IPP_TAG_URI
)) == NULL
)
10071 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10073 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10074 "Returning HTTP %s for %s (%s) from %s",
10075 httpStatus(status
),
10076 ippOpString(con
->request
->request
.op
.operation_id
),
10077 uri
? uri
->values
[0].string
.text
: "no URI",
10078 con
->http
.hostname
);
10082 int auth_type
; /* Type of authentication required */
10085 auth_type
= CUPSD_AUTH_NONE
;
10087 if (status
== HTTP_UNAUTHORIZED
&&
10088 printer
->num_auth_info_required
> 0 &&
10089 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10091 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10092 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10093 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10096 * Creating and authenticating jobs requires Kerberos...
10099 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10104 * Use policy/location-defined authentication requirements...
10107 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10108 cupsd_location_t
*auth
; /* Pointer to authentication element */
10111 if (printer
->type
& CUPS_PRINTER_CLASS
)
10112 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10114 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10116 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10117 auth
->type
== CUPSD_AUTH_NONE
)
10118 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10120 con
->request
->request
.op
.operation_id
:
10125 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10126 auth_type
= DefaultAuthType
;
10128 auth_type
= auth
->type
;
10132 cupsdSendError(con
, status
, auth_type
);
10135 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10137 ippDelete(con
->response
);
10138 con
->response
= NULL
;
10145 * 'send_ipp_status()' - Send a status back to the IPP client.
10149 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10150 ipp_status_t status
, /* I - IPP status code */
10151 const char *message
,/* I - Status message */
10152 ...) /* I - Additional args as needed */
10154 va_list ap
; /* Pointer to additional args */
10155 char formatted
[1024]; /* Formatted errror message */
10158 va_start(ap
, message
);
10159 vsnprintf(formatted
, sizeof(formatted
),
10160 _cupsLangString(con
->language
, message
), ap
);
10163 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10164 ippOpString(con
->request
->request
.op
.operation_id
),
10165 ippErrorString(status
), formatted
);
10167 con
->response
->request
.status
.status_code
= status
;
10169 if (ippFindAttribute(con
->response
, "attributes-charset",
10170 IPP_TAG_ZERO
) == NULL
)
10171 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10172 "attributes-charset", NULL
, DefaultCharset
);
10174 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10175 IPP_TAG_ZERO
) == NULL
)
10176 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10177 "attributes-natural-language", NULL
, DefaultLanguage
);
10179 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10180 "status-message", NULL
, formatted
);
10185 * 'set_default()' - Set the default destination...
10189 set_default(cupsd_client_t
*con
, /* I - Client connection */
10190 ipp_attribute_t
*uri
) /* I - Printer URI */
10192 http_status_t status
; /* Policy status */
10193 cups_ptype_t dtype
; /* Destination type (printer/class) */
10194 cupsd_printer_t
*printer
, /* Printer */
10195 *oldprinter
; /* Old default printer */
10198 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10199 con
->http
.fd
, uri
->values
[0].string
.text
);
10202 * Is the destination valid?
10205 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10211 send_ipp_status(con
, IPP_NOT_FOUND
,
10212 _("The printer or class was not found."));
10220 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10222 send_http_error(con
, status
, NULL
);
10227 * Set it as the default...
10230 oldprinter
= DefaultPrinter
;
10231 DefaultPrinter
= printer
;
10234 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10235 "%s is no longer the default printer.", oldprinter
->name
);
10237 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10238 "%s is now the default printer.", printer
->name
);
10240 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10241 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10243 cupsdLogMessage(CUPSD_LOG_INFO
,
10244 "Default destination set to \"%s\" by \"%s\".",
10245 printer
->name
, get_username(con
));
10248 * Everything was ok, so return OK status...
10251 con
->response
->request
.status
.status_code
= IPP_OK
;
10256 * 'set_job_attrs()' - Set job attributes.
10260 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10261 ipp_attribute_t
*uri
) /* I - Job URI */
10263 ipp_attribute_t
*attr
, /* Current attribute */
10264 *attr2
; /* Job attribute */
10265 int jobid
; /* Job ID */
10266 cupsd_job_t
*job
; /* Current job */
10267 char scheme
[HTTP_MAX_URI
],
10268 /* Method portion of URI */
10269 username
[HTTP_MAX_URI
],
10270 /* Username portion of URI */
10271 host
[HTTP_MAX_URI
],
10272 /* Host portion of URI */
10273 resource
[HTTP_MAX_URI
];
10274 /* Resource portion of URI */
10275 int port
; /* Port portion of URI */
10276 int event
; /* Events? */
10277 int check_jobs
; /* Check jobs? */
10280 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10281 con
->http
.fd
, uri
->values
[0].string
.text
);
10284 * Start with "everything is OK" status...
10287 con
->response
->request
.status
.status_code
= IPP_OK
;
10290 * See if we have a job URI or a printer URI...
10293 if (!strcmp(uri
->name
, "printer-uri"))
10296 * Got a printer URI; see if we also have a job-id attribute...
10299 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10300 IPP_TAG_INTEGER
)) == NULL
)
10302 send_ipp_status(con
, IPP_BAD_REQUEST
,
10303 _("Got a printer-uri attribute but no job-id!"));
10307 jobid
= attr
->values
[0].integer
;
10312 * Got a job URI; parse it to get the job ID...
10315 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10316 sizeof(scheme
), username
, sizeof(username
), host
,
10317 sizeof(host
), &port
, resource
, sizeof(resource
));
10319 if (strncmp(resource
, "/jobs/", 6))
10325 send_ipp_status(con
, IPP_BAD_REQUEST
,
10326 _("Bad job-uri attribute \"%s\"!"),
10327 uri
->values
[0].string
.text
);
10331 jobid
= atoi(resource
+ 6);
10335 * See if the job exists...
10338 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10341 * Nope - return a "not found" error...
10344 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
10349 * See if the job has been completed...
10352 if (job
->state_value
> IPP_JOB_STOPPED
)
10355 * Return a "not-possible" error...
10358 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10359 _("Job #%d is finished and cannot be altered!"), jobid
);
10364 * See if the job is owned by the requesting user...
10367 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10369 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10370 cupsdFindDest(job
->dest
));
10375 * See what the user wants to change.
10383 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10385 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10388 if (!strcmp(attr
->name
, "attributes-charset") ||
10389 !strcmp(attr
->name
, "attributes-natural-language") ||
10390 !strcmp(attr
->name
, "document-compression") ||
10391 !strcmp(attr
->name
, "document-format") ||
10392 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10393 !strcmp(attr
->name
, "job-document-access-errors") ||
10394 !strcmp(attr
->name
, "job-id") ||
10395 !strcmp(attr
->name
, "job-impressions-completed") ||
10396 !strcmp(attr
->name
, "job-k-octets") ||
10397 !strcmp(attr
->name
, "job-originating-host-name") ||
10398 !strcmp(attr
->name
, "job-originating-user-name") ||
10399 !strcmp(attr
->name
, "job-printer-up-time") ||
10400 !strcmp(attr
->name
, "job-printer-uri") ||
10401 !strcmp(attr
->name
, "job-sheets") ||
10402 !strcmp(attr
->name
, "job-state-message") ||
10403 !strcmp(attr
->name
, "job-state-reasons") ||
10404 !strcmp(attr
->name
, "job-uri") ||
10405 !strcmp(attr
->name
, "number-of-documents") ||
10406 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10407 !strcmp(attr
->name
, "output-device-assigned") ||
10408 !strncmp(attr
->name
, "date-time-at-", 13) ||
10409 !strncmp(attr
->name
, "job-k-octets", 12) ||
10410 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10411 !strncmp(attr
->name
, "time-at-", 8))
10417 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10418 _("%s cannot be changed."), attr
->name
);
10420 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10421 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10426 if (!strcmp(attr
->name
, "job-priority"))
10429 * Change the job priority...
10432 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10434 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
10436 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10437 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10439 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10441 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10442 _("Job is completed and cannot be changed."));
10445 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10447 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10448 attr
->values
[0].integer
);
10449 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10452 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10453 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10456 else if (!strcmp(attr
->name
, "job-state"))
10459 * Change the job state...
10462 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10464 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
10466 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10467 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10471 switch (attr
->values
[0].integer
)
10473 case IPP_JOB_PENDING
:
10474 case IPP_JOB_HELD
:
10475 if (job
->state_value
> IPP_JOB_HELD
)
10477 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10478 _("Job state cannot be changed."));
10481 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10483 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10484 attr
->values
[0].integer
);
10485 cupsdSetJobState(job
, attr
->values
[0].integer
,
10487 "Job state changed by \"%s\"", username
);
10492 case IPP_JOB_PROCESSING
:
10493 case IPP_JOB_STOPPED
:
10494 if (job
->state_value
!= attr
->values
[0].integer
)
10496 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10497 _("Job state cannot be changed."));
10502 case IPP_JOB_CANCELED
:
10503 case IPP_JOB_ABORTED
:
10504 case IPP_JOB_COMPLETED
:
10505 if (job
->state_value
> IPP_JOB_PROCESSING
)
10507 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10508 _("Job state cannot be changed."));
10511 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10513 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10514 attr
->values
[0].integer
);
10515 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10517 "Job state changed by \"%s\"", username
);
10524 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10526 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10527 IPP_TAG_ZERO
)) != NULL
)
10530 * Some other value; first free the old value...
10533 if (job
->attrs
->prev
)
10534 job
->attrs
->prev
->next
= attr2
->next
;
10536 job
->attrs
->attrs
= attr2
->next
;
10538 if (job
->attrs
->last
== attr2
)
10539 job
->attrs
->last
= job
->attrs
->prev
;
10541 _ippFreeAttr(attr2
);
10544 * Then copy the attribute...
10547 copy_attribute(job
->attrs
, attr
, 0);
10550 * See if the job-name or job-hold-until is being changed.
10553 if (!strcmp(attr
->name
, "job-hold-until"))
10555 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10556 attr
->values
[0].string
.text
);
10557 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10559 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10561 cupsdReleaseJob(job
);
10565 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10566 "Job held by \"%s\".", username
);
10568 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10571 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10574 * Delete the attribute...
10577 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10578 IPP_TAG_ZERO
)) != NULL
)
10580 if (job
->attrs
->prev
)
10581 job
->attrs
->prev
->next
= attr2
->next
;
10583 job
->attrs
->attrs
= attr2
->next
;
10585 if (attr2
== job
->attrs
->last
)
10586 job
->attrs
->last
= job
->attrs
->prev
;
10588 _ippFreeAttr(attr2
);
10590 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10596 * Add new option by copying it...
10599 copy_attribute(job
->attrs
, attr
, 0);
10601 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10610 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10613 * Send events as needed...
10616 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10617 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10618 cupsdFindDest(job
->dest
), job
,
10619 "Job priority changed by user.");
10621 if (event
& CUPSD_EVENT_JOB_STATE
)
10622 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10623 job
->state_value
== IPP_JOB_HELD
?
10624 "Job held by user." : "Job restarted by user.");
10626 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10627 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10628 "Job options changed by user.");
10631 * Start jobs if possible...
10640 * 'set_printer_attrs()' - Set printer attributes.
10644 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10645 ipp_attribute_t
*uri
) /* I - Printer */
10647 http_status_t status
; /* Policy status */
10648 cups_ptype_t dtype
; /* Destination type (printer/class) */
10649 cupsd_printer_t
*printer
; /* Printer/class */
10650 ipp_attribute_t
*attr
; /* Printer attribute */
10651 int changed
= 0; /* Was anything changed? */
10654 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10655 con
->http
.fd
, uri
->values
[0].string
.text
);
10658 * Is the destination valid?
10661 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10667 send_ipp_status(con
, IPP_NOT_FOUND
,
10668 _("The printer or class was not found."));
10676 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10678 send_http_error(con
, status
, printer
);
10683 * Return a list of attributes that can be set via Set-Printer-Attributes.
10686 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10687 IPP_TAG_TEXT
)) != NULL
)
10689 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10693 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10694 IPP_TAG_TEXT
)) != NULL
)
10696 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10701 * Update the printer attributes and return...
10706 cupsdSetPrinterAttrs(printer
);
10707 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10709 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10710 "Printer \"%s\" description or location changed by \"%s\".",
10711 printer
->name
, get_username(con
));
10713 cupsdLogMessage(CUPSD_LOG_INFO
,
10714 "Printer \"%s\" description or location changed by \"%s\".",
10715 printer
->name
, get_username(con
));
10718 con
->response
->request
.status
.status_code
= IPP_OK
;
10723 * 'set_printer_defaults()' - Set printer default options from a request.
10727 set_printer_defaults(
10728 cupsd_client_t
*con
, /* I - Client connection */
10729 cupsd_printer_t
*printer
) /* I - Printer */
10731 int i
; /* Looping var */
10732 ipp_attribute_t
*attr
; /* Current attribute */
10733 int namelen
; /* Length of attribute name */
10734 char name
[256], /* New attribute name */
10735 value
[256]; /* String version of integer attrs */
10738 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10741 * Skip non-printer attributes...
10744 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10747 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10749 if (!strcmp(attr
->name
, "job-sheets-default"))
10752 * Only allow keywords and names...
10755 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10759 * Only allow job-sheets-default to be set when running without a
10760 * system high classification level...
10763 if (Classification
)
10766 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10768 if (attr
->num_values
> 1)
10769 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10771 cupsdSetString(&printer
->job_sheets
[1], "none");
10773 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10775 cupsdFreePrinterUsers(printer
);
10777 printer
->deny_users
= 0;
10779 if (attr
->value_tag
== IPP_TAG_NAME
&&
10780 (attr
->num_values
> 1 ||
10781 strcmp(attr
->values
[0].string
.text
, "all")))
10783 for (i
= 0; i
< attr
->num_values
; i
++)
10784 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10787 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10789 cupsdFreePrinterUsers(printer
);
10791 printer
->deny_users
= 1;
10793 if (attr
->value_tag
== IPP_TAG_NAME
&&
10794 (attr
->num_values
> 1 ||
10795 strcmp(attr
->values
[0].string
.text
, "none")))
10797 for (i
= 0; i
< attr
->num_values
; i
++)
10798 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10801 else if (!strcmp(attr
->name
, "job-quota-period"))
10803 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10806 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10807 attr
->values
[0].integer
);
10808 cupsdFreeQuotas(printer
);
10810 printer
->quota_period
= attr
->values
[0].integer
;
10812 else if (!strcmp(attr
->name
, "job-k-limit"))
10814 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10817 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10818 attr
->values
[0].integer
);
10819 cupsdFreeQuotas(printer
);
10821 printer
->k_limit
= attr
->values
[0].integer
;
10823 else if (!strcmp(attr
->name
, "job-page-limit"))
10825 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10828 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10829 attr
->values
[0].integer
);
10830 cupsdFreeQuotas(printer
);
10832 printer
->page_limit
= attr
->values
[0].integer
;
10834 else if (!strcmp(attr
->name
, "printer-op-policy"))
10836 cupsd_policy_t
*p
; /* Policy */
10839 if (attr
->value_tag
!= IPP_TAG_NAME
)
10842 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10844 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10845 "Setting printer-op-policy to \"%s\"...",
10846 attr
->values
[0].string
.text
);
10847 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10848 printer
->op_policy_ptr
= p
;
10852 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10853 _("Unknown printer-op-policy \"%s\"."),
10854 attr
->values
[0].string
.text
);
10858 else if (!strcmp(attr
->name
, "printer-error-policy"))
10860 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10863 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10864 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
10865 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10866 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10867 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10869 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10870 _("Unknown printer-error-policy \"%s\"."),
10871 attr
->values
[0].string
.text
);
10875 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10876 "Setting printer-error-policy to \"%s\"...",
10877 attr
->values
[0].string
.text
);
10878 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10882 * Skip any other non-default attributes...
10885 namelen
= strlen(attr
->name
);
10886 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10887 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10891 * OK, anything else must be a user-defined default...
10894 strlcpy(name
, attr
->name
, sizeof(name
));
10895 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10897 switch (attr
->value_tag
)
10899 case IPP_TAG_DELETEATTR
:
10900 printer
->num_options
= cupsRemoveOption(name
,
10901 printer
->num_options
,
10902 &(printer
->options
));
10903 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10904 "Deleting %s", attr
->name
);
10907 case IPP_TAG_NAME
:
10908 case IPP_TAG_KEYWORD
:
10910 printer
->num_options
= cupsAddOption(name
,
10911 attr
->values
[0].string
.text
,
10912 printer
->num_options
,
10913 &(printer
->options
));
10914 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10915 "Setting %s to \"%s\"...", attr
->name
,
10916 attr
->values
[0].string
.text
);
10919 case IPP_TAG_BOOLEAN
:
10920 printer
->num_options
= cupsAddOption(name
,
10921 attr
->values
[0].boolean
?
10923 printer
->num_options
,
10924 &(printer
->options
));
10925 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10926 "Setting %s to %s...", attr
->name
,
10927 attr
->values
[0].boolean
? "true" : "false");
10930 case IPP_TAG_INTEGER
:
10931 case IPP_TAG_ENUM
:
10932 sprintf(value
, "%d", attr
->values
[0].integer
);
10933 printer
->num_options
= cupsAddOption(name
, value
,
10934 printer
->num_options
,
10935 &(printer
->options
));
10936 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10937 "Setting %s to %s...", attr
->name
, value
);
10940 case IPP_TAG_RANGE
:
10941 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10942 attr
->values
[0].range
.upper
);
10943 printer
->num_options
= cupsAddOption(name
, value
,
10944 printer
->num_options
,
10945 &(printer
->options
));
10946 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10947 "Setting %s to %s...", attr
->name
, value
);
10950 case IPP_TAG_RESOLUTION
:
10951 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10952 attr
->values
[0].resolution
.yres
,
10953 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10955 printer
->num_options
= cupsAddOption(name
, value
,
10956 printer
->num_options
,
10957 &(printer
->options
));
10958 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10959 "Setting %s to %s...", attr
->name
, value
);
10963 /* Do nothing for other values */
10971 * 'start_printer()' - Start a printer.
10975 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10976 ipp_attribute_t
*uri
) /* I - Printer URI */
10978 http_status_t status
; /* Policy status */
10979 cups_ptype_t dtype
; /* Destination type (printer/class) */
10980 cupsd_printer_t
*printer
; /* Printer data */
10983 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10984 con
->http
.fd
, uri
->values
[0].string
.text
);
10987 * Is the destination valid?
10990 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10996 send_ipp_status(con
, IPP_NOT_FOUND
,
10997 _("The printer or class was not found."));
11005 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11007 send_http_error(con
, status
, printer
);
11012 * Start the printer...
11015 printer
->state_message
[0] = '\0';
11017 cupsdStartPrinter(printer
, 1);
11019 if (dtype
& CUPS_PRINTER_CLASS
)
11020 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11021 printer
->name
, get_username(con
));
11023 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11024 printer
->name
, get_username(con
));
11029 * Everything was ok, so return OK status...
11032 con
->response
->request
.status
.status_code
= IPP_OK
;
11037 * 'stop_printer()' - Stop a printer.
11041 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11042 ipp_attribute_t
*uri
) /* I - Printer URI */
11044 http_status_t status
; /* Policy status */
11045 cups_ptype_t dtype
; /* Destination type (printer/class) */
11046 cupsd_printer_t
*printer
; /* Printer data */
11047 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11050 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11051 con
->http
.fd
, uri
->values
[0].string
.text
);
11054 * Is the destination valid?
11057 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11063 send_ipp_status(con
, IPP_NOT_FOUND
,
11064 _("The printer or class was not found."));
11072 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11074 send_http_error(con
, status
, printer
);
11079 * Stop the printer...
11082 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11083 IPP_TAG_TEXT
)) == NULL
)
11084 strcpy(printer
->state_message
, "Paused");
11087 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11088 sizeof(printer
->state_message
));
11091 cupsdStopPrinter(printer
, 1);
11093 if (dtype
& CUPS_PRINTER_CLASS
)
11094 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11095 printer
->name
, get_username(con
));
11097 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11098 printer
->name
, get_username(con
));
11101 * Everything was ok, so return OK status...
11104 con
->response
->request
.status
.status_code
= IPP_OK
;
11109 * 'url_encode_attr()' - URL-encode a string attribute.
11113 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11114 char *buffer
,/* I - String buffer */
11115 int bufsize
)/* I - Size of buffer */
11117 int i
; /* Looping var */
11118 char *bufptr
, /* Pointer into buffer */
11119 *bufend
; /* End of buffer */
11122 strlcpy(buffer
, attr
->name
, bufsize
);
11123 bufptr
= buffer
+ strlen(buffer
);
11124 bufend
= buffer
+ bufsize
- 1;
11126 for (i
= 0; i
< attr
->num_values
; i
++)
11128 if (bufptr
>= bufend
)
11136 if (bufptr
>= bufend
)
11141 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11142 bufptr
, bufend
- bufptr
+ 1);
11144 if (bufptr
>= bufend
)
11155 * 'url_encode_string()' - URL-encode a string.
11158 static char * /* O - End of string */
11159 url_encode_string(const char *s
, /* I - String */
11160 char *buffer
, /* I - String buffer */
11161 int bufsize
) /* I - Size of buffer */
11163 char *bufptr
, /* Pointer into buffer */
11164 *bufend
; /* End of buffer */
11165 static const char *hex
= "0123456789ABCDEF";
11170 bufend
= buffer
+ bufsize
- 1;
11172 while (*s
&& bufptr
< bufend
)
11174 if (*s
== ' ' || *s
== '%' || *s
== '+')
11176 if (bufptr
>= (bufend
- 2))
11180 *bufptr
++ = hex
[(*s
>> 4) & 15];
11181 *bufptr
++ = hex
[*s
& 15];
11185 else if (*s
== '\'' || *s
== '\\')
11187 if (bufptr
>= (bufend
- 1))
11204 * 'user_allowed()' - See if a user is allowed to print to a queue.
11207 static int /* O - 0 if not allowed, 1 if allowed */
11208 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11209 const char *username
) /* I - Username */
11211 int i
; /* Looping var */
11212 struct passwd
*pw
; /* User password data */
11213 char baseuser
[256], /* Base username */
11214 *baseptr
; /* Pointer to "@" in base username */
11217 if (p
->num_users
== 0)
11220 if (!strcmp(username
, "root"))
11223 if (strchr(username
, '@'))
11226 * Strip @REALM for username check...
11229 strlcpy(baseuser
, username
, sizeof(baseuser
));
11231 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11234 username
= baseuser
;
11237 pw
= getpwnam(username
);
11240 for (i
= 0; i
< p
->num_users
; i
++)
11242 if (p
->users
[i
][0] == '@')
11245 * Check group membership...
11248 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
11251 else if (p
->users
[i
][0] == '#')
11257 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
11260 else if (!strcasecmp(username
, p
->users
[i
]))
11264 return ((i
< p
->num_users
) != p
->deny_users
);
11269 * 'validate_job()' - Validate printer options and destination.
11273 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11274 ipp_attribute_t
*uri
) /* I - Printer URI */
11276 http_status_t status
; /* Policy status */
11277 ipp_attribute_t
*attr
; /* Current attribute */
11278 ipp_attribute_t
*format
; /* Document-format attribute */
11279 cups_ptype_t dtype
; /* Destination type (printer/class) */
11280 char super
[MIME_MAX_SUPER
],
11281 /* Supertype of file */
11282 type
[MIME_MAX_TYPE
];
11283 /* Subtype of file */
11284 cupsd_printer_t
*printer
; /* Printer */
11287 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11288 con
->http
.fd
, uri
->values
[0].string
.text
);
11291 * OK, see if the client is sending the document compressed - CUPS
11292 * doesn't support compression yet...
11295 if ((attr
= ippFindAttribute(con
->request
, "compression",
11296 IPP_TAG_KEYWORD
)) != NULL
&&
11297 !strcmp(attr
->values
[0].string
.text
, "none"))
11299 send_ipp_status(con
, IPP_ATTRIBUTES
,
11300 _("Unsupported compression attribute %s!"),
11301 attr
->values
[0].string
.text
);
11302 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11303 "compression", NULL
, attr
->values
[0].string
.text
);
11308 * Is it a format we support?
11311 if ((format
= ippFindAttribute(con
->request
, "document-format",
11312 IPP_TAG_MIMETYPE
)) != NULL
)
11314 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11317 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
11318 format
->values
[0].string
.text
);
11322 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11323 !mimeType(MimeDatabase
, super
, type
))
11325 cupsdLogMessage(CUPSD_LOG_INFO
,
11326 "Hint: Do you have the raw file printing rules enabled?");
11327 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11328 _("Unsupported format \"%s\"!"),
11329 format
->values
[0].string
.text
);
11330 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11331 "document-format", NULL
, format
->values
[0].string
.text
);
11337 * Is the destination valid?
11340 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11346 send_ipp_status(con
, IPP_NOT_FOUND
,
11347 _("The printer or class was not found."));
11355 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11357 send_http_error(con
, status
, printer
);
11362 * Everything was ok, so return OK status...
11365 con
->response
->request
.status
.status_code
= IPP_OK
;
11370 * 'validate_name()' - Make sure the printer name only contains valid chars.
11373 static int /* O - 0 if name is no good, 1 if good */
11374 validate_name(const char *name
) /* I - Name to check */
11376 const char *ptr
; /* Pointer into name */
11380 * Scan the whole name...
11383 for (ptr
= name
; *ptr
; ptr
++)
11384 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11388 * All the characters are good; validate the length, too...
11391 return ((ptr
- name
) < 128);
11396 * 'validate_user()' - Validate the user for the request.
11399 static int /* O - 1 if permitted, 0 otherwise */
11400 validate_user(cupsd_job_t
*job
, /* I - Job */
11401 cupsd_client_t
*con
, /* I - Client connection */
11402 const char *owner
, /* I - Owner of job/resource */
11403 char *username
, /* O - Authenticated username */
11404 int userlen
) /* I - Length of username */
11406 cupsd_printer_t
*printer
; /* Printer for job */
11409 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11410 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11412 job
->id
, con
? con
->http
.fd
: 0,
11413 owner
? owner
: "(null)", username
, userlen
);
11416 * Validate input...
11419 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11423 * Get the best authenticated username that is available.
11426 strlcpy(username
, get_username(con
), userlen
);
11429 * Check the username against the owner...
11432 printer
= cupsdFindDest(job
->dest
);
11434 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11435 con
, owner
) == HTTP_OK
);
11440 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".