2 * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
4 * IPP routines for the Common UNIX Printing System (CUPS) scheduler.
6 * Copyright 2007-2009 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * This file contains Kerberos support code, copyright 2006 by
12 * These coded instructions, statements, and computer programs are the
13 * property of Apple Inc. and are protected by Federal copyright
14 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 * which should have been included with this file. If this file is
16 * file is missing or damaged, see the license at "http://www.cups.org/".
20 * cupsdProcessIPPRequest() - Process an incoming IPP request.
21 * cupsdTimeoutJob() - Timeout a job waiting on job files.
22 * accept_jobs() - Accept print jobs to a printer.
23 * add_class() - Add a class to the system.
24 * add_file() - Add a file to a job.
25 * add_job() - Add a job to a print queue.
26 * add_job_state_reasons() - Add the "job-state-reasons" attribute based
27 * upon the job and printer state...
28 * add_job_subscriptions() - Add any subscriptions for a job.
29 * add_job_uuid() - Add job-uuid attribute to a job.
30 * add_printer() - Add a printer to the system.
31 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
32 * based upon the printer state...
33 * add_queued_job_count() - Add the "queued-job-count" attribute for the
34 * specified printer or class.
35 * apple_init_profile() - Initialize a color profile.
36 * apple_register_profiles() - Register color profiles for a printer.
37 * apple_unregister_profiles() - Remove color profiles for the specified
39 * apply_printer_defaults() - Apply printer default options to a job.
40 * authenticate_job() - Set job authentication info.
41 * cancel_all_jobs() - Cancel all print jobs.
42 * cancel_job() - Cancel a print job.
43 * cancel_subscription() - Cancel a subscription.
44 * check_quotas() - Check quotas for a printer and user.
45 * check_rss_recipient() - Check that we do not have a duplicate RSS
47 * copy_attribute() - Copy a single attribute.
48 * copy_attrs() - Copy attributes from one request to another.
49 * copy_banner() - Copy a banner file to the requests directory
50 * for the specified job.
51 * copy_file() - Copy a PPD file or interface script...
52 * copy_model() - Copy a PPD model file, substituting default
54 * copy_job_attrs() - Copy job attributes.
55 * copy_printer_attrs() - Copy printer attributes.
56 * copy_subscription_attrs() - Copy subscription attributes.
57 * create_job() - Print a file to a printer or class.
58 * create_requested_array() - Create an array for the requested-attributes.
59 * create_subscription() - Create a notification subscription.
60 * delete_printer() - Remove a printer or class from the system.
61 * get_default() - Get the default destination.
62 * get_devices() - Get the list of available devices on the
64 * get_document() - Get a copy of a job file.
65 * get_job_attrs() - Get job attributes.
66 * get_jobs() - Get a list of jobs for the specified printer.
67 * get_notifications() - Get events for a subscription.
68 * get_ppd() - Get a named PPD from the local system.
69 * get_ppds() - Get the list of PPD files on the local
71 * get_printer_attrs() - Get printer attributes.
72 * get_printers() - Get a list of printers or classes.
73 * get_subscription_attrs() - Get subscription attributes.
74 * get_subscriptions() - Get subscriptions.
75 * get_username() - Get the username associated with a request.
76 * hold_job() - Hold a print job.
77 * move_job() - Move a job to a new destination.
78 * ppd_parse_line() - Parse a PPD default line.
79 * print_job() - Print a file to a printer or class.
80 * read_job_ticket() - Read a job ticket embedded in a print file.
81 * reject_jobs() - Reject print jobs to a printer.
82 * release_job() - Release a held print job.
83 * renew_subscription() - Renew an existing subscription...
84 * restart_job() - Restart an old print job.
85 * save_auth_info() - Save authentication information for a job.
86 * save_krb5_creds() - Save Kerberos credentials for the job.
87 * send_document() - Send a file to a printer or class.
88 * send_http_error() - Send a HTTP error back to the IPP client.
89 * send_ipp_status() - Send a status back to the IPP client.
90 * set_default() - Set the default destination...
91 * set_job_attrs() - Set job attributes.
92 * set_printer_attrs() - Set printer attributes.
93 * set_printer_defaults() - Set printer default options from a request.
94 * start_printer() - Start a printer.
95 * stop_printer() - Stop a printer.
96 * url_encode_attr() - URL-encode a string attribute.
97 * url_encode_string() - URL-encode a string.
98 * user_allowed() - See if a user is allowed to print to a queue.
99 * validate_job() - Validate printer options and destination.
100 * validate_name() - Make sure the printer name only contains
102 * validate_user() - Validate the user for the request.
106 * Include necessary headers...
110 #include <cups/ppd-private.h>
114 #endif /* HAVE_LIBPAPER */
117 # include <ApplicationServices/ApplicationServices.h>
118 # include <CoreFoundation/CoreFoundation.h>
119 # ifdef HAVE_MEMBERSHIP_H
120 # include <membership.h>
121 # endif /* HAVE_MEMBERSHIP_H */
122 # ifdef HAVE_MEMBERSHIPPRIV_H
123 # include <membershipPriv.h>
125 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
126 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
127 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
128 # endif /* HAVE_MEMBERSHIPPRIV_H */
129 #endif /* __APPLE__ */
136 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
137 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
138 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
139 mime_type_t
*filetype
, int compression
);
140 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
141 mime_type_t
*filetype
);
142 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
143 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
144 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
145 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
146 static void add_printer_state_reasons(cupsd_client_t
*con
,
148 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
150 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
151 CMDeviceProfileInfo
*profile
, unsigned id
,
152 const char *name
, const char *text
,
153 const char *iccfile
);
154 static void apple_register_profiles(cupsd_printer_t
*p
);
155 static void apple_unregister_profiles(cupsd_printer_t
*p
);
156 #endif /* __APPLE__ */
157 static void apply_printer_defaults(cupsd_printer_t
*printer
,
159 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
160 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
161 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
162 static void cancel_subscription(cupsd_client_t
*con
, int id
);
163 static int check_rss_recipient(const char *recipient
);
164 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
165 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
167 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
168 ipp_tag_t group
, int quickcopy
);
169 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
171 static int copy_file(const char *from
, const char *to
);
172 static int copy_model(cupsd_client_t
*con
, const char *from
,
174 static void copy_job_attrs(cupsd_client_t
*con
,
177 static void copy_printer_attrs(cupsd_client_t
*con
,
178 cupsd_printer_t
*printer
,
180 static void copy_subscription_attrs(cupsd_client_t
*con
,
181 cupsd_subscription_t
*sub
,
183 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
184 static cups_array_t
*create_requested_array(ipp_t
*request
);
185 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
187 static void get_default(cupsd_client_t
*con
);
188 static void get_devices(cupsd_client_t
*con
);
189 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
191 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
192 static void get_notifications(cupsd_client_t
*con
);
193 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
194 static void get_ppds(cupsd_client_t
*con
);
195 static void get_printers(cupsd_client_t
*con
, int type
);
196 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
197 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
199 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
200 static const char *get_username(cupsd_client_t
*con
);
201 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
202 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
203 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
204 static int ppd_parse_line(const char *line
, char *option
, int olen
,
205 char *choice
, int clen
);
206 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
207 static void read_job_ticket(cupsd_client_t
*con
);
208 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
209 static void release_held_new_jobs(cupsd_client_t
*con
,
210 ipp_attribute_t
*uri
);
211 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
212 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
213 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
214 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
215 ipp_attribute_t
*auth_info
);
216 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
217 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
218 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
219 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
220 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
221 cupsd_printer_t
*printer
);
222 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
223 const char *message
, ...)
225 __attribute__ ((__format__ (__printf__
, 3, 4)))
226 # endif /* __GNUC__ */
228 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
229 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
230 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
231 static void set_printer_defaults(cupsd_client_t
*con
,
232 cupsd_printer_t
*printer
);
233 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
234 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
235 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
237 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
238 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
239 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
240 static int validate_name(const char *name
);
241 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
242 const char *owner
, char *username
,
247 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
250 int /* O - 1 on success, 0 on failure */
251 cupsdProcessIPPRequest(
252 cupsd_client_t
*con
) /* I - Client connection */
254 ipp_tag_t group
; /* Current group tag */
255 ipp_attribute_t
*attr
; /* Current attribute */
256 ipp_attribute_t
*charset
; /* Character set attribute */
257 ipp_attribute_t
*language
; /* Language attribute */
258 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
259 ipp_attribute_t
*username
; /* requesting-user-name attr */
260 int sub_id
; /* Subscription ID */
263 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
264 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
265 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
268 * First build an empty response message for this request...
271 con
->response
= ippNew();
273 con
->response
->request
.status
.version
[0] =
274 con
->request
->request
.op
.version
[0];
275 con
->response
->request
.status
.version
[1] =
276 con
->request
->request
.op
.version
[1];
277 con
->response
->request
.status
.request_id
=
278 con
->request
->request
.op
.request_id
;
281 * Then validate the request header and required attributes...
284 if (con
->request
->request
.any
.version
[0] != 1 &&
285 con
->request
->request
.any
.version
[0] != 2)
288 * Return an error, since we only support IPP 1.x and 2.x.
291 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
292 "%04X %s Bad request version number %d.%d",
293 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
294 con
->request
->request
.any
.version
[0],
295 con
->request
->request
.any
.version
[1]);
297 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
298 _("Bad request version number %d.%d!"),
299 con
->request
->request
.any
.version
[0],
300 con
->request
->request
.any
.version
[1]);
302 else if (!con
->request
->attrs
)
304 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
305 "%04X %s No attributes in request",
306 IPP_BAD_REQUEST
, con
->http
.hostname
);
308 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request!"));
313 * Make sure that the attributes are provided in the correct order and
314 * don't repeat groups...
317 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
320 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
323 * Out of order; return an error...
326 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
327 "%04X %s Attribute groups are out of order",
328 IPP_BAD_REQUEST
, con
->http
.hostname
);
330 send_ipp_status(con
, IPP_BAD_REQUEST
,
331 _("Attribute groups are out of order (%x < %x)!"),
332 attr
->group_tag
, group
);
336 group
= attr
->group_tag
;
341 * Then make sure that the first three attributes are:
344 * attributes-natural-language
345 * printer-uri/job-uri
348 attr
= con
->request
->attrs
;
349 if (attr
&& !strcmp(attr
->name
, "attributes-charset") &&
350 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
358 if (attr
&& !strcmp(attr
->name
, "attributes-natural-language") &&
359 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
364 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
365 IPP_TAG_URI
)) != NULL
)
367 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
368 IPP_TAG_URI
)) != NULL
)
370 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
371 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
376 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
377 "attributes-charset", NULL
,
378 charset
->values
[0].string
.text
);
380 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
381 "attributes-charset", NULL
, DefaultCharset
);
384 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
385 "attributes-natural-language", NULL
,
386 language
->values
[0].string
.text
);
388 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
389 "attributes-natural-language", NULL
, DefaultLanguage
);
392 strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
393 strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
396 * Bad character set...
399 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"!",
400 charset
->values
[0].string
.text
);
401 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
402 "%04X %s Unsupported attributes-charset value \"%s\"",
403 IPP_CHARSET
, con
->http
.hostname
,
404 charset
->values
[0].string
.text
);
405 send_ipp_status(con
, IPP_BAD_REQUEST
,
406 _("Unsupported character set \"%s\"!"),
407 charset
->values
[0].string
.text
);
409 else if (!charset
|| !language
||
411 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
412 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
413 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
414 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
415 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
418 * Return an error, since attributes-charset,
419 * attributes-natural-language, and printer-uri/job-uri are required
420 * for all operations.
425 cupsdLogMessage(CUPSD_LOG_ERROR
,
426 "Missing attributes-charset attribute!");
428 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
429 "%04X %s Missing attributes-charset attribute",
430 IPP_BAD_REQUEST
, con
->http
.hostname
);
435 cupsdLogMessage(CUPSD_LOG_ERROR
,
436 "Missing attributes-natural-language attribute!");
438 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
439 "%04X %s Missing attributes-natural-language attribute",
440 IPP_BAD_REQUEST
, con
->http
.hostname
);
445 cupsdLogMessage(CUPSD_LOG_ERROR
,
446 "Missing printer-uri, job-uri, or ppd-name "
449 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
450 "%04X %s Missing printer-uri, job-uri, or ppd-name "
451 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
454 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
456 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
457 cupsdLogMessage(CUPSD_LOG_DEBUG
,
458 "attr \"%s\": group_tag = %x, value_tag = %x",
459 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
462 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
464 send_ipp_status(con
, IPP_BAD_REQUEST
,
465 _("Missing required attributes!"));
470 * OK, all the checks pass so far; make sure requesting-user-name is
471 * not "root" from a remote host...
474 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
475 IPP_TAG_NAME
)) != NULL
)
478 * Check for root user...
481 if (!strcmp(username
->values
[0].string
.text
, "root") &&
482 strcasecmp(con
->http
.hostname
, "localhost") &&
483 strcmp(con
->username
, "root"))
486 * Remote unauthenticated user masquerading as local root...
489 _cupsStrFree(username
->values
[0].string
.text
);
490 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
494 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
495 IPP_TAG_INTEGER
)) != NULL
)
496 sub_id
= attr
->values
[0].integer
;
501 * Then try processing the operation...
505 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
506 ippOpString(con
->request
->request
.op
.operation_id
),
507 uri
->values
[0].string
.text
);
509 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
510 ippOpString(con
->request
->request
.op
.operation_id
));
512 switch (con
->request
->request
.op
.operation_id
)
518 case IPP_VALIDATE_JOB
:
519 validate_job(con
, uri
);
522 case IPP_CREATE_JOB
:
523 create_job(con
, uri
);
526 case IPP_SEND_DOCUMENT
:
527 send_document(con
, uri
);
530 case IPP_CANCEL_JOB
:
531 cancel_job(con
, uri
);
534 case IPP_GET_JOB_ATTRIBUTES
:
535 get_job_attrs(con
, uri
);
542 case IPP_GET_PRINTER_ATTRIBUTES
:
543 get_printer_attrs(con
, uri
);
546 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
547 get_printer_supported(con
, uri
);
554 case IPP_RELEASE_JOB
:
555 release_job(con
, uri
);
558 case IPP_RESTART_JOB
:
559 restart_job(con
, uri
);
562 case IPP_PAUSE_PRINTER
:
563 stop_printer(con
, uri
);
566 case IPP_RESUME_PRINTER
:
567 start_printer(con
, uri
);
570 case IPP_PURGE_JOBS
:
571 cancel_all_jobs(con
, uri
);
574 case IPP_SET_JOB_ATTRIBUTES
:
575 set_job_attrs(con
, uri
);
578 case IPP_SET_PRINTER_ATTRIBUTES
:
579 set_printer_attrs(con
, uri
);
582 case IPP_HOLD_NEW_JOBS
:
583 hold_new_jobs(con
, uri
);
586 case IPP_RELEASE_HELD_NEW_JOBS
:
587 release_held_new_jobs(con
, uri
);
590 case CUPS_GET_DEFAULT
:
594 case CUPS_GET_PRINTERS
:
595 get_printers(con
, 0);
598 case CUPS_GET_CLASSES
:
599 get_printers(con
, CUPS_PRINTER_CLASS
);
602 case CUPS_ADD_PRINTER
:
603 add_printer(con
, uri
);
606 case CUPS_DELETE_PRINTER
:
607 delete_printer(con
, uri
);
610 case CUPS_ADD_CLASS
:
614 case CUPS_DELETE_CLASS
:
615 delete_printer(con
, uri
);
618 case CUPS_ACCEPT_JOBS
:
619 case IPP_ENABLE_PRINTER
:
620 accept_jobs(con
, uri
);
623 case CUPS_REJECT_JOBS
:
624 case IPP_DISABLE_PRINTER
:
625 reject_jobs(con
, uri
);
628 case CUPS_SET_DEFAULT
:
629 set_default(con
, uri
);
632 case CUPS_GET_DEVICES
:
636 case CUPS_GET_DOCUMENT
:
637 get_document(con
, uri
);
652 case CUPS_AUTHENTICATE_JOB
:
653 authenticate_job(con
, uri
);
656 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
657 case IPP_CREATE_JOB_SUBSCRIPTION
:
658 create_subscription(con
, uri
);
661 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
662 get_subscription_attrs(con
, sub_id
);
665 case IPP_GET_SUBSCRIPTIONS
:
666 get_subscriptions(con
, uri
);
669 case IPP_RENEW_SUBSCRIPTION
:
670 renew_subscription(con
, sub_id
);
673 case IPP_CANCEL_SUBSCRIPTION
:
674 cancel_subscription(con
, sub_id
);
677 case IPP_GET_NOTIFICATIONS
:
678 get_notifications(con
);
682 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
683 "%04X %s Operation %04X (%s) not supported",
684 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
685 con
->request
->request
.op
.operation_id
,
686 ippOpString(con
->request
->request
.op
.operation_id
));
688 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
689 _("%s not supported!"),
691 con
->request
->request
.op
.operation_id
));
701 * Sending data from the scheduler...
704 cupsdLogMessage(con
->response
->request
.status
.status_code
705 >= IPP_BAD_REQUEST
&&
706 con
->response
->request
.status
.status_code
707 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
708 "Returning IPP %s for %s (%s) from %s",
709 ippErrorString(con
->response
->request
.status
.status_code
),
710 ippOpString(con
->request
->request
.op
.operation_id
),
711 uri
? uri
->values
[0].string
.text
: "no URI",
714 if (LogLevel
== CUPSD_LOG_DEBUG2
)
715 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
716 "cupsdProcessIPPRequest: ippLength(response)=%ld",
717 (long)ippLength(con
->response
));
719 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
721 #ifdef CUPSD_USE_CHUNKING
723 * Because older versions of CUPS (1.1.17 and older) and some IPP
724 * clients do not implement chunking properly, we cannot use
725 * chunking by default. This may become the default in future
726 * CUPS releases, or we might add a configuration directive for
730 if (con
->http
.version
== HTTP_1_1
)
732 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
735 if (cupsdFlushHeader(con
) < 0)
738 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
741 #endif /* CUPSD_USE_CHUNKING */
743 size_t length
; /* Length of response */
746 length
= ippLength(con
->response
);
748 if (con
->file
>= 0 && !con
->pipe_pid
)
750 struct stat fileinfo
; /* File information */
753 if (!fstat(con
->file
, &fileinfo
))
754 length
+= fileinfo
.st_size
;
757 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
758 CUPS_LLCAST length
) < 0)
761 if (cupsdFlushHeader(con
) < 0)
764 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
765 con
->http
.data_remaining
= length
;
767 if (con
->http
.data_remaining
<= INT_MAX
)
768 con
->http
._data_remaining
= con
->http
.data_remaining
;
770 con
->http
._data_remaining
= INT_MAX
;
773 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
774 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
777 * Tell the caller the response header was sent successfully...
785 * Tell the caller the response header could not be sent...
794 * Sending data from a subprocess like cups-deviced; tell the caller
795 * everything is A-OK so far...
804 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
807 int /* O - 0 on success, -1 on error */
808 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
810 cupsd_printer_t
*printer
; /* Destination printer or class */
811 ipp_attribute_t
*attr
; /* job-sheets attribute */
812 int kbytes
; /* Kilobytes in banner */
815 job
->pending_timeout
= 0;
818 * See if we need to add the ending sheet...
821 printer
= cupsdFindDest(job
->dest
);
822 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
825 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
826 attr
&& attr
->num_values
> 1)
832 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
833 attr
->values
[1].string
.text
);
835 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
838 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
846 * 'accept_jobs()' - Accept print jobs to a printer.
850 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
851 ipp_attribute_t
*uri
) /* I - Printer or class URI */
853 http_status_t status
; /* Policy status */
854 cups_ptype_t dtype
; /* Destination type (printer/class) */
855 cupsd_printer_t
*printer
; /* Printer data */
858 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
859 con
->http
.fd
, uri
->values
[0].string
.text
);
862 * Is the destination valid?
865 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
871 send_ipp_status(con
, IPP_NOT_FOUND
,
872 _("The printer or class was not found."));
880 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
882 send_http_error(con
, status
, printer
);
887 * Accept jobs sent to the printer...
890 printer
->accepting
= 1;
891 printer
->state_message
[0] = '\0';
893 cupsdAddPrinterHistory(printer
);
895 if (dtype
& CUPS_PRINTER_CLASS
)
897 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
899 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
900 printer
->name
, get_username(con
));
904 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
906 cupsdLogMessage(CUPSD_LOG_INFO
,
907 "Printer \"%s\" now accepting jobs (\"%s\").",
908 printer
->name
, get_username(con
));
912 * Everything was ok, so return OK status...
915 con
->response
->request
.status
.status_code
= IPP_OK
;
920 * 'add_class()' - Add a class to the system.
924 add_class(cupsd_client_t
*con
, /* I - Client connection */
925 ipp_attribute_t
*uri
) /* I - URI of class */
927 http_status_t status
; /* Policy status */
928 int i
; /* Looping var */
929 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
930 username
[HTTP_MAX_URI
], /* Username portion of URI */
931 host
[HTTP_MAX_URI
], /* Host portion of URI */
932 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
933 int port
; /* Port portion of URI */
934 cupsd_printer_t
*pclass
, /* Class */
935 *member
; /* Member printer/class */
936 cups_ptype_t dtype
; /* Destination type */
937 ipp_attribute_t
*attr
; /* Printer attribute */
938 int modify
; /* Non-zero if we just modified */
939 char newname
[IPP_MAX_NAME
]; /* New class name */
940 int need_restart_job
; /* Need to restart job? */
943 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
944 con
->http
.fd
, uri
->values
[0].string
.text
);
947 * Do we have a valid URI?
950 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
951 sizeof(scheme
), username
, sizeof(username
), host
,
952 sizeof(host
), &port
, resource
, sizeof(resource
));
955 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
958 * No, return an error...
961 send_ipp_status(con
, IPP_BAD_REQUEST
,
962 _("The printer-uri must be of the form "
963 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
968 * Do we have a valid printer name?
971 if (!validate_name(resource
+ 9))
974 * No, return an error...
977 send_ipp_status(con
, IPP_BAD_REQUEST
,
978 _("The printer-uri \"%s\" contains invalid characters."),
979 uri
->values
[0].string
.text
);
984 * See if the class already exists; if not, create a new class...
987 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
990 * Class doesn't exist; see if we have a printer of the same name...
993 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
994 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
997 * Yes, return an error...
1000 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1001 _("A printer named \"%s\" already exists!"),
1007 * No, check the default policy and then add the class...
1010 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1012 send_http_error(con
, status
, NULL
);
1016 pclass
= cupsdAddClass(resource
+ 9);
1019 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1022 * Check the default policy, then rename the implicit class to "AnyClass"
1026 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1028 send_http_error(con
, status
, NULL
);
1032 if (ImplicitAnyClasses
)
1034 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1035 cupsdRenamePrinter(pclass
, newname
);
1038 cupsdDeletePrinter(pclass
, 1);
1041 * Add the class as a new local class...
1044 pclass
= cupsdAddClass(resource
+ 9);
1047 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1050 * Check the default policy, then rename the remote class to "Class"...
1053 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1055 send_http_error(con
, status
, NULL
);
1059 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1060 cupsdRenamePrinter(pclass
, newname
);
1063 * Add the class as a new local class...
1066 pclass
= cupsdAddClass(resource
+ 9);
1069 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1072 send_http_error(con
, status
, pclass
);
1079 * Look for attributes and copy them over as needed...
1082 need_restart_job
= 0;
1084 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1085 IPP_TAG_TEXT
)) != NULL
)
1086 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1088 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1089 IPP_TAG_TEXT
)) != NULL
)
1090 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1092 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1093 IPP_TAG_BOOLEAN
)) != NULL
)
1095 cupsdLogMessage(CUPSD_LOG_INFO
,
1096 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1097 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1099 pclass
->accepting
= attr
->values
[0].boolean
;
1100 cupsdAddPrinterHistory(pclass
);
1103 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1104 IPP_TAG_BOOLEAN
)) != NULL
)
1106 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1107 cupsdDeregisterPrinter(pclass
, 1);
1109 cupsdLogMessage(CUPSD_LOG_INFO
,
1110 "Setting %s printer-is-shared to %d (was %d.)",
1111 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1113 pclass
->shared
= attr
->values
[0].boolean
;
1116 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1117 IPP_TAG_ENUM
)) != NULL
)
1119 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1120 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1122 send_ipp_status(con
, IPP_BAD_REQUEST
,
1123 _("Attempt to set %s printer-state to bad value %d!"),
1124 pclass
->name
, attr
->values
[0].integer
);
1128 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1129 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1131 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1132 cupsdStopPrinter(pclass
, 0);
1135 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1136 need_restart_job
= 1;
1139 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1140 IPP_TAG_TEXT
)) != NULL
)
1142 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1143 sizeof(pclass
->state_message
));
1144 cupsdAddPrinterHistory(pclass
);
1146 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1147 IPP_TAG_URI
)) != NULL
)
1150 * Clear the printer array as needed...
1153 need_restart_job
= 1;
1155 if (pclass
->num_printers
> 0)
1157 free(pclass
->printers
);
1158 pclass
->num_printers
= 0;
1162 * Add each printer or class that is listed...
1165 for (i
= 0; i
< attr
->num_values
; i
++)
1168 * Search for the printer or class URI...
1171 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1177 send_ipp_status(con
, IPP_NOT_FOUND
,
1178 _("The printer or class was not found."));
1183 * Add it to the class...
1186 cupsdAddPrinterToClass(pclass
, member
);
1190 set_printer_defaults(con
, pclass
);
1192 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1193 IPP_TAG_KEYWORD
)) != NULL
)
1194 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1197 * Update the printer class attributes and return...
1200 cupsdSetPrinterAttrs(pclass
);
1201 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1203 if (need_restart_job
&& pclass
->job
)
1208 * Stop the current job and then restart it below...
1211 job
= (cupsd_job_t
*)pclass
->job
;
1213 cupsdStopJob(job
, 1);
1215 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1216 job
->state_value
= IPP_JOB_PENDING
;
1219 if (need_restart_job
)
1222 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1226 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, pclass
, NULL
,
1227 "Class \"%s\" modified by \"%s\".", pclass
->name
,
1230 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1231 pclass
->name
, get_username(con
));
1235 cupsdAddPrinterHistory(pclass
);
1237 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, pclass
, NULL
,
1238 "New class \"%s\" added by \"%s\".", pclass
->name
,
1241 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1242 pclass
->name
, get_username(con
));
1245 con
->response
->request
.status
.status_code
= IPP_OK
;
1250 * 'add_file()' - Add a file to a job.
1253 static int /* O - 0 on success, -1 on error */
1254 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1255 cupsd_job_t
*job
, /* I - Job to add to */
1256 mime_type_t
*filetype
, /* I - Type of file */
1257 int compression
) /* I - Compression */
1259 mime_type_t
**filetypes
; /* New filetypes array... */
1260 int *compressions
; /* New compressions array... */
1263 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1264 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1265 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1266 filetype
->super
, filetype
->type
, compression
);
1269 * Add the file to the job...
1272 if (job
->num_files
== 0)
1274 compressions
= (int *)malloc(sizeof(int));
1275 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1279 compressions
= (int *)realloc(job
->compressions
,
1280 (job
->num_files
+ 1) * sizeof(int));
1281 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1282 (job
->num_files
+ 1) *
1283 sizeof(mime_type_t
*));
1286 if (!compressions
|| !filetypes
)
1288 cupsdCancelJob(job
, 1, IPP_JOB_ABORTED
);
1291 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1292 _("Unable to allocate memory for file types!"));
1297 job
->compressions
= compressions
;
1298 job
->compressions
[job
->num_files
] = compression
;
1299 job
->filetypes
= filetypes
;
1300 job
->filetypes
[job
->num_files
] = filetype
;
1305 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1312 * 'add_job()' - Add a job to a print queue.
1315 static cupsd_job_t
* /* O - Job object */
1316 add_job(cupsd_client_t
*con
, /* I - Client connection */
1317 cupsd_printer_t
*printer
, /* I - Destination printer */
1318 mime_type_t
*filetype
) /* I - First print file type, if any */
1320 http_status_t status
; /* Policy status */
1321 ipp_attribute_t
*attr
, /* Current attribute */
1322 *auth_info
; /* auth-info attribute */
1323 const char *val
; /* Default option value */
1324 int priority
; /* Job priority */
1325 char *title
; /* Job name/title */
1326 cupsd_job_t
*job
; /* Current job */
1327 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1328 int kbytes
; /* Size of print file */
1329 int i
; /* Looping var */
1330 int lowerpagerange
; /* Page range bound */
1333 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1334 con
, con
->http
.fd
, printer
, printer
->name
,
1335 filetype
, filetype
? filetype
->super
: "none",
1336 filetype
? filetype
->type
: "none");
1339 * Check remote printing to non-shared printer...
1342 if (!printer
->shared
&&
1343 strcasecmp(con
->http
.hostname
, "localhost") &&
1344 strcasecmp(con
->http
.hostname
, ServerName
))
1346 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1347 _("The printer or class is not shared!"));
1355 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1357 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1359 send_http_error(con
, status
, printer
);
1362 else if (printer
->num_auth_info_required
> 0 &&
1363 strcmp(printer
->auth_info_required
[0], "none") &&
1364 !con
->username
[0] && !auth_info
)
1366 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1370 else if (auth_info
&& !con
->http
.tls
&&
1371 !httpAddrLocalhost(con
->http
.hostaddr
))
1374 * Require encryption of auth-info over non-local connections...
1377 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1380 #endif /* HAVE_SSL */
1383 * See if the printer is accepting jobs...
1386 if (!printer
->accepting
)
1388 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1389 _("Destination \"%s\" is not accepting jobs."),
1395 * Validate job template attributes; for now just document-format,
1396 * copies, number-up, and page-ranges...
1399 if (filetype
&& printer
->filetypes
&&
1400 !cupsArrayFind(printer
->filetypes
, filetype
))
1402 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1403 /* MIME media type string */
1406 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1409 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1410 _("Unsupported format \'%s\'!"), mimetype
);
1412 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1413 "document-format", NULL
, mimetype
);
1418 if ((attr
= ippFindAttribute(con
->request
, "copies",
1419 IPP_TAG_INTEGER
)) != NULL
)
1421 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1423 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1424 attr
->values
[0].integer
);
1425 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1426 "copies", attr
->values
[0].integer
);
1431 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1432 IPP_TAG_ZERO
)) != NULL
)
1434 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1435 attr
->value_tag
!= IPP_TAG_NAME
)
1437 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type!"));
1441 if (attr
->num_values
> 2)
1443 send_ipp_status(con
, IPP_BAD_REQUEST
,
1444 _("Too many job-sheets values (%d > 2)!"),
1449 for (i
= 0; i
< attr
->num_values
; i
++)
1450 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1451 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1453 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"!"),
1454 attr
->values
[i
].string
.text
);
1459 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1460 IPP_TAG_INTEGER
)) != NULL
)
1462 if (attr
->values
[0].integer
!= 1 &&
1463 attr
->values
[0].integer
!= 2 &&
1464 attr
->values
[0].integer
!= 4 &&
1465 attr
->values
[0].integer
!= 6 &&
1466 attr
->values
[0].integer
!= 9 &&
1467 attr
->values
[0].integer
!= 16)
1469 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1470 attr
->values
[0].integer
);
1471 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1472 "number-up", attr
->values
[0].integer
);
1477 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1478 IPP_TAG_RANGE
)) != NULL
)
1480 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1482 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1483 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1485 send_ipp_status(con
, IPP_BAD_REQUEST
,
1486 _("Bad page-ranges values %d-%d."),
1487 attr
->values
[i
].range
.lower
,
1488 attr
->values
[i
].range
.upper
);
1492 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1497 * Make sure we aren't over our limit...
1500 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1503 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1505 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1506 _("Too many active jobs."));
1510 if ((i
= check_quotas(con
, printer
)) < 0)
1512 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1517 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1522 * Create the job and set things up...
1525 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1526 IPP_TAG_INTEGER
)) != NULL
)
1527 priority
= attr
->values
[0].integer
;
1530 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1531 printer
->options
)) != NULL
)
1532 priority
= atoi(val
);
1536 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1540 if ((attr
= ippFindAttribute(con
->request
, "job-name",
1541 IPP_TAG_NAME
)) != NULL
)
1542 title
= attr
->values
[0].string
.text
;
1544 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1545 title
= "Untitled");
1547 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1549 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1550 _("Unable to add job for destination \"%s\"!"),
1555 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1556 CUPS_PRINTER_REMOTE
);
1557 job
->attrs
= con
->request
;
1559 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1561 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1563 add_job_uuid(con
, job
);
1564 apply_printer_defaults(printer
, job
);
1566 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1568 if (con
->username
[0])
1570 cupsdSetString(&job
->username
, con
->username
);
1573 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1577 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1578 "add_job: requesting-user-name=\"%s\"",
1579 attr
->values
[0].string
.text
);
1581 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1584 cupsdSetString(&job
->username
, "anonymous");
1587 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1588 "job-originating-user-name", NULL
, job
->username
);
1591 attr
->group_tag
= IPP_TAG_JOB
;
1592 _cupsStrFree(attr
->name
);
1593 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1596 if (con
->username
[0] || auth_info
)
1598 save_auth_info(con
, job
, auth_info
);
1601 * Remove the auth-info attribute from the attribute data...
1605 ippDeleteAttribute(job
->attrs
, auth_info
);
1608 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1609 IPP_TAG_ZERO
)) != NULL
)
1612 * Request contains a job-originating-host-name attribute; validate it...
1615 if (attr
->value_tag
!= IPP_TAG_NAME
||
1616 attr
->num_values
!= 1 ||
1617 strcmp(con
->http
.hostname
, "localhost"))
1620 * Can't override the value if we aren't connected via localhost.
1621 * Also, we can only have 1 value and it must be a name value.
1624 switch (attr
->value_tag
)
1626 case IPP_TAG_STRING
:
1627 case IPP_TAG_TEXTLANG
:
1628 case IPP_TAG_NAMELANG
:
1631 case IPP_TAG_KEYWORD
:
1633 case IPP_TAG_URISCHEME
:
1634 case IPP_TAG_CHARSET
:
1635 case IPP_TAG_LANGUAGE
:
1636 case IPP_TAG_MIMETYPE
:
1638 * Free old strings...
1641 for (i
= 0; i
< attr
->num_values
; i
++)
1643 _cupsStrFree(attr
->values
[i
].string
.text
);
1644 attr
->values
[i
].string
.text
= NULL
;
1645 if (attr
->values
[i
].string
.charset
)
1647 _cupsStrFree(attr
->values
[i
].string
.charset
);
1648 attr
->values
[i
].string
.charset
= NULL
;
1657 * Use the default connection hostname instead...
1660 attr
->value_tag
= IPP_TAG_NAME
;
1661 attr
->num_values
= 1;
1662 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1665 attr
->group_tag
= IPP_TAG_JOB
;
1670 * No job-originating-host-name attribute, so use the hostname from
1674 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1675 "job-originating-host-name", NULL
, con
->http
.hostname
);
1678 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1680 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1681 "time-at-processing", 0);
1682 attr
->value_tag
= IPP_TAG_NOVALUE
;
1683 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1684 "time-at-completed", 0);
1685 attr
->value_tag
= IPP_TAG_NOVALUE
;
1688 * Add remaining job attributes...
1691 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1692 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1693 "job-state", IPP_JOB_STOPPED
);
1694 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1695 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1696 "job-media-sheets-completed", 0);
1697 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1699 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1702 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1703 IPP_TAG_INTEGER
)) != NULL
)
1704 attr
->values
[0].integer
= 0;
1706 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1708 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1709 IPP_TAG_KEYWORD
)) == NULL
)
1710 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1713 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1714 printer
->options
)) == NULL
)
1717 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1718 "job-hold-until", NULL
, val
);
1720 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold") &&
1721 !(printer
->type
& CUPS_PRINTER_REMOTE
))
1724 * Hold job until specified time...
1727 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
1729 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1730 job
->state_value
= IPP_JOB_HELD
;
1732 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1734 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1735 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1736 job
->state_value
= IPP_JOB_HELD
;
1740 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1741 job
->state_value
= IPP_JOB_PENDING
;
1744 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1748 * Add job sheets options...
1751 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1752 IPP_TAG_ZERO
)) == NULL
)
1754 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1755 "Adding default job-sheets values \"%s,%s\"...",
1756 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1758 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1760 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1761 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1764 job
->job_sheets
= attr
;
1767 * Enforce classification level if set...
1772 cupsdLogMessage(CUPSD_LOG_INFO
,
1773 "Classification=\"%s\", ClassifyOverride=%d",
1774 Classification
? Classification
: "(null)",
1777 if (ClassifyOverride
)
1779 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1780 (attr
->num_values
== 1 ||
1781 !strcmp(attr
->values
[1].string
.text
, "none")))
1784 * Force the leading banner to have the classification on it...
1787 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1789 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1790 "job-sheets=\"%s,none\", "
1791 "job-originating-user-name=\"%s\"",
1792 Classification
, job
->username
);
1794 else if (attr
->num_values
== 2 &&
1795 strcmp(attr
->values
[0].string
.text
,
1796 attr
->values
[1].string
.text
) &&
1797 strcmp(attr
->values
[0].string
.text
, "none") &&
1798 strcmp(attr
->values
[1].string
.text
, "none"))
1801 * Can't put two different security markings on the same document!
1804 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1806 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1807 "job-sheets=\"%s,%s\", "
1808 "job-originating-user-name=\"%s\"",
1809 attr
->values
[0].string
.text
,
1810 attr
->values
[1].string
.text
, job
->username
);
1812 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1813 strcmp(attr
->values
[0].string
.text
, "none") &&
1814 (attr
->num_values
== 1 ||
1815 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1816 strcmp(attr
->values
[1].string
.text
, "none"))))
1818 if (attr
->num_values
== 1)
1819 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1820 "CLASSIFICATION OVERRIDDEN "
1821 "job-sheets=\"%s\", "
1822 "job-originating-user-name=\"%s\"",
1823 attr
->values
[0].string
.text
, job
->username
);
1825 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1826 "CLASSIFICATION OVERRIDDEN "
1827 "job-sheets=\"%s,%s\",fffff "
1828 "job-originating-user-name=\"%s\"",
1829 attr
->values
[0].string
.text
,
1830 attr
->values
[1].string
.text
, job
->username
);
1833 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1834 (attr
->num_values
== 1 ||
1835 strcmp(attr
->values
[1].string
.text
, Classification
)))
1838 * Force the banner to have the classification on it...
1841 if (attr
->num_values
> 1 &&
1842 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1844 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1845 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1849 if (attr
->num_values
== 1 ||
1850 strcmp(attr
->values
[0].string
.text
, "none"))
1851 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1853 if (attr
->num_values
> 1 &&
1854 strcmp(attr
->values
[1].string
.text
, "none"))
1855 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1858 if (attr
->num_values
> 1)
1859 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1860 "CLASSIFICATION FORCED "
1861 "job-sheets=\"%s,%s\", "
1862 "job-originating-user-name=\"%s\"",
1863 attr
->values
[0].string
.text
,
1864 attr
->values
[1].string
.text
, job
->username
);
1866 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1867 "CLASSIFICATION FORCED "
1868 "job-sheets=\"%s\", "
1869 "job-originating-user-name=\"%s\"",
1870 Classification
, job
->username
);
1875 * See if we need to add the starting sheet...
1878 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1880 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1881 attr
->values
[0].string
.text
);
1883 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1885 cupsdDeleteJob(job
);
1889 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1892 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1893 IPP_TAG_ZERO
)) != NULL
)
1897 * Fill in the response info...
1900 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1901 LocalPort
, job
->id
);
1903 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1906 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1908 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1910 add_job_state_reasons(con
, job
);
1912 con
->response
->request
.status
.status_code
= IPP_OK
;
1915 * Add any job subscriptions...
1918 add_job_subscriptions(con
, job
);
1921 * Set all but the first two attributes to the job attributes group...
1924 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1925 attr
->group_tag
= IPP_TAG_JOB
;
1928 * Fire the "job created" event...
1931 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1934 * Return the new job...
1942 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1943 * upon the job and printer state...
1947 add_job_state_reasons(
1948 cupsd_client_t
*con
, /* I - Client connection */
1949 cupsd_job_t
*job
) /* I - Job info */
1951 cupsd_printer_t
*dest
; /* Destination printer */
1954 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1955 con
, con
->http
.fd
, job
? job
->id
: 0);
1957 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1959 case IPP_JOB_PENDING
:
1960 dest
= cupsdFindDest(job
->dest
);
1962 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1963 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1964 "job-state-reasons", NULL
, "printer-stopped");
1966 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1967 "job-state-reasons", NULL
, "none");
1971 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1972 IPP_TAG_KEYWORD
) != NULL
||
1973 ippFindAttribute(job
->attrs
, "job-hold-until",
1974 IPP_TAG_NAME
) != NULL
)
1975 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1976 "job-state-reasons", NULL
, "job-hold-until-specified");
1978 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1979 "job-state-reasons", NULL
, "job-incoming");
1982 case IPP_JOB_PROCESSING
:
1983 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1984 "job-state-reasons", NULL
, "job-printing");
1987 case IPP_JOB_STOPPED
:
1988 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1989 "job-state-reasons", NULL
, "job-stopped");
1992 case IPP_JOB_CANCELED
:
1993 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1994 "job-state-reasons", NULL
, "job-canceled-by-user");
1997 case IPP_JOB_ABORTED
:
1998 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1999 "job-state-reasons", NULL
, "aborted-by-system");
2002 case IPP_JOB_COMPLETED
:
2003 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2004 "job-state-reasons", NULL
, "job-completed-successfully");
2011 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2015 add_job_subscriptions(
2016 cupsd_client_t
*con
, /* I - Client connection */
2017 cupsd_job_t
*job
) /* I - Newly created job */
2019 int i
; /* Looping var */
2020 ipp_attribute_t
*prev
, /* Previous attribute */
2021 *next
, /* Next attribute */
2022 *attr
; /* Current attribute */
2023 cupsd_subscription_t
*sub
; /* Subscription object */
2024 const char *recipient
, /* notify-recipient-uri */
2025 *pullmethod
; /* notify-pull-method */
2026 ipp_attribute_t
*user_data
; /* notify-user-data */
2027 int interval
; /* notify-time-interval */
2028 unsigned mask
; /* notify-events */
2032 * Find the first subscription group attribute; return if we have
2036 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2037 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2044 * Process the subscription attributes in the request...
2053 mask
= CUPSD_EVENT_NONE
;
2055 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2057 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2058 attr
->value_tag
== IPP_TAG_URI
)
2061 * Validate the recipient scheme against the ServerBin/notifier
2065 char notifier
[1024], /* Notifier filename */
2066 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2067 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2068 host
[HTTP_MAX_URI
], /* Host portion of URI */
2069 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2070 int port
; /* Port portion of URI */
2073 recipient
= attr
->values
[0].string
.text
;
2075 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2076 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2077 host
, sizeof(host
), &port
,
2078 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2080 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2081 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
2082 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2083 "notify-status-code", IPP_URI_SCHEME
);
2087 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2089 if (access(notifier
, X_OK
))
2091 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2092 _("notify-recipient-uri URI \"%s\" uses unknown "
2093 "scheme!"), recipient
);
2094 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2095 "notify-status-code", IPP_URI_SCHEME
);
2099 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2101 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2102 _("notify-recipient-uri URI \"%s\" is already used!"),
2104 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2105 "notify-status-code", IPP_ATTRIBUTES
);
2109 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2110 attr
->value_tag
== IPP_TAG_KEYWORD
)
2112 pullmethod
= attr
->values
[0].string
.text
;
2114 if (strcmp(pullmethod
, "ippget"))
2116 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2117 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
2118 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2119 "notify-status-code", IPP_ATTRIBUTES
);
2123 else if (!strcmp(attr
->name
, "notify-charset") &&
2124 attr
->value_tag
== IPP_TAG_CHARSET
&&
2125 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2126 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2128 send_ipp_status(con
, IPP_CHARSET
,
2129 _("Character set \"%s\" not supported!"),
2130 attr
->values
[0].string
.text
);
2133 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2134 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2135 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2137 send_ipp_status(con
, IPP_CHARSET
,
2138 _("Language \"%s\" not supported!"),
2139 attr
->values
[0].string
.text
);
2142 else if (!strcmp(attr
->name
, "notify-user-data") &&
2143 attr
->value_tag
== IPP_TAG_STRING
)
2145 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2147 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2148 _("The notify-user-data value is too large "
2149 "(%d > 63 octets)!"),
2150 attr
->values
[0].unknown
.length
);
2156 else if (!strcmp(attr
->name
, "notify-events") &&
2157 attr
->value_tag
== IPP_TAG_KEYWORD
)
2159 for (i
= 0; i
< attr
->num_values
; i
++)
2160 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2162 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2164 send_ipp_status(con
, IPP_BAD_REQUEST
,
2165 _("The notify-lease-duration attribute cannot be "
2166 "used with job subscriptions."));
2169 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2170 attr
->value_tag
== IPP_TAG_INTEGER
)
2171 interval
= attr
->values
[0].integer
;
2176 if (!recipient
&& !pullmethod
)
2179 if (mask
== CUPSD_EVENT_NONE
)
2180 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2182 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2183 recipient
, 0)) != NULL
)
2185 sub
->interval
= interval
;
2187 cupsdSetString(&sub
->owner
, job
->username
);
2191 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2192 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2193 sub
->user_data_len
);
2196 ippAddSeparator(con
->response
);
2197 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2198 "notify-subscription-id", sub
->id
);
2205 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2208 * Remove all of the subscription attributes from the job request...
2210 * TODO: Optimize this since subscription groups have to come at the
2211 * end of the request...
2214 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2218 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2219 attr
->group_tag
== IPP_TAG_ZERO
)
2222 * Free and remove this attribute...
2230 job
->attrs
->attrs
= next
;
2236 job
->attrs
->last
= prev
;
2237 job
->attrs
->current
= prev
;
2242 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2244 * See RFC 4122 for the definition of UUIDs and the format.
2248 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2249 cupsd_job_t
*job
) /* I - Job */
2251 char uuid
[1024]; /* job-uuid string */
2252 _cups_md5_state_t md5state
; /* MD5 state */
2253 unsigned char md5sum
[16]; /* MD5 digest/sum */
2257 * First see if the job already has a job-uuid attribute; if so, return...
2260 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2264 * No job-uuid attribute, so build a version 3 UUID with the local job
2265 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2266 * the ServerName, server name and port that the client connected to,
2267 * and local job ID...
2270 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2271 con
->serverport
, job
->id
);
2273 _cupsMD5Init(&md5state
);
2274 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2275 _cupsMD5Finish(&md5state
, md5sum
);
2278 * Format the UUID URI using the MD5 sum and job ID.
2281 snprintf(uuid
, sizeof(uuid
),
2282 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2283 "%02x%02x%02x%02x%02x%02x",
2284 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2285 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2286 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2287 md5sum
[14], md5sum
[15]);
2289 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2294 * 'add_printer()' - Add a printer to the system.
2298 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2299 ipp_attribute_t
*uri
) /* I - URI of printer */
2301 http_status_t status
; /* Policy status */
2302 int i
; /* Looping var */
2303 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2304 username
[HTTP_MAX_URI
], /* Username portion of URI */
2305 host
[HTTP_MAX_URI
], /* Host portion of URI */
2306 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2307 int port
; /* Port portion of URI */
2308 cupsd_printer_t
*printer
; /* Printer/class */
2309 ipp_attribute_t
*attr
; /* Printer attribute */
2310 cups_file_t
*fp
; /* Script/PPD file */
2311 char line
[1024]; /* Line from file... */
2312 char srcfile
[1024], /* Source Script/PPD file */
2313 dstfile
[1024]; /* Destination Script/PPD file */
2314 int modify
; /* Non-zero if we are modifying */
2315 char newname
[IPP_MAX_NAME
]; /* New printer name */
2316 int need_restart_job
; /* Need to restart job? */
2317 int set_device_uri
, /* Did we set the device URI? */
2318 set_port_monitor
; /* Did we set the port monitor? */
2321 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2322 con
->http
.fd
, uri
->values
[0].string
.text
);
2325 * Do we have a valid URI?
2328 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2329 sizeof(scheme
), username
, sizeof(username
), host
,
2330 sizeof(host
), &port
, resource
, sizeof(resource
));
2332 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2335 * No, return an error...
2338 send_ipp_status(con
, IPP_BAD_REQUEST
,
2339 _("The printer-uri must be of the form "
2340 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2345 * Do we have a valid printer name?
2348 if (!validate_name(resource
+ 10))
2351 * No, return an error...
2354 send_ipp_status(con
, IPP_BAD_REQUEST
,
2355 _("The printer-uri \"%s\" contains invalid characters."),
2356 uri
->values
[0].string
.text
);
2361 * See if the printer already exists; if not, create a new printer...
2364 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2367 * Printer doesn't exist; see if we have a class of the same name...
2370 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2371 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2374 * Yes, return an error...
2377 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2378 _("A class named \"%s\" already exists!"),
2384 * No, check the default policy then add the printer...
2387 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2389 send_http_error(con
, status
, NULL
);
2393 printer
= cupsdAddPrinter(resource
+ 10);
2396 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2399 * Check the default policy, then rename the implicit printer to
2400 * "AnyPrinter" or delete it...
2403 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2405 send_http_error(con
, status
, NULL
);
2409 if (ImplicitAnyClasses
)
2411 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2412 cupsdRenamePrinter(printer
, newname
);
2415 cupsdDeletePrinter(printer
, 1);
2418 * Add the printer as a new local printer...
2421 printer
= cupsdAddPrinter(resource
+ 10);
2424 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2427 * Check the default policy, then rename the remote printer to
2428 * "Printer@server"...
2431 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2433 send_http_error(con
, status
, NULL
);
2437 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2439 cupsdRenamePrinter(printer
, newname
);
2442 * Add the printer as a new local printer...
2445 printer
= cupsdAddPrinter(resource
+ 10);
2448 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2451 send_http_error(con
, status
, printer
);
2458 * Look for attributes and copy them over as needed...
2461 need_restart_job
= 0;
2463 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2464 IPP_TAG_TEXT
)) != NULL
)
2465 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2467 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2468 IPP_TAG_TEXT
)) != NULL
)
2469 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2473 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2474 IPP_TAG_URI
)) != NULL
)
2477 * Do we have a valid device URI?
2480 http_uri_status_t uri_status
; /* URI separation status */
2481 char old_device_uri
[1024];
2482 /* Old device URI */
2485 need_restart_job
= 1;
2487 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2488 attr
->values
[0].string
.text
,
2489 scheme
, sizeof(scheme
),
2490 username
, sizeof(username
),
2491 host
, sizeof(host
), &port
,
2492 resource
, sizeof(resource
));
2494 if (uri_status
< HTTP_URI_OK
)
2496 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"!"),
2497 attr
->values
[0].string
.text
);
2498 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2499 "add_printer: httpSeparateURI returned %d", uri_status
);
2503 if (!strcmp(scheme
, "file"))
2506 * See if the administrator has enabled file devices...
2509 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2512 * File devices are disabled and the URL is not file:/dev/null...
2515 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2516 _("File device URIs have been disabled! "
2517 "To enable, see the FileDevice directive in "
2518 "\"%s/cupsd.conf\"."),
2526 * See if the backend exists and is executable...
2529 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2530 if (access(srcfile
, X_OK
))
2533 * Could not find device in list!
2536 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\"!"),
2542 if (printer
->sanitized_device_uri
)
2543 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2544 sizeof(old_device_uri
));
2546 old_device_uri
[0] = '\0';
2548 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2550 cupsdLogMessage(CUPSD_LOG_INFO
,
2551 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2552 printer
->name
, printer
->sanitized_device_uri
,
2558 set_port_monitor
= 0;
2560 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2561 IPP_TAG_NAME
)) != NULL
)
2563 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2566 need_restart_job
= 1;
2568 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2572 for (i
= 0; i
< supported
->num_values
; i
++)
2573 if (!strcmp(supported
->values
[i
].string
.text
,
2574 attr
->values
[0].string
.text
))
2578 if (!supported
|| i
>= supported
->num_values
)
2580 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"!"),
2581 attr
->values
[0].string
.text
);
2585 cupsdLogMessage(CUPSD_LOG_INFO
,
2586 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2587 printer
->name
, attr
->values
[0].string
.text
,
2588 printer
->port_monitor
? printer
->port_monitor
: "none");
2590 if (strcmp(attr
->values
[0].string
.text
, "none"))
2591 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2593 cupsdClearString(&printer
->port_monitor
);
2595 set_port_monitor
= 1;
2598 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2599 IPP_TAG_BOOLEAN
)) != NULL
)
2601 cupsdLogMessage(CUPSD_LOG_INFO
,
2602 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2603 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2605 printer
->accepting
= attr
->values
[0].boolean
;
2606 cupsdAddPrinterHistory(printer
);
2609 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2610 IPP_TAG_BOOLEAN
)) != NULL
)
2612 if (printer
->shared
&& !attr
->values
[0].boolean
)
2613 cupsdDeregisterPrinter(printer
, 1);
2615 cupsdLogMessage(CUPSD_LOG_INFO
,
2616 "Setting %s printer-is-shared to %d (was %d.)",
2617 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2619 printer
->shared
= attr
->values
[0].boolean
;
2622 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2623 IPP_TAG_ENUM
)) != NULL
)
2625 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2626 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2628 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d!"),
2629 attr
->values
[0].integer
);
2633 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2634 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2636 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2637 cupsdStopPrinter(printer
, 0);
2640 need_restart_job
= 1;
2641 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2645 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2646 IPP_TAG_TEXT
)) != NULL
)
2648 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2649 sizeof(printer
->state_message
));
2650 cupsdAddPrinterHistory(printer
);
2653 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2654 IPP_TAG_KEYWORD
)) != NULL
)
2656 if (attr
->num_values
>
2657 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2659 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2660 _("Too many printer-state-reasons values (%d > %d)!"),
2662 (int)(sizeof(printer
->reasons
) /
2663 sizeof(printer
->reasons
[0])));
2667 for (i
= 0; i
< printer
->num_reasons
; i
++)
2668 _cupsStrFree(printer
->reasons
[i
]);
2670 printer
->num_reasons
= 0;
2671 for (i
= 0; i
< attr
->num_values
; i
++)
2673 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2676 printer
->reasons
[printer
->num_reasons
] =
2677 _cupsStrRetain(attr
->values
[i
].string
.text
);
2678 printer
->num_reasons
++;
2680 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2681 printer
->state
!= IPP_PRINTER_STOPPED
)
2683 cupsdLogMessage(CUPSD_LOG_INFO
,
2684 "Setting %s printer-state to %d (was %d.)",
2685 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2686 cupsdStopPrinter(printer
, 0);
2690 if (PrintcapFormat
== PRINTCAP_PLIST
)
2691 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2694 set_printer_defaults(con
, printer
);
2696 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2697 IPP_TAG_KEYWORD
)) != NULL
)
2698 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2701 * See if we have all required attributes...
2704 if (!printer
->device_uri
)
2705 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2708 * See if we have an interface script or PPD file attached to the request...
2713 need_restart_job
= 1;
2715 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2717 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2720 * Yes; get the first line from it...
2724 cupsFileGets(fp
, line
, sizeof(line
));
2728 * Then see what kind of file it is...
2731 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2734 if (!strncmp(line
, "*PPD-Adobe", 10))
2737 * The new file is a PPD file, so remove any old interface script
2738 * that might be lying around...
2746 * This must be an interface script, so move the file over to the
2747 * interfaces directory and make it executable...
2750 if (copy_file(srcfile
, dstfile
))
2752 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2753 _("Unable to copy interface script - %s!"),
2758 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2759 "Copied interface script successfully!");
2760 chmod(dstfile
, 0755);
2763 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2766 if (!strncmp(line
, "*PPD-Adobe", 10))
2769 * The new file is a PPD file, so move the file over to the
2770 * ppd directory and make it readable by all...
2773 if (copy_file(srcfile
, dstfile
))
2775 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2776 _("Unable to copy PPD file - %s!"),
2781 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2782 "Copied PPD file successfully!");
2783 chmod(dstfile
, 0644);
2787 * (Re)register color profiles...
2792 apple_unregister_profiles(printer
);
2793 apple_register_profiles(printer
);
2795 #endif /* __APPLE__ */
2800 * This must be an interface script, so remove any old PPD file that
2801 * may be lying around...
2808 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2809 IPP_TAG_NAME
)) != NULL
)
2811 need_restart_job
= 1;
2813 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2816 * Raw driver, remove any existing PPD or interface script files.
2819 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2823 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2833 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2837 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2840 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2842 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file!"));
2846 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2847 "Copied PPD file successfully!");
2848 chmod(dstfile
, 0644);
2852 * (Re)register color profiles...
2857 apple_unregister_profiles(printer
);
2858 apple_register_profiles(printer
);
2860 #endif /* __APPLE__ */
2865 * If we set the device URI but not the port monitor, check which port
2866 * monitor to use by default...
2869 if (set_device_uri
&& !set_port_monitor
)
2871 ppd_file_t
*ppd
; /* PPD file */
2872 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2875 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2876 sizeof(scheme
), username
, sizeof(username
), host
,
2877 sizeof(host
), &port
, resource
, sizeof(resource
));
2879 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2881 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2883 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2885 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2886 if (!strcmp(scheme
, ppdattr
->spec
))
2888 cupsdLogMessage(CUPSD_LOG_INFO
,
2889 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2890 printer
->name
, ppdattr
->value
,
2891 printer
->port_monitor
? printer
->port_monitor
2894 if (strcmp(ppdattr
->value
, "none"))
2895 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2897 cupsdClearString(&printer
->port_monitor
);
2907 * Update the printer attributes and return...
2910 cupsdSetPrinterAttrs(printer
);
2911 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2913 if (need_restart_job
&& printer
->job
)
2918 * Stop the current job and then restart it below...
2921 job
= (cupsd_job_t
*)printer
->job
;
2923 cupsdStopJob(job
, 1);
2925 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2926 job
->state_value
= IPP_JOB_PENDING
;
2929 if (need_restart_job
)
2932 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2936 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2937 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2940 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2941 printer
->name
, get_username(con
));
2945 cupsdAddPrinterHistory(printer
);
2947 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2948 "New printer \"%s\" added by \"%s\".", printer
->name
,
2951 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2952 printer
->name
, get_username(con
));
2955 con
->response
->request
.status
.status_code
= IPP_OK
;
2960 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2961 * based upon the printer state...
2965 add_printer_state_reasons(
2966 cupsd_client_t
*con
, /* I - Client connection */
2967 cupsd_printer_t
*p
) /* I - Printer info */
2969 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2970 "add_printer_state_reasons(%p[%d], %p[%s])",
2971 con
, con
->http
.fd
, p
, p
->name
);
2973 if (p
->num_reasons
== 0)
2974 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2975 "printer-state-reasons", NULL
, "none");
2977 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2978 "printer-state-reasons", p
->num_reasons
, NULL
,
2979 (const char * const *)p
->reasons
);
2984 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2985 * the specified printer or class.
2989 add_queued_job_count(
2990 cupsd_client_t
*con
, /* I - Client connection */
2991 cupsd_printer_t
*p
) /* I - Printer or class */
2993 int count
; /* Number of jobs on destination */
2996 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2997 con
, con
->http
.fd
, p
, p
->name
);
2999 count
= cupsdGetPrinterJobCount(p
->name
);
3001 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3002 "queued-job-count", count
);
3008 * 'apple_init_profile()' - Initialize a color profile.
3013 ppd_file_t
*ppd
, /* I - PPD file */
3014 cups_array_t
*languages
, /* I - Languages in the PPD file */
3015 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3016 unsigned id
, /* I - Profile ID */
3017 const char *name
, /* I - Profile name */
3018 const char *text
, /* I - Profile UI text */
3019 const char *iccfile
) /* I - ICC filename */
3021 char url
[1024]; /* URL for profile filename */
3022 CFMutableDictionaryRef dict
; /* Dictionary for name */
3023 char *language
; /* Current language */
3024 ppd_attr_t
*attr
; /* Profile attribute */
3025 CFStringRef cflang
, /* Language string */
3026 cftext
; /* Localized text */
3030 * Build the profile name dictionary...
3033 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3034 &kCFTypeDictionaryKeyCallBacks
,
3035 &kCFTypeDictionaryValueCallBacks
);
3037 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3038 kCFStringEncodingUTF8
);
3042 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
3049 * Find localized names for the color profiles...
3052 cupsArraySave(ppd
->sorted_attrs
);
3054 for (language
= (char *)cupsArrayFirst(languages
);
3056 language
= (char *)cupsArrayNext(languages
))
3060 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3062 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3065 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3067 if (attr
&& attr
->text
[0])
3069 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3070 kCFStringEncodingUTF8
);
3071 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3072 kCFStringEncodingUTF8
);
3074 if (cflang
&& cftext
)
3075 CFDictionarySetValue(dict
, cflang
, cftext
);
3085 cupsArrayRestore(ppd
->sorted_attrs
);
3089 * Fill in the profile data...
3093 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3096 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3097 profile
->profileID
= id
;
3098 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3099 profile
->profileName
= dict
;
3102 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3103 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3108 * 'apple_register_profiles()' - Register color profiles for a printer.
3112 apple_register_profiles(
3113 cupsd_printer_t
*p
) /* I - Printer */
3115 int i
; /* Looping var */
3116 char ppdfile
[1024], /* PPD filename */
3117 iccfile
[1024], /* ICC filename */
3118 selector
[PPD_MAX_NAME
];
3119 /* Profile selection string */
3120 ppd_file_t
*ppd
; /* PPD file */
3121 ppd_attr_t
*attr
, /* Profile attributes */
3122 *profileid_attr
,/* cupsProfileID attribute */
3123 *q1_attr
, /* ColorModel (or other) qualifier */
3124 *q2_attr
, /* MediaType (or other) qualifier */
3125 *q3_attr
; /* Resolution (or other) qualifier */
3126 char q_keyword
[PPD_MAX_NAME
];
3127 /* Qualifier keyword */
3128 const char *q1_choice
, /* ColorModel (or other) choice */
3129 *q2_choice
, /* MediaType (or other) choice */
3130 *q3_choice
; /* Resolution (or other) choice */
3131 const char *profile_key
; /* Profile keyword */
3132 ppd_option_t
*cm_option
; /* Color model option */
3133 ppd_choice_t
*cm_choice
; /* Color model choice */
3134 int num_profiles
; /* Number of profiles */
3135 CMError error
; /* Last error */
3136 unsigned device_id
, /* Printer device ID */
3137 profile_id
, /* Profile ID */
3138 default_profile_id
= 0;
3139 /* Default profile ID */
3140 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3141 CFStringRef printer_name
; /* Printer name string */
3142 CMDeviceScope scope
= /* Scope of the registration */
3144 kCFPreferencesAnyUser
,
3145 kCFPreferencesCurrentHost
3147 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3148 CMDeviceProfileInfo
*profile
; /* Current profile */
3149 cups_array_t
*languages
; /* Languages array */
3153 * Make sure ColorSync is available...
3156 if (CMRegisterColorDevice
== NULL
)
3160 * Try opening the PPD file for this printer...
3163 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3164 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3168 * See if we have any profiles...
3171 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3172 profile_key
= "APTiogaProfile";
3175 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3176 profile_key
= "cupsICCProfile";
3179 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3180 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3182 if (attr
->value
[0] != '/')
3183 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3186 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3188 if (access(iccfile
, 0))
3196 * If we have profiles, add them...
3199 if (num_profiles
> 0)
3201 if (profile_key
[0] == 'A')
3204 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3208 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3210 default_profile_id
= atoi(attr
->value
);
3212 q1_choice
= q2_choice
= q3_choice
= NULL
;
3217 * For CUPS PPDs, figure out the default profile selector values...
3220 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3221 attr
->value
&& attr
->value
[0])
3223 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3224 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3226 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3227 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3229 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3230 q1_choice
= q1_attr
->value
;
3234 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3235 attr
->value
&& attr
->value
[0])
3237 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3238 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3241 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3243 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3244 q2_choice
= q2_attr
->value
;
3248 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3249 attr
->value
&& attr
->value
[0])
3251 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3252 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3255 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3257 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3258 q3_choice
= q3_attr
->value
;
3264 * Build the array of profiles...
3266 * Note: This calloc actually requests slightly more memory than needed.
3269 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3271 cupsdLogMessage(CUPSD_LOG_ERROR
,
3272 "Unable to allocate memory for %d profiles!",
3278 profiles
->profileCount
= num_profiles
;
3279 languages
= _ppdGetLanguages(ppd
);
3281 for (profile
= profiles
->profiles
,
3282 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3284 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3285 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3288 * Add this profile...
3291 if (attr
->value
[0] != '/')
3292 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3295 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3297 if (access(iccfile
, 0))
3300 if (profile_key
[0] == 'c')
3302 cupsArraySave(ppd
->sorted_attrs
);
3304 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3305 attr
->spec
)) != NULL
&&
3306 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3307 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3309 profile_id
= _ppdHashName(attr
->spec
);
3311 cupsArrayRestore(ppd
->sorted_attrs
);
3314 profile_id
= atoi(attr
->spec
);
3316 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3317 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3322 * See if this is the default profile...
3325 if (!default_profile_id
)
3331 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3332 q1_choice
, q2_choice
, q3_choice
);
3333 if (!strcmp(selector
, attr
->spec
))
3334 default_profile_id
= profile_id
;
3337 if (!default_profile_id
)
3339 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3341 if (!strcmp(selector
, attr
->spec
))
3342 default_profile_id
= profile_id
;
3346 if (!default_profile_id
&& q3_choice
)
3348 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3350 if (!strcmp(selector
, attr
->spec
))
3351 default_profile_id
= profile_id
;
3354 if (!default_profile_id
)
3356 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3357 if (!strcmp(selector
, attr
->spec
))
3358 default_profile_id
= profile_id
;
3363 _ppdFreeLanguages(languages
);
3365 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3368 * Extract profiles from ColorModel option...
3371 const char *profile_name
; /* Name of generic profile */
3374 num_profiles
= cm_option
->num_choices
;
3376 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3378 cupsdLogMessage(CUPSD_LOG_ERROR
,
3379 "Unable to allocate memory for %d profiles!",
3385 profiles
->profileCount
= num_profiles
;
3387 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3388 cm_choice
= cm_option
->choices
;
3390 i
--, cm_choice
++, profile
++)
3392 if (!strcmp(cm_choice
->choice
, "Gray") ||
3393 !strcmp(cm_choice
->choice
, "Black"))
3394 profile_name
= "Gray";
3395 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3396 !strcmp(cm_choice
->choice
, "CMY"))
3397 profile_name
= "RGB";
3398 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3399 !strcmp(cm_choice
->choice
, "KCMY"))
3400 profile_name
= "CMYK";
3402 profile_name
= "DeviceN";
3404 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3405 profile_id
= _ppdHashName(selector
);
3407 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3408 cm_choice
->text
, NULL
);
3410 if (cm_choice
->marked
)
3411 default_profile_id
= profile_id
;
3417 * Use the default colorspace...
3420 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3422 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3424 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3426 cupsdLogMessage(CUPSD_LOG_ERROR
,
3427 "Unable to allocate memory for %d profiles!",
3433 profiles
->profileCount
= num_profiles
;
3435 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3436 "Gray", "Gray", NULL
);
3438 switch (ppd
->colorspace
)
3442 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3443 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3447 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3448 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3456 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3457 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3463 if (num_profiles
> 0)
3466 * Make sure we have a default profile ID...
3469 if (!default_profile_id
)
3470 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3473 * Get the device ID hash and pathelogical name dictionary.
3476 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3479 device_id
= _ppdHashName(p
->name
);
3480 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3481 &kCFTypeDictionaryKeyCallBacks
,
3482 &kCFTypeDictionaryValueCallBacks
);
3483 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3484 p
->name
, kCFStringEncodingUTF8
);
3486 if (device_name
&& printer_name
)
3488 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3491 * Register the device with ColorSync...
3494 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3495 device_name
, &scope
);
3498 * Register the profiles...
3502 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3503 default_profile_id
, profiles
);
3513 cupsdLogMessage(CUPSD_LOG_ERROR
,
3514 "Unable to register ICC color profiles for \"%s\" - %d",
3515 p
->name
, (int)error
);
3517 for (profile
= profiles
->profiles
;
3519 profile
++, num_profiles
--)
3520 CFRelease(profile
->profileName
);
3525 CFRelease(printer_name
);
3528 CFRelease(device_name
);
3536 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3541 apple_unregister_profiles(
3542 cupsd_printer_t
*p
) /* I - Printer */
3545 * Make sure ColorSync is available...
3548 if (CMUnregisterColorDevice
!= NULL
)
3549 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3551 #endif /* __APPLE__ */
3554 * 'apply_printer_defaults()' - Apply printer default options to a job.
3558 apply_printer_defaults(
3559 cupsd_printer_t
*printer
, /* I - Printer */
3560 cupsd_job_t
*job
) /* I - Job */
3562 int i
, /* Looping var */
3563 num_options
; /* Number of default options */
3564 cups_option_t
*options
, /* Default options */
3565 *option
; /* Current option */
3569 * Collect all of the default options and add the missing ones to the
3573 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3574 option
= printer
->options
;
3577 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3579 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3584 * Encode these options as attributes in the job object...
3587 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3588 cupsFreeOptions(num_options
, options
);
3593 * 'authenticate_job()' - Set job authentication info.
3597 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3598 ipp_attribute_t
*uri
) /* I - Job URI */
3600 ipp_attribute_t
*attr
, /* job-id attribute */
3601 *auth_info
; /* auth-info attribute */
3602 int jobid
; /* Job ID */
3603 cupsd_job_t
*job
; /* Current job */
3604 char scheme
[HTTP_MAX_URI
],
3605 /* Method portion of URI */
3606 username
[HTTP_MAX_URI
],
3607 /* Username portion of URI */
3609 /* Host portion of URI */
3610 resource
[HTTP_MAX_URI
];
3611 /* Resource portion of URI */
3612 int port
; /* Port portion of URI */
3615 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3616 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3619 * Start with "everything is OK" status...
3622 con
->response
->request
.status
.status_code
= IPP_OK
;
3625 * See if we have a job URI or a printer URI...
3628 if (!strcmp(uri
->name
, "printer-uri"))
3631 * Got a printer URI; see if we also have a job-id attribute...
3634 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3635 IPP_TAG_INTEGER
)) == NULL
)
3637 send_ipp_status(con
, IPP_BAD_REQUEST
,
3638 _("Got a printer-uri attribute but no job-id!"));
3642 jobid
= attr
->values
[0].integer
;
3647 * Got a job URI; parse it to get the job ID...
3650 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3651 sizeof(scheme
), username
, sizeof(username
), host
,
3652 sizeof(host
), &port
, resource
, sizeof(resource
));
3654 if (strncmp(resource
, "/jobs/", 6))
3660 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
3661 uri
->values
[0].string
.text
);
3665 jobid
= atoi(resource
+ 6);
3669 * See if the job exists...
3672 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3675 * Nope - return a "not found" error...
3678 send_ipp_status(con
, IPP_NOT_FOUND
,
3679 _("Job #%d does not exist!"), jobid
);
3684 * See if the job has been completed...
3687 if (job
->state_value
!= IPP_JOB_HELD
)
3690 * Return a "not-possible" error...
3693 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3694 _("Job #%d is not held for authentication!"),
3700 * See if we have already authenticated...
3703 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3705 if (!con
->username
[0] && !auth_info
)
3707 cupsd_printer_t
*printer
; /* Job destination */
3711 * No auth data. If we need to authenticate via Kerberos, send a
3712 * HTTP auth challenge, otherwise just return an IPP error...
3715 printer
= cupsdFindDest(job
->dest
);
3717 if (printer
&& printer
->num_auth_info_required
> 0 &&
3718 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3719 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3721 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3722 _("No authentication information provided!"));
3727 * See if the job is owned by the requesting user...
3730 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3732 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
3737 * Save the authentication information for this job...
3740 save_auth_info(con
, job
, auth_info
);
3743 * Reset the job-hold-until value to "no-hold"...
3746 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3747 IPP_TAG_KEYWORD
)) == NULL
)
3748 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3752 attr
->value_tag
= IPP_TAG_KEYWORD
;
3753 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3757 * Release the job and return...
3760 cupsdReleaseJob(job
);
3762 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3767 * 'cancel_all_jobs()' - Cancel all print jobs.
3771 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3772 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3774 http_status_t status
; /* Policy status */
3775 cups_ptype_t dtype
; /* Destination type */
3776 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3777 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3778 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3779 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3780 int port
; /* Port portion of URI */
3781 ipp_attribute_t
*attr
; /* Attribute in request */
3782 const char *username
; /* Username */
3783 int purge
; /* Purge? */
3784 cupsd_printer_t
*printer
; /* Printer */
3787 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3788 con
->http
.fd
, uri
->values
[0].string
.text
);
3791 * See if we have a printer URI...
3794 if (strcmp(uri
->name
, "printer-uri"))
3796 send_ipp_status(con
, IPP_BAD_REQUEST
,
3797 _("The printer-uri attribute is required!"));
3802 * Get the username (if any) for the jobs we want to cancel (only if
3803 * "my-jobs" is specified...
3806 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3807 IPP_TAG_BOOLEAN
)) != NULL
&&
3808 attr
->values
[0].boolean
)
3810 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3811 IPP_TAG_NAME
)) != NULL
)
3812 username
= attr
->values
[0].string
.text
;
3815 send_ipp_status(con
, IPP_BAD_REQUEST
,
3816 _("Missing requesting-user-name attribute!"));
3824 * Look for the "purge-jobs" attribute...
3827 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3828 IPP_TAG_BOOLEAN
)) != NULL
)
3829 purge
= attr
->values
[0].boolean
;
3834 * And if the destination is valid...
3837 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3843 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3844 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3845 hostname
, sizeof(hostname
), &port
,
3846 resource
, sizeof(resource
));
3848 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3849 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3851 send_ipp_status(con
, IPP_NOT_FOUND
,
3852 _("The printer or class was not found."));
3860 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3862 send_http_error(con
, status
, NULL
);
3867 * Cancel all jobs on all printers...
3870 cupsdCancelJobs(NULL
, username
, purge
);
3872 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3873 purge
? "purged" : "canceled", get_username(con
));
3881 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3884 send_http_error(con
, status
, printer
);
3889 * Cancel all of the jobs on the named printer...
3892 cupsdCancelJobs(printer
->name
, username
, purge
);
3894 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3895 printer
->name
, purge
? "purged" : "canceled",
3899 con
->response
->request
.status
.status_code
= IPP_OK
;
3904 * 'cancel_job()' - Cancel a print job.
3908 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3909 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3911 ipp_attribute_t
*attr
; /* Current attribute */
3912 int jobid
; /* Job ID */
3913 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3914 username
[HTTP_MAX_URI
], /* Username portion of URI */
3915 host
[HTTP_MAX_URI
], /* Host portion of URI */
3916 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3917 int port
; /* Port portion of URI */
3918 cupsd_job_t
*job
; /* Job information */
3919 cups_ptype_t dtype
; /* Destination type (printer/class) */
3920 cupsd_printer_t
*printer
; /* Printer data */
3921 int purge
; /* Purge the job? */
3924 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3925 con
->http
.fd
, uri
->values
[0].string
.text
);
3928 * See if we have a job URI or a printer URI...
3931 if (!strcmp(uri
->name
, "printer-uri"))
3934 * Got a printer URI; see if we also have a job-id attribute...
3937 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3938 IPP_TAG_INTEGER
)) == NULL
)
3940 send_ipp_status(con
, IPP_BAD_REQUEST
,
3941 _("Got a printer-uri attribute but no job-id!"));
3945 if ((jobid
= attr
->values
[0].integer
) == 0)
3948 * Find the current job on the specified printer...
3951 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3957 send_ipp_status(con
, IPP_NOT_FOUND
,
3958 _("The printer or class was not found."));
3963 * See if the printer is currently printing a job...
3967 jobid
= ((cupsd_job_t
*)printer
->job
)->id
;
3971 * No, see if there are any pending jobs...
3974 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3976 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3977 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3978 !strcasecmp(job
->dest
, printer
->name
))
3985 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3987 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3988 if (job
->state_value
== IPP_JOB_STOPPED
&&
3989 !strcasecmp(job
->dest
, printer
->name
))
3996 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
;
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
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
4064 * See if the job is already completed, canceled, or aborted; if so,
4065 * we can't cancel...
4068 if (job
->state_value
>= IPP_JOB_CANCELED
&& !purge
)
4070 switch (job
->state_value
)
4072 case IPP_JOB_CANCELED
:
4073 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4074 _("Job #%d is already canceled - can\'t cancel."),
4078 case IPP_JOB_ABORTED
:
4079 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4080 _("Job #%d is already aborted - can\'t cancel."),
4085 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4086 _("Job #%d is already completed - can\'t cancel."),
4095 * Cancel the job and return...
4098 cupsdCancelJob(job
, purge
, IPP_JOB_CANCELED
);
4102 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4105 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4108 con
->response
->request
.status
.status_code
= IPP_OK
;
4113 * 'cancel_subscription()' - Cancel a subscription.
4117 cancel_subscription(
4118 cupsd_client_t
*con
, /* I - Client connection */
4119 int sub_id
) /* I - Subscription ID */
4121 http_status_t status
; /* Policy status */
4122 cupsd_subscription_t
*sub
; /* Subscription */
4125 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4126 "cancel_subscription(con=%p[%d], sub_id=%d)",
4127 con
, con
->http
.fd
, sub_id
);
4130 * Is the subscription ID valid?
4133 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4136 * Bad subscription ID...
4139 send_ipp_status(con
, IPP_NOT_FOUND
,
4140 _("notify-subscription-id %d no good!"), sub_id
);
4148 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4150 con
, sub
->owner
)) != HTTP_OK
)
4152 send_http_error(con
, status
, sub
->dest
);
4157 * Cancel the subscription...
4160 cupsdDeleteSubscription(sub
, 1);
4162 con
->response
->request
.status
.status_code
= IPP_OK
;
4167 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4170 static int /* O - 1 if OK, 0 if not */
4171 check_rss_recipient(
4172 const char *recipient
) /* I - Recipient URI */
4174 cupsd_subscription_t
*sub
; /* Current subscription */
4177 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4179 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4183 * Compare the URIs up to the first ?...
4186 const char *r1
, *r2
;
4188 for (r1
= recipient
, r2
= sub
->recipient
;
4189 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4201 * 'check_quotas()' - Check quotas for a printer and user.
4204 static int /* O - 1 if OK, 0 if not */
4205 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4206 cupsd_printer_t
*p
) /* I - Printer or class */
4208 int i
; /* Looping var */
4209 char username
[33]; /* Username */
4210 cupsd_quota_t
*q
; /* Quota data */
4211 #ifdef HAVE_MBR_UID_TO_UUID
4213 * Use Apple membership APIs which require that all names represent
4214 * valid user account or group records accessible by the server.
4217 uuid_t usr_uuid
; /* UUID for job requesting user */
4218 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4219 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4220 int mbr_err
; /* Error from membership function */
4221 int is_member
; /* Is this user a member? */
4224 * Use standard POSIX APIs for checking users and groups...
4227 struct passwd
*pw
; /* User password data */
4228 #endif /* HAVE_MBR_UID_TO_UUID */
4231 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4232 con
, con
->http
.fd
, p
, p
->name
);
4235 * Figure out who is printing...
4238 strlcpy(username
, get_username(con
), sizeof(username
));
4241 * Check global active job limits for printers and users...
4244 if (MaxJobsPerPrinter
)
4247 * Check if there are too many pending jobs on this printer...
4250 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4252 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4261 * Check if there are too many pending jobs for this user...
4264 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4266 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4273 * Check against users...
4276 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4281 #ifdef HAVE_MBR_UID_TO_UUID
4283 * Get UUID for job requesting user...
4286 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4292 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4293 "check_quotas: UUID lookup failed for user \"%s\"",
4295 cupsdLogMessage(CUPSD_LOG_INFO
,
4296 "Denying user \"%s\" access to printer \"%s\" "
4297 "(unknown user)...",
4303 * Get UID and GID of requesting user...
4306 pw
= getpwnam(username
);
4308 #endif /* HAVE_MBR_UID_TO_UUID */
4310 for (i
= 0; i
< p
->num_users
; i
++)
4311 if (p
->users
[i
][0] == '@')
4314 * Check group membership...
4317 #ifdef HAVE_MBR_UID_TO_UUID
4318 if (p
->users
[i
][1] == '#')
4320 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4321 uuid_clear(grp_uuid
);
4323 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4327 * Invalid ACL entries are ignored for matching; just record a
4328 * warning in the log...
4331 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4332 "check_quotas: UUID lookup failed for ACL entry "
4333 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4334 cupsdLogMessage(CUPSD_LOG_WARN
,
4335 "Access control entry \"%s\" not a valid group name; "
4336 "entry ignored", p
->users
[i
]);
4339 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4343 * At this point, there should be no errors, but check anyways...
4346 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4347 "check_quotas: group \"%s\" membership check "
4348 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4353 * Stop if we found a match...
4360 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4362 #endif /* HAVE_MBR_UID_TO_UUID */
4364 #ifdef HAVE_MBR_UID_TO_UUID
4367 if (p
->users
[i
][0] == '#')
4369 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4370 uuid_clear(usr2_uuid
);
4372 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4376 * Invalid ACL entries are ignored for matching; just record a
4377 * warning in the log...
4380 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4381 "check_quotas: UUID lookup failed for ACL entry "
4382 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4383 cupsdLogMessage(CUPSD_LOG_WARN
,
4384 "Access control entry \"%s\" not a valid user name; "
4385 "entry ignored", p
->users
[i
]);
4388 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4392 else if (!strcasecmp(username
, p
->users
[i
]))
4394 #endif /* HAVE_MBR_UID_TO_UUID */
4396 if ((i
< p
->num_users
) == p
->deny_users
)
4398 cupsdLogMessage(CUPSD_LOG_INFO
,
4399 "Denying user \"%s\" access to printer \"%s\"...",
4410 if (AppleQuotas
&& (q
= cupsdFindQuota(p
, username
)) != NULL
)
4413 * TODO: Define these special page count values as constants!
4416 if (q
->page_count
== -4) /* special case: unlimited user */
4418 cupsdLogMessage(CUPSD_LOG_INFO
,
4419 "User \"%s\" request approved for printer %s (%s): "
4421 username
, p
->name
, p
->info
);
4422 q
->page_count
= 0; /* allow user to print */
4425 else if (q
->page_count
== -3) /* quota exceeded */
4427 cupsdLogMessage(CUPSD_LOG_INFO
,
4428 "User \"%s\" request denied for printer %s (%s): "
4429 "quota limit exceeded.",
4430 username
, p
->name
, p
->info
);
4431 q
->page_count
= 2; /* force quota exceeded failure */
4434 else if (q
->page_count
== -2) /* quota disabled for user */
4436 cupsdLogMessage(CUPSD_LOG_INFO
,
4437 "User \"%s\" request denied for printer %s (%s): "
4438 "printing disabled for user.",
4439 username
, p
->name
, p
->info
);
4440 q
->page_count
= 2; /* force quota exceeded failure */
4443 else if (q
->page_count
== -1) /* quota access error */
4445 cupsdLogMessage(CUPSD_LOG_INFO
,
4446 "User \"%s\" request denied for printer %s (%s): "
4447 "unable to determine quota limit.",
4448 username
, p
->name
, p
->info
);
4449 q
->page_count
= 2; /* force quota exceeded failure */
4452 else if (q
->page_count
< 0) /* user not found or other error */
4454 cupsdLogMessage(CUPSD_LOG_INFO
,
4455 "User \"%s\" request denied for printer %s (%s): "
4456 "user disabled / missing quota.",
4457 username
, p
->name
, p
->info
);
4458 q
->page_count
= 2; /* force quota exceeded failure */
4461 else /* page within user limits */
4463 q
->page_count
= 0; /* allow user to print */
4468 #endif /* __APPLE__ */
4469 if (p
->k_limit
|| p
->page_limit
)
4471 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4473 cupsdLogMessage(CUPSD_LOG_ERROR
,
4474 "Unable to allocate quota data for user \"%s\"!",
4479 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4480 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4482 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4489 * If we have gotten this far, we're done!
4497 * 'copy_attribute()' - Copy a single attribute.
4500 static ipp_attribute_t
* /* O - New attribute */
4502 ipp_t
*to
, /* O - Destination request/response */
4503 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4504 int quickcopy
) /* I - Do a quick copy? */
4506 int i
; /* Looping var */
4507 ipp_attribute_t
*toattr
; /* Destination attribute */
4510 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4511 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4512 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4515 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4518 toattr
= ippAddSeparator(to
);
4521 case IPP_TAG_INTEGER
:
4523 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4524 attr
->name
, attr
->num_values
, NULL
);
4526 for (i
= 0; i
< attr
->num_values
; i
++)
4527 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4530 case IPP_TAG_BOOLEAN
:
4531 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4532 attr
->num_values
, NULL
);
4534 for (i
= 0; i
< attr
->num_values
; i
++)
4535 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4538 case IPP_TAG_STRING
:
4541 case IPP_TAG_KEYWORD
:
4543 case IPP_TAG_URISCHEME
:
4544 case IPP_TAG_CHARSET
:
4545 case IPP_TAG_LANGUAGE
:
4546 case IPP_TAG_MIMETYPE
:
4547 toattr
= ippAddStrings(to
, attr
->group_tag
,
4548 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4549 attr
->name
, attr
->num_values
, NULL
, NULL
);
4553 for (i
= 0; i
< attr
->num_values
; i
++)
4554 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4556 else if (attr
->value_tag
& IPP_TAG_COPY
)
4558 for (i
= 0; i
< attr
->num_values
; i
++)
4559 toattr
->values
[i
].string
.text
=
4560 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4564 for (i
= 0; i
< attr
->num_values
; i
++)
4565 toattr
->values
[i
].string
.text
=
4566 _cupsStrRetain(attr
->values
[i
].string
.text
);
4571 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4572 attr
->values
[0].date
);
4575 case IPP_TAG_RESOLUTION
:
4576 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4577 attr
->num_values
, IPP_RES_PER_INCH
,
4580 for (i
= 0; i
< attr
->num_values
; i
++)
4582 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4583 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4584 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4588 case IPP_TAG_RANGE
:
4589 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4590 attr
->num_values
, NULL
, NULL
);
4592 for (i
= 0; i
< attr
->num_values
; i
++)
4594 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4595 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4599 case IPP_TAG_TEXTLANG
:
4600 case IPP_TAG_NAMELANG
:
4601 toattr
= ippAddStrings(to
, attr
->group_tag
,
4602 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4603 attr
->name
, attr
->num_values
, NULL
, NULL
);
4607 for (i
= 0; i
< attr
->num_values
; i
++)
4609 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4610 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4613 else if (attr
->value_tag
& IPP_TAG_COPY
)
4615 for (i
= 0; i
< attr
->num_values
; i
++)
4618 toattr
->values
[i
].string
.charset
=
4619 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4621 toattr
->values
[i
].string
.charset
=
4622 toattr
->values
[0].string
.charset
;
4624 toattr
->values
[i
].string
.text
=
4625 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4630 for (i
= 0; i
< attr
->num_values
; i
++)
4633 toattr
->values
[i
].string
.charset
=
4634 _cupsStrRetain(attr
->values
[i
].string
.charset
);
4636 toattr
->values
[i
].string
.charset
=
4637 toattr
->values
[0].string
.charset
;
4639 toattr
->values
[i
].string
.text
=
4640 _cupsStrRetain(attr
->values
[i
].string
.text
);
4645 case IPP_TAG_BEGIN_COLLECTION
:
4646 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4647 attr
->num_values
, NULL
);
4649 for (i
= 0; i
< attr
->num_values
; i
++)
4651 toattr
->values
[i
].collection
= ippNew();
4652 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
4653 NULL
, IPP_TAG_ZERO
, 0);
4658 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4659 attr
->name
, attr
->num_values
, NULL
);
4661 for (i
= 0; i
< attr
->num_values
; i
++)
4663 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4665 if (toattr
->values
[i
].unknown
.length
> 0)
4667 if ((toattr
->values
[i
].unknown
.data
=
4668 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4669 toattr
->values
[i
].unknown
.length
= 0;
4671 memcpy(toattr
->values
[i
].unknown
.data
,
4672 attr
->values
[i
].unknown
.data
,
4673 toattr
->values
[i
].unknown
.length
);
4676 break; /* anti-compiler-warning-code */
4684 * 'copy_attrs()' - Copy attributes from one request to another.
4688 copy_attrs(ipp_t
*to
, /* I - Destination request */
4689 ipp_t
*from
, /* I - Source request */
4690 cups_array_t
*ra
, /* I - Requested attributes */
4691 ipp_tag_t group
, /* I - Group to copy */
4692 int quickcopy
) /* I - Do a quick copy? */
4694 ipp_attribute_t
*fromattr
; /* Source attribute */
4697 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4698 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4699 to
, from
, ra
, group
, quickcopy
);
4704 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4707 * Filter attributes as needed...
4710 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4711 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4714 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4717 * Don't send collection attributes by default to IPP/1.x clients
4718 * since many do not support collections...
4721 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4722 !ra
&& to
->request
.status
.version
[0] == 1)
4725 copy_attribute(to
, fromattr
, quickcopy
);
4732 * 'copy_banner()' - Copy a banner file to the requests directory for the
4736 static int /* O - Size of banner file in kbytes */
4737 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4738 cupsd_job_t
*job
, /* I - Job information */
4739 const char *name
) /* I - Name of banner */
4741 int i
; /* Looping var */
4742 int kbytes
; /* Size of banner file in kbytes */
4743 char filename
[1024]; /* Job filename */
4744 cupsd_banner_t
*banner
; /* Pointer to banner */
4745 cups_file_t
*in
; /* Input file */
4746 cups_file_t
*out
; /* Output file */
4747 int ch
; /* Character from file */
4748 char attrname
[255], /* Name of attribute */
4749 *s
; /* Pointer into name */
4750 ipp_attribute_t
*attr
; /* Attribute */
4753 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4754 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4755 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4756 name
? name
: "(null)");
4759 * Find the banner; return if not found or "none"...
4762 if (!name
|| !strcmp(name
, "none") ||
4763 (banner
= cupsdFindBanner(name
)) == NULL
)
4767 * Open the banner and job files...
4770 if (add_file(con
, job
, banner
->filetype
, 0))
4773 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4775 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4777 cupsdLogMessage(CUPSD_LOG_ERROR
,
4778 "Unable to create banner job file %s - %s",
4779 filename
, strerror(errno
));
4784 fchmod(cupsFileNumber(out
), 0640);
4785 fchown(cupsFileNumber(out
), RunUser
, Group
);
4788 * Try the localized banner file under the subdirectory...
4791 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4793 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4796 * Convert ll-cc to ll_CC...
4800 attrname
[3] = toupper(attrname
[3] & 255);
4801 attrname
[4] = toupper(attrname
[4] & 255);
4804 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4807 if (access(filename
, 0) && strlen(attrname
) > 2)
4810 * Wasn't able to find "ll_CC" locale file; try the non-national
4811 * localization banner directory.
4816 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4820 if (access(filename
, 0))
4823 * Use the non-localized banner file.
4826 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4829 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4833 cupsdLogMessage(CUPSD_LOG_ERROR
,
4834 "Unable to open banner template file %s - %s",
4835 filename
, strerror(errno
));
4841 * Parse the file to the end...
4844 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4848 * Get an attribute name...
4851 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4852 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4854 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4864 * Ignore { followed by stuff that is not an attribute name...
4867 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4872 * See if it is defined...
4875 if (attrname
[0] == '?')
4880 if (!strcmp(s
, "printer-name"))
4882 cupsFilePuts(out
, job
->dest
);
4885 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4888 * See if we have a leading question mark...
4891 if (attrname
[0] != '?')
4894 * Nope, write to file as-is; probably a PostScript procedure...
4897 cupsFilePrintf(out
, "{%s}", attrname
);
4904 * Output value(s)...
4907 for (i
= 0; i
< attr
->num_values
; i
++)
4910 cupsFilePutChar(out
, ',');
4912 switch (attr
->value_tag
)
4914 case IPP_TAG_INTEGER
:
4916 if (!strncmp(s
, "time-at-", 8))
4918 struct timeval tv
= { attr
->values
[i
].integer
, 0 };
4919 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4922 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4925 case IPP_TAG_BOOLEAN
:
4926 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4929 case IPP_TAG_NOVALUE
:
4930 cupsFilePuts(out
, "novalue");
4933 case IPP_TAG_RANGE
:
4934 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4935 attr
->values
[i
].range
.upper
);
4938 case IPP_TAG_RESOLUTION
:
4939 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4940 attr
->values
[i
].resolution
.yres
,
4941 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4946 case IPP_TAG_STRING
:
4949 case IPP_TAG_KEYWORD
:
4950 case IPP_TAG_CHARSET
:
4951 case IPP_TAG_LANGUAGE
:
4952 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
4955 * Need to quote strings for PS banners...
4960 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4962 if (*p
== '(' || *p
== ')' || *p
== '\\')
4964 cupsFilePutChar(out
, '\\');
4965 cupsFilePutChar(out
, *p
);
4967 else if (*p
< 32 || *p
> 126)
4968 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4970 cupsFilePutChar(out
, *p
);
4974 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4978 break; /* anti-compiler-warning-code */
4982 else if (ch
== '\\') /* Quoted char */
4984 ch
= cupsFileGetChar(in
);
4986 if (ch
!= '{') /* Only do special handling for \{ */
4987 cupsFilePutChar(out
, '\\');
4989 cupsFilePutChar(out
, ch
);
4992 cupsFilePutChar(out
, ch
);
4996 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4998 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4999 IPP_TAG_INTEGER
)) != NULL
)
5000 attr
->values
[0].integer
+= kbytes
;
5009 * 'copy_file()' - Copy a PPD file or interface script...
5012 static int /* O - 0 = success, -1 = error */
5013 copy_file(const char *from
, /* I - Source file */
5014 const char *to
) /* I - Destination file */
5016 cups_file_t
*src
, /* Source file */
5017 *dst
; /* Destination file */
5018 int bytes
; /* Bytes to read/write */
5019 char buffer
[2048]; /* Copy buffer */
5022 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5025 * Open the source and destination file for a copy...
5028 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5031 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5038 * Copy the source file to the destination...
5041 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5042 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5050 * Close both files and return...
5055 return (cupsFileClose(dst
));
5060 * 'copy_model()' - Copy a PPD model file, substituting default values
5064 static int /* O - 0 = success, -1 = error */
5065 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5066 const char *from
, /* I - Source file */
5067 const char *to
) /* I - Destination file */
5069 fd_set input
; /* select() input set */
5070 struct timeval timeout
; /* select() timeout */
5071 int maxfd
; /* Max file descriptor for select() */
5072 char tempfile
[1024]; /* Temporary PPD file */
5073 int tempfd
; /* Temporary PPD file descriptor */
5074 int temppid
; /* Process ID of cups-driverd */
5075 int temppipe
[2]; /* Temporary pipes */
5076 char *argv
[4], /* Command-line arguments */
5077 *envp
[MAX_ENV
]; /* Environment */
5078 cups_file_t
*src
, /* Source file */
5079 *dst
; /* Destination file */
5080 ppd_file_t
*ppd
; /* PPD file */
5081 int bytes
, /* Bytes from pipe */
5082 total
; /* Total bytes from pipe */
5083 char buffer
[2048]; /* Copy buffer */
5084 int i
; /* Looping var */
5085 char option
[PPD_MAX_NAME
], /* Option name */
5086 choice
[PPD_MAX_NAME
]; /* Choice name */
5087 int num_defaults
; /* Number of default options */
5088 cups_option_t
*defaults
; /* Default options */
5089 char cups_protocol
[PPD_MAX_LINE
];
5090 /* cupsProtocol attribute */
5093 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5094 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5098 * Run cups-driverd to get the PPD file...
5101 argv
[0] = "cups-driverd";
5103 argv
[2] = (char *)from
;
5106 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5108 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5109 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5110 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5114 cupsdOpenPipe(temppipe
);
5116 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5117 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5119 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5120 -1, -1, 0, DefaultProfile
, &temppid
))
5131 * Wait up to 30 seconds for the PPD file to be copied...
5136 if (temppipe
[0] > CGIPipes
[0])
5137 maxfd
= temppipe
[0] + 1;
5139 maxfd
= CGIPipes
[0] + 1;
5144 * See if we have data ready...
5148 FD_SET(temppipe
[0], &input
);
5149 FD_SET(CGIPipes
[0], &input
);
5151 timeout
.tv_sec
= 30;
5152 timeout
.tv_usec
= 0;
5154 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5164 * We have timed out...
5170 if (FD_ISSET(temppipe
[0], &input
))
5173 * Read the PPD file from the pipe, and write it to the PPD file.
5176 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5178 if (write(tempfd
, buffer
, bytes
) < bytes
)
5187 if (FD_ISSET(CGIPipes
[0], &input
))
5197 * No data from cups-deviced...
5200 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
5206 * Read the source file and see what page sizes are supported...
5209 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5216 * Open the destination (if possible) and set the default options...
5221 cups_protocol
[0] = '\0';
5223 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5226 * Read all of the default lines from the old PPD...
5229 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5230 if (!strncmp(buffer
, "*Default", 8))
5233 * Add the default option...
5236 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5237 choice
, sizeof(choice
)))
5239 ppd_option_t
*ppdo
; /* PPD option */
5243 * Only add the default if the default hasn't already been
5244 * set and the choice exists in the new PPD...
5247 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5248 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5249 ppdFindChoice(ppdo
, choice
))
5250 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5254 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5255 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5259 else if (ppdPageSize(ppd
, DefaultPaperSize
))
5262 * Add the default media sizes...
5265 num_defaults
= cupsAddOption("PageSize", DefaultPaperSize
,
5266 num_defaults
, &defaults
);
5267 num_defaults
= cupsAddOption("PageRegion", DefaultPaperSize
,
5268 num_defaults
, &defaults
);
5269 num_defaults
= cupsAddOption("PaperDimension", DefaultPaperSize
,
5270 num_defaults
, &defaults
);
5271 num_defaults
= cupsAddOption("ImageableArea", DefaultPaperSize
,
5272 num_defaults
, &defaults
);
5278 * Open the source file for a copy...
5281 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5283 cupsFreeOptions(num_defaults
, defaults
);
5289 * Open the destination file for a copy...
5292 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5294 cupsFreeOptions(num_defaults
, defaults
);
5301 * Copy the source file to the destination...
5304 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5306 if (!strncmp(buffer
, "*Default", 8))
5309 * Check for an previous default option choice...
5312 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5313 choice
, sizeof(choice
)))
5315 const char *val
; /* Default option value */
5318 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5321 * Substitute the previous choice...
5324 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5329 cupsFilePrintf(dst
, "%s\n", buffer
);
5332 if (cups_protocol
[0])
5333 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5335 cupsFreeOptions(num_defaults
, defaults
);
5338 * Close both files and return...
5345 return (cupsFileClose(dst
));
5350 * 'copy_job_attrs()' - Copy job attributes.
5354 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5355 cupsd_job_t
*job
, /* I - Job */
5356 cups_array_t
*ra
) /* I - Requested attributes array */
5358 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5362 * Send the requested attributes for each job...
5365 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5366 con
->servername
, con
->serverport
, "/jobs/%d",
5369 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5370 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5371 "document-count", job
->num_files
);
5373 if (!ra
|| cupsArrayFind(ra
, "job-media-progress"))
5374 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5375 "job-media-progress", job
->progress
);
5377 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5378 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5379 "job-more-info", NULL
, job_uri
);
5381 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5382 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5383 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5384 job
->num_files
> 0);
5386 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5387 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5388 "job-printer-up-time", time(NULL
));
5390 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5391 add_job_state_reasons(con
, job
);
5393 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5394 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5395 "job-uri", NULL
, job_uri
);
5397 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5402 * 'copy_printer_attrs()' - Copy printer attributes.
5407 cupsd_client_t
*con
, /* I - Client connection */
5408 cupsd_printer_t
*printer
, /* I - Printer */
5409 cups_array_t
*ra
) /* I - Requested attributes array */
5411 char printer_uri
[HTTP_MAX_URI
];
5413 time_t curtime
; /* Current time */
5414 int i
; /* Looping var */
5415 ipp_attribute_t
*history
; /* History collection */
5419 * Copy the printer attributes to the response using requested-attributes
5420 * and document-format attributes that may be provided by the client.
5423 curtime
= time(NULL
);
5426 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
5427 printer
->recoverable
)
5428 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5429 "com.apple.print.recoverable-message", NULL
,
5430 printer
->recoverable
);
5431 #endif /* __APPLE__ */
5433 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5434 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5435 "marker-change-time", printer
->marker_time
);
5437 if (printer
->num_printers
> 0 &&
5438 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5440 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5441 cupsd_printer_t
*p2
; /* Printer in class */
5442 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5445 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5446 IPP_TAG_URI
, "member-uris",
5447 printer
->num_printers
, NULL
,
5450 for (i
= 0; i
< printer
->num_printers
; i
++)
5452 p2
= printer
->printers
[i
];
5454 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5455 IPP_TAG_URI
)) != NULL
)
5456 member_uris
->values
[i
].string
.text
=
5457 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5460 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5461 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5463 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5464 "/classes/%s" : "/printers/%s", p2
->name
);
5465 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5471 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5472 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5473 "printer-alert", NULL
, printer
->alert
);
5475 if (printer
->alert_description
&&
5476 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5477 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5478 "printer-alert-description", NULL
,
5479 printer
->alert_description
);
5481 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5482 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5483 ippTimeToDate(curtime
));
5486 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5488 if (printer
->reg_name
)
5489 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5490 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5492 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5493 "printer-dns-sd-name", 0);
5495 #endif /* HAVE_DNSSD */
5497 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5498 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5499 "printer-error-policy", NULL
, printer
->error_policy
);
5501 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5502 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5503 printer
->accepting
);
5505 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5506 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5509 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5510 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5512 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5513 "http", NULL
, con
->servername
, con
->serverport
,
5514 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5515 "/classes/%s" : "/printers/%s", printer
->name
);
5516 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5517 "printer-more-info", NULL
, printer_uri
);
5520 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5521 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5522 "printer-op-policy", NULL
, printer
->op_policy
);
5524 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5525 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5528 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5529 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5530 "printer-state-change-time", printer
->state_time
);
5532 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5533 cupsArrayFind(ra
, "printer-state-history"))
5536 * Printer history is only sent if specifically requested, so that
5537 * older CUPS/IPP clients won't barf on the collection attributes.
5540 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5541 "printer-state-history",
5542 printer
->num_history
, NULL
);
5544 for (i
= 0; i
< printer
->num_history
; i
++)
5545 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5546 NULL
, IPP_TAG_ZERO
, 0);
5549 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5550 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5551 "printer-state-message", NULL
, printer
->state_message
);
5553 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5554 add_printer_state_reasons(con
, printer
);
5556 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5558 int type
; /* printer-type value */
5562 * Add the CUPS-specific printer-type attribute...
5565 type
= printer
->type
;
5567 if (printer
== DefaultPrinter
)
5568 type
|= CUPS_PRINTER_DEFAULT
;
5570 if (!printer
->accepting
)
5571 type
|= CUPS_PRINTER_REJECTING
;
5573 if (!printer
->shared
)
5574 type
|= CUPS_PRINTER_NOT_SHARED
;
5576 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5580 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5581 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5582 "printer-up-time", curtime
);
5584 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5585 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5587 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5588 "ipp", NULL
, con
->servername
, con
->serverport
,
5589 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5590 "/classes/%s" : "/printers/%s", printer
->name
);
5591 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5592 "printer-uri-supported", NULL
, printer_uri
);
5593 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5597 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5598 add_queued_job_count(con
, printer
);
5600 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5601 if (printer
->ppd_attrs
)
5602 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0);
5603 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5608 * 'copy_subscription_attrs()' - Copy subscription attributes.
5612 copy_subscription_attrs(
5613 cupsd_client_t
*con
, /* I - Client connection */
5614 cupsd_subscription_t
*sub
, /* I - Subscription */
5615 cups_array_t
*ra
) /* I - Requested attributes array */
5617 ipp_attribute_t
*attr
; /* Current attribute */
5618 char printer_uri
[HTTP_MAX_URI
];
5620 int count
; /* Number of events */
5621 unsigned mask
; /* Current event mask */
5622 const char *name
; /* Current event name */
5626 * Copy the subscription attributes to the response using the
5627 * requested-attributes attribute that may be provided by the client.
5630 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5632 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5635 * Simple event list...
5638 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5639 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5640 "notify-events", NULL
, name
);
5645 * Complex event list...
5648 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5649 if (sub
->mask
& mask
)
5652 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5653 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5654 "notify-events", count
, NULL
, NULL
);
5656 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5657 if (sub
->mask
& mask
)
5659 attr
->values
[count
].string
.text
=
5660 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5667 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5668 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5669 "notify-job-id", sub
->job
->id
);
5671 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5672 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5673 "notify-lease-duration", sub
->lease
);
5675 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5677 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5678 "ipp", NULL
, con
->servername
, con
->serverport
,
5679 "/printers/%s", sub
->dest
->name
);
5680 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5681 "notify-printer-uri", NULL
, printer_uri
);
5684 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5685 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5686 "notify-recipient-uri", NULL
, sub
->recipient
);
5687 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5688 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5689 "notify-pull-method", NULL
, "ippget");
5691 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5692 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5693 "notify-subscriber-user-name", NULL
, sub
->owner
);
5695 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5696 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5697 "notify-subscription-id", sub
->id
);
5699 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5700 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5701 "notify-time-interval", sub
->interval
);
5703 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5704 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5705 sub
->user_data
, sub
->user_data_len
);
5710 * 'create_job()' - Print a file to a printer or class.
5714 create_job(cupsd_client_t
*con
, /* I - Client connection */
5715 ipp_attribute_t
*uri
) /* I - Printer URI */
5717 cupsd_printer_t
*printer
; /* Printer */
5718 cupsd_job_t
*job
; /* New job */
5721 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5722 con
->http
.fd
, uri
->values
[0].string
.text
);
5725 * Is the destination valid?
5728 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5734 send_ipp_status(con
, IPP_NOT_FOUND
,
5735 _("The printer or class was not found."));
5740 * Create the job object...
5743 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5746 job
->pending_timeout
= 1;
5749 * Save and log the job...
5752 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5753 job
->dest
, job
->username
);
5758 * 'create_requested_array()' - Create an array for the requested-attributes.
5761 static cups_array_t
* /* O - Array of attributes or NULL */
5762 create_requested_array(ipp_t
*request
) /* I - IPP request */
5764 int i
; /* Looping var */
5765 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5766 cups_array_t
*ra
; /* Requested attributes array */
5767 char *value
; /* Current value */
5771 * Get the requested-attributes attribute, and return NULL if we don't
5775 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5776 IPP_TAG_KEYWORD
)) == NULL
)
5780 * If the attribute contains a single "all" keyword, return NULL...
5783 if (requested
->num_values
== 1 &&
5784 !strcmp(requested
->values
[0].string
.text
, "all"))
5788 * Create an array using "strcmp" as the comparison function...
5791 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5793 for (i
= 0; i
< requested
->num_values
; i
++)
5795 value
= requested
->values
[i
].string
.text
;
5797 if (!strcmp(value
, "job-template"))
5799 cupsArrayAdd(ra
, "copies");
5800 cupsArrayAdd(ra
, "copies-default");
5801 cupsArrayAdd(ra
, "copies-supported");
5802 cupsArrayAdd(ra
, "finishings");
5803 cupsArrayAdd(ra
, "finishings-default");
5804 cupsArrayAdd(ra
, "finishings-supported");
5805 cupsArrayAdd(ra
, "job-hold-until");
5806 cupsArrayAdd(ra
, "job-hold-until-default");
5807 cupsArrayAdd(ra
, "job-hold-until-supported");
5808 cupsArrayAdd(ra
, "job-priority");
5809 cupsArrayAdd(ra
, "job-priority-default");
5810 cupsArrayAdd(ra
, "job-priority-supported");
5811 cupsArrayAdd(ra
, "job-sheets");
5812 cupsArrayAdd(ra
, "job-sheets-default");
5813 cupsArrayAdd(ra
, "job-sheets-supported");
5814 cupsArrayAdd(ra
, "media");
5815 cupsArrayAdd(ra
, "media-default");
5816 cupsArrayAdd(ra
, "media-supported");
5817 cupsArrayAdd(ra
, "multiple-document-handling");
5818 cupsArrayAdd(ra
, "multiple-document-handling-default");
5819 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5820 cupsArrayAdd(ra
, "number-up");
5821 cupsArrayAdd(ra
, "number-up-default");
5822 cupsArrayAdd(ra
, "number-up-supported");
5823 cupsArrayAdd(ra
, "orientation-requested");
5824 cupsArrayAdd(ra
, "orientation-requested-default");
5825 cupsArrayAdd(ra
, "orientation-requested-supported");
5826 cupsArrayAdd(ra
, "page-ranges");
5827 cupsArrayAdd(ra
, "page-ranges-supported");
5828 cupsArrayAdd(ra
, "printer-resolution");
5829 cupsArrayAdd(ra
, "printer-resolution-default");
5830 cupsArrayAdd(ra
, "printer-resolution-supported");
5831 cupsArrayAdd(ra
, "print-quality");
5832 cupsArrayAdd(ra
, "print-quality-default");
5833 cupsArrayAdd(ra
, "print-quality-supported");
5834 cupsArrayAdd(ra
, "sides");
5835 cupsArrayAdd(ra
, "sides-default");
5836 cupsArrayAdd(ra
, "sides-supported");
5838 else if (!strcmp(value
, "job-description"))
5840 cupsArrayAdd(ra
, "date-time-at-completed");
5841 cupsArrayAdd(ra
, "date-time-at-creation");
5842 cupsArrayAdd(ra
, "date-time-at-processing");
5843 cupsArrayAdd(ra
, "job-detailed-status-message");
5844 cupsArrayAdd(ra
, "job-document-access-errors");
5845 cupsArrayAdd(ra
, "job-id");
5846 cupsArrayAdd(ra
, "job-impressions");
5847 cupsArrayAdd(ra
, "job-impressions-completed");
5848 cupsArrayAdd(ra
, "job-k-octets");
5849 cupsArrayAdd(ra
, "job-k-octets-processed");
5850 cupsArrayAdd(ra
, "job-media-progress");
5851 cupsArrayAdd(ra
, "job-media-sheets");
5852 cupsArrayAdd(ra
, "job-media-sheets-completed");
5853 cupsArrayAdd(ra
, "job-message-from-operator");
5854 cupsArrayAdd(ra
, "job-more-info");
5855 cupsArrayAdd(ra
, "job-name");
5856 cupsArrayAdd(ra
, "job-originating-user-name");
5857 cupsArrayAdd(ra
, "job-printer-up-time");
5858 cupsArrayAdd(ra
, "job-printer-uri");
5859 cupsArrayAdd(ra
, "job-state");
5860 cupsArrayAdd(ra
, "job-state-message");
5861 cupsArrayAdd(ra
, "job-state-reasons");
5862 cupsArrayAdd(ra
, "job-uri");
5863 cupsArrayAdd(ra
, "number-of-documents");
5864 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5865 cupsArrayAdd(ra
, "output-device-assigned");
5866 cupsArrayAdd(ra
, "time-at-completed");
5867 cupsArrayAdd(ra
, "time-at-creation");
5868 cupsArrayAdd(ra
, "time-at-processing");
5870 else if (!strcmp(value
, "printer-description"))
5872 cupsArrayAdd(ra
, "charset-configured");
5873 cupsArrayAdd(ra
, "charset-supported");
5874 cupsArrayAdd(ra
, "color-supported");
5875 cupsArrayAdd(ra
, "compression-supported");
5876 cupsArrayAdd(ra
, "document-format-default");
5877 cupsArrayAdd(ra
, "document-format-supported");
5878 cupsArrayAdd(ra
, "generated-natural-language-supported");
5879 cupsArrayAdd(ra
, "ipp-versions-supported");
5880 cupsArrayAdd(ra
, "job-impressions-supported");
5881 cupsArrayAdd(ra
, "job-k-octets-supported");
5882 cupsArrayAdd(ra
, "job-media-sheets-supported");
5883 cupsArrayAdd(ra
, "job-settable-attributes-supported");
5884 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5885 cupsArrayAdd(ra
, "multiple-operation-time-out");
5886 cupsArrayAdd(ra
, "natural-language-configured");
5887 cupsArrayAdd(ra
, "notify-attributes-supported");
5888 cupsArrayAdd(ra
, "notify-lease-duration-default");
5889 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5890 cupsArrayAdd(ra
, "notify-max-events-supported");
5891 cupsArrayAdd(ra
, "notify-events-default");
5892 cupsArrayAdd(ra
, "notify-events-supported");
5893 cupsArrayAdd(ra
, "notify-pull-method-supported");
5894 cupsArrayAdd(ra
, "notify-schemes-supported");
5895 cupsArrayAdd(ra
, "operations-supported");
5896 cupsArrayAdd(ra
, "pages-per-minute");
5897 cupsArrayAdd(ra
, "pages-per-minute-color");
5898 cupsArrayAdd(ra
, "pdl-override-supported");
5899 cupsArrayAdd(ra
, "printer-alert");
5900 cupsArrayAdd(ra
, "printer-alert-description");
5901 cupsArrayAdd(ra
, "printer-commands");
5902 cupsArrayAdd(ra
, "printer-current-time");
5903 cupsArrayAdd(ra
, "printer-driver-installer");
5904 cupsArrayAdd(ra
, "printer-dns-sd-name");
5905 cupsArrayAdd(ra
, "printer-info");
5906 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5907 cupsArrayAdd(ra
, "printer-location");
5908 cupsArrayAdd(ra
, "printer-make-and-model");
5909 cupsArrayAdd(ra
, "printer-message-from-operator");
5910 cupsArrayAdd(ra
, "printer-more-info");
5911 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5912 cupsArrayAdd(ra
, "printer-name");
5913 cupsArrayAdd(ra
, "printer-state");
5914 cupsArrayAdd(ra
, "printer-state-message");
5915 cupsArrayAdd(ra
, "printer-state-reasons");
5916 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
5917 cupsArrayAdd(ra
, "printer-type");
5918 cupsArrayAdd(ra
, "printer-up-time");
5919 cupsArrayAdd(ra
, "printer-uri-supported");
5920 cupsArrayAdd(ra
, "queued-job-count");
5921 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5922 cupsArrayAdd(ra
, "uri-authentication-supported");
5923 cupsArrayAdd(ra
, "uri-security-supported");
5925 else if (!strcmp(value
, "printer-defaults"))
5927 char *name
; /* Option name */
5930 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5932 name
= (char *)cupsArrayNext(CommonDefaults
))
5933 cupsArrayAdd(ra
, name
);
5935 else if (!strcmp(value
, "subscription-template"))
5937 cupsArrayAdd(ra
, "notify-attributes");
5938 cupsArrayAdd(ra
, "notify-charset");
5939 cupsArrayAdd(ra
, "notify-events");
5940 cupsArrayAdd(ra
, "notify-lease-duration");
5941 cupsArrayAdd(ra
, "notify-natural-language");
5942 cupsArrayAdd(ra
, "notify-pull-method");
5943 cupsArrayAdd(ra
, "notify-recipient-uri");
5944 cupsArrayAdd(ra
, "notify-time-interval");
5945 cupsArrayAdd(ra
, "notify-user-data");
5948 cupsArrayAdd(ra
, value
);
5956 * 'create_subscription()' - Create a notification subscription.
5960 create_subscription(
5961 cupsd_client_t
*con
, /* I - Client connection */
5962 ipp_attribute_t
*uri
) /* I - Printer URI */
5964 http_status_t status
; /* Policy status */
5965 int i
; /* Looping var */
5966 ipp_attribute_t
*attr
; /* Current attribute */
5967 cups_ptype_t dtype
; /* Destination type (printer/class) */
5968 char scheme
[HTTP_MAX_URI
],
5969 /* Scheme portion of URI */
5970 userpass
[HTTP_MAX_URI
],
5971 /* Username portion of URI */
5973 /* Host portion of URI */
5974 resource
[HTTP_MAX_URI
];
5975 /* Resource portion of URI */
5976 int port
; /* Port portion of URI */
5977 cupsd_printer_t
*printer
; /* Printer/class */
5978 cupsd_job_t
*job
; /* Job */
5979 int jobid
; /* Job ID */
5980 cupsd_subscription_t
*sub
; /* Subscription object */
5981 const char *username
, /* requesting-user-name or
5982 authenticated username */
5983 *recipient
, /* notify-recipient-uri */
5984 *pullmethod
; /* notify-pull-method */
5985 ipp_attribute_t
*user_data
; /* notify-user-data */
5986 int interval
, /* notify-time-interval */
5987 lease
; /* notify-lease-duration */
5988 unsigned mask
; /* notify-events */
5989 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5990 *notify_lease
; /* notify-lease-duration(-default) */
5994 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5996 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5997 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5998 attr
->value_tag
, attr
->name
);
6000 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6005 * Is the destination valid?
6008 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6009 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6010 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6012 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6013 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6014 sizeof(host
), &port
, resource
, sizeof(resource
));
6016 if (!strcmp(resource
, "/"))
6018 dtype
= (cups_ptype_t
)0;
6021 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6023 dtype
= (cups_ptype_t
)0;
6026 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6028 dtype
= CUPS_PRINTER_CLASS
;
6031 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6037 send_ipp_status(con
, IPP_NOT_FOUND
,
6038 _("The printer or class was not found."));
6048 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6051 send_http_error(con
, status
, printer
);
6055 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6057 send_http_error(con
, status
, NULL
);
6062 * Get the user that is requesting the subscription...
6065 username
= get_username(con
);
6068 * Find the first subscription group attribute; return if we have
6072 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6073 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6078 send_ipp_status(con
, IPP_BAD_REQUEST
,
6079 _("No subscription attributes in request!"));
6084 * Process the subscription attributes in the request...
6087 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6095 lease
= DefaultLeaseDuration
;
6097 mask
= CUPSD_EVENT_NONE
;
6101 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6103 notify_lease
= ippFindAttribute(printer
->attrs
,
6104 "notify-lease-duration-default",
6108 lease
= notify_lease
->values
[0].integer
;
6112 notify_events
= NULL
;
6113 notify_lease
= NULL
;
6116 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6118 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6119 attr
->value_tag
== IPP_TAG_URI
)
6122 * Validate the recipient scheme against the ServerBin/notifier
6126 char notifier
[1024]; /* Notifier filename */
6129 recipient
= attr
->values
[0].string
.text
;
6131 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6132 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6133 host
, sizeof(host
), &port
,
6134 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6136 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6137 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
6138 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6139 "notify-status-code", IPP_URI_SCHEME
);
6143 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6145 if (access(notifier
, X_OK
))
6147 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6148 _("notify-recipient-uri URI \"%s\" uses unknown "
6149 "scheme!"), recipient
);
6150 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6151 "notify-status-code", IPP_URI_SCHEME
);
6155 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6157 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6158 _("notify-recipient-uri URI \"%s\" is already used!"),
6160 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6161 "notify-status-code", IPP_ATTRIBUTES
);
6165 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6166 attr
->value_tag
== IPP_TAG_KEYWORD
)
6168 pullmethod
= attr
->values
[0].string
.text
;
6170 if (strcmp(pullmethod
, "ippget"))
6172 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6173 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
6174 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6175 "notify-status-code", IPP_ATTRIBUTES
);
6179 else if (!strcmp(attr
->name
, "notify-charset") &&
6180 attr
->value_tag
== IPP_TAG_CHARSET
&&
6181 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6182 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6184 send_ipp_status(con
, IPP_CHARSET
,
6185 _("Character set \"%s\" not supported!"),
6186 attr
->values
[0].string
.text
);
6189 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6190 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6191 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6193 send_ipp_status(con
, IPP_CHARSET
,
6194 _("Language \"%s\" not supported!"),
6195 attr
->values
[0].string
.text
);
6198 else if (!strcmp(attr
->name
, "notify-user-data") &&
6199 attr
->value_tag
== IPP_TAG_STRING
)
6201 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6203 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6204 _("The notify-user-data value is too large "
6205 "(%d > 63 octets)!"),
6206 attr
->values
[0].unknown
.length
);
6212 else if (!strcmp(attr
->name
, "notify-events") &&
6213 attr
->value_tag
== IPP_TAG_KEYWORD
)
6214 notify_events
= attr
;
6215 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6216 attr
->value_tag
== IPP_TAG_INTEGER
)
6217 lease
= attr
->values
[0].integer
;
6218 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6219 attr
->value_tag
== IPP_TAG_INTEGER
)
6220 interval
= attr
->values
[0].integer
;
6221 else if (!strcmp(attr
->name
, "notify-job-id") &&
6222 attr
->value_tag
== IPP_TAG_INTEGER
)
6223 jobid
= attr
->values
[0].integer
;
6230 for (i
= 0; i
< notify_events
->num_values
; i
++)
6231 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6235 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6237 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6238 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6239 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6241 if (!recipient
&& !pullmethod
)
6244 if (mask
== CUPSD_EVENT_NONE
)
6247 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6249 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6252 send_ipp_status(con
, IPP_BAD_REQUEST
,
6253 _("notify-events not specified!"));
6258 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6260 cupsdLogMessage(CUPSD_LOG_INFO
,
6261 "create_subscription: Limiting notify-lease-duration to "
6264 lease
= MaxLeaseDuration
;
6269 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6271 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
6278 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6280 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6281 _("There are too many subscriptions."));
6286 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6289 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6290 "Added subscription %d for printer \"%s\"",
6291 sub
->id
, printer
->name
);
6293 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6296 sub
->interval
= interval
;
6298 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6300 cupsdSetString(&sub
->owner
, username
);
6304 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6305 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6306 sub
->user_data_len
);
6309 ippAddSeparator(con
->response
);
6310 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6311 "notify-subscription-id", sub
->id
);
6313 con
->response
->request
.status
.status_code
= IPP_OK
;
6319 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6324 * 'delete_printer()' - Remove a printer or class from the system.
6328 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6329 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6331 http_status_t status
; /* Policy status */
6332 cups_ptype_t dtype
; /* Destination type (printer/class) */
6333 cupsd_printer_t
*printer
; /* Printer/class */
6334 char filename
[1024]; /* Script/PPD filename */
6337 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6338 con
->http
.fd
, uri
->values
[0].string
.text
);
6341 * Do we have a valid URI?
6344 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6350 send_ipp_status(con
, IPP_NOT_FOUND
,
6351 _("The printer or class was not found."));
6359 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6361 send_http_error(con
, status
, NULL
);
6366 * Remove old jobs...
6369 cupsdCancelJobs(printer
->name
, NULL
, 1);
6372 * Remove old subscriptions and send a "deleted printer" event...
6375 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6376 "%s \"%s\" deleted by \"%s\".",
6377 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6378 printer
->name
, get_username(con
));
6380 cupsdExpireSubscriptions(printer
, NULL
);
6383 * Remove any old PPD or script files...
6386 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6390 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6394 snprintf(filename
, sizeof(filename
), "%s/%s.ipp", CacheDir
, printer
->name
);
6399 * Unregister color profiles...
6402 apple_unregister_profiles(printer
);
6403 #endif /* __APPLE__ */
6405 if (dtype
& CUPS_PRINTER_CLASS
)
6407 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6408 printer
->name
, get_username(con
));
6410 cupsdDeletePrinter(printer
, 0);
6411 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6415 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6416 printer
->name
, get_username(con
));
6418 cupsdDeletePrinter(printer
, 0);
6419 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6422 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6425 * Return with no errors...
6428 con
->response
->request
.status
.status_code
= IPP_OK
;
6433 * 'get_default()' - Get the default destination.
6437 get_default(cupsd_client_t
*con
) /* I - Client connection */
6439 http_status_t status
; /* Policy status */
6440 cups_array_t
*ra
; /* Requested attributes array */
6443 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6449 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6451 send_http_error(con
, status
, NULL
);
6457 ra
= create_requested_array(con
->request
);
6459 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6461 cupsArrayDelete(ra
);
6463 con
->response
->request
.status
.status_code
= IPP_OK
;
6466 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6471 * 'get_devices()' - Get the list of available devices on the local system.
6475 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6477 http_status_t status
; /* Policy status */
6478 ipp_attribute_t
*limit
, /* limit attribute */
6479 *timeout
, /* timeout attribute */
6480 *requested
, /* requested-attributes attribute */
6481 *exclude
, /* exclude-schemes attribute */
6482 *include
; /* include-schemes attribute */
6483 char command
[1024], /* cups-deviced command */
6484 options
[2048], /* Options to pass to command */
6486 /* String for requested attributes */
6488 /* String for excluded schemes */
6490 /* String for included schemes */
6493 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6499 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6501 send_http_error(con
, status
, NULL
);
6506 * Run cups-deviced command with the given options...
6509 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6510 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6511 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6513 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6514 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6517 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6519 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6522 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6524 exclude_str
[0] = '\0';
6527 url_encode_attr(include
, include_str
, sizeof(include_str
));
6529 include_str
[0] = '\0';
6531 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6532 snprintf(options
, sizeof(options
),
6533 "%d+%d+%d+%d+%s%s%s%s%s",
6534 con
->request
->request
.op
.request_id
,
6535 limit
? limit
->values
[0].integer
: 0,
6536 timeout
? timeout
->values
[0].integer
: 10,
6539 exclude_str
[0] ? "%20" : "", exclude_str
,
6540 include_str
[0] ? "%20" : "", include_str
);
6542 if (cupsdSendCommand(con
, command
, options
, 1))
6545 * Command started successfully, don't send an IPP response here...
6548 ippDelete(con
->response
);
6549 con
->response
= NULL
;
6554 * Command failed, return "internal error" so the user knows something
6558 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6559 _("cups-deviced failed to execute."));
6565 * 'get_document()' - Get a copy of a job file.
6569 get_document(cupsd_client_t
*con
, /* I - Client connection */
6570 ipp_attribute_t
*uri
) /* I - Job URI */
6572 http_status_t status
; /* Policy status */
6573 ipp_attribute_t
*attr
; /* Current attribute */
6574 int jobid
; /* Job ID */
6575 int docnum
; /* Document number */
6576 cupsd_job_t
*job
; /* Current job */
6577 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6578 username
[HTTP_MAX_URI
], /* Username portion of URI */
6579 host
[HTTP_MAX_URI
], /* Host portion of URI */
6580 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6581 int port
; /* Port portion of URI */
6582 char filename
[1024], /* Filename for document */
6583 format
[1024]; /* Format for document */
6586 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6587 con
->http
.fd
, uri
->values
[0].string
.text
);
6590 * See if we have a job URI or a printer URI...
6593 if (!strcmp(uri
->name
, "printer-uri"))
6596 * Got a printer URI; see if we also have a job-id attribute...
6599 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6600 IPP_TAG_INTEGER
)) == NULL
)
6602 send_ipp_status(con
, IPP_BAD_REQUEST
,
6603 _("Got a printer-uri attribute but no job-id!"));
6607 jobid
= attr
->values
[0].integer
;
6612 * Got a job URI; parse it to get the job ID...
6615 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6616 sizeof(scheme
), username
, sizeof(username
), host
,
6617 sizeof(host
), &port
, resource
, sizeof(resource
));
6619 if (strncmp(resource
, "/jobs/", 6))
6625 send_ipp_status(con
, IPP_BAD_REQUEST
,
6626 _("Bad job-uri attribute \"%s\"!"),
6627 uri
->values
[0].string
.text
);
6631 jobid
= atoi(resource
+ 6);
6635 * See if the job exists...
6638 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6641 * Nope - return a "not found" error...
6644 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6652 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6654 send_http_error(con
, status
, NULL
);
6659 * Get the document number...
6662 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6663 IPP_TAG_INTEGER
)) == NULL
)
6665 send_ipp_status(con
, IPP_BAD_REQUEST
,
6666 _("Missing document-number attribute!"));
6670 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6671 attr
->num_values
> 1)
6673 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6678 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6680 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6682 cupsdLogMessage(CUPSD_LOG_ERROR
,
6683 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6685 send_ipp_status(con
, IPP_NOT_FOUND
,
6686 _("Unable to open document %d in job %d!"), docnum
, jobid
);
6690 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6694 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6695 job
->filetypes
[docnum
- 1]->type
);
6697 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6699 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6701 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6702 IPP_TAG_NAME
)) != NULL
)
6703 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6704 NULL
, attr
->values
[0].string
.text
);
6709 * 'get_job_attrs()' - Get job attributes.
6713 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6714 ipp_attribute_t
*uri
) /* I - Job URI */
6716 http_status_t status
; /* Policy status */
6717 ipp_attribute_t
*attr
; /* Current attribute */
6718 int jobid
; /* Job ID */
6719 cupsd_job_t
*job
; /* Current job */
6720 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6721 username
[HTTP_MAX_URI
], /* Username portion of URI */
6722 host
[HTTP_MAX_URI
], /* Host portion of URI */
6723 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6724 int port
; /* Port portion of URI */
6725 cups_array_t
*ra
; /* Requested attributes array */
6728 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6729 con
->http
.fd
, uri
->values
[0].string
.text
);
6732 * See if we have a job URI or a printer URI...
6735 if (!strcmp(uri
->name
, "printer-uri"))
6738 * Got a printer URI; see if we also have a job-id attribute...
6741 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6742 IPP_TAG_INTEGER
)) == NULL
)
6744 send_ipp_status(con
, IPP_BAD_REQUEST
,
6745 _("Got a printer-uri attribute but no job-id!"));
6749 jobid
= attr
->values
[0].integer
;
6754 * Got a job URI; parse it to get the job ID...
6757 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6758 sizeof(scheme
), username
, sizeof(username
), host
,
6759 sizeof(host
), &port
, resource
, sizeof(resource
));
6761 if (strncmp(resource
, "/jobs/", 6))
6767 send_ipp_status(con
, IPP_BAD_REQUEST
,
6768 _("Bad job-uri attribute \"%s\"!"),
6769 uri
->values
[0].string
.text
);
6773 jobid
= atoi(resource
+ 6);
6777 * See if the job exists...
6780 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6783 * Nope - return a "not found" error...
6786 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6794 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6796 send_http_error(con
, status
, NULL
);
6801 * Copy attributes...
6806 ra
= create_requested_array(con
->request
);
6807 copy_job_attrs(con
, job
, ra
);
6808 cupsArrayDelete(ra
);
6810 con
->response
->request
.status
.status_code
= IPP_OK
;
6815 * 'get_jobs()' - Get a list of jobs for the specified printer.
6819 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6820 ipp_attribute_t
*uri
) /* I - Printer URI */
6822 http_status_t status
; /* Policy status */
6823 ipp_attribute_t
*attr
; /* Current attribute */
6824 const char *dest
; /* Destination */
6825 cups_ptype_t dtype
; /* Destination type (printer/class) */
6826 cups_ptype_t dmask
; /* Destination type mask */
6827 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6828 username
[HTTP_MAX_URI
], /* Username portion of URI */
6829 host
[HTTP_MAX_URI
], /* Host portion of URI */
6830 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6831 int port
; /* Port portion of URI */
6832 int completed
; /* Completed jobs? */
6833 int first_job_id
; /* First job ID */
6834 int limit
; /* Maximum number of jobs to return */
6835 int count
; /* Number of jobs that match */
6836 cupsd_job_t
*job
; /* Current job pointer */
6837 cupsd_printer_t
*printer
; /* Printer */
6838 cups_array_t
*list
; /* Which job list... */
6839 cups_array_t
*ra
; /* Requested attributes array */
6842 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6843 uri
->values
[0].string
.text
);
6846 * Is the destination valid?
6849 if (strcmp(uri
->name
, "printer-uri"))
6851 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request!"));
6855 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6856 sizeof(scheme
), username
, sizeof(username
), host
,
6857 sizeof(host
), &port
, resource
, sizeof(resource
));
6859 if (!strcmp(resource
, "/"))
6862 dtype
= (cups_ptype_t
)0;
6863 dmask
= (cups_ptype_t
)0;
6866 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6869 dtype
= (cups_ptype_t
)0;
6870 dmask
= CUPS_PRINTER_CLASS
;
6873 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6876 dtype
= CUPS_PRINTER_CLASS
;
6877 dmask
= CUPS_PRINTER_CLASS
;
6880 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6887 send_ipp_status(con
, IPP_NOT_FOUND
,
6888 _("The printer or class was not found."));
6893 dtype
&= CUPS_PRINTER_CLASS
;
6894 dmask
= CUPS_PRINTER_CLASS
;
6903 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6906 send_http_error(con
, status
, printer
);
6910 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6912 send_http_error(con
, status
, NULL
);
6917 * See if the "which-jobs" attribute have been specified...
6920 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6921 IPP_TAG_KEYWORD
)) != NULL
&&
6922 !strcmp(attr
->values
[0].string
.text
, "completed"))
6927 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
6932 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "processing"))
6935 list
= PrintingJobs
;
6944 * See if they want to limit the number of jobs reported...
6947 if ((attr
= ippFindAttribute(con
->request
, "limit",
6948 IPP_TAG_INTEGER
)) != NULL
)
6949 limit
= attr
->values
[0].integer
;
6953 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6954 IPP_TAG_INTEGER
)) != NULL
)
6955 first_job_id
= attr
->values
[0].integer
;
6960 * See if we only want to see jobs for a specific user...
6963 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6964 IPP_TAG_BOOLEAN
)) != NULL
&&
6965 attr
->values
[0].boolean
)
6966 strlcpy(username
, get_username(con
), sizeof(username
));
6970 ra
= create_requested_array(con
->request
);
6973 * OK, build a list of jobs for this printer...
6976 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6977 (limit
<= 0 || count
< limit
) && job
;
6978 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6981 * Filter out jobs that don't match...
6984 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6985 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6986 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6987 job
->username
, job
->state_value
, job
->attrs
);
6989 if (!job
->dest
|| !job
->username
)
6992 if (!job
->dest
|| !job
->username
)
6995 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6996 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6998 if ((job
->dtype
& dmask
) != dtype
&&
6999 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7001 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
7004 if (job
->id
< first_job_id
)
7011 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d!",
7016 if (username
[0] && strcasecmp(username
, job
->username
))
7020 ippAddSeparator(con
->response
);
7024 copy_job_attrs(con
, job
, ra
);
7027 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7029 cupsArrayDelete(ra
);
7031 con
->response
->request
.status
.status_code
= IPP_OK
;
7036 * 'get_notifications()' - Get events for a subscription.
7040 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7042 int i
, j
; /* Looping vars */
7043 http_status_t status
; /* Policy status */
7044 cupsd_subscription_t
*sub
; /* Subscription */
7045 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7046 *sequences
; /* notify-sequence-numbers */
7047 int min_seq
; /* Minimum sequence number */
7048 int interval
; /* Poll interval */
7051 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7055 * Get subscription attributes...
7058 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7060 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7065 send_ipp_status(con
, IPP_BAD_REQUEST
,
7066 _("Missing notify-subscription-ids attribute!"));
7071 * Are the subscription IDs valid?
7074 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7076 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7079 * Bad subscription ID...
7082 send_ipp_status(con
, IPP_NOT_FOUND
,
7083 _("notify-subscription-id %d no good!"),
7084 ids
->values
[i
].integer
);
7092 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7094 con
, sub
->owner
)) != HTTP_OK
)
7096 send_http_error(con
, status
, sub
->dest
);
7101 * Check the subscription type and update the interval accordingly.
7104 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7107 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7109 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7115 * Tell the client to poll again in N seconds...
7119 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7120 "notify-get-interval", interval
);
7122 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7123 "printer-up-time", time(NULL
));
7126 * Copy the subscription event attributes to the response.
7129 con
->response
->request
.status
.status_code
=
7130 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7132 for (i
= 0; i
< ids
->num_values
; i
++)
7135 * Get the subscription and sequence number...
7138 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7140 if (sequences
&& i
< sequences
->num_values
)
7141 min_seq
= sequences
->values
[i
].integer
;
7146 * If we don't have any new events, nothing to do here...
7149 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7153 * Otherwise copy all of the new events...
7156 if (sub
->first_event_id
> min_seq
)
7159 j
= min_seq
- sub
->first_event_id
;
7161 for (; j
< sub
->num_events
; j
++)
7163 ippAddSeparator(con
->response
);
7165 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7166 IPP_TAG_EVENT_NOTIFICATION
, 0);
7173 * 'get_ppd()' - Get a named PPD from the local system.
7177 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7178 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7180 http_status_t status
; /* Policy status */
7181 cupsd_printer_t
*dest
; /* Destination */
7182 cups_ptype_t dtype
; /* Destination type */
7185 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7186 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7188 if (!strcmp(uri
->name
, "ppd-name"))
7191 * Return a PPD file from cups-driverd...
7194 char command
[1024], /* cups-driverd command */
7195 options
[1024], /* Options to pass to command */
7196 ppd_name
[1024]; /* ppd-name */
7203 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7205 send_http_error(con
, status
, NULL
);
7210 * Run cups-driverd command with the given options...
7213 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7214 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7215 snprintf(options
, sizeof(options
), "get+%d+%s",
7216 con
->request
->request
.op
.request_id
, ppd_name
);
7218 if (cupsdSendCommand(con
, command
, options
, 0))
7221 * Command started successfully, don't send an IPP response here...
7224 ippDelete(con
->response
);
7225 con
->response
= NULL
;
7230 * Command failed, return "internal error" so the user knows something
7234 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7235 _("cups-driverd failed to execute."));
7238 else if (!strcmp(uri
->name
, "printer-uri") &&
7239 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7241 int i
; /* Looping var */
7242 char filename
[1024]; /* PPD filename */
7249 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7251 send_http_error(con
, status
, dest
);
7256 * See if we need the PPD for a class or remote printer...
7259 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7262 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7264 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7265 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7266 "printer-uri", NULL
, dest
->uri
);
7269 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7271 for (i
= 0; i
< dest
->num_printers
; i
++)
7272 if (!(dest
->printers
[i
]->type
&
7273 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7275 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7276 dest
->printers
[i
]->name
);
7278 if (!access(filename
, 0))
7282 if (i
< dest
->num_printers
)
7283 dest
= dest
->printers
[i
];
7286 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7287 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7288 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7294 * Found the printer with the PPD file, now see if there is one...
7297 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7299 send_ipp_status(con
, IPP_NOT_FOUND
,
7300 _("The PPD file \"%s\" could not be opened: %s"),
7301 uri
->values
[0].string
.text
, strerror(errno
));
7305 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7309 con
->response
->request
.status
.status_code
= IPP_OK
;
7312 send_ipp_status(con
, IPP_NOT_FOUND
,
7313 _("The PPD file \"%s\" could not be found."),
7314 uri
->values
[0].string
.text
);
7319 * 'get_ppds()' - Get the list of PPD files on the local system.
7323 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7325 http_status_t status
; /* Policy status */
7326 ipp_attribute_t
*limit
, /* Limit attribute */
7327 *device
, /* ppd-device-id attribute */
7328 *language
, /* ppd-natural-language attribute */
7329 *make
, /* ppd-make attribute */
7330 *model
, /* ppd-make-and-model attribute */
7331 *model_number
, /* ppd-model-number attribute */
7332 *product
, /* ppd-product attribute */
7333 *psversion
, /* ppd-psverion attribute */
7334 *type
, /* ppd-type attribute */
7335 *requested
, /* requested-attributes attribute */
7336 *exclude
, /* exclude-schemes attribute */
7337 *include
; /* include-schemes attribute */
7338 char command
[1024], /* cups-driverd command */
7339 options
[4096], /* Options to pass to command */
7340 device_str
[256],/* Escaped ppd-device-id string */
7342 /* Escaped ppd-natural-language */
7343 make_str
[256], /* Escaped ppd-make string */
7344 model_str
[256], /* Escaped ppd-make-and-model string */
7345 model_number_str
[256],
7346 /* ppd-model-number string */
7348 /* Escaped ppd-product string */
7350 /* Escaped ppd-psversion string */
7351 type_str
[256], /* Escaped ppd-type string */
7353 /* String for requested attributes */
7355 /* String for excluded schemes */
7357 /* String for included schemes */
7360 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7366 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7368 send_http_error(con
, status
, NULL
);
7373 * Run cups-driverd command with the given options...
7376 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7377 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7378 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7380 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7381 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7383 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7385 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7386 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7387 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7388 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7390 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7392 include
= ippFindAttribute(con
->request
, "include-schemes",
7396 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7398 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7401 url_encode_attr(device
, device_str
, sizeof(device_str
));
7403 device_str
[0] = '\0';
7406 url_encode_attr(language
, language_str
, sizeof(language_str
));
7408 language_str
[0] = '\0';
7411 url_encode_attr(make
, make_str
, sizeof(make_str
));
7416 url_encode_attr(model
, model_str
, sizeof(model_str
));
7418 model_str
[0] = '\0';
7421 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7422 model_number
->values
[0].integer
);
7424 model_number_str
[0] = '\0';
7427 url_encode_attr(product
, product_str
, sizeof(product_str
));
7429 product_str
[0] = '\0';
7432 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7434 psversion_str
[0] = '\0';
7437 url_encode_attr(type
, type_str
, sizeof(type_str
));
7442 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7444 exclude_str
[0] = '\0';
7447 url_encode_attr(include
, include_str
, sizeof(include_str
));
7449 include_str
[0] = '\0';
7451 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7452 snprintf(options
, sizeof(options
),
7453 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7454 con
->request
->request
.op
.request_id
,
7455 limit
? limit
->values
[0].integer
: 0,
7457 device
? "%20" : "", device_str
,
7458 language
? "%20" : "", language_str
,
7459 make
? "%20" : "", make_str
,
7460 model
? "%20" : "", model_str
,
7461 model_number
? "%20" : "", model_number_str
,
7462 product
? "%20" : "", product_str
,
7463 psversion
? "%20" : "", psversion_str
,
7464 type
? "%20" : "", type_str
,
7465 exclude_str
[0] ? "%20" : "", exclude_str
,
7466 include_str
[0] ? "%20" : "", include_str
);
7468 if (cupsdSendCommand(con
, command
, options
, 0))
7471 * Command started successfully, don't send an IPP response here...
7474 ippDelete(con
->response
);
7475 con
->response
= NULL
;
7480 * Command failed, return "internal error" so the user knows something
7484 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7485 _("cups-driverd failed to execute."));
7491 * 'get_printer_attrs()' - Get printer attributes.
7495 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7496 ipp_attribute_t
*uri
) /* I - Printer URI */
7498 http_status_t status
; /* Policy status */
7499 cups_ptype_t dtype
; /* Destination type (printer/class) */
7500 cupsd_printer_t
*printer
; /* Printer/class */
7501 cups_array_t
*ra
; /* Requested attributes array */
7504 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7505 con
->http
.fd
, uri
->values
[0].string
.text
);
7508 * Is the destination valid?
7511 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7517 send_ipp_status(con
, IPP_NOT_FOUND
,
7518 _("The printer or class was not found."));
7526 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7528 send_http_error(con
, status
, printer
);
7533 * Send the attributes...
7536 ra
= create_requested_array(con
->request
);
7538 copy_printer_attrs(con
, printer
, ra
);
7540 cupsArrayDelete(ra
);
7542 con
->response
->request
.status
.status_code
= IPP_OK
;
7547 * 'get_printer_supported()' - Get printer supported values.
7551 get_printer_supported(
7552 cupsd_client_t
*con
, /* I - Client connection */
7553 ipp_attribute_t
*uri
) /* I - Printer URI */
7555 http_status_t status
; /* Policy status */
7556 cups_ptype_t dtype
; /* Destination type (printer/class) */
7557 cupsd_printer_t
*printer
; /* Printer/class */
7560 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7561 con
->http
.fd
, uri
->values
[0].string
.text
);
7564 * Is the destination valid?
7567 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7573 send_ipp_status(con
, IPP_NOT_FOUND
,
7574 _("The printer or class was not found."));
7582 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7584 send_http_error(con
, status
, printer
);
7589 * Return a list of attributes that can be set via Set-Printer-Attributes.
7592 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7594 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7595 "printer-location", 0);
7597 con
->response
->request
.status
.status_code
= IPP_OK
;
7602 * 'get_printers()' - Get a list of printers or classes.
7606 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7607 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7609 http_status_t status
; /* Policy status */
7610 ipp_attribute_t
*attr
; /* Current attribute */
7611 int limit
; /* Max number of printers to return */
7612 int count
; /* Number of printers that match */
7613 cupsd_printer_t
*printer
; /* Current printer pointer */
7614 int printer_type
, /* printer-type attribute */
7615 printer_mask
; /* printer-type-mask attribute */
7616 char *location
; /* Location string */
7617 const char *username
; /* Current user */
7618 char *first_printer_name
; /* first-printer-name attribute */
7619 cups_array_t
*ra
; /* Requested attributes array */
7622 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7623 con
->http
.fd
, type
);
7629 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7631 send_http_error(con
, status
, NULL
);
7636 * Check for printers...
7639 if (!Printers
|| !cupsArrayCount(Printers
))
7641 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7646 * See if they want to limit the number of printers reported...
7649 if ((attr
= ippFindAttribute(con
->request
, "limit",
7650 IPP_TAG_INTEGER
)) != NULL
)
7651 limit
= attr
->values
[0].integer
;
7655 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7656 IPP_TAG_NAME
)) != NULL
)
7657 first_printer_name
= attr
->values
[0].string
.text
;
7659 first_printer_name
= NULL
;
7662 * Support filtering...
7665 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7666 IPP_TAG_ENUM
)) != NULL
)
7667 printer_type
= attr
->values
[0].integer
;
7671 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7672 IPP_TAG_ENUM
)) != NULL
)
7673 printer_mask
= attr
->values
[0].integer
;
7677 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7678 IPP_TAG_TEXT
)) != NULL
)
7679 location
= attr
->values
[0].string
.text
;
7683 if (con
->username
[0])
7684 username
= con
->username
;
7685 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7686 IPP_TAG_NAME
)) != NULL
)
7687 username
= attr
->values
[0].string
.text
;
7691 ra
= create_requested_array(con
->request
);
7694 * OK, build a list of printers for this printer...
7697 if (first_printer_name
)
7699 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7700 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7703 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7706 count
< limit
&& printer
;
7707 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7709 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7710 (printer
->type
& printer_mask
) == printer_type
&&
7712 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
7715 * If HideImplicitMembers is enabled, see if this printer or class
7716 * is a member of an implicit class...
7719 if (ImplicitClasses
&& HideImplicitMembers
&&
7720 printer
->in_implicit_class
)
7724 * If a username is specified, see if it is allowed or denied
7728 if (!(printer
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
7729 printer
->num_users
&& username
&& !user_allowed(printer
, username
))
7733 * Add the group separator as needed...
7737 ippAddSeparator(con
->response
);
7742 * Send the attributes...
7745 copy_printer_attrs(con
, printer
, ra
);
7749 cupsArrayDelete(ra
);
7751 con
->response
->request
.status
.status_code
= IPP_OK
;
7756 * 'get_subscription_attrs()' - Get subscription attributes.
7760 get_subscription_attrs(
7761 cupsd_client_t
*con
, /* I - Client connection */
7762 int sub_id
) /* I - Subscription ID */
7764 http_status_t status
; /* Policy status */
7765 cupsd_subscription_t
*sub
; /* Subscription */
7766 cups_array_t
*ra
; /* Requested attributes array */
7769 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7770 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7771 con
, con
->http
.fd
, sub_id
);
7774 * Is the subscription ID valid?
7777 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7780 * Bad subscription ID...
7783 send_ipp_status(con
, IPP_NOT_FOUND
,
7784 _("notify-subscription-id %d no good!"), sub_id
);
7792 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7794 con
, sub
->owner
)) != HTTP_OK
)
7796 send_http_error(con
, status
, sub
->dest
);
7801 * Copy the subscription attributes to the response using the
7802 * requested-attributes attribute that may be provided by the client.
7805 ra
= create_requested_array(con
->request
);
7807 copy_subscription_attrs(con
, sub
, ra
);
7809 cupsArrayDelete(ra
);
7811 con
->response
->request
.status
.status_code
= IPP_OK
;
7816 * 'get_subscriptions()' - Get subscriptions.
7820 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7821 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7823 http_status_t status
; /* Policy status */
7824 int count
; /* Number of subscriptions */
7825 int limit
; /* Limit */
7826 cupsd_subscription_t
*sub
; /* Subscription */
7827 cups_array_t
*ra
; /* Requested attributes array */
7828 ipp_attribute_t
*attr
; /* Attribute */
7829 cups_ptype_t dtype
; /* Destination type (printer/class) */
7830 char scheme
[HTTP_MAX_URI
],
7831 /* Scheme portion of URI */
7832 username
[HTTP_MAX_URI
],
7833 /* Username portion of URI */
7835 /* Host portion of URI */
7836 resource
[HTTP_MAX_URI
];
7837 /* Resource portion of URI */
7838 int port
; /* Port portion of URI */
7839 cupsd_job_t
*job
; /* Job pointer */
7840 cupsd_printer_t
*printer
; /* Printer */
7843 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7844 "get_subscriptions(con=%p[%d], uri=%s)",
7845 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7848 * Is the destination valid?
7851 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7852 sizeof(scheme
), username
, sizeof(username
), host
,
7853 sizeof(host
), &port
, resource
, sizeof(resource
));
7855 if (!strcmp(resource
, "/") ||
7856 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7857 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7858 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7863 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7866 job
= cupsdFindJob(atoi(resource
+ 6));
7870 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
7875 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7881 send_ipp_status(con
, IPP_NOT_FOUND
,
7882 _("The printer or class was not found."));
7885 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7886 IPP_TAG_INTEGER
)) != NULL
)
7888 job
= cupsdFindJob(attr
->values
[0].integer
);
7892 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
7893 attr
->values
[0].integer
);
7904 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
7906 con
, NULL
)) != HTTP_OK
)
7908 send_http_error(con
, status
, printer
);
7913 * Copy the subscription attributes to the response using the
7914 * requested-attributes attribute that may be provided by the client.
7917 ra
= create_requested_array(con
->request
);
7919 if ((attr
= ippFindAttribute(con
->request
, "limit",
7920 IPP_TAG_INTEGER
)) != NULL
)
7921 limit
= attr
->values
[0].integer
;
7926 * See if we only want to see subscriptions for a specific user...
7929 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7930 IPP_TAG_BOOLEAN
)) != NULL
&&
7931 attr
->values
[0].boolean
)
7932 strlcpy(username
, get_username(con
), sizeof(username
));
7936 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7938 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7939 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7940 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
7942 ippAddSeparator(con
->response
);
7943 copy_subscription_attrs(con
, sub
, ra
);
7946 if (limit
&& count
>= limit
)
7950 cupsArrayDelete(ra
);
7953 con
->response
->request
.status
.status_code
= IPP_OK
;
7955 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7960 * 'get_username()' - Get the username associated with a request.
7963 static const char * /* O - Username */
7964 get_username(cupsd_client_t
*con
) /* I - Connection */
7966 ipp_attribute_t
*attr
; /* Attribute */
7969 if (con
->username
[0])
7970 return (con
->username
);
7971 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7972 IPP_TAG_NAME
)) != NULL
)
7973 return (attr
->values
[0].string
.text
);
7975 return ("anonymous");
7980 * 'hold_job()' - Hold a print job.
7984 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7985 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7987 ipp_attribute_t
*attr
, /* Current job-hold-until */
7988 *newattr
; /* New job-hold-until */
7989 int jobid
; /* Job ID */
7990 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7991 username
[HTTP_MAX_URI
], /* Username portion of URI */
7992 host
[HTTP_MAX_URI
], /* Host portion of URI */
7993 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7994 int port
; /* Port portion of URI */
7995 cupsd_job_t
*job
; /* Job information */
7998 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
7999 uri
->values
[0].string
.text
);
8002 * See if we have a job URI or a printer URI...
8005 if (!strcmp(uri
->name
, "printer-uri"))
8008 * Got a printer URI; see if we also have a job-id attribute...
8011 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8012 IPP_TAG_INTEGER
)) == NULL
)
8014 send_ipp_status(con
, IPP_BAD_REQUEST
,
8015 _("Got a printer-uri attribute but no job-id!"));
8019 jobid
= attr
->values
[0].integer
;
8024 * Got a job URI; parse it to get the job ID...
8027 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8028 sizeof(scheme
), username
, sizeof(username
), host
,
8029 sizeof(host
), &port
, resource
, sizeof(resource
));
8031 if (strncmp(resource
, "/jobs/", 6))
8037 send_ipp_status(con
, IPP_BAD_REQUEST
,
8038 _("Bad job-uri attribute \"%s\"!"),
8039 uri
->values
[0].string
.text
);
8043 jobid
= atoi(resource
+ 6);
8047 * See if the job exists...
8050 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8053 * Nope - return a "not found" error...
8056 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8061 * See if the job is owned by the requesting user...
8064 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8066 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8071 * Hold the job and return...
8076 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8077 "Job held by user.");
8079 if ((newattr
= ippFindAttribute(con
->request
, "job-hold-until",
8080 IPP_TAG_KEYWORD
)) == NULL
)
8081 newattr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8083 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8084 IPP_TAG_KEYWORD
)) == NULL
)
8085 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8090 * Free the old hold value and copy the new one over...
8093 _cupsStrFree(attr
->values
[0].string
.text
);
8097 attr
->value_tag
= newattr
->value_tag
;
8098 attr
->values
[0].string
.text
=
8099 _cupsStrRetain(newattr
->values
[0].string
.text
);
8103 attr
->value_tag
= IPP_TAG_KEYWORD
;
8104 attr
->values
[0].string
.text
= _cupsStrAlloc("indefinite");
8108 * Hold job until specified time...
8111 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
8113 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8114 "Job job-hold-until value changed by user.");
8117 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Held by \"%s\".", username
);
8119 con
->response
->request
.status
.status_code
= IPP_OK
;
8124 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8128 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8129 ipp_attribute_t
*uri
) /* I - Printer URI */
8131 http_status_t status
; /* Policy status */
8132 cups_ptype_t dtype
; /* Destination type (printer/class) */
8133 cupsd_printer_t
*printer
; /* Printer data */
8136 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8137 con
->http
.fd
, uri
->values
[0].string
.text
);
8140 * Is the destination valid?
8143 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8149 send_ipp_status(con
, IPP_NOT_FOUND
,
8150 _("The printer or class was not found."));
8158 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8160 send_http_error(con
, status
, printer
);
8165 * Hold pending/new jobs sent to the printer...
8168 printer
->holding_new_jobs
= 1;
8170 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8171 cupsdAddPrinterHistory(printer
);
8173 if (dtype
& CUPS_PRINTER_CLASS
)
8174 cupsdLogMessage(CUPSD_LOG_INFO
,
8175 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8176 printer
->name
, get_username(con
));
8178 cupsdLogMessage(CUPSD_LOG_INFO
,
8179 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8180 printer
->name
, get_username(con
));
8183 * Everything was ok, so return OK status...
8186 con
->response
->request
.status
.status_code
= IPP_OK
;
8191 * 'move_job()' - Move a job to a new destination.
8195 move_job(cupsd_client_t
*con
, /* I - Client connection */
8196 ipp_attribute_t
*uri
) /* I - Job URI */
8198 http_status_t status
; /* Policy status */
8199 ipp_attribute_t
*attr
; /* Current attribute */
8200 int jobid
; /* Job ID */
8201 cupsd_job_t
*job
; /* Current job */
8202 const char *src
; /* Source printer/class */
8203 cups_ptype_t stype
, /* Source type (printer or class) */
8204 dtype
; /* Destination type (printer/class) */
8205 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8206 username
[HTTP_MAX_URI
], /* Username portion of URI */
8207 host
[HTTP_MAX_URI
], /* Host portion of URI */
8208 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8209 int port
; /* Port portion of URI */
8210 cupsd_printer_t
*sprinter
, /* Source printer */
8211 *dprinter
; /* Destination printer */
8214 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8215 uri
->values
[0].string
.text
);
8218 * Get the new printer or class...
8221 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8222 IPP_TAG_URI
)) == NULL
)
8225 * Need job-printer-uri...
8228 send_ipp_status(con
, IPP_BAD_REQUEST
,
8229 _("job-printer-uri attribute missing!"));
8233 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8239 send_ipp_status(con
, IPP_NOT_FOUND
,
8240 _("The printer or class was not found."));
8245 * See if we have a job URI or a printer URI...
8248 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8249 sizeof(scheme
), username
, sizeof(username
), host
,
8250 sizeof(host
), &port
, resource
, sizeof(resource
));
8252 if (!strcmp(uri
->name
, "printer-uri"))
8255 * Got a printer URI; see if we also have a job-id attribute...
8258 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8259 IPP_TAG_INTEGER
)) == NULL
)
8265 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8266 &sprinter
)) == NULL
)
8272 send_ipp_status(con
, IPP_NOT_FOUND
,
8273 _("The printer or class was not found."));
8282 * Otherwise, just move a single job...
8285 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8288 * Nope - return a "not found" error...
8291 send_ipp_status(con
, IPP_NOT_FOUND
,
8292 _("Job #%d does not exist!"), attr
->values
[0].integer
);
8298 * Job found, initialize source pointers...
8309 * Got a job URI; parse it to get the job ID...
8312 if (strncmp(resource
, "/jobs/", 6))
8318 send_ipp_status(con
, IPP_BAD_REQUEST
,
8319 _("Bad job-uri attribute \"%s\"!"),
8320 uri
->values
[0].string
.text
);
8325 * See if the job exists...
8328 jobid
= atoi(resource
+ 6);
8330 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8333 * Nope - return a "not found" error...
8336 send_ipp_status(con
, IPP_NOT_FOUND
,
8337 _("Job #%d does not exist!"), jobid
);
8343 * Job found, initialize source pointers...
8352 * Check the policy of the destination printer...
8355 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8356 job
? job
->username
: NULL
)) != HTTP_OK
)
8358 send_http_error(con
, status
, dprinter
);
8363 * Now move the job or jobs...
8369 * See if the job has been completed...
8372 if (job
->state_value
> IPP_JOB_STOPPED
)
8375 * Return a "not-possible" error...
8378 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8379 _("Job #%d is finished and cannot be altered!"),
8385 * See if the job is owned by the requesting user...
8388 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8390 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8395 * Move the job to a different printer or class...
8398 cupsdMoveJob(job
, dprinter
);
8403 * Got the source printer, now look through the jobs...
8406 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8408 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8411 * See if the job is pointing at the source printer or has not been
8415 if (strcasecmp(job
->dest
, src
) ||
8416 job
->state_value
> IPP_JOB_STOPPED
)
8420 * See if the job can be moved by the requesting user...
8423 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8427 * Move the job to a different printer or class...
8430 cupsdMoveJob(job
, dprinter
);
8435 * Start jobs if possible...
8441 * Return with "everything is OK" status...
8444 con
->response
->request
.status
.status_code
= IPP_OK
;
8449 * 'ppd_parse_line()' - Parse a PPD default line.
8452 static int /* O - 0 on success, -1 on failure */
8453 ppd_parse_line(const char *line
, /* I - Line */
8454 char *option
, /* O - Option name */
8455 int olen
, /* I - Size of option name */
8456 char *choice
, /* O - Choice name */
8457 int clen
) /* I - Size of choice name */
8460 * Verify this is a default option line...
8463 if (strncmp(line
, "*Default", 8))
8467 * Read the option name...
8470 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
8480 * Skip everything else up to the colon (:)...
8483 while (*line
&& *line
!= ':')
8492 * Now grab the option choice, skipping leading whitespace...
8495 while (isspace(*line
& 255))
8498 for (clen
--; isalnum(*line
& 255); line
++)
8508 * Return with no errors...
8516 * 'print_job()' - Print a file to a printer or class.
8520 print_job(cupsd_client_t
*con
, /* I - Client connection */
8521 ipp_attribute_t
*uri
) /* I - Printer URI */
8523 ipp_attribute_t
*attr
; /* Current attribute */
8524 ipp_attribute_t
*format
; /* Document-format attribute */
8525 const char *default_format
; /* document-format-default value */
8526 cupsd_job_t
*job
; /* New job */
8527 char filename
[1024]; /* Job filename */
8528 mime_type_t
*filetype
; /* Type of file */
8529 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8530 type
[MIME_MAX_TYPE
], /* Subtype of file */
8531 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8532 /* Textual name of mime type */
8533 cupsd_printer_t
*printer
; /* Printer data */
8534 struct stat fileinfo
; /* File information */
8535 int kbytes
; /* Size of file */
8536 int compression
; /* Document compression */
8539 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8540 uri
->values
[0].string
.text
);
8543 * Validate print file attributes, for now just document-format and
8544 * compression (CUPS only supports "none" and "gzip")...
8547 compression
= CUPS_FILE_NONE
;
8549 if ((attr
= ippFindAttribute(con
->request
, "compression",
8550 IPP_TAG_KEYWORD
)) != NULL
)
8552 if (strcmp(attr
->values
[0].string
.text
, "none")
8554 && strcmp(attr
->values
[0].string
.text
, "gzip")
8555 #endif /* HAVE_LIBZ */
8558 send_ipp_status(con
, IPP_ATTRIBUTES
,
8559 _("Unsupported compression \"%s\"!"),
8560 attr
->values
[0].string
.text
);
8561 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8562 "compression", NULL
, attr
->values
[0].string
.text
);
8567 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8568 compression
= CUPS_FILE_GZIP
;
8569 #endif /* HAVE_LIBZ */
8573 * Do we have a file to print?
8578 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8583 * Is the destination valid?
8586 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8592 send_ipp_status(con
, IPP_NOT_FOUND
,
8593 _("The printer or class was not found."));
8598 * Is it a format we support?
8601 if ((format
= ippFindAttribute(con
->request
, "document-format",
8602 IPP_TAG_MIMETYPE
)) != NULL
)
8605 * Grab format from client...
8608 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8611 send_ipp_status(con
, IPP_BAD_REQUEST
,
8612 _("Could not scan type \"%s\"!"),
8613 format
->values
[0].string
.text
);
8617 else if ((default_format
= cupsGetOption("document-format",
8618 printer
->num_options
,
8619 printer
->options
)) != NULL
)
8622 * Use default document format...
8625 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8627 send_ipp_status(con
, IPP_BAD_REQUEST
,
8628 _("Could not scan type \"%s\"!"),
8639 strcpy(super
, "application");
8640 strcpy(type
, "octet-stream");
8643 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8646 * Auto-type the file...
8649 ipp_attribute_t
*doc_name
; /* document-name attribute */
8652 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8654 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8655 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8656 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8660 filetype
= mimeType(MimeDatabase
, super
, type
);
8662 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8663 filetype
->super
, filetype
->type
);
8666 filetype
= mimeType(MimeDatabase
, super
, type
);
8670 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8673 * Replace the document-format attribute value with the auto-typed or
8677 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8682 _cupsStrFree(format
->values
[0].string
.text
);
8684 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8687 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8688 "document-format", NULL
, mimetype
);
8692 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8693 _("Unsupported format \'%s/%s\'!"), super
, type
);
8694 cupsdLogMessage(CUPSD_LOG_INFO
,
8695 "Hint: Do you have the raw file printing rules enabled?");
8698 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8699 "document-format", NULL
, format
->values
[0].string
.text
);
8705 * Read any embedded job ticket info from PS files...
8708 if (!strcasecmp(filetype
->super
, "application") &&
8709 (!strcasecmp(filetype
->type
, "postscript") ||
8710 !strcasecmp(filetype
->type
, "pdf")))
8711 read_job_ticket(con
);
8714 * Create the job object...
8717 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8721 * Update quota data...
8724 if (stat(con
->filename
, &fileinfo
))
8727 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8729 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8731 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8732 IPP_TAG_INTEGER
)) != NULL
)
8733 attr
->values
[0].integer
+= kbytes
;
8736 * Add the job file...
8739 if (add_file(con
, job
, filetype
, compression
))
8742 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8744 rename(con
->filename
, filename
);
8745 cupsdClearString(&con
->filename
);
8748 * See if we need to add the ending sheet...
8751 if (cupsdTimeoutJob(job
))
8755 * Log and save the job...
8758 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8759 "File of type %s/%s queued by \"%s\".",
8760 filetype
->super
, filetype
->type
, job
->username
);
8761 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8762 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8763 job
->dest
, job
->username
);
8766 * Start the job if possible...
8774 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8776 * This function only gets called when printing a single PDF or PostScript
8777 * file using the Print-Job operation. It doesn't work for Create-Job +
8778 * Send-File, since the job attributes need to be set at job creation
8779 * time for banners to work. The embedded job ticket stuff is here
8780 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8781 * options and IPP attributes which otherwise would be lost.
8783 * The format of a job ticket is simple:
8785 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8787 * %cupsJobTicket: attr1=value1
8788 * %cupsJobTicket: attr2=value2
8790 * %cupsJobTicket: attrN=valueN
8792 * Job ticket lines must appear immediately after the first line that
8793 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8794 * stops looking for job ticket info when it finds a line that does not begin
8795 * with "%cupsJobTicket:".
8797 * The maximum length of a job ticket line, including the prefix, is
8798 * 255 characters to conform with the Adobe DSC.
8800 * Read-only attributes are rejected with a notice to the error log in
8801 * case a malicious user tries anything. Since the job ticket is read
8802 * prior to attribute validation in print_job(), job ticket attributes
8803 * will go through the same validation as IPP attributes...
8807 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8809 cups_file_t
*fp
; /* File to read from */
8810 char line
[256]; /* Line data */
8811 int num_options
; /* Number of options */
8812 cups_option_t
*options
; /* Options */
8813 ipp_t
*ticket
; /* New attributes */
8814 ipp_attribute_t
*attr
, /* Current attribute */
8815 *attr2
, /* Job attribute */
8816 *prev2
; /* Previous job attribute */
8820 * First open the print file...
8823 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8825 cupsdLogMessage(CUPSD_LOG_ERROR
,
8826 "Unable to open print file for job ticket - %s",
8832 * Skip the first line...
8835 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8837 cupsdLogMessage(CUPSD_LOG_ERROR
,
8838 "Unable to read from print file for job ticket - %s",
8844 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8847 * Not a DSC-compliant file, so no job ticket info will be available...
8855 * Read job ticket info from the file...
8861 while (cupsFileGets(fp
, line
, sizeof(line
)))
8864 * Stop at the first non-ticket line...
8867 if (strncmp(line
, "%cupsJobTicket:", 15))
8871 * Add the options to the option array...
8874 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8878 * Done with the file; see if we have any options...
8883 if (num_options
== 0)
8887 * OK, convert the options to an attribute list, and apply them to
8892 cupsEncodeOptions(ticket
, num_options
, options
);
8895 * See what the user wants to change.
8898 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8900 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8903 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8904 !strcmp(attr
->name
, "job-originating-user-name") ||
8905 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8906 !strcmp(attr
->name
, "job-k-octets") ||
8907 !strcmp(attr
->name
, "job-id") ||
8908 !strncmp(attr
->name
, "job-state", 9) ||
8909 !strncmp(attr
->name
, "time-at-", 8))
8910 continue; /* Read-only attrs */
8912 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8913 IPP_TAG_ZERO
)) != NULL
)
8916 * Some other value; first free the old value...
8919 if (con
->request
->attrs
== attr2
)
8921 con
->request
->attrs
= attr2
->next
;
8926 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8927 if (prev2
->next
== attr2
)
8929 prev2
->next
= attr2
->next
;
8934 if (con
->request
->last
== attr2
)
8935 con
->request
->last
= prev2
;
8937 _ippFreeAttr(attr2
);
8941 * Add new option by copying it...
8944 copy_attribute(con
->request
, attr
, 0);
8948 * Then free the attribute list and option array...
8952 cupsFreeOptions(num_options
, options
);
8957 * 'reject_jobs()' - Reject print jobs to a printer.
8961 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8962 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8964 http_status_t status
; /* Policy status */
8965 cups_ptype_t dtype
; /* Destination type (printer/class) */
8966 cupsd_printer_t
*printer
; /* Printer data */
8967 ipp_attribute_t
*attr
; /* printer-state-message text */
8970 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8971 con
->http
.fd
, uri
->values
[0].string
.text
);
8974 * Is the destination valid?
8977 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8983 send_ipp_status(con
, IPP_NOT_FOUND
,
8984 _("The printer or class was not found."));
8992 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8994 send_http_error(con
, status
, printer
);
8999 * Reject jobs sent to the printer...
9002 printer
->accepting
= 0;
9004 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9005 IPP_TAG_TEXT
)) == NULL
)
9006 strcpy(printer
->state_message
, "Rejecting Jobs");
9008 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9009 sizeof(printer
->state_message
));
9011 cupsdAddPrinterHistory(printer
);
9013 if (dtype
& CUPS_PRINTER_CLASS
)
9015 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9017 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9018 printer
->name
, get_username(con
));
9022 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9024 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9025 printer
->name
, get_username(con
));
9029 * Everything was ok, so return OK status...
9032 con
->response
->request
.status
.status_code
= IPP_OK
;
9037 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9041 release_held_new_jobs(
9042 cupsd_client_t
*con
, /* I - Connection */
9043 ipp_attribute_t
*uri
) /* I - Printer URI */
9045 http_status_t status
; /* Policy status */
9046 cups_ptype_t dtype
; /* Destination type (printer/class) */
9047 cupsd_printer_t
*printer
; /* Printer data */
9050 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9051 con
->http
.fd
, uri
->values
[0].string
.text
);
9054 * Is the destination valid?
9057 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9063 send_ipp_status(con
, IPP_NOT_FOUND
,
9064 _("The printer or class was not found."));
9072 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9074 send_http_error(con
, status
, printer
);
9079 * Hold pending/new jobs sent to the printer...
9082 printer
->holding_new_jobs
= 0;
9084 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9085 cupsdAddPrinterHistory(printer
);
9087 if (dtype
& CUPS_PRINTER_CLASS
)
9088 cupsdLogMessage(CUPSD_LOG_INFO
,
9089 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9090 printer
->name
, get_username(con
));
9092 cupsdLogMessage(CUPSD_LOG_INFO
,
9093 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9094 printer
->name
, get_username(con
));
9097 * Everything was ok, so return OK status...
9100 con
->response
->request
.status
.status_code
= IPP_OK
;
9105 * 'release_job()' - Release a held print job.
9109 release_job(cupsd_client_t
*con
, /* I - Client connection */
9110 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9112 ipp_attribute_t
*attr
; /* Current attribute */
9113 int jobid
; /* Job ID */
9114 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9115 username
[HTTP_MAX_URI
], /* Username portion of URI */
9116 host
[HTTP_MAX_URI
], /* Host portion of URI */
9117 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9118 int port
; /* Port portion of URI */
9119 cupsd_job_t
*job
; /* Job information */
9122 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9123 con
->http
.fd
, uri
->values
[0].string
.text
);
9126 * See if we have a job URI or a printer URI...
9129 if (!strcmp(uri
->name
, "printer-uri"))
9132 * Got a printer URI; see if we also have a job-id attribute...
9135 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9136 IPP_TAG_INTEGER
)) == NULL
)
9138 send_ipp_status(con
, IPP_BAD_REQUEST
,
9139 _("Got a printer-uri attribute but no job-id!"));
9143 jobid
= attr
->values
[0].integer
;
9148 * Got a job URI; parse it to get the job ID...
9151 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9152 sizeof(scheme
), username
, sizeof(username
), host
,
9153 sizeof(host
), &port
, resource
, sizeof(resource
));
9155 if (strncmp(resource
, "/jobs/", 6))
9161 send_ipp_status(con
, IPP_BAD_REQUEST
,
9162 _("Bad job-uri attribute \"%s\"!"),
9163 uri
->values
[0].string
.text
);
9167 jobid
= atoi(resource
+ 6);
9171 * See if the job exists...
9174 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9177 * Nope - return a "not found" error...
9180 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9185 * See if job is "held"...
9188 if (job
->state_value
!= IPP_JOB_HELD
)
9191 * Nope - return a "not possible" error...
9194 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
9199 * See if the job is owned by the requesting user...
9202 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9204 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9209 * Reset the job-hold-until value to "no-hold"...
9212 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9213 IPP_TAG_KEYWORD
)) == NULL
)
9214 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9218 _cupsStrFree(attr
->values
[0].string
.text
);
9220 attr
->value_tag
= IPP_TAG_KEYWORD
;
9221 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9223 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9224 "Job job-hold-until value changed by user.");
9228 * Release the job and return...
9231 cupsdReleaseJob(job
);
9233 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9234 "Job released by user.");
9236 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9238 con
->response
->request
.status
.status_code
= IPP_OK
;
9245 * 'renew_subscription()' - Renew an existing subscription...
9250 cupsd_client_t
*con
, /* I - Client connection */
9251 int sub_id
) /* I - Subscription ID */
9253 http_status_t status
; /* Policy status */
9254 cupsd_subscription_t
*sub
; /* Subscription */
9255 ipp_attribute_t
*lease
; /* notify-lease-duration */
9258 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9259 "renew_subscription(con=%p[%d], sub_id=%d)",
9260 con
, con
->http
.fd
, sub_id
);
9263 * Is the subscription ID valid?
9266 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9269 * Bad subscription ID...
9272 send_ipp_status(con
, IPP_NOT_FOUND
,
9273 _("notify-subscription-id %d no good!"), sub_id
);
9280 * Job subscriptions cannot be renewed...
9283 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9284 _("Job subscriptions cannot be renewed!"));
9292 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9294 con
, sub
->owner
)) != HTTP_OK
)
9296 send_http_error(con
, status
, sub
->dest
);
9301 * Renew the subscription...
9304 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9307 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9309 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9311 cupsdLogMessage(CUPSD_LOG_INFO
,
9312 "renew_subscription: Limiting notify-lease-duration to "
9315 sub
->lease
= MaxLeaseDuration
;
9318 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9320 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9322 con
->response
->request
.status
.status_code
= IPP_OK
;
9324 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9325 "notify-lease-duration", sub
->lease
);
9330 * 'restart_job()' - Restart an old print job.
9334 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9335 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9337 ipp_attribute_t
*attr
; /* Current attribute */
9338 int jobid
; /* Job ID */
9339 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9340 username
[HTTP_MAX_URI
], /* Username portion of URI */
9341 host
[HTTP_MAX_URI
], /* Host portion of URI */
9342 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9343 int port
; /* Port portion of URI */
9344 cupsd_job_t
*job
; /* Job information */
9347 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9348 con
->http
.fd
, uri
->values
[0].string
.text
);
9351 * See if we have a job URI or a printer URI...
9354 if (!strcmp(uri
->name
, "printer-uri"))
9357 * Got a printer URI; see if we also have a job-id attribute...
9360 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9361 IPP_TAG_INTEGER
)) == NULL
)
9363 send_ipp_status(con
, IPP_BAD_REQUEST
,
9364 _("Got a printer-uri attribute but no job-id!"));
9368 jobid
= attr
->values
[0].integer
;
9373 * Got a job URI; parse it to get the job ID...
9376 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9377 sizeof(scheme
), username
, sizeof(username
), host
,
9378 sizeof(host
), &port
, resource
, sizeof(resource
));
9380 if (strncmp(resource
, "/jobs/", 6))
9386 send_ipp_status(con
, IPP_BAD_REQUEST
,
9387 _("Bad job-uri attribute \"%s\"!"),
9388 uri
->values
[0].string
.text
);
9392 jobid
= atoi(resource
+ 6);
9396 * See if the job exists...
9399 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9402 * Nope - return a "not found" error...
9405 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9410 * See if job is in any of the "completed" states...
9413 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9416 * Nope - return a "not possible" error...
9419 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
9425 * See if we have retained the job files...
9430 if (!job
->attrs
|| job
->num_files
== 0)
9433 * Nope - return a "not possible" error...
9436 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9437 _("Job #%d cannot be restarted - no files!"), jobid
);
9442 * See if the job is owned by the requesting user...
9445 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9447 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9452 * Restart the job and return...
9455 cupsdRestartJob(job
);
9457 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9459 con
->response
->request
.status
.status_code
= IPP_OK
;
9464 * 'save_auth_info()' - Save authentication information for a job.
9469 cupsd_client_t
*con
, /* I - Client connection */
9470 cupsd_job_t
*job
, /* I - Job */
9471 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9473 int i
; /* Looping var */
9474 char filename
[1024]; /* Job authentication filename */
9475 cups_file_t
*fp
; /* Job authentication file */
9476 char line
[2048]; /* Line for file */
9477 cupsd_printer_t
*dest
; /* Destination printer/class */
9481 * This function saves the in-memory authentication information for
9482 * a job so that it can be used to authenticate with a remote host.
9483 * The information is stored in a file that is readable only by the
9484 * root user. The fields are Base-64 encoded, each on a separate line,
9485 * followed by random number (up to 1024) of newlines to limit the
9486 * amount of information that is exposed.
9488 * Because of the potential for exposing of authentication information,
9489 * this functionality is only enabled when running cupsd as root.
9491 * This caching only works for the Basic and BasicDigest authentication
9492 * types. Digest authentication cannot be cached this way, and in
9493 * the future Kerberos authentication may make all of this obsolete.
9495 * Authentication information is saved whenever an authenticated
9496 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9499 * This information is deleted after a job is completed or canceled,
9500 * so reprints may require subsequent re-authentication.
9506 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9510 * Create the authentication file and change permissions...
9513 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9514 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9516 cupsdLogMessage(CUPSD_LOG_ERROR
,
9517 "Unable to save authentication info to \"%s\" - %s",
9518 filename
, strerror(errno
));
9522 fchown(cupsFileNumber(fp
), 0, 0);
9523 fchmod(cupsFileNumber(fp
), 0400);
9525 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9528 * Write 1 to 3 auth values...
9531 cupsdClearString(&job
->auth_username
);
9532 cupsdClearString(&job
->auth_domain
);
9533 cupsdClearString(&job
->auth_password
);
9535 for (i
= 0; i
< auth_info
->num_values
; i
++)
9537 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9538 strlen(auth_info
->values
[i
].string
.text
));
9539 cupsFilePrintf(fp
, "%s\n", line
);
9541 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9542 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9543 auth_info
->values
[i
].string
.text
);
9544 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9545 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9546 auth_info
->values
[i
].string
.text
);
9547 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9548 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9549 auth_info
->values
[i
].string
.text
);
9552 else if (con
->username
[0])
9555 * Write the authenticated username...
9558 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9559 cupsFilePrintf(fp
, "%s\n", line
);
9561 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9562 cupsdClearString(&job
->auth_domain
);
9565 * Write the authenticated password...
9568 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9569 cupsFilePrintf(fp
, "%s\n", line
);
9571 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
9575 * Write a random number of newlines to the end of the file...
9578 for (i
= (rand() % 1024); i
>= 0; i
--)
9579 cupsFilePutChar(fp
, '\n');
9582 * Close the file and return...
9587 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9588 if (con
->gss_have_creds
)
9589 save_krb5_creds(con
, job
);
9590 else if (job
->ccname
)
9591 cupsdClearString(&(job
->ccname
));
9592 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9596 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9598 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
9602 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
9603 cupsd_job_t
*job
) /* I - Job */
9605 # if !defined(HAVE_KRB5_CC_NEW_UNIQUE) && !defined(HAVE_HEIMDAL)
9606 cupsdLogMessage(CUPSD_LOG_INFO
,
9607 "Sorry, your version of Kerberos does not support delegated "
9612 krb5_error_code error
; /* Kerberos error code */
9613 OM_uint32 major_status
, /* Major status code */
9614 minor_status
; /* Minor status code */
9615 krb5_principal principal
; /* Kerberos principal */
9620 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
9624 if (krb5_init_context
== NULL
)
9626 # endif /* __APPLE__ */
9628 if (!KerberosInitialized
)
9631 * Setup a Kerberos context for the scheduler to use...
9634 KerberosInitialized
= 1;
9636 if (krb5_init_context(&KerberosContext
))
9638 KerberosContext
= NULL
;
9640 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to initialize Kerberos context");
9646 * We MUST create a file-based cache because memory-based caches are
9647 * only valid for the current process/address space.
9649 * Due to various bugs/features in different versions of Kerberos, we
9650 * need either the krb5_cc_new_unique() function or Heimdal's version
9651 * of krb5_cc_gen_new() to create a new FILE: credential cache that
9652 * can be passed to the backend. These functions create a temporary
9653 * file (typically in /tmp) containing the cached credentials, which
9654 * are removed when we have successfully printed a job.
9657 # ifdef HAVE_KRB5_CC_NEW_UNIQUE
9658 if ((error
= krb5_cc_new_unique(KerberosContext
, "FILE", NULL
,
9659 &(job
->ccache
))) != 0)
9660 # else /* HAVE_HEIMDAL */
9661 if ((error
= krb5_cc_gen_new(KerberosContext
, &krb5_fcc_ops
,
9662 &(job
->ccache
))) != 0)
9663 # endif /* HAVE_KRB5_CC_NEW_UNIQUE */
9665 cupsdLogMessage(CUPSD_LOG_ERROR
,
9666 "Unable to create new credentials cache (%d/%s)",
9667 error
, strerror(errno
));
9672 if ((error
= krb5_parse_name(KerberosContext
, con
->username
, &principal
)) != 0)
9674 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to parse kerberos username (%d/%s)",
9675 error
, strerror(errno
));
9676 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9681 if ((error
= krb5_cc_initialize(KerberosContext
, job
->ccache
, principal
)))
9683 cupsdLogMessage(CUPSD_LOG_ERROR
,
9684 "Unable to initialize credentials cache (%d/%s)", error
,
9686 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9687 krb5_free_principal(KerberosContext
, principal
);
9692 krb5_free_principal(KerberosContext
, principal
);
9695 * Copy the user's credentials to the new cache file...
9698 major_status
= gss_krb5_copy_ccache(&minor_status
, con
->gss_delegated_cred
,
9701 if (GSS_ERROR(major_status
))
9703 cupsdLogGSSMessage(CUPSD_LOG_ERROR
, major_status
, minor_status
,
9704 "Unable to import client credentials cache");
9705 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9711 * Add the KRB5CCNAME environment variable to the job so that the
9712 * backend can use the credentials when printing.
9715 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
9716 krb5_cc_get_name(KerberosContext
, job
->ccache
));
9718 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
9719 # endif /* HAVE_KRB5_CC_NEW_UNIQUE || HAVE_HEIMDAL */
9721 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9725 * 'send_document()' - Send a file to a printer or class.
9729 send_document(cupsd_client_t
*con
, /* I - Client connection */
9730 ipp_attribute_t
*uri
) /* I - Printer URI */
9732 ipp_attribute_t
*attr
; /* Current attribute */
9733 ipp_attribute_t
*format
; /* Request's document-format attribute */
9734 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9735 const char *default_format
;/* document-format-default value */
9736 int jobid
; /* Job ID number */
9737 cupsd_job_t
*job
; /* Current job */
9738 char job_uri
[HTTP_MAX_URI
],
9740 scheme
[HTTP_MAX_URI
],
9741 /* Method portion of URI */
9742 username
[HTTP_MAX_URI
],
9743 /* Username portion of URI */
9745 /* Host portion of URI */
9746 resource
[HTTP_MAX_URI
];
9747 /* Resource portion of URI */
9748 int port
; /* Port portion of URI */
9749 mime_type_t
*filetype
; /* Type of file */
9750 char super
[MIME_MAX_SUPER
],
9751 /* Supertype of file */
9752 type
[MIME_MAX_TYPE
],
9753 /* Subtype of file */
9754 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9755 /* Textual name of mime type */
9756 char filename
[1024]; /* Job filename */
9757 cupsd_printer_t
*printer
; /* Current printer */
9758 struct stat fileinfo
; /* File information */
9759 int kbytes
; /* Size of file */
9760 int compression
; /* Type of compression */
9761 int start_job
; /* Start the job? */
9764 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9765 con
->http
.fd
, uri
->values
[0].string
.text
);
9768 * See if we have a job URI or a printer URI...
9771 if (!strcmp(uri
->name
, "printer-uri"))
9774 * Got a printer URI; see if we also have a job-id attribute...
9777 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9778 IPP_TAG_INTEGER
)) == NULL
)
9780 send_ipp_status(con
, IPP_BAD_REQUEST
,
9781 _("Got a printer-uri attribute but no job-id!"));
9785 jobid
= attr
->values
[0].integer
;
9790 * Got a job URI; parse it to get the job ID...
9793 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9794 sizeof(scheme
), username
, sizeof(username
), host
,
9795 sizeof(host
), &port
, resource
, sizeof(resource
));
9797 if (strncmp(resource
, "/jobs/", 6))
9803 send_ipp_status(con
, IPP_BAD_REQUEST
,
9804 _("Bad job-uri attribute \"%s\"!"),
9805 uri
->values
[0].string
.text
);
9809 jobid
= atoi(resource
+ 6);
9813 * See if the job exists...
9816 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9819 * Nope - return a "not found" error...
9822 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9826 printer
= cupsdFindDest(job
->dest
);
9829 * See if the job is owned by the requesting user...
9832 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9834 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9839 * OK, see if the client is sending the document compressed - CUPS
9840 * only supports "none" and "gzip".
9843 compression
= CUPS_FILE_NONE
;
9845 if ((attr
= ippFindAttribute(con
->request
, "compression",
9846 IPP_TAG_KEYWORD
)) != NULL
)
9848 if (strcmp(attr
->values
[0].string
.text
, "none")
9850 && strcmp(attr
->values
[0].string
.text
, "gzip")
9851 #endif /* HAVE_LIBZ */
9854 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
9855 attr
->values
[0].string
.text
);
9856 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9857 "compression", NULL
, attr
->values
[0].string
.text
);
9862 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9863 compression
= CUPS_FILE_GZIP
;
9864 #endif /* HAVE_LIBZ */
9868 * Do we have a file to print?
9873 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
9878 * Is it a format we support?
9881 if ((format
= ippFindAttribute(con
->request
, "document-format",
9882 IPP_TAG_MIMETYPE
)) != NULL
)
9885 * Grab format from client...
9888 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9891 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9892 format
->values
[0].string
.text
);
9896 else if ((default_format
= cupsGetOption("document-format",
9897 printer
->num_options
,
9898 printer
->options
)) != NULL
)
9901 * Use default document format...
9904 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9906 send_ipp_status(con
, IPP_BAD_REQUEST
,
9907 _("Could not scan type \"%s\"!"),
9915 * No document format attribute? Auto-type it!
9918 strcpy(super
, "application");
9919 strcpy(type
, "octet-stream");
9922 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9925 * Auto-type the file...
9928 ipp_attribute_t
*doc_name
; /* document-name attribute */
9931 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9933 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9934 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9935 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9939 filetype
= mimeType(MimeDatabase
, super
, type
);
9941 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9942 filetype
->super
, filetype
->type
);
9945 filetype
= mimeType(MimeDatabase
, super
, type
);
9950 * Replace the document-format attribute value with the auto-typed or
9954 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9957 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9958 IPP_TAG_MIMETYPE
)) != NULL
)
9960 _cupsStrFree(jformat
->values
[0].string
.text
);
9962 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9965 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9966 "document-format", NULL
, mimetype
);
9970 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9971 _("Unsupported format \'%s/%s\'!"), super
, type
);
9972 cupsdLogMessage(CUPSD_LOG_INFO
,
9973 "Hint: Do you have the raw file printing rules enabled?");
9976 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9977 "document-format", NULL
, format
->values
[0].string
.text
);
9982 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9984 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9987 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9988 _("Unsupported format \'%s\'!"), mimetype
);
9990 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9991 "document-format", NULL
, mimetype
);
9997 * Add the file to the job...
10002 if (add_file(con
, job
, filetype
, compression
))
10005 if (stat(con
->filename
, &fileinfo
))
10008 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10010 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10012 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10013 IPP_TAG_INTEGER
)) != NULL
)
10014 attr
->values
[0].integer
+= kbytes
;
10016 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10018 rename(con
->filename
, filename
);
10020 cupsdClearString(&con
->filename
);
10022 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10023 filetype
->super
, filetype
->type
, job
->username
);
10026 * Start the job if this is the last document...
10029 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10030 IPP_TAG_BOOLEAN
)) != NULL
&&
10031 attr
->values
[0].boolean
)
10034 * See if we need to add the ending sheet...
10037 if (cupsdTimeoutJob(job
))
10040 if (job
->state_value
== IPP_JOB_STOPPED
)
10042 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10043 job
->state_value
= IPP_JOB_PENDING
;
10045 else if (job
->state_value
== IPP_JOB_HELD
)
10047 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10048 IPP_TAG_KEYWORD
)) == NULL
)
10049 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10051 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10053 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10054 job
->state_value
= IPP_JOB_PENDING
;
10059 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10065 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10066 IPP_TAG_KEYWORD
)) == NULL
)
10067 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10069 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10071 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10072 job
->state_value
= IPP_JOB_HELD
;
10073 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10076 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10083 * Fill in the response info...
10086 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10089 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10092 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10094 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10096 add_job_state_reasons(con
, job
);
10098 con
->response
->request
.status
.status_code
= IPP_OK
;
10101 * Start the job if necessary...
10110 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10115 cupsd_client_t
*con
, /* I - Client connection */
10116 http_status_t status
, /* I - HTTP status code */
10117 cupsd_printer_t
*printer
) /* I - Printer, if any */
10119 ipp_attribute_t
*uri
; /* Request URI, if any */
10122 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10123 IPP_TAG_URI
)) == NULL
)
10124 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10126 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10127 "Returning HTTP %s for %s (%s) from %s",
10128 httpStatus(status
),
10129 ippOpString(con
->request
->request
.op
.operation_id
),
10130 uri
? uri
->values
[0].string
.text
: "no URI",
10131 con
->http
.hostname
);
10135 int auth_type
; /* Type of authentication required */
10138 auth_type
= CUPSD_AUTH_NONE
;
10140 if (status
== HTTP_UNAUTHORIZED
&&
10141 printer
->num_auth_info_required
> 0 &&
10142 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10144 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10145 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10146 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10149 * Creating and authenticating jobs requires Kerberos...
10152 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10157 * Use policy/location-defined authentication requirements...
10160 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10161 cupsd_location_t
*auth
; /* Pointer to authentication element */
10164 if (printer
->type
& CUPS_PRINTER_CLASS
)
10165 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10167 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10169 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10170 auth
->type
== CUPSD_AUTH_NONE
)
10171 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10173 con
->request
->request
.op
.operation_id
:
10178 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10179 auth_type
= DefaultAuthType
;
10181 auth_type
= auth
->type
;
10185 cupsdSendError(con
, status
, auth_type
);
10188 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10190 ippDelete(con
->response
);
10191 con
->response
= NULL
;
10198 * 'send_ipp_status()' - Send a status back to the IPP client.
10202 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10203 ipp_status_t status
, /* I - IPP status code */
10204 const char *message
,/* I - Status message */
10205 ...) /* I - Additional args as needed */
10207 va_list ap
; /* Pointer to additional args */
10208 char formatted
[1024]; /* Formatted errror message */
10211 va_start(ap
, message
);
10212 vsnprintf(formatted
, sizeof(formatted
),
10213 _cupsLangString(con
->language
, message
), ap
);
10216 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10217 ippOpString(con
->request
->request
.op
.operation_id
),
10218 ippErrorString(status
), formatted
);
10220 con
->response
->request
.status
.status_code
= status
;
10222 if (ippFindAttribute(con
->response
, "attributes-charset",
10223 IPP_TAG_ZERO
) == NULL
)
10224 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10225 "attributes-charset", NULL
, DefaultCharset
);
10227 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10228 IPP_TAG_ZERO
) == NULL
)
10229 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10230 "attributes-natural-language", NULL
, DefaultLanguage
);
10232 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10233 "status-message", NULL
, formatted
);
10238 * 'set_default()' - Set the default destination...
10242 set_default(cupsd_client_t
*con
, /* I - Client connection */
10243 ipp_attribute_t
*uri
) /* I - Printer URI */
10245 http_status_t status
; /* Policy status */
10246 cups_ptype_t dtype
; /* Destination type (printer/class) */
10247 cupsd_printer_t
*printer
, /* Printer */
10248 *oldprinter
; /* Old default printer */
10251 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10252 con
->http
.fd
, uri
->values
[0].string
.text
);
10255 * Is the destination valid?
10258 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10264 send_ipp_status(con
, IPP_NOT_FOUND
,
10265 _("The printer or class was not found."));
10273 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10275 send_http_error(con
, status
, NULL
);
10280 * Set it as the default...
10283 oldprinter
= DefaultPrinter
;
10284 DefaultPrinter
= printer
;
10287 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10288 "%s is no longer the default printer.", oldprinter
->name
);
10290 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10291 "%s is now the default printer.", printer
->name
);
10293 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10294 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10296 cupsdLogMessage(CUPSD_LOG_INFO
,
10297 "Default destination set to \"%s\" by \"%s\".",
10298 printer
->name
, get_username(con
));
10301 * Everything was ok, so return OK status...
10304 con
->response
->request
.status
.status_code
= IPP_OK
;
10309 * 'set_job_attrs()' - Set job attributes.
10313 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10314 ipp_attribute_t
*uri
) /* I - Job URI */
10316 ipp_attribute_t
*attr
, /* Current attribute */
10317 *attr2
; /* Job attribute */
10318 int jobid
; /* Job ID */
10319 cupsd_job_t
*job
; /* Current job */
10320 char scheme
[HTTP_MAX_URI
],
10321 /* Method portion of URI */
10322 username
[HTTP_MAX_URI
],
10323 /* Username portion of URI */
10324 host
[HTTP_MAX_URI
],
10325 /* Host portion of URI */
10326 resource
[HTTP_MAX_URI
];
10327 /* Resource portion of URI */
10328 int port
; /* Port portion of URI */
10329 int event
; /* Events? */
10330 int check_jobs
; /* Check jobs? */
10333 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10334 con
->http
.fd
, uri
->values
[0].string
.text
);
10337 * Start with "everything is OK" status...
10340 con
->response
->request
.status
.status_code
= IPP_OK
;
10343 * See if we have a job URI or a printer URI...
10346 if (!strcmp(uri
->name
, "printer-uri"))
10349 * Got a printer URI; see if we also have a job-id attribute...
10352 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10353 IPP_TAG_INTEGER
)) == NULL
)
10355 send_ipp_status(con
, IPP_BAD_REQUEST
,
10356 _("Got a printer-uri attribute but no job-id!"));
10360 jobid
= attr
->values
[0].integer
;
10365 * Got a job URI; parse it to get the job ID...
10368 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10369 sizeof(scheme
), username
, sizeof(username
), host
,
10370 sizeof(host
), &port
, resource
, sizeof(resource
));
10372 if (strncmp(resource
, "/jobs/", 6))
10378 send_ipp_status(con
, IPP_BAD_REQUEST
,
10379 _("Bad job-uri attribute \"%s\"!"),
10380 uri
->values
[0].string
.text
);
10384 jobid
= atoi(resource
+ 6);
10388 * See if the job exists...
10391 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10394 * Nope - return a "not found" error...
10397 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
10402 * See if the job has been completed...
10405 if (job
->state_value
> IPP_JOB_STOPPED
)
10408 * Return a "not-possible" error...
10411 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10412 _("Job #%d is finished and cannot be altered!"), jobid
);
10417 * See if the job is owned by the requesting user...
10420 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10422 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
10427 * See what the user wants to change.
10435 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10437 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10440 if (!strcmp(attr
->name
, "attributes-charset") ||
10441 !strcmp(attr
->name
, "attributes-natural-language") ||
10442 !strcmp(attr
->name
, "document-compression") ||
10443 !strcmp(attr
->name
, "document-format") ||
10444 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10445 !strcmp(attr
->name
, "job-document-access-errors") ||
10446 !strcmp(attr
->name
, "job-id") ||
10447 !strcmp(attr
->name
, "job-impressions-completed") ||
10448 !strcmp(attr
->name
, "job-k-octets") ||
10449 !strcmp(attr
->name
, "job-originating-host-name") ||
10450 !strcmp(attr
->name
, "job-originating-user-name") ||
10451 !strcmp(attr
->name
, "job-printer-up-time") ||
10452 !strcmp(attr
->name
, "job-printer-uri") ||
10453 !strcmp(attr
->name
, "job-sheets") ||
10454 !strcmp(attr
->name
, "job-state-message") ||
10455 !strcmp(attr
->name
, "job-state-reasons") ||
10456 !strcmp(attr
->name
, "job-uri") ||
10457 !strcmp(attr
->name
, "number-of-documents") ||
10458 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10459 !strcmp(attr
->name
, "output-device-assigned") ||
10460 !strncmp(attr
->name
, "date-time-at-", 13) ||
10461 !strncmp(attr
->name
, "job-k-octets", 12) ||
10462 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10463 !strncmp(attr
->name
, "time-at-", 8))
10469 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10470 _("%s cannot be changed."), attr
->name
);
10472 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10473 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10478 if (!strcmp(attr
->name
, "job-priority"))
10481 * Change the job priority...
10484 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10486 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
10488 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10489 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10491 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10493 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10494 _("Job is completed and cannot be changed."));
10497 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10499 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10500 attr
->values
[0].integer
);
10501 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10504 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10505 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10508 else if (!strcmp(attr
->name
, "job-state"))
10511 * Change the job state...
10514 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10516 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
10518 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10519 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10523 switch (attr
->values
[0].integer
)
10525 case IPP_JOB_PENDING
:
10526 case IPP_JOB_HELD
:
10527 if (job
->state_value
> IPP_JOB_HELD
)
10529 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10530 _("Job state cannot be changed."));
10533 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10535 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10536 attr
->values
[0].integer
);
10538 job
->state
->values
[0].integer
= attr
->values
[0].integer
;
10539 job
->state_value
= (ipp_jstate_t
)attr
->values
[0].integer
;
10541 event
|= CUPSD_EVENT_JOB_STATE
;
10546 case IPP_JOB_PROCESSING
:
10547 case IPP_JOB_STOPPED
:
10548 if (job
->state_value
!= attr
->values
[0].integer
)
10550 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10551 _("Job state cannot be changed."));
10556 case IPP_JOB_CANCELED
:
10557 case IPP_JOB_ABORTED
:
10558 case IPP_JOB_COMPLETED
:
10559 if (job
->state_value
> IPP_JOB_PROCESSING
)
10561 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10562 _("Job state cannot be changed."));
10565 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10567 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10568 attr
->values
[0].integer
);
10569 cupsdCancelJob(job
, 0, (ipp_jstate_t
)attr
->values
[0].integer
);
10577 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10579 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10580 IPP_TAG_ZERO
)) != NULL
)
10583 * Some other value; first free the old value...
10586 if (job
->attrs
->prev
)
10587 job
->attrs
->prev
->next
= attr2
->next
;
10589 job
->attrs
->attrs
= attr2
->next
;
10591 if (job
->attrs
->last
== attr2
)
10592 job
->attrs
->last
= job
->attrs
->prev
;
10594 _ippFreeAttr(attr2
);
10597 * Then copy the attribute...
10600 copy_attribute(job
->attrs
, attr
, 0);
10603 * See if the job-name or job-hold-until is being changed.
10606 if (!strcmp(attr
->name
, "job-hold-until"))
10608 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10609 attr
->values
[0].string
.text
);
10610 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
10612 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10613 cupsdReleaseJob(job
);
10618 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10621 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10624 * Delete the attribute...
10627 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10628 IPP_TAG_ZERO
)) != NULL
)
10630 if (job
->attrs
->prev
)
10631 job
->attrs
->prev
->next
= attr2
->next
;
10633 job
->attrs
->attrs
= attr2
->next
;
10635 if (attr2
== job
->attrs
->last
)
10636 job
->attrs
->last
= job
->attrs
->prev
;
10638 _ippFreeAttr(attr2
);
10640 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10646 * Add new option by copying it...
10649 copy_attribute(job
->attrs
, attr
, 0);
10651 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10660 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10663 * Send events as needed...
10666 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10667 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10668 cupsdFindDest(job
->dest
), job
,
10669 "Job priority changed by user.");
10671 if (event
& CUPSD_EVENT_JOB_STATE
)
10672 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10673 job
->state_value
== IPP_JOB_HELD
?
10674 "Job held by user." : "Job restarted by user.");
10676 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10677 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10678 "Job options changed by user.");
10681 * Start jobs if possible...
10690 * 'set_printer_attrs()' - Set printer attributes.
10694 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10695 ipp_attribute_t
*uri
) /* I - Printer */
10697 http_status_t status
; /* Policy status */
10698 cups_ptype_t dtype
; /* Destination type (printer/class) */
10699 cupsd_printer_t
*printer
; /* Printer/class */
10700 ipp_attribute_t
*attr
; /* Printer attribute */
10701 int changed
= 0; /* Was anything changed? */
10704 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10705 con
->http
.fd
, uri
->values
[0].string
.text
);
10708 * Is the destination valid?
10711 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10717 send_ipp_status(con
, IPP_NOT_FOUND
,
10718 _("The printer or class was not found."));
10726 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10728 send_http_error(con
, status
, printer
);
10733 * Return a list of attributes that can be set via Set-Printer-Attributes.
10736 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10737 IPP_TAG_TEXT
)) != NULL
)
10739 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10743 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10744 IPP_TAG_TEXT
)) != NULL
)
10746 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10751 * Update the printer attributes and return...
10756 cupsdSetPrinterAttrs(printer
);
10757 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10759 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10760 "Printer \"%s\" description or location changed by \"%s\".",
10761 printer
->name
, get_username(con
));
10763 cupsdLogMessage(CUPSD_LOG_INFO
,
10764 "Printer \"%s\" description or location changed by \"%s\".",
10765 printer
->name
, get_username(con
));
10768 con
->response
->request
.status
.status_code
= IPP_OK
;
10773 * 'set_printer_defaults()' - Set printer default options from a request.
10777 set_printer_defaults(
10778 cupsd_client_t
*con
, /* I - Client connection */
10779 cupsd_printer_t
*printer
) /* I - Printer */
10781 int i
; /* Looping var */
10782 ipp_attribute_t
*attr
; /* Current attribute */
10783 int namelen
; /* Length of attribute name */
10784 char name
[256], /* New attribute name */
10785 value
[256]; /* String version of integer attrs */
10788 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10791 * Skip non-printer attributes...
10794 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10797 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10799 if (!strcmp(attr
->name
, "job-sheets-default"))
10802 * Only allow keywords and names...
10805 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10809 * Only allow job-sheets-default to be set when running without a
10810 * system high classification level...
10813 if (Classification
)
10816 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10818 if (attr
->num_values
> 1)
10819 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10821 cupsdSetString(&printer
->job_sheets
[1], "none");
10823 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10825 cupsdFreePrinterUsers(printer
);
10827 printer
->deny_users
= 0;
10829 if (attr
->value_tag
== IPP_TAG_NAME
&&
10830 (attr
->num_values
> 1 ||
10831 strcmp(attr
->values
[0].string
.text
, "all")))
10833 for (i
= 0; i
< attr
->num_values
; i
++)
10834 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10837 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10839 cupsdFreePrinterUsers(printer
);
10841 printer
->deny_users
= 1;
10843 if (attr
->value_tag
== IPP_TAG_NAME
&&
10844 (attr
->num_values
> 1 ||
10845 strcmp(attr
->values
[0].string
.text
, "none")))
10847 for (i
= 0; i
< attr
->num_values
; i
++)
10848 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10851 else if (!strcmp(attr
->name
, "job-quota-period"))
10853 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10856 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10857 attr
->values
[0].integer
);
10858 cupsdFreeQuotas(printer
);
10860 printer
->quota_period
= attr
->values
[0].integer
;
10862 else if (!strcmp(attr
->name
, "job-k-limit"))
10864 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10867 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10868 attr
->values
[0].integer
);
10869 cupsdFreeQuotas(printer
);
10871 printer
->k_limit
= attr
->values
[0].integer
;
10873 else if (!strcmp(attr
->name
, "job-page-limit"))
10875 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10878 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10879 attr
->values
[0].integer
);
10880 cupsdFreeQuotas(printer
);
10882 printer
->page_limit
= attr
->values
[0].integer
;
10884 else if (!strcmp(attr
->name
, "printer-op-policy"))
10886 cupsd_policy_t
*p
; /* Policy */
10889 if (attr
->value_tag
!= IPP_TAG_NAME
)
10892 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10894 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10895 "Setting printer-op-policy to \"%s\"...",
10896 attr
->values
[0].string
.text
);
10897 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10898 printer
->op_policy_ptr
= p
;
10902 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10903 _("Unknown printer-op-policy \"%s\"."),
10904 attr
->values
[0].string
.text
);
10908 else if (!strcmp(attr
->name
, "printer-error-policy"))
10910 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10913 if (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10914 strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10915 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10916 strcmp(attr
->values
[0].string
.text
, "stop-printer"))
10918 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10919 _("Unknown printer-error-policy \"%s\"."),
10920 attr
->values
[0].string
.text
);
10924 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10925 "Setting printer-error-policy to \"%s\"...",
10926 attr
->values
[0].string
.text
);
10927 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10931 * Skip any other non-default attributes...
10934 namelen
= strlen(attr
->name
);
10935 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10936 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10940 * OK, anything else must be a user-defined default...
10943 strlcpy(name
, attr
->name
, sizeof(name
));
10944 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10946 switch (attr
->value_tag
)
10948 case IPP_TAG_DELETEATTR
:
10949 printer
->num_options
= cupsRemoveOption(name
,
10950 printer
->num_options
,
10951 &(printer
->options
));
10952 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10953 "Deleting %s", attr
->name
);
10956 case IPP_TAG_NAME
:
10957 case IPP_TAG_KEYWORD
:
10959 printer
->num_options
= cupsAddOption(name
,
10960 attr
->values
[0].string
.text
,
10961 printer
->num_options
,
10962 &(printer
->options
));
10963 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10964 "Setting %s to \"%s\"...", attr
->name
,
10965 attr
->values
[0].string
.text
);
10968 case IPP_TAG_BOOLEAN
:
10969 printer
->num_options
= cupsAddOption(name
,
10970 attr
->values
[0].boolean
?
10972 printer
->num_options
,
10973 &(printer
->options
));
10974 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10975 "Setting %s to %s...", attr
->name
,
10976 attr
->values
[0].boolean
? "true" : "false");
10979 case IPP_TAG_INTEGER
:
10980 case IPP_TAG_ENUM
:
10981 sprintf(value
, "%d", attr
->values
[0].integer
);
10982 printer
->num_options
= cupsAddOption(name
, value
,
10983 printer
->num_options
,
10984 &(printer
->options
));
10985 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10986 "Setting %s to %s...", attr
->name
, value
);
10989 case IPP_TAG_RANGE
:
10990 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10991 attr
->values
[0].range
.upper
);
10992 printer
->num_options
= cupsAddOption(name
, value
,
10993 printer
->num_options
,
10994 &(printer
->options
));
10995 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10996 "Setting %s to %s...", attr
->name
, value
);
10999 case IPP_TAG_RESOLUTION
:
11000 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11001 attr
->values
[0].resolution
.yres
,
11002 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11004 printer
->num_options
= cupsAddOption(name
, value
,
11005 printer
->num_options
,
11006 &(printer
->options
));
11007 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11008 "Setting %s to %s...", attr
->name
, value
);
11012 /* Do nothing for other values */
11020 * 'start_printer()' - Start a printer.
11024 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11025 ipp_attribute_t
*uri
) /* I - Printer URI */
11027 http_status_t status
; /* Policy status */
11028 cups_ptype_t dtype
; /* Destination type (printer/class) */
11029 cupsd_printer_t
*printer
; /* Printer data */
11032 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11033 con
->http
.fd
, uri
->values
[0].string
.text
);
11036 * Is the destination valid?
11039 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11045 send_ipp_status(con
, IPP_NOT_FOUND
,
11046 _("The printer or class was not found."));
11054 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11056 send_http_error(con
, status
, printer
);
11061 * Start the printer...
11064 printer
->state_message
[0] = '\0';
11066 cupsdStartPrinter(printer
, 1);
11068 if (dtype
& CUPS_PRINTER_CLASS
)
11069 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11070 printer
->name
, get_username(con
));
11072 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11073 printer
->name
, get_username(con
));
11078 * Everything was ok, so return OK status...
11081 con
->response
->request
.status
.status_code
= IPP_OK
;
11086 * 'stop_printer()' - Stop a printer.
11090 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11091 ipp_attribute_t
*uri
) /* I - Printer URI */
11093 http_status_t status
; /* Policy status */
11094 cups_ptype_t dtype
; /* Destination type (printer/class) */
11095 cupsd_printer_t
*printer
; /* Printer data */
11096 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11099 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11100 con
->http
.fd
, uri
->values
[0].string
.text
);
11103 * Is the destination valid?
11106 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11112 send_ipp_status(con
, IPP_NOT_FOUND
,
11113 _("The printer or class was not found."));
11121 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11123 send_http_error(con
, status
, printer
);
11128 * Stop the printer...
11131 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11132 IPP_TAG_TEXT
)) == NULL
)
11133 strcpy(printer
->state_message
, "Paused");
11136 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11137 sizeof(printer
->state_message
));
11140 cupsdStopPrinter(printer
, 1);
11142 if (dtype
& CUPS_PRINTER_CLASS
)
11143 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11144 printer
->name
, get_username(con
));
11146 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11147 printer
->name
, get_username(con
));
11150 * Everything was ok, so return OK status...
11153 con
->response
->request
.status
.status_code
= IPP_OK
;
11158 * 'url_encode_attr()' - URL-encode a string attribute.
11162 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11163 char *buffer
,/* I - String buffer */
11164 int bufsize
)/* I - Size of buffer */
11166 int i
; /* Looping var */
11167 char *bufptr
, /* Pointer into buffer */
11168 *bufend
; /* End of buffer */
11171 strlcpy(buffer
, attr
->name
, bufsize
);
11172 bufptr
= buffer
+ strlen(buffer
);
11173 bufend
= buffer
+ bufsize
- 1;
11175 for (i
= 0; i
< attr
->num_values
; i
++)
11177 if (bufptr
>= bufend
)
11185 if (bufptr
>= bufend
)
11190 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11191 bufptr
, bufend
- bufptr
+ 1);
11193 if (bufptr
>= bufend
)
11204 * 'url_encode_string()' - URL-encode a string.
11207 static char * /* O - End of string */
11208 url_encode_string(const char *s
, /* I - String */
11209 char *buffer
, /* I - String buffer */
11210 int bufsize
) /* I - Size of buffer */
11212 char *bufptr
, /* Pointer into buffer */
11213 *bufend
; /* End of buffer */
11214 static const char *hex
= "0123456789ABCDEF";
11219 bufend
= buffer
+ bufsize
- 1;
11221 while (*s
&& bufptr
< bufend
)
11223 if (*s
== ' ' || *s
== '%')
11225 if (bufptr
>= (bufend
- 2))
11229 *bufptr
++ = hex
[(*s
>> 4) & 15];
11230 *bufptr
++ = hex
[*s
& 15];
11234 else if (*s
== '\'' || *s
== '\\')
11236 if (bufptr
>= (bufend
- 1))
11253 * 'user_allowed()' - See if a user is allowed to print to a queue.
11256 static int /* O - 0 if not allowed, 1 if allowed */
11257 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11258 const char *username
) /* I - Username */
11260 int i
; /* Looping var */
11261 struct passwd
*pw
; /* User password data */
11262 char baseuser
[256], /* Base username */
11263 *baseptr
; /* Pointer to "@" in base username */
11266 if (p
->num_users
== 0)
11269 if (!strcmp(username
, "root"))
11272 if (strchr(username
, '@'))
11275 * Strip @REALM for username check...
11278 strlcpy(baseuser
, username
, sizeof(baseuser
));
11280 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11283 username
= baseuser
;
11286 pw
= getpwnam(username
);
11289 for (i
= 0; i
< p
->num_users
; i
++)
11291 if (p
->users
[i
][0] == '@')
11294 * Check group membership...
11297 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
11300 else if (p
->users
[i
][0] == '#')
11306 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
11309 else if (!strcasecmp(username
, p
->users
[i
]))
11313 return ((i
< p
->num_users
) != p
->deny_users
);
11318 * 'validate_job()' - Validate printer options and destination.
11322 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11323 ipp_attribute_t
*uri
) /* I - Printer URI */
11325 http_status_t status
; /* Policy status */
11326 ipp_attribute_t
*attr
; /* Current attribute */
11327 ipp_attribute_t
*format
; /* Document-format attribute */
11328 cups_ptype_t dtype
; /* Destination type (printer/class) */
11329 char super
[MIME_MAX_SUPER
],
11330 /* Supertype of file */
11331 type
[MIME_MAX_TYPE
];
11332 /* Subtype of file */
11333 cupsd_printer_t
*printer
; /* Printer */
11336 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11337 con
->http
.fd
, uri
->values
[0].string
.text
);
11340 * OK, see if the client is sending the document compressed - CUPS
11341 * doesn't support compression yet...
11344 if ((attr
= ippFindAttribute(con
->request
, "compression",
11345 IPP_TAG_KEYWORD
)) != NULL
&&
11346 !strcmp(attr
->values
[0].string
.text
, "none"))
11348 send_ipp_status(con
, IPP_ATTRIBUTES
,
11349 _("Unsupported compression attribute %s!"),
11350 attr
->values
[0].string
.text
);
11351 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11352 "compression", NULL
, attr
->values
[0].string
.text
);
11357 * Is it a format we support?
11360 if ((format
= ippFindAttribute(con
->request
, "document-format",
11361 IPP_TAG_MIMETYPE
)) != NULL
)
11363 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11366 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
11367 format
->values
[0].string
.text
);
11371 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11372 !mimeType(MimeDatabase
, super
, type
))
11374 cupsdLogMessage(CUPSD_LOG_INFO
,
11375 "Hint: Do you have the raw file printing rules enabled?");
11376 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11377 _("Unsupported format \"%s\"!"),
11378 format
->values
[0].string
.text
);
11379 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11380 "document-format", NULL
, format
->values
[0].string
.text
);
11386 * Is the destination valid?
11389 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11395 send_ipp_status(con
, IPP_NOT_FOUND
,
11396 _("The printer or class was not found."));
11404 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11406 send_http_error(con
, status
, printer
);
11411 * Everything was ok, so return OK status...
11414 con
->response
->request
.status
.status_code
= IPP_OK
;
11419 * 'validate_name()' - Make sure the printer name only contains valid chars.
11422 static int /* O - 0 if name is no good, 1 if good */
11423 validate_name(const char *name
) /* I - Name to check */
11425 const char *ptr
; /* Pointer into name */
11429 * Scan the whole name...
11432 for (ptr
= name
; *ptr
; ptr
++)
11433 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11437 * All the characters are good; validate the length, too...
11440 return ((ptr
- name
) < 128);
11445 * 'validate_user()' - Validate the user for the request.
11448 static int /* O - 1 if permitted, 0 otherwise */
11449 validate_user(cupsd_job_t
*job
, /* I - Job */
11450 cupsd_client_t
*con
, /* I - Client connection */
11451 const char *owner
, /* I - Owner of job/resource */
11452 char *username
, /* O - Authenticated username */
11453 int userlen
) /* I - Length of username */
11455 cupsd_printer_t
*printer
; /* Printer for job */
11458 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11459 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11461 job
->id
, con
? con
->http
.fd
: 0,
11462 owner
? owner
: "(null)", username
, userlen
);
11465 * Validate input...
11468 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11472 * Get the best authenticated username that is available.
11475 strlcpy(username
, get_username(con
), userlen
);
11478 * Check the username against the owner...
11481 printer
= cupsdFindDest(job
->dest
);
11483 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11484 con
, owner
) == HTTP_OK
);
11489 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".