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
) + 60;
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);
2644 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2645 IPP_TAG_TEXT
)) != NULL
)
2647 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2648 sizeof(printer
->state_message
));
2649 cupsdAddPrinterHistory(printer
);
2652 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2653 IPP_TAG_KEYWORD
)) != NULL
)
2655 if (attr
->num_values
>
2656 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2658 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2659 _("Too many printer-state-reasons values (%d > %d)!"),
2661 (int)(sizeof(printer
->reasons
) /
2662 sizeof(printer
->reasons
[0])));
2666 for (i
= 0; i
< printer
->num_reasons
; i
++)
2667 _cupsStrFree(printer
->reasons
[i
]);
2669 printer
->num_reasons
= 0;
2670 for (i
= 0; i
< attr
->num_values
; i
++)
2672 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2675 printer
->reasons
[printer
->num_reasons
] =
2676 _cupsStrRetain(attr
->values
[i
].string
.text
);
2678 if (!strcmp(printer
->reasons
[printer
->num_reasons
], "paused") &&
2679 printer
->state
!= IPP_PRINTER_STOPPED
)
2681 cupsdLogMessage(CUPSD_LOG_INFO
,
2682 "Setting %s printer-state to %d (was %d.)",
2683 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2684 cupsdStopPrinter(printer
, 0);
2687 printer
->num_reasons
++;
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
,
2976 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
2978 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2979 "printer-state-reasons", p
->num_reasons
, NULL
,
2980 (const char * const *)p
->reasons
);
2985 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2986 * the specified printer or class.
2990 add_queued_job_count(
2991 cupsd_client_t
*con
, /* I - Client connection */
2992 cupsd_printer_t
*p
) /* I - Printer or class */
2994 int count
; /* Number of jobs on destination */
2997 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2998 con
, con
->http
.fd
, p
, p
->name
);
3000 count
= cupsdGetPrinterJobCount(p
->name
);
3002 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3003 "queued-job-count", count
);
3009 * 'apple_init_profile()' - Initialize a color profile.
3014 ppd_file_t
*ppd
, /* I - PPD file */
3015 cups_array_t
*languages
, /* I - Languages in the PPD file */
3016 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3017 unsigned id
, /* I - Profile ID */
3018 const char *name
, /* I - Profile name */
3019 const char *text
, /* I - Profile UI text */
3020 const char *iccfile
) /* I - ICC filename */
3022 char url
[1024]; /* URL for profile filename */
3023 CFMutableDictionaryRef dict
; /* Dictionary for name */
3024 char *language
; /* Current language */
3025 ppd_attr_t
*attr
; /* Profile attribute */
3026 CFStringRef cflang
, /* Language string */
3027 cftext
; /* Localized text */
3031 * Build the profile name dictionary...
3034 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3035 &kCFTypeDictionaryKeyCallBacks
,
3036 &kCFTypeDictionaryValueCallBacks
);
3038 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3039 kCFStringEncodingUTF8
);
3043 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
3050 * Find localized names for the color profiles...
3053 cupsArraySave(ppd
->sorted_attrs
);
3055 for (language
= (char *)cupsArrayFirst(languages
);
3057 language
= (char *)cupsArrayNext(languages
))
3061 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3063 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3066 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3068 if (attr
&& attr
->text
[0])
3070 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3071 kCFStringEncodingUTF8
);
3072 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3073 kCFStringEncodingUTF8
);
3075 if (cflang
&& cftext
)
3076 CFDictionarySetValue(dict
, cflang
, cftext
);
3086 cupsArrayRestore(ppd
->sorted_attrs
);
3090 * Fill in the profile data...
3094 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3097 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3098 profile
->profileID
= id
;
3099 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3100 profile
->profileName
= dict
;
3103 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3104 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3109 * 'apple_register_profiles()' - Register color profiles for a printer.
3113 apple_register_profiles(
3114 cupsd_printer_t
*p
) /* I - Printer */
3116 int i
; /* Looping var */
3117 char ppdfile
[1024], /* PPD filename */
3118 iccfile
[1024], /* ICC filename */
3119 selector
[PPD_MAX_NAME
];
3120 /* Profile selection string */
3121 ppd_file_t
*ppd
; /* PPD file */
3122 ppd_attr_t
*attr
, /* Profile attributes */
3123 *profileid_attr
,/* cupsProfileID attribute */
3124 *q1_attr
, /* ColorModel (or other) qualifier */
3125 *q2_attr
, /* MediaType (or other) qualifier */
3126 *q3_attr
; /* Resolution (or other) qualifier */
3127 char q_keyword
[PPD_MAX_NAME
];
3128 /* Qualifier keyword */
3129 const char *q1_choice
, /* ColorModel (or other) choice */
3130 *q2_choice
, /* MediaType (or other) choice */
3131 *q3_choice
; /* Resolution (or other) choice */
3132 const char *profile_key
; /* Profile keyword */
3133 ppd_option_t
*cm_option
; /* Color model option */
3134 ppd_choice_t
*cm_choice
; /* Color model choice */
3135 int num_profiles
; /* Number of profiles */
3136 CMError error
; /* Last error */
3137 unsigned device_id
, /* Printer device ID */
3138 profile_id
, /* Profile ID */
3139 default_profile_id
= 0;
3140 /* Default profile ID */
3141 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3142 CFStringRef printer_name
; /* Printer name string */
3143 CMDeviceScope scope
= /* Scope of the registration */
3145 kCFPreferencesAnyUser
,
3146 kCFPreferencesCurrentHost
3148 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3149 CMDeviceProfileInfo
*profile
; /* Current profile */
3150 cups_array_t
*languages
; /* Languages array */
3154 * Make sure ColorSync is available...
3157 if (CMRegisterColorDevice
== NULL
)
3161 * Try opening the PPD file for this printer...
3164 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3165 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3169 * See if we have any profiles...
3172 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3173 profile_key
= "APTiogaProfile";
3176 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3177 profile_key
= "cupsICCProfile";
3180 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3181 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3183 if (attr
->value
[0] != '/')
3184 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3187 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3189 if (access(iccfile
, 0))
3197 * If we have profiles, add them...
3200 if (num_profiles
> 0)
3202 if (profile_key
[0] == 'A')
3205 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3209 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3211 default_profile_id
= atoi(attr
->value
);
3213 q1_choice
= q2_choice
= q3_choice
= NULL
;
3218 * For CUPS PPDs, figure out the default profile selector values...
3221 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3222 attr
->value
&& attr
->value
[0])
3224 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3225 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3227 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3228 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3230 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3231 q1_choice
= q1_attr
->value
;
3235 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3236 attr
->value
&& attr
->value
[0])
3238 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3239 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3242 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3244 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3245 q2_choice
= q2_attr
->value
;
3249 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3250 attr
->value
&& attr
->value
[0])
3252 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3253 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3256 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3258 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3259 q3_choice
= q3_attr
->value
;
3265 * Build the array of profiles...
3267 * Note: This calloc actually requests slightly more memory than needed.
3270 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3272 cupsdLogMessage(CUPSD_LOG_ERROR
,
3273 "Unable to allocate memory for %d profiles!",
3279 profiles
->profileCount
= num_profiles
;
3280 languages
= _ppdGetLanguages(ppd
);
3282 for (profile
= profiles
->profiles
,
3283 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3285 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3286 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3289 * Add this profile...
3292 if (attr
->value
[0] != '/')
3293 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3296 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3298 if (access(iccfile
, 0))
3301 if (profile_key
[0] == 'c')
3303 cupsArraySave(ppd
->sorted_attrs
);
3305 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3306 attr
->spec
)) != NULL
&&
3307 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3308 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3310 profile_id
= _ppdHashName(attr
->spec
);
3312 cupsArrayRestore(ppd
->sorted_attrs
);
3315 profile_id
= atoi(attr
->spec
);
3317 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3318 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3323 * See if this is the default profile...
3326 if (!default_profile_id
)
3332 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3333 q1_choice
, q2_choice
, q3_choice
);
3334 if (!strcmp(selector
, attr
->spec
))
3335 default_profile_id
= profile_id
;
3338 if (!default_profile_id
)
3340 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3342 if (!strcmp(selector
, attr
->spec
))
3343 default_profile_id
= profile_id
;
3347 if (!default_profile_id
&& q3_choice
)
3349 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3351 if (!strcmp(selector
, attr
->spec
))
3352 default_profile_id
= profile_id
;
3355 if (!default_profile_id
)
3357 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3358 if (!strcmp(selector
, attr
->spec
))
3359 default_profile_id
= profile_id
;
3364 _ppdFreeLanguages(languages
);
3366 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3369 * Extract profiles from ColorModel option...
3372 const char *profile_name
; /* Name of generic profile */
3375 num_profiles
= cm_option
->num_choices
;
3377 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3379 cupsdLogMessage(CUPSD_LOG_ERROR
,
3380 "Unable to allocate memory for %d profiles!",
3386 profiles
->profileCount
= num_profiles
;
3388 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3389 cm_choice
= cm_option
->choices
;
3391 i
--, cm_choice
++, profile
++)
3393 if (!strcmp(cm_choice
->choice
, "Gray") ||
3394 !strcmp(cm_choice
->choice
, "Black"))
3395 profile_name
= "Gray";
3396 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3397 !strcmp(cm_choice
->choice
, "CMY"))
3398 profile_name
= "RGB";
3399 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3400 !strcmp(cm_choice
->choice
, "KCMY"))
3401 profile_name
= "CMYK";
3403 profile_name
= "DeviceN";
3405 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3406 profile_id
= _ppdHashName(selector
);
3408 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3409 cm_choice
->text
, NULL
);
3411 if (cm_choice
->marked
)
3412 default_profile_id
= profile_id
;
3418 * Use the default colorspace...
3423 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3425 cupsdLogMessage(CUPSD_LOG_ERROR
,
3426 "Unable to allocate memory for %d profiles!",
3432 profiles
->profileCount
= num_profiles
;
3434 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3435 "Gray", "Gray", NULL
);
3437 switch (ppd
->colorspace
)
3441 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3442 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3446 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3447 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3452 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3453 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3459 if (num_profiles
> 0)
3462 * Make sure we have a default profile ID...
3465 if (!default_profile_id
)
3466 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3469 * Get the device ID hash and pathelogical name dictionary.
3472 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3475 device_id
= _ppdHashName(p
->name
);
3476 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3477 &kCFTypeDictionaryKeyCallBacks
,
3478 &kCFTypeDictionaryValueCallBacks
);
3479 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3480 p
->name
, kCFStringEncodingUTF8
);
3482 if (device_name
&& printer_name
)
3484 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3487 * Register the device with ColorSync...
3490 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3491 device_name
, &scope
);
3494 * Register the profiles...
3498 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3499 default_profile_id
, profiles
);
3509 cupsdLogMessage(CUPSD_LOG_ERROR
,
3510 "Unable to register ICC color profiles for \"%s\" - %d",
3511 p
->name
, (int)error
);
3513 for (profile
= profiles
->profiles
;
3515 profile
++, num_profiles
--)
3516 CFRelease(profile
->profileName
);
3521 CFRelease(printer_name
);
3524 CFRelease(device_name
);
3532 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3537 apple_unregister_profiles(
3538 cupsd_printer_t
*p
) /* I - Printer */
3541 * Make sure ColorSync is available...
3544 if (CMUnregisterColorDevice
!= NULL
)
3545 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3547 #endif /* __APPLE__ */
3550 * 'apply_printer_defaults()' - Apply printer default options to a job.
3554 apply_printer_defaults(
3555 cupsd_printer_t
*printer
, /* I - Printer */
3556 cupsd_job_t
*job
) /* I - Job */
3558 int i
, /* Looping var */
3559 num_options
; /* Number of default options */
3560 cups_option_t
*options
, /* Default options */
3561 *option
; /* Current option */
3565 * Collect all of the default options and add the missing ones to the
3569 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3570 option
= printer
->options
;
3573 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3575 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3580 * Encode these options as attributes in the job object...
3583 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3584 cupsFreeOptions(num_options
, options
);
3589 * 'authenticate_job()' - Set job authentication info.
3593 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3594 ipp_attribute_t
*uri
) /* I - Job URI */
3596 ipp_attribute_t
*attr
, /* job-id attribute */
3597 *auth_info
; /* auth-info attribute */
3598 int jobid
; /* Job ID */
3599 cupsd_job_t
*job
; /* Current job */
3600 char scheme
[HTTP_MAX_URI
],
3601 /* Method portion of URI */
3602 username
[HTTP_MAX_URI
],
3603 /* Username portion of URI */
3605 /* Host portion of URI */
3606 resource
[HTTP_MAX_URI
];
3607 /* Resource portion of URI */
3608 int port
; /* Port portion of URI */
3611 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3612 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3615 * Start with "everything is OK" status...
3618 con
->response
->request
.status
.status_code
= IPP_OK
;
3621 * See if we have a job URI or a printer URI...
3624 if (!strcmp(uri
->name
, "printer-uri"))
3627 * Got a printer URI; see if we also have a job-id attribute...
3630 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3631 IPP_TAG_INTEGER
)) == NULL
)
3633 send_ipp_status(con
, IPP_BAD_REQUEST
,
3634 _("Got a printer-uri attribute but no job-id!"));
3638 jobid
= attr
->values
[0].integer
;
3643 * Got a job URI; parse it to get the job ID...
3646 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3647 sizeof(scheme
), username
, sizeof(username
), host
,
3648 sizeof(host
), &port
, resource
, sizeof(resource
));
3650 if (strncmp(resource
, "/jobs/", 6))
3656 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
3657 uri
->values
[0].string
.text
);
3661 jobid
= atoi(resource
+ 6);
3665 * See if the job exists...
3668 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3671 * Nope - return a "not found" error...
3674 send_ipp_status(con
, IPP_NOT_FOUND
,
3675 _("Job #%d does not exist!"), jobid
);
3680 * See if the job has been completed...
3683 if (job
->state_value
!= IPP_JOB_HELD
)
3686 * Return a "not-possible" error...
3689 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3690 _("Job #%d is not held for authentication!"),
3696 * See if we have already authenticated...
3699 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3701 if (!con
->username
[0] && !auth_info
)
3703 cupsd_printer_t
*printer
; /* Job destination */
3707 * No auth data. If we need to authenticate via Kerberos, send a
3708 * HTTP auth challenge, otherwise just return an IPP error...
3711 printer
= cupsdFindDest(job
->dest
);
3713 if (printer
&& printer
->num_auth_info_required
> 0 &&
3714 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3715 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3717 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3718 _("No authentication information provided!"));
3723 * See if the job is owned by the requesting user...
3726 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3728 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
3733 * Save the authentication information for this job...
3736 save_auth_info(con
, job
, auth_info
);
3739 * Reset the job-hold-until value to "no-hold"...
3742 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3743 IPP_TAG_KEYWORD
)) == NULL
)
3744 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3748 attr
->value_tag
= IPP_TAG_KEYWORD
;
3749 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3753 * Release the job and return...
3756 cupsdReleaseJob(job
);
3758 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3763 * 'cancel_all_jobs()' - Cancel all print jobs.
3767 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3768 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3770 http_status_t status
; /* Policy status */
3771 cups_ptype_t dtype
; /* Destination type */
3772 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3773 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3774 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3775 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3776 int port
; /* Port portion of URI */
3777 ipp_attribute_t
*attr
; /* Attribute in request */
3778 const char *username
; /* Username */
3779 int purge
; /* Purge? */
3780 cupsd_printer_t
*printer
; /* Printer */
3783 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3784 con
->http
.fd
, uri
->values
[0].string
.text
);
3787 * See if we have a printer URI...
3790 if (strcmp(uri
->name
, "printer-uri"))
3792 send_ipp_status(con
, IPP_BAD_REQUEST
,
3793 _("The printer-uri attribute is required!"));
3798 * Get the username (if any) for the jobs we want to cancel (only if
3799 * "my-jobs" is specified...
3802 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3803 IPP_TAG_BOOLEAN
)) != NULL
&&
3804 attr
->values
[0].boolean
)
3806 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3807 IPP_TAG_NAME
)) != NULL
)
3808 username
= attr
->values
[0].string
.text
;
3811 send_ipp_status(con
, IPP_BAD_REQUEST
,
3812 _("Missing requesting-user-name attribute!"));
3820 * Look for the "purge-jobs" attribute...
3823 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3824 IPP_TAG_BOOLEAN
)) != NULL
)
3825 purge
= attr
->values
[0].boolean
;
3830 * And if the destination is valid...
3833 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3839 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3840 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3841 hostname
, sizeof(hostname
), &port
,
3842 resource
, sizeof(resource
));
3844 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3845 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3847 send_ipp_status(con
, IPP_NOT_FOUND
,
3848 _("The printer or class was not found."));
3856 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3858 send_http_error(con
, status
, NULL
);
3863 * Cancel all jobs on all printers...
3866 cupsdCancelJobs(NULL
, username
, purge
);
3868 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3869 purge
? "purged" : "canceled", get_username(con
));
3877 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3880 send_http_error(con
, status
, printer
);
3885 * Cancel all of the jobs on the named printer...
3888 cupsdCancelJobs(printer
->name
, username
, purge
);
3890 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3891 printer
->name
, purge
? "purged" : "canceled",
3895 con
->response
->request
.status
.status_code
= IPP_OK
;
3900 * 'cancel_job()' - Cancel a print job.
3904 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3905 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3907 ipp_attribute_t
*attr
; /* Current attribute */
3908 int jobid
; /* Job ID */
3909 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3910 username
[HTTP_MAX_URI
], /* Username portion of URI */
3911 host
[HTTP_MAX_URI
], /* Host portion of URI */
3912 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3913 int port
; /* Port portion of URI */
3914 cupsd_job_t
*job
; /* Job information */
3915 cups_ptype_t dtype
; /* Destination type (printer/class) */
3916 cupsd_printer_t
*printer
; /* Printer data */
3917 int purge
; /* Purge the job? */
3920 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3921 con
->http
.fd
, uri
->values
[0].string
.text
);
3924 * See if we have a job URI or a printer URI...
3927 if (!strcmp(uri
->name
, "printer-uri"))
3930 * Got a printer URI; see if we also have a job-id attribute...
3933 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3934 IPP_TAG_INTEGER
)) == NULL
)
3936 send_ipp_status(con
, IPP_BAD_REQUEST
,
3937 _("Got a printer-uri attribute but no job-id!"));
3941 if ((jobid
= attr
->values
[0].integer
) == 0)
3944 * Find the current job on the specified printer...
3947 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3953 send_ipp_status(con
, IPP_NOT_FOUND
,
3954 _("The printer or class was not found."));
3959 * See if the printer is currently printing a job...
3963 jobid
= ((cupsd_job_t
*)printer
->job
)->id
;
3967 * No, see if there are any pending jobs...
3970 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3972 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3973 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3974 !strcasecmp(job
->dest
, printer
->name
))
3981 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3983 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3984 if (job
->state_value
== IPP_JOB_STOPPED
&&
3985 !strcasecmp(job
->dest
, printer
->name
))
3992 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s!"),
4003 * Got a job URI; parse it to get the job ID...
4006 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4007 sizeof(scheme
), username
, sizeof(username
), host
,
4008 sizeof(host
), &port
, resource
, sizeof(resource
));
4010 if (strncmp(resource
, "/jobs/", 6))
4016 send_ipp_status(con
, IPP_BAD_REQUEST
,
4017 _("Bad job-uri attribute \"%s\"!"),
4018 uri
->values
[0].string
.text
);
4022 jobid
= atoi(resource
+ 6);
4026 * Look for the "purge-job" attribute...
4029 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4030 IPP_TAG_BOOLEAN
)) != NULL
)
4031 purge
= attr
->values
[0].boolean
;
4036 * See if the job exists...
4039 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4042 * Nope - return a "not found" error...
4045 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
4050 * See if the job is owned by the requesting user...
4053 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4055 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
4060 * See if the job is already completed, canceled, or aborted; if so,
4061 * we can't cancel...
4064 if (job
->state_value
>= IPP_JOB_CANCELED
&& !purge
)
4066 switch (job
->state_value
)
4068 case IPP_JOB_CANCELED
:
4069 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4070 _("Job #%d is already canceled - can\'t cancel."),
4074 case IPP_JOB_ABORTED
:
4075 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4076 _("Job #%d is already aborted - can\'t cancel."),
4081 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4082 _("Job #%d is already completed - can\'t cancel."),
4091 * Cancel the job and return...
4094 cupsdCancelJob(job
, purge
, IPP_JOB_CANCELED
);
4098 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4101 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4104 con
->response
->request
.status
.status_code
= IPP_OK
;
4109 * 'cancel_subscription()' - Cancel a subscription.
4113 cancel_subscription(
4114 cupsd_client_t
*con
, /* I - Client connection */
4115 int sub_id
) /* I - Subscription ID */
4117 http_status_t status
; /* Policy status */
4118 cupsd_subscription_t
*sub
; /* Subscription */
4121 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4122 "cancel_subscription(con=%p[%d], sub_id=%d)",
4123 con
, con
->http
.fd
, sub_id
);
4126 * Is the subscription ID valid?
4129 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4132 * Bad subscription ID...
4135 send_ipp_status(con
, IPP_NOT_FOUND
,
4136 _("notify-subscription-id %d no good!"), sub_id
);
4144 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4146 con
, sub
->owner
)) != HTTP_OK
)
4148 send_http_error(con
, status
, sub
->dest
);
4153 * Cancel the subscription...
4156 cupsdDeleteSubscription(sub
, 1);
4158 con
->response
->request
.status
.status_code
= IPP_OK
;
4163 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4166 static int /* O - 1 if OK, 0 if not */
4167 check_rss_recipient(
4168 const char *recipient
) /* I - Recipient URI */
4170 cupsd_subscription_t
*sub
; /* Current subscription */
4173 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4175 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4179 * Compare the URIs up to the first ?...
4182 const char *r1
, *r2
;
4184 for (r1
= recipient
, r2
= sub
->recipient
;
4185 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4197 * 'check_quotas()' - Check quotas for a printer and user.
4200 static int /* O - 1 if OK, 0 if not */
4201 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4202 cupsd_printer_t
*p
) /* I - Printer or class */
4204 int i
; /* Looping var */
4205 char username
[33]; /* Username */
4206 cupsd_quota_t
*q
; /* Quota data */
4207 #ifdef HAVE_MBR_UID_TO_UUID
4209 * Use Apple membership APIs which require that all names represent
4210 * valid user account or group records accessible by the server.
4213 uuid_t usr_uuid
; /* UUID for job requesting user */
4214 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4215 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4216 int mbr_err
; /* Error from membership function */
4217 int is_member
; /* Is this user a member? */
4220 * Use standard POSIX APIs for checking users and groups...
4223 struct passwd
*pw
; /* User password data */
4224 #endif /* HAVE_MBR_UID_TO_UUID */
4227 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4228 con
, con
->http
.fd
, p
, p
->name
);
4231 * Figure out who is printing...
4234 strlcpy(username
, get_username(con
), sizeof(username
));
4237 * Check global active job limits for printers and users...
4240 if (MaxJobsPerPrinter
)
4243 * Check if there are too many pending jobs on this printer...
4246 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4248 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4257 * Check if there are too many pending jobs for this user...
4260 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4262 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4269 * Check against users...
4272 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4277 #ifdef HAVE_MBR_UID_TO_UUID
4279 * Get UUID for job requesting user...
4282 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4288 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4289 "check_quotas: UUID lookup failed for user \"%s\"",
4291 cupsdLogMessage(CUPSD_LOG_INFO
,
4292 "Denying user \"%s\" access to printer \"%s\" "
4293 "(unknown user)...",
4299 * Get UID and GID of requesting user...
4302 pw
= getpwnam(username
);
4304 #endif /* HAVE_MBR_UID_TO_UUID */
4306 for (i
= 0; i
< p
->num_users
; i
++)
4307 if (p
->users
[i
][0] == '@')
4310 * Check group membership...
4313 #ifdef HAVE_MBR_UID_TO_UUID
4314 if (p
->users
[i
][1] == '#')
4316 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4317 uuid_clear(grp_uuid
);
4319 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4323 * Invalid ACL entries are ignored for matching; just record a
4324 * warning in the log...
4327 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4328 "check_quotas: UUID lookup failed for ACL entry "
4329 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4330 cupsdLogMessage(CUPSD_LOG_WARN
,
4331 "Access control entry \"%s\" not a valid group name; "
4332 "entry ignored", p
->users
[i
]);
4335 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4339 * At this point, there should be no errors, but check anyways...
4342 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4343 "check_quotas: group \"%s\" membership check "
4344 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4349 * Stop if we found a match...
4356 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4358 #endif /* HAVE_MBR_UID_TO_UUID */
4360 #ifdef HAVE_MBR_UID_TO_UUID
4363 if (p
->users
[i
][0] == '#')
4365 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4366 uuid_clear(usr2_uuid
);
4368 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4372 * Invalid ACL entries are ignored for matching; just record a
4373 * warning in the log...
4376 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4377 "check_quotas: UUID lookup failed for ACL entry "
4378 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4379 cupsdLogMessage(CUPSD_LOG_WARN
,
4380 "Access control entry \"%s\" not a valid user name; "
4381 "entry ignored", p
->users
[i
]);
4384 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4388 else if (!strcasecmp(username
, p
->users
[i
]))
4390 #endif /* HAVE_MBR_UID_TO_UUID */
4392 if ((i
< p
->num_users
) == p
->deny_users
)
4394 cupsdLogMessage(CUPSD_LOG_INFO
,
4395 "Denying user \"%s\" access to printer \"%s\"...",
4406 if (AppleQuotas
&& (q
= cupsdFindQuota(p
, username
)) != NULL
)
4409 * TODO: Define these special page count values as constants!
4412 if (q
->page_count
== -4) /* special case: unlimited user */
4414 cupsdLogMessage(CUPSD_LOG_INFO
,
4415 "User \"%s\" request approved for printer %s (%s): "
4417 username
, p
->name
, p
->info
);
4418 q
->page_count
= 0; /* allow user to print */
4421 else if (q
->page_count
== -3) /* quota exceeded */
4423 cupsdLogMessage(CUPSD_LOG_INFO
,
4424 "User \"%s\" request denied for printer %s (%s): "
4425 "quota limit exceeded.",
4426 username
, p
->name
, p
->info
);
4427 q
->page_count
= 2; /* force quota exceeded failure */
4430 else if (q
->page_count
== -2) /* quota disabled for user */
4432 cupsdLogMessage(CUPSD_LOG_INFO
,
4433 "User \"%s\" request denied for printer %s (%s): "
4434 "printing disabled for user.",
4435 username
, p
->name
, p
->info
);
4436 q
->page_count
= 2; /* force quota exceeded failure */
4439 else if (q
->page_count
== -1) /* quota access error */
4441 cupsdLogMessage(CUPSD_LOG_INFO
,
4442 "User \"%s\" request denied for printer %s (%s): "
4443 "unable to determine quota limit.",
4444 username
, p
->name
, p
->info
);
4445 q
->page_count
= 2; /* force quota exceeded failure */
4448 else if (q
->page_count
< 0) /* user not found or other error */
4450 cupsdLogMessage(CUPSD_LOG_INFO
,
4451 "User \"%s\" request denied for printer %s (%s): "
4452 "user disabled / missing quota.",
4453 username
, p
->name
, p
->info
);
4454 q
->page_count
= 2; /* force quota exceeded failure */
4457 else /* page within user limits */
4459 q
->page_count
= 0; /* allow user to print */
4464 #endif /* __APPLE__ */
4465 if (p
->k_limit
|| p
->page_limit
)
4467 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4469 cupsdLogMessage(CUPSD_LOG_ERROR
,
4470 "Unable to allocate quota data for user \"%s\"!",
4475 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4476 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4478 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4485 * If we have gotten this far, we're done!
4493 * 'copy_attribute()' - Copy a single attribute.
4496 static ipp_attribute_t
* /* O - New attribute */
4498 ipp_t
*to
, /* O - Destination request/response */
4499 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4500 int quickcopy
) /* I - Do a quick copy? */
4502 int i
; /* Looping var */
4503 ipp_attribute_t
*toattr
; /* Destination attribute */
4506 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4507 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4508 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4511 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4514 toattr
= ippAddSeparator(to
);
4517 case IPP_TAG_INTEGER
:
4519 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4520 attr
->name
, attr
->num_values
, NULL
);
4522 for (i
= 0; i
< attr
->num_values
; i
++)
4523 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4526 case IPP_TAG_BOOLEAN
:
4527 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4528 attr
->num_values
, NULL
);
4530 for (i
= 0; i
< attr
->num_values
; i
++)
4531 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4534 case IPP_TAG_STRING
:
4537 case IPP_TAG_KEYWORD
:
4539 case IPP_TAG_URISCHEME
:
4540 case IPP_TAG_CHARSET
:
4541 case IPP_TAG_LANGUAGE
:
4542 case IPP_TAG_MIMETYPE
:
4543 toattr
= ippAddStrings(to
, attr
->group_tag
,
4544 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4545 attr
->name
, attr
->num_values
, NULL
, NULL
);
4549 for (i
= 0; i
< attr
->num_values
; i
++)
4550 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4552 else if (attr
->value_tag
& IPP_TAG_COPY
)
4554 for (i
= 0; i
< attr
->num_values
; i
++)
4555 toattr
->values
[i
].string
.text
=
4556 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4560 for (i
= 0; i
< attr
->num_values
; i
++)
4561 toattr
->values
[i
].string
.text
=
4562 _cupsStrRetain(attr
->values
[i
].string
.text
);
4567 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4568 attr
->values
[0].date
);
4571 case IPP_TAG_RESOLUTION
:
4572 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4573 attr
->num_values
, IPP_RES_PER_INCH
,
4576 for (i
= 0; i
< attr
->num_values
; i
++)
4578 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4579 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4580 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4584 case IPP_TAG_RANGE
:
4585 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4586 attr
->num_values
, NULL
, NULL
);
4588 for (i
= 0; i
< attr
->num_values
; i
++)
4590 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4591 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4595 case IPP_TAG_TEXTLANG
:
4596 case IPP_TAG_NAMELANG
:
4597 toattr
= ippAddStrings(to
, attr
->group_tag
,
4598 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4599 attr
->name
, attr
->num_values
, NULL
, NULL
);
4603 for (i
= 0; i
< attr
->num_values
; i
++)
4605 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4606 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4609 else if (attr
->value_tag
& IPP_TAG_COPY
)
4611 for (i
= 0; i
< attr
->num_values
; i
++)
4614 toattr
->values
[i
].string
.charset
=
4615 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4617 toattr
->values
[i
].string
.charset
=
4618 toattr
->values
[0].string
.charset
;
4620 toattr
->values
[i
].string
.text
=
4621 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4626 for (i
= 0; i
< attr
->num_values
; i
++)
4629 toattr
->values
[i
].string
.charset
=
4630 _cupsStrRetain(attr
->values
[i
].string
.charset
);
4632 toattr
->values
[i
].string
.charset
=
4633 toattr
->values
[0].string
.charset
;
4635 toattr
->values
[i
].string
.text
=
4636 _cupsStrRetain(attr
->values
[i
].string
.text
);
4641 case IPP_TAG_BEGIN_COLLECTION
:
4642 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4643 attr
->num_values
, NULL
);
4645 for (i
= 0; i
< attr
->num_values
; i
++)
4647 toattr
->values
[i
].collection
= ippNew();
4648 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
4649 NULL
, IPP_TAG_ZERO
, 0);
4654 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4655 attr
->name
, attr
->num_values
, NULL
);
4657 for (i
= 0; i
< attr
->num_values
; i
++)
4659 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4661 if (toattr
->values
[i
].unknown
.length
> 0)
4663 if ((toattr
->values
[i
].unknown
.data
=
4664 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4665 toattr
->values
[i
].unknown
.length
= 0;
4667 memcpy(toattr
->values
[i
].unknown
.data
,
4668 attr
->values
[i
].unknown
.data
,
4669 toattr
->values
[i
].unknown
.length
);
4672 break; /* anti-compiler-warning-code */
4680 * 'copy_attrs()' - Copy attributes from one request to another.
4684 copy_attrs(ipp_t
*to
, /* I - Destination request */
4685 ipp_t
*from
, /* I - Source request */
4686 cups_array_t
*ra
, /* I - Requested attributes */
4687 ipp_tag_t group
, /* I - Group to copy */
4688 int quickcopy
) /* I - Do a quick copy? */
4690 ipp_attribute_t
*fromattr
; /* Source attribute */
4693 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4694 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4695 to
, from
, ra
, group
, quickcopy
);
4700 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4703 * Filter attributes as needed...
4706 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4707 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4710 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4713 * Don't send collection attributes by default to IPP/1.x clients
4714 * since many do not support collections...
4717 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4718 !ra
&& to
->request
.status
.version
[0] == 1)
4721 copy_attribute(to
, fromattr
, quickcopy
);
4728 * 'copy_banner()' - Copy a banner file to the requests directory for the
4732 static int /* O - Size of banner file in kbytes */
4733 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4734 cupsd_job_t
*job
, /* I - Job information */
4735 const char *name
) /* I - Name of banner */
4737 int i
; /* Looping var */
4738 int kbytes
; /* Size of banner file in kbytes */
4739 char filename
[1024]; /* Job filename */
4740 cupsd_banner_t
*banner
; /* Pointer to banner */
4741 cups_file_t
*in
; /* Input file */
4742 cups_file_t
*out
; /* Output file */
4743 int ch
; /* Character from file */
4744 char attrname
[255], /* Name of attribute */
4745 *s
; /* Pointer into name */
4746 ipp_attribute_t
*attr
; /* Attribute */
4749 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4750 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4751 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4752 name
? name
: "(null)");
4755 * Find the banner; return if not found or "none"...
4758 if (!name
|| !strcmp(name
, "none") ||
4759 (banner
= cupsdFindBanner(name
)) == NULL
)
4763 * Open the banner and job files...
4766 if (add_file(con
, job
, banner
->filetype
, 0))
4769 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4771 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4773 cupsdLogMessage(CUPSD_LOG_ERROR
,
4774 "Unable to create banner job file %s - %s",
4775 filename
, strerror(errno
));
4780 fchmod(cupsFileNumber(out
), 0640);
4781 fchown(cupsFileNumber(out
), RunUser
, Group
);
4784 * Try the localized banner file under the subdirectory...
4787 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4789 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4792 * Convert ll-cc to ll_CC...
4796 attrname
[3] = toupper(attrname
[3] & 255);
4797 attrname
[4] = toupper(attrname
[4] & 255);
4800 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4803 if (access(filename
, 0) && strlen(attrname
) > 2)
4806 * Wasn't able to find "ll_CC" locale file; try the non-national
4807 * localization banner directory.
4812 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4816 if (access(filename
, 0))
4819 * Use the non-localized banner file.
4822 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4825 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4829 cupsdLogMessage(CUPSD_LOG_ERROR
,
4830 "Unable to open banner template file %s - %s",
4831 filename
, strerror(errno
));
4837 * Parse the file to the end...
4840 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4844 * Get an attribute name...
4847 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4848 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4850 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4860 * Ignore { followed by stuff that is not an attribute name...
4863 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4868 * See if it is defined...
4871 if (attrname
[0] == '?')
4876 if (!strcmp(s
, "printer-name"))
4878 cupsFilePuts(out
, job
->dest
);
4881 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4884 * See if we have a leading question mark...
4887 if (attrname
[0] != '?')
4890 * Nope, write to file as-is; probably a PostScript procedure...
4893 cupsFilePrintf(out
, "{%s}", attrname
);
4900 * Output value(s)...
4903 for (i
= 0; i
< attr
->num_values
; i
++)
4906 cupsFilePutChar(out
, ',');
4908 switch (attr
->value_tag
)
4910 case IPP_TAG_INTEGER
:
4912 if (!strncmp(s
, "time-at-", 8))
4913 cupsFilePuts(out
, cupsdGetDateTime(attr
->values
[i
].integer
));
4915 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4918 case IPP_TAG_BOOLEAN
:
4919 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4922 case IPP_TAG_NOVALUE
:
4923 cupsFilePuts(out
, "novalue");
4926 case IPP_TAG_RANGE
:
4927 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4928 attr
->values
[i
].range
.upper
);
4931 case IPP_TAG_RESOLUTION
:
4932 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4933 attr
->values
[i
].resolution
.yres
,
4934 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4939 case IPP_TAG_STRING
:
4942 case IPP_TAG_KEYWORD
:
4943 case IPP_TAG_CHARSET
:
4944 case IPP_TAG_LANGUAGE
:
4945 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
4948 * Need to quote strings for PS banners...
4953 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4955 if (*p
== '(' || *p
== ')' || *p
== '\\')
4957 cupsFilePutChar(out
, '\\');
4958 cupsFilePutChar(out
, *p
);
4960 else if (*p
< 32 || *p
> 126)
4961 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4963 cupsFilePutChar(out
, *p
);
4967 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4971 break; /* anti-compiler-warning-code */
4975 else if (ch
== '\\') /* Quoted char */
4977 ch
= cupsFileGetChar(in
);
4979 if (ch
!= '{') /* Only do special handling for \{ */
4980 cupsFilePutChar(out
, '\\');
4982 cupsFilePutChar(out
, ch
);
4985 cupsFilePutChar(out
, ch
);
4989 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4991 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4992 IPP_TAG_INTEGER
)) != NULL
)
4993 attr
->values
[0].integer
+= kbytes
;
5002 * 'copy_file()' - Copy a PPD file or interface script...
5005 static int /* O - 0 = success, -1 = error */
5006 copy_file(const char *from
, /* I - Source file */
5007 const char *to
) /* I - Destination file */
5009 cups_file_t
*src
, /* Source file */
5010 *dst
; /* Destination file */
5011 int bytes
; /* Bytes to read/write */
5012 char buffer
[2048]; /* Copy buffer */
5015 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5018 * Open the source and destination file for a copy...
5021 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5024 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5031 * Copy the source file to the destination...
5034 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5035 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5043 * Close both files and return...
5048 return (cupsFileClose(dst
));
5053 * 'copy_model()' - Copy a PPD model file, substituting default values
5057 static int /* O - 0 = success, -1 = error */
5058 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5059 const char *from
, /* I - Source file */
5060 const char *to
) /* I - Destination file */
5062 fd_set input
; /* select() input set */
5063 struct timeval timeout
; /* select() timeout */
5064 int maxfd
; /* Max file descriptor for select() */
5065 char tempfile
[1024]; /* Temporary PPD file */
5066 int tempfd
; /* Temporary PPD file descriptor */
5067 int temppid
; /* Process ID of cups-driverd */
5068 int temppipe
[2]; /* Temporary pipes */
5069 char *argv
[4], /* Command-line arguments */
5070 *envp
[MAX_ENV
]; /* Environment */
5071 cups_file_t
*src
, /* Source file */
5072 *dst
; /* Destination file */
5073 ppd_file_t
*ppd
; /* PPD file */
5074 int bytes
, /* Bytes from pipe */
5075 total
; /* Total bytes from pipe */
5076 char buffer
[2048]; /* Copy buffer */
5077 int i
; /* Looping var */
5078 char option
[PPD_MAX_NAME
], /* Option name */
5079 choice
[PPD_MAX_NAME
]; /* Choice name */
5080 int num_defaults
; /* Number of default options */
5081 cups_option_t
*defaults
; /* Default options */
5082 char cups_protocol
[PPD_MAX_LINE
];
5083 /* cupsProtocol attribute */
5086 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5087 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5091 * Run cups-driverd to get the PPD file...
5094 argv
[0] = "cups-driverd";
5096 argv
[2] = (char *)from
;
5099 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5101 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5102 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5103 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5107 cupsdOpenPipe(temppipe
);
5109 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5110 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5112 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5113 -1, -1, 0, DefaultProfile
, &temppid
))
5124 * Wait up to 30 seconds for the PPD file to be copied...
5129 if (temppipe
[0] > CGIPipes
[0])
5130 maxfd
= temppipe
[0] + 1;
5132 maxfd
= CGIPipes
[0] + 1;
5137 * See if we have data ready...
5141 FD_SET(temppipe
[0], &input
);
5142 FD_SET(CGIPipes
[0], &input
);
5144 timeout
.tv_sec
= 30;
5145 timeout
.tv_usec
= 0;
5147 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5157 * We have timed out...
5163 if (FD_ISSET(temppipe
[0], &input
))
5166 * Read the PPD file from the pipe, and write it to the PPD file.
5169 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5171 if (write(tempfd
, buffer
, bytes
) < bytes
)
5180 if (FD_ISSET(CGIPipes
[0], &input
))
5190 * No data from cups-deviced...
5193 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
5199 * Read the source file and see what page sizes are supported...
5202 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5209 * Open the destination (if possible) and set the default options...
5214 cups_protocol
[0] = '\0';
5216 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5219 * Read all of the default lines from the old PPD...
5222 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5223 if (!strncmp(buffer
, "*Default", 8))
5226 * Add the default option...
5229 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5230 choice
, sizeof(choice
)))
5232 ppd_option_t
*ppdo
; /* PPD option */
5236 * Only add the default if the default hasn't already been
5237 * set and the choice exists in the new PPD...
5240 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5241 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5242 ppdFindChoice(ppdo
, choice
))
5243 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5247 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5248 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5252 else if (ppdPageSize(ppd
, DefaultPaperSize
))
5255 * Add the default media sizes...
5258 num_defaults
= cupsAddOption("PageSize", DefaultPaperSize
,
5259 num_defaults
, &defaults
);
5260 num_defaults
= cupsAddOption("PageRegion", DefaultPaperSize
,
5261 num_defaults
, &defaults
);
5262 num_defaults
= cupsAddOption("PaperDimension", DefaultPaperSize
,
5263 num_defaults
, &defaults
);
5264 num_defaults
= cupsAddOption("ImageableArea", DefaultPaperSize
,
5265 num_defaults
, &defaults
);
5271 * Open the source file for a copy...
5274 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5276 cupsFreeOptions(num_defaults
, defaults
);
5282 * Open the destination file for a copy...
5285 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5287 cupsFreeOptions(num_defaults
, defaults
);
5294 * Copy the source file to the destination...
5297 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5299 if (!strncmp(buffer
, "*Default", 8))
5302 * Check for an previous default option choice...
5305 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5306 choice
, sizeof(choice
)))
5308 const char *val
; /* Default option value */
5311 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5314 * Substitute the previous choice...
5317 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5322 cupsFilePrintf(dst
, "%s\n", buffer
);
5325 if (cups_protocol
[0])
5326 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5328 cupsFreeOptions(num_defaults
, defaults
);
5331 * Close both files and return...
5338 return (cupsFileClose(dst
));
5343 * 'copy_job_attrs()' - Copy job attributes.
5347 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5348 cupsd_job_t
*job
, /* I - Job */
5349 cups_array_t
*ra
) /* I - Requested attributes array */
5351 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5355 * Send the requested attributes for each job...
5358 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5359 con
->servername
, con
->serverport
, "/jobs/%d",
5362 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5363 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5364 "document-count", job
->num_files
);
5366 if (!ra
|| cupsArrayFind(ra
, "job-media-progress"))
5367 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5368 "job-media-progress", job
->progress
);
5370 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5371 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5372 "job-more-info", NULL
, job_uri
);
5374 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5375 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5376 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5377 job
->num_files
> 0);
5379 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5380 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5381 "job-printer-up-time", time(NULL
));
5383 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5384 add_job_state_reasons(con
, job
);
5386 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5387 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5388 "job-uri", NULL
, job_uri
);
5390 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5395 * 'copy_printer_attrs()' - Copy printer attributes.
5400 cupsd_client_t
*con
, /* I - Client connection */
5401 cupsd_printer_t
*printer
, /* I - Printer */
5402 cups_array_t
*ra
) /* I - Requested attributes array */
5404 char printer_uri
[HTTP_MAX_URI
];
5406 time_t curtime
; /* Current time */
5407 int i
; /* Looping var */
5408 ipp_attribute_t
*history
; /* History collection */
5412 * Copy the printer attributes to the response using requested-attributes
5413 * and document-format attributes that may be provided by the client.
5416 curtime
= time(NULL
);
5419 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
5420 printer
->recoverable
)
5421 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5422 "com.apple.print.recoverable-message", NULL
,
5423 printer
->recoverable
);
5424 #endif /* __APPLE__ */
5426 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5427 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5428 "marker-change-time", printer
->marker_time
);
5430 if (printer
->num_printers
> 0 &&
5431 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5433 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5434 cupsd_printer_t
*p2
; /* Printer in class */
5435 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5438 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5439 IPP_TAG_URI
, "member-uris",
5440 printer
->num_printers
, NULL
,
5443 for (i
= 0; i
< printer
->num_printers
; i
++)
5445 p2
= printer
->printers
[i
];
5447 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5448 IPP_TAG_URI
)) != NULL
)
5449 member_uris
->values
[i
].string
.text
=
5450 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5453 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5454 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5456 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5457 "/classes/%s" : "/printers/%s", p2
->name
);
5458 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5464 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5465 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5466 "printer-alert", NULL
, printer
->alert
);
5468 if (printer
->alert_description
&&
5469 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5470 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5471 "printer-alert-description", NULL
,
5472 printer
->alert_description
);
5474 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5475 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5476 ippTimeToDate(curtime
));
5479 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5481 if (printer
->reg_name
)
5482 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5483 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5485 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5486 "printer-dns-sd-name", 0);
5488 #endif /* HAVE_DNSSD */
5490 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5491 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5492 "printer-error-policy", NULL
, printer
->error_policy
);
5494 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5495 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5496 printer
->accepting
);
5498 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5499 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5502 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5503 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5505 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5506 "http", NULL
, con
->servername
, con
->serverport
,
5507 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5508 "/classes/%s" : "/printers/%s", printer
->name
);
5509 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5510 "printer-more-info", NULL
, printer_uri
);
5513 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5514 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5515 "printer-op-policy", NULL
, printer
->op_policy
);
5517 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5518 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5521 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5522 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5523 "printer-state-change-time", printer
->state_time
);
5525 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5526 cupsArrayFind(ra
, "printer-state-history"))
5529 * Printer history is only sent if specifically requested, so that
5530 * older CUPS/IPP clients won't barf on the collection attributes.
5533 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5534 "printer-state-history",
5535 printer
->num_history
, NULL
);
5537 for (i
= 0; i
< printer
->num_history
; i
++)
5538 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5539 NULL
, IPP_TAG_ZERO
, 0);
5542 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5543 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5544 "printer-state-message", NULL
, printer
->state_message
);
5546 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5547 add_printer_state_reasons(con
, printer
);
5549 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5551 int type
; /* printer-type value */
5555 * Add the CUPS-specific printer-type attribute...
5558 type
= printer
->type
;
5560 if (printer
== DefaultPrinter
)
5561 type
|= CUPS_PRINTER_DEFAULT
;
5563 if (!printer
->accepting
)
5564 type
|= CUPS_PRINTER_REJECTING
;
5566 if (!printer
->shared
)
5567 type
|= CUPS_PRINTER_NOT_SHARED
;
5569 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5573 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5574 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5575 "printer-up-time", curtime
);
5577 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5578 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5580 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5581 "ipp", NULL
, con
->servername
, con
->serverport
,
5582 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5583 "/classes/%s" : "/printers/%s", printer
->name
);
5584 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5585 "printer-uri-supported", NULL
, printer_uri
);
5586 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5590 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5591 add_queued_job_count(con
, printer
);
5593 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5594 if (printer
->ppd_attrs
)
5595 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0);
5596 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5601 * 'copy_subscription_attrs()' - Copy subscription attributes.
5605 copy_subscription_attrs(
5606 cupsd_client_t
*con
, /* I - Client connection */
5607 cupsd_subscription_t
*sub
, /* I - Subscription */
5608 cups_array_t
*ra
) /* I - Requested attributes array */
5610 ipp_attribute_t
*attr
; /* Current attribute */
5611 char printer_uri
[HTTP_MAX_URI
];
5613 int count
; /* Number of events */
5614 unsigned mask
; /* Current event mask */
5615 const char *name
; /* Current event name */
5619 * Copy the subscription attributes to the response using the
5620 * requested-attributes attribute that may be provided by the client.
5623 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5625 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5628 * Simple event list...
5631 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5632 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5633 "notify-events", NULL
, name
);
5638 * Complex event list...
5641 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5642 if (sub
->mask
& mask
)
5645 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5646 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5647 "notify-events", count
, NULL
, NULL
);
5649 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5650 if (sub
->mask
& mask
)
5652 attr
->values
[count
].string
.text
=
5653 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5660 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5661 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5662 "notify-job-id", sub
->job
->id
);
5664 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5665 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5666 "notify-lease-duration", sub
->lease
);
5668 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5670 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5671 "ipp", NULL
, con
->servername
, con
->serverport
,
5672 "/printers/%s", sub
->dest
->name
);
5673 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5674 "notify-printer-uri", NULL
, printer_uri
);
5677 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5678 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5679 "notify-recipient-uri", NULL
, sub
->recipient
);
5680 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5681 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5682 "notify-pull-method", NULL
, "ippget");
5684 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5685 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5686 "notify-subscriber-user-name", NULL
, sub
->owner
);
5688 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5689 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5690 "notify-subscription-id", sub
->id
);
5692 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5693 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5694 "notify-time-interval", sub
->interval
);
5696 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5697 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5698 sub
->user_data
, sub
->user_data_len
);
5703 * 'create_job()' - Print a file to a printer or class.
5707 create_job(cupsd_client_t
*con
, /* I - Client connection */
5708 ipp_attribute_t
*uri
) /* I - Printer URI */
5710 cupsd_printer_t
*printer
; /* Printer */
5711 cupsd_job_t
*job
; /* New job */
5714 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5715 con
->http
.fd
, uri
->values
[0].string
.text
);
5718 * Is the destination valid?
5721 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5727 send_ipp_status(con
, IPP_NOT_FOUND
,
5728 _("The printer or class was not found."));
5733 * Create the job object...
5736 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5739 job
->pending_timeout
= 1;
5742 * Save and log the job...
5745 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5746 job
->dest
, job
->username
);
5751 * 'create_requested_array()' - Create an array for the requested-attributes.
5754 static cups_array_t
* /* O - Array of attributes or NULL */
5755 create_requested_array(ipp_t
*request
) /* I - IPP request */
5757 int i
; /* Looping var */
5758 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5759 cups_array_t
*ra
; /* Requested attributes array */
5760 char *value
; /* Current value */
5764 * Get the requested-attributes attribute, and return NULL if we don't
5768 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5769 IPP_TAG_KEYWORD
)) == NULL
)
5773 * If the attribute contains a single "all" keyword, return NULL...
5776 if (requested
->num_values
== 1 &&
5777 !strcmp(requested
->values
[0].string
.text
, "all"))
5781 * Create an array using "strcmp" as the comparison function...
5784 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5786 for (i
= 0; i
< requested
->num_values
; i
++)
5788 value
= requested
->values
[i
].string
.text
;
5790 if (!strcmp(value
, "job-template"))
5792 cupsArrayAdd(ra
, "copies");
5793 cupsArrayAdd(ra
, "copies-default");
5794 cupsArrayAdd(ra
, "copies-supported");
5795 cupsArrayAdd(ra
, "finishings");
5796 cupsArrayAdd(ra
, "finishings-default");
5797 cupsArrayAdd(ra
, "finishings-supported");
5798 cupsArrayAdd(ra
, "job-hold-until");
5799 cupsArrayAdd(ra
, "job-hold-until-default");
5800 cupsArrayAdd(ra
, "job-hold-until-supported");
5801 cupsArrayAdd(ra
, "job-priority");
5802 cupsArrayAdd(ra
, "job-priority-default");
5803 cupsArrayAdd(ra
, "job-priority-supported");
5804 cupsArrayAdd(ra
, "job-sheets");
5805 cupsArrayAdd(ra
, "job-sheets-default");
5806 cupsArrayAdd(ra
, "job-sheets-supported");
5807 cupsArrayAdd(ra
, "media");
5808 cupsArrayAdd(ra
, "media-default");
5809 cupsArrayAdd(ra
, "media-supported");
5810 cupsArrayAdd(ra
, "multiple-document-handling");
5811 cupsArrayAdd(ra
, "multiple-document-handling-default");
5812 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5813 cupsArrayAdd(ra
, "number-up");
5814 cupsArrayAdd(ra
, "number-up-default");
5815 cupsArrayAdd(ra
, "number-up-supported");
5816 cupsArrayAdd(ra
, "orientation-requested");
5817 cupsArrayAdd(ra
, "orientation-requested-default");
5818 cupsArrayAdd(ra
, "orientation-requested-supported");
5819 cupsArrayAdd(ra
, "page-ranges");
5820 cupsArrayAdd(ra
, "page-ranges-supported");
5821 cupsArrayAdd(ra
, "printer-resolution");
5822 cupsArrayAdd(ra
, "printer-resolution-default");
5823 cupsArrayAdd(ra
, "printer-resolution-supported");
5824 cupsArrayAdd(ra
, "print-quality");
5825 cupsArrayAdd(ra
, "print-quality-default");
5826 cupsArrayAdd(ra
, "print-quality-supported");
5827 cupsArrayAdd(ra
, "sides");
5828 cupsArrayAdd(ra
, "sides-default");
5829 cupsArrayAdd(ra
, "sides-supported");
5831 else if (!strcmp(value
, "job-description"))
5833 cupsArrayAdd(ra
, "date-time-at-completed");
5834 cupsArrayAdd(ra
, "date-time-at-creation");
5835 cupsArrayAdd(ra
, "date-time-at-processing");
5836 cupsArrayAdd(ra
, "job-detailed-status-message");
5837 cupsArrayAdd(ra
, "job-document-access-errors");
5838 cupsArrayAdd(ra
, "job-id");
5839 cupsArrayAdd(ra
, "job-impressions");
5840 cupsArrayAdd(ra
, "job-impressions-completed");
5841 cupsArrayAdd(ra
, "job-k-octets");
5842 cupsArrayAdd(ra
, "job-k-octets-processed");
5843 cupsArrayAdd(ra
, "job-media-progress");
5844 cupsArrayAdd(ra
, "job-media-sheets");
5845 cupsArrayAdd(ra
, "job-media-sheets-completed");
5846 cupsArrayAdd(ra
, "job-message-from-operator");
5847 cupsArrayAdd(ra
, "job-more-info");
5848 cupsArrayAdd(ra
, "job-name");
5849 cupsArrayAdd(ra
, "job-originating-user-name");
5850 cupsArrayAdd(ra
, "job-printer-up-time");
5851 cupsArrayAdd(ra
, "job-printer-uri");
5852 cupsArrayAdd(ra
, "job-state");
5853 cupsArrayAdd(ra
, "job-state-message");
5854 cupsArrayAdd(ra
, "job-state-reasons");
5855 cupsArrayAdd(ra
, "job-uri");
5856 cupsArrayAdd(ra
, "number-of-documents");
5857 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5858 cupsArrayAdd(ra
, "output-device-assigned");
5859 cupsArrayAdd(ra
, "time-at-completed");
5860 cupsArrayAdd(ra
, "time-at-creation");
5861 cupsArrayAdd(ra
, "time-at-processing");
5863 else if (!strcmp(value
, "printer-description"))
5865 cupsArrayAdd(ra
, "charset-configured");
5866 cupsArrayAdd(ra
, "charset-supported");
5867 cupsArrayAdd(ra
, "color-supported");
5868 cupsArrayAdd(ra
, "compression-supported");
5869 cupsArrayAdd(ra
, "document-format-default");
5870 cupsArrayAdd(ra
, "document-format-supported");
5871 cupsArrayAdd(ra
, "generated-natural-language-supported");
5872 cupsArrayAdd(ra
, "ipp-versions-supported");
5873 cupsArrayAdd(ra
, "job-impressions-supported");
5874 cupsArrayAdd(ra
, "job-k-octets-supported");
5875 cupsArrayAdd(ra
, "job-media-sheets-supported");
5876 cupsArrayAdd(ra
, "job-settable-attributes-supported");
5877 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5878 cupsArrayAdd(ra
, "multiple-operation-time-out");
5879 cupsArrayAdd(ra
, "natural-language-configured");
5880 cupsArrayAdd(ra
, "notify-attributes-supported");
5881 cupsArrayAdd(ra
, "notify-lease-duration-default");
5882 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5883 cupsArrayAdd(ra
, "notify-max-events-supported");
5884 cupsArrayAdd(ra
, "notify-events-default");
5885 cupsArrayAdd(ra
, "notify-events-supported");
5886 cupsArrayAdd(ra
, "notify-pull-method-supported");
5887 cupsArrayAdd(ra
, "notify-schemes-supported");
5888 cupsArrayAdd(ra
, "operations-supported");
5889 cupsArrayAdd(ra
, "pages-per-minute");
5890 cupsArrayAdd(ra
, "pages-per-minute-color");
5891 cupsArrayAdd(ra
, "pdl-override-supported");
5892 cupsArrayAdd(ra
, "printer-alert");
5893 cupsArrayAdd(ra
, "printer-alert-description");
5894 cupsArrayAdd(ra
, "printer-commands");
5895 cupsArrayAdd(ra
, "printer-current-time");
5896 cupsArrayAdd(ra
, "printer-driver-installer");
5897 cupsArrayAdd(ra
, "printer-dns-sd-name");
5898 cupsArrayAdd(ra
, "printer-info");
5899 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5900 cupsArrayAdd(ra
, "printer-location");
5901 cupsArrayAdd(ra
, "printer-make-and-model");
5902 cupsArrayAdd(ra
, "printer-message-from-operator");
5903 cupsArrayAdd(ra
, "printer-more-info");
5904 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5905 cupsArrayAdd(ra
, "printer-name");
5906 cupsArrayAdd(ra
, "printer-state");
5907 cupsArrayAdd(ra
, "printer-state-message");
5908 cupsArrayAdd(ra
, "printer-state-reasons");
5909 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
5910 cupsArrayAdd(ra
, "printer-type");
5911 cupsArrayAdd(ra
, "printer-up-time");
5912 cupsArrayAdd(ra
, "printer-uri-supported");
5913 cupsArrayAdd(ra
, "queued-job-count");
5914 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5915 cupsArrayAdd(ra
, "uri-authentication-supported");
5916 cupsArrayAdd(ra
, "uri-security-supported");
5918 else if (!strcmp(value
, "printer-defaults"))
5920 char *name
; /* Option name */
5923 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5925 name
= (char *)cupsArrayNext(CommonDefaults
))
5926 cupsArrayAdd(ra
, name
);
5928 else if (!strcmp(value
, "subscription-template"))
5930 cupsArrayAdd(ra
, "notify-attributes");
5931 cupsArrayAdd(ra
, "notify-charset");
5932 cupsArrayAdd(ra
, "notify-events");
5933 cupsArrayAdd(ra
, "notify-lease-duration");
5934 cupsArrayAdd(ra
, "notify-natural-language");
5935 cupsArrayAdd(ra
, "notify-pull-method");
5936 cupsArrayAdd(ra
, "notify-recipient-uri");
5937 cupsArrayAdd(ra
, "notify-time-interval");
5938 cupsArrayAdd(ra
, "notify-user-data");
5941 cupsArrayAdd(ra
, value
);
5949 * 'create_subscription()' - Create a notification subscription.
5953 create_subscription(
5954 cupsd_client_t
*con
, /* I - Client connection */
5955 ipp_attribute_t
*uri
) /* I - Printer URI */
5957 http_status_t status
; /* Policy status */
5958 int i
; /* Looping var */
5959 ipp_attribute_t
*attr
; /* Current attribute */
5960 cups_ptype_t dtype
; /* Destination type (printer/class) */
5961 char scheme
[HTTP_MAX_URI
],
5962 /* Scheme portion of URI */
5963 userpass
[HTTP_MAX_URI
],
5964 /* Username portion of URI */
5966 /* Host portion of URI */
5967 resource
[HTTP_MAX_URI
];
5968 /* Resource portion of URI */
5969 int port
; /* Port portion of URI */
5970 cupsd_printer_t
*printer
; /* Printer/class */
5971 cupsd_job_t
*job
; /* Job */
5972 int jobid
; /* Job ID */
5973 cupsd_subscription_t
*sub
; /* Subscription object */
5974 const char *username
, /* requesting-user-name or
5975 authenticated username */
5976 *recipient
, /* notify-recipient-uri */
5977 *pullmethod
; /* notify-pull-method */
5978 ipp_attribute_t
*user_data
; /* notify-user-data */
5979 int interval
, /* notify-time-interval */
5980 lease
; /* notify-lease-duration */
5981 unsigned mask
; /* notify-events */
5982 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5983 *notify_lease
; /* notify-lease-duration(-default) */
5987 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5989 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5990 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5991 attr
->value_tag
, attr
->name
);
5993 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5998 * Is the destination valid?
6001 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6002 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6003 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6005 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6006 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6007 sizeof(host
), &port
, resource
, sizeof(resource
));
6009 if (!strcmp(resource
, "/"))
6011 dtype
= (cups_ptype_t
)0;
6014 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6016 dtype
= (cups_ptype_t
)0;
6019 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6021 dtype
= CUPS_PRINTER_CLASS
;
6024 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6030 send_ipp_status(con
, IPP_NOT_FOUND
,
6031 _("The printer or class was not found."));
6041 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6044 send_http_error(con
, status
, printer
);
6048 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6050 send_http_error(con
, status
, NULL
);
6055 * Get the user that is requesting the subscription...
6058 username
= get_username(con
);
6061 * Find the first subscription group attribute; return if we have
6065 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6066 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6071 send_ipp_status(con
, IPP_BAD_REQUEST
,
6072 _("No subscription attributes in request!"));
6077 * Process the subscription attributes in the request...
6080 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6088 lease
= DefaultLeaseDuration
;
6090 mask
= CUPSD_EVENT_NONE
;
6094 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6096 notify_lease
= ippFindAttribute(printer
->attrs
,
6097 "notify-lease-duration-default",
6101 lease
= notify_lease
->values
[0].integer
;
6105 notify_events
= NULL
;
6106 notify_lease
= NULL
;
6109 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6111 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6112 attr
->value_tag
== IPP_TAG_URI
)
6115 * Validate the recipient scheme against the ServerBin/notifier
6119 char notifier
[1024]; /* Notifier filename */
6122 recipient
= attr
->values
[0].string
.text
;
6124 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6125 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6126 host
, sizeof(host
), &port
,
6127 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6129 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6130 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
6131 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6132 "notify-status-code", IPP_URI_SCHEME
);
6136 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6138 if (access(notifier
, X_OK
))
6140 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6141 _("notify-recipient-uri URI \"%s\" uses unknown "
6142 "scheme!"), recipient
);
6143 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6144 "notify-status-code", IPP_URI_SCHEME
);
6148 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6150 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6151 _("notify-recipient-uri URI \"%s\" is already used!"),
6153 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6154 "notify-status-code", IPP_ATTRIBUTES
);
6158 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6159 attr
->value_tag
== IPP_TAG_KEYWORD
)
6161 pullmethod
= attr
->values
[0].string
.text
;
6163 if (strcmp(pullmethod
, "ippget"))
6165 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6166 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
6167 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6168 "notify-status-code", IPP_ATTRIBUTES
);
6172 else if (!strcmp(attr
->name
, "notify-charset") &&
6173 attr
->value_tag
== IPP_TAG_CHARSET
&&
6174 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6175 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6177 send_ipp_status(con
, IPP_CHARSET
,
6178 _("Character set \"%s\" not supported!"),
6179 attr
->values
[0].string
.text
);
6182 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6183 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6184 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6186 send_ipp_status(con
, IPP_CHARSET
,
6187 _("Language \"%s\" not supported!"),
6188 attr
->values
[0].string
.text
);
6191 else if (!strcmp(attr
->name
, "notify-user-data") &&
6192 attr
->value_tag
== IPP_TAG_STRING
)
6194 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6196 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6197 _("The notify-user-data value is too large "
6198 "(%d > 63 octets)!"),
6199 attr
->values
[0].unknown
.length
);
6205 else if (!strcmp(attr
->name
, "notify-events") &&
6206 attr
->value_tag
== IPP_TAG_KEYWORD
)
6207 notify_events
= attr
;
6208 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6209 attr
->value_tag
== IPP_TAG_INTEGER
)
6210 lease
= attr
->values
[0].integer
;
6211 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6212 attr
->value_tag
== IPP_TAG_INTEGER
)
6213 interval
= attr
->values
[0].integer
;
6214 else if (!strcmp(attr
->name
, "notify-job-id") &&
6215 attr
->value_tag
== IPP_TAG_INTEGER
)
6216 jobid
= attr
->values
[0].integer
;
6223 for (i
= 0; i
< notify_events
->num_values
; i
++)
6224 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6228 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6230 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6231 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6232 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6234 if (!recipient
&& !pullmethod
)
6237 if (mask
== CUPSD_EVENT_NONE
)
6240 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6242 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6245 send_ipp_status(con
, IPP_BAD_REQUEST
,
6246 _("notify-events not specified!"));
6251 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6253 cupsdLogMessage(CUPSD_LOG_INFO
,
6254 "create_subscription: Limiting notify-lease-duration to "
6257 lease
= MaxLeaseDuration
;
6262 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6264 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
6271 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6273 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6274 _("There are too many subscriptions."));
6279 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6282 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6283 "Added subscription %d for printer \"%s\"",
6284 sub
->id
, printer
->name
);
6286 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6289 sub
->interval
= interval
;
6291 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6293 cupsdSetString(&sub
->owner
, username
);
6297 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6298 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6299 sub
->user_data_len
);
6302 ippAddSeparator(con
->response
);
6303 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6304 "notify-subscription-id", sub
->id
);
6306 con
->response
->request
.status
.status_code
= IPP_OK
;
6312 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6317 * 'delete_printer()' - Remove a printer or class from the system.
6321 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6322 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6324 http_status_t status
; /* Policy status */
6325 cups_ptype_t dtype
; /* Destination type (printer/class) */
6326 cupsd_printer_t
*printer
; /* Printer/class */
6327 char filename
[1024]; /* Script/PPD filename */
6330 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6331 con
->http
.fd
, uri
->values
[0].string
.text
);
6334 * Do we have a valid URI?
6337 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6343 send_ipp_status(con
, IPP_NOT_FOUND
,
6344 _("The printer or class was not found."));
6352 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6354 send_http_error(con
, status
, NULL
);
6359 * Remove old jobs...
6362 cupsdCancelJobs(printer
->name
, NULL
, 1);
6365 * Remove old subscriptions and send a "deleted printer" event...
6368 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6369 "%s \"%s\" deleted by \"%s\".",
6370 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6371 printer
->name
, get_username(con
));
6373 cupsdExpireSubscriptions(printer
, NULL
);
6376 * Remove any old PPD or script files...
6379 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6383 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6387 snprintf(filename
, sizeof(filename
), "%s/%s.ipp", CacheDir
, printer
->name
);
6392 * Unregister color profiles...
6395 apple_unregister_profiles(printer
);
6396 #endif /* __APPLE__ */
6398 if (dtype
& CUPS_PRINTER_CLASS
)
6400 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6401 printer
->name
, get_username(con
));
6403 cupsdDeletePrinter(printer
, 0);
6404 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6408 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6409 printer
->name
, get_username(con
));
6411 cupsdDeletePrinter(printer
, 0);
6412 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6415 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6418 * Return with no errors...
6421 con
->response
->request
.status
.status_code
= IPP_OK
;
6426 * 'get_default()' - Get the default destination.
6430 get_default(cupsd_client_t
*con
) /* I - Client connection */
6432 http_status_t status
; /* Policy status */
6433 cups_array_t
*ra
; /* Requested attributes array */
6436 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6442 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6444 send_http_error(con
, status
, NULL
);
6450 ra
= create_requested_array(con
->request
);
6452 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6454 cupsArrayDelete(ra
);
6456 con
->response
->request
.status
.status_code
= IPP_OK
;
6459 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6464 * 'get_devices()' - Get the list of available devices on the local system.
6468 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6470 http_status_t status
; /* Policy status */
6471 ipp_attribute_t
*limit
, /* limit attribute */
6472 *timeout
, /* timeout attribute */
6473 *requested
, /* requested-attributes attribute */
6474 *exclude
, /* exclude-schemes attribute */
6475 *include
; /* include-schemes attribute */
6476 char command
[1024], /* cups-deviced command */
6477 options
[2048], /* Options to pass to command */
6479 /* String for requested attributes */
6481 /* String for excluded schemes */
6483 /* String for included schemes */
6486 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6492 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6494 send_http_error(con
, status
, NULL
);
6499 * Run cups-deviced command with the given options...
6502 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6503 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6504 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6506 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6507 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6510 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6512 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6515 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6517 exclude_str
[0] = '\0';
6520 url_encode_attr(include
, include_str
, sizeof(include_str
));
6522 include_str
[0] = '\0';
6524 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6525 snprintf(options
, sizeof(options
),
6526 "%d+%d+%d+%d+%s%s%s%s%s",
6527 con
->request
->request
.op
.request_id
,
6528 limit
? limit
->values
[0].integer
: 0,
6529 timeout
? timeout
->values
[0].integer
: 10,
6532 exclude_str
[0] ? "%20" : "", exclude_str
,
6533 include_str
[0] ? "%20" : "", include_str
);
6535 if (cupsdSendCommand(con
, command
, options
, 1))
6538 * Command started successfully, don't send an IPP response here...
6541 ippDelete(con
->response
);
6542 con
->response
= NULL
;
6547 * Command failed, return "internal error" so the user knows something
6551 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6552 _("cups-deviced failed to execute."));
6558 * 'get_document()' - Get a copy of a job file.
6562 get_document(cupsd_client_t
*con
, /* I - Client connection */
6563 ipp_attribute_t
*uri
) /* I - Job URI */
6565 http_status_t status
; /* Policy status */
6566 ipp_attribute_t
*attr
; /* Current attribute */
6567 int jobid
; /* Job ID */
6568 int docnum
; /* Document number */
6569 cupsd_job_t
*job
; /* Current job */
6570 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6571 username
[HTTP_MAX_URI
], /* Username portion of URI */
6572 host
[HTTP_MAX_URI
], /* Host portion of URI */
6573 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6574 int port
; /* Port portion of URI */
6575 char filename
[1024], /* Filename for document */
6576 format
[1024]; /* Format for document */
6579 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6580 con
->http
.fd
, uri
->values
[0].string
.text
);
6583 * See if we have a job URI or a printer URI...
6586 if (!strcmp(uri
->name
, "printer-uri"))
6589 * Got a printer URI; see if we also have a job-id attribute...
6592 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6593 IPP_TAG_INTEGER
)) == NULL
)
6595 send_ipp_status(con
, IPP_BAD_REQUEST
,
6596 _("Got a printer-uri attribute but no job-id!"));
6600 jobid
= attr
->values
[0].integer
;
6605 * Got a job URI; parse it to get the job ID...
6608 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6609 sizeof(scheme
), username
, sizeof(username
), host
,
6610 sizeof(host
), &port
, resource
, sizeof(resource
));
6612 if (strncmp(resource
, "/jobs/", 6))
6618 send_ipp_status(con
, IPP_BAD_REQUEST
,
6619 _("Bad job-uri attribute \"%s\"!"),
6620 uri
->values
[0].string
.text
);
6624 jobid
= atoi(resource
+ 6);
6628 * See if the job exists...
6631 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6634 * Nope - return a "not found" error...
6637 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6645 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6647 send_http_error(con
, status
, NULL
);
6652 * Get the document number...
6655 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6656 IPP_TAG_INTEGER
)) == NULL
)
6658 send_ipp_status(con
, IPP_BAD_REQUEST
,
6659 _("Missing document-number attribute!"));
6663 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6664 attr
->num_values
> 1)
6666 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6671 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6673 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6675 cupsdLogMessage(CUPSD_LOG_ERROR
,
6676 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6678 send_ipp_status(con
, IPP_NOT_FOUND
,
6679 _("Unable to open document %d in job %d!"), docnum
, jobid
);
6683 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6687 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6688 job
->filetypes
[docnum
- 1]->type
);
6690 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6692 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6694 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6695 IPP_TAG_NAME
)) != NULL
)
6696 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6697 NULL
, attr
->values
[0].string
.text
);
6702 * 'get_job_attrs()' - Get job attributes.
6706 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6707 ipp_attribute_t
*uri
) /* I - Job URI */
6709 http_status_t status
; /* Policy status */
6710 ipp_attribute_t
*attr
; /* Current attribute */
6711 int jobid
; /* Job ID */
6712 cupsd_job_t
*job
; /* Current job */
6713 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6714 username
[HTTP_MAX_URI
], /* Username portion of URI */
6715 host
[HTTP_MAX_URI
], /* Host portion of URI */
6716 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6717 int port
; /* Port portion of URI */
6718 cups_array_t
*ra
; /* Requested attributes array */
6721 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6722 con
->http
.fd
, uri
->values
[0].string
.text
);
6725 * See if we have a job URI or a printer URI...
6728 if (!strcmp(uri
->name
, "printer-uri"))
6731 * Got a printer URI; see if we also have a job-id attribute...
6734 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6735 IPP_TAG_INTEGER
)) == NULL
)
6737 send_ipp_status(con
, IPP_BAD_REQUEST
,
6738 _("Got a printer-uri attribute but no job-id!"));
6742 jobid
= attr
->values
[0].integer
;
6747 * Got a job URI; parse it to get the job ID...
6750 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6751 sizeof(scheme
), username
, sizeof(username
), host
,
6752 sizeof(host
), &port
, resource
, sizeof(resource
));
6754 if (strncmp(resource
, "/jobs/", 6))
6760 send_ipp_status(con
, IPP_BAD_REQUEST
,
6761 _("Bad job-uri attribute \"%s\"!"),
6762 uri
->values
[0].string
.text
);
6766 jobid
= atoi(resource
+ 6);
6770 * See if the job exists...
6773 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6776 * Nope - return a "not found" error...
6779 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6787 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6789 send_http_error(con
, status
, NULL
);
6794 * Copy attributes...
6799 ra
= create_requested_array(con
->request
);
6800 copy_job_attrs(con
, job
, ra
);
6801 cupsArrayDelete(ra
);
6803 con
->response
->request
.status
.status_code
= IPP_OK
;
6808 * 'get_jobs()' - Get a list of jobs for the specified printer.
6812 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6813 ipp_attribute_t
*uri
) /* I - Printer URI */
6815 http_status_t status
; /* Policy status */
6816 ipp_attribute_t
*attr
; /* Current attribute */
6817 const char *dest
; /* Destination */
6818 cups_ptype_t dtype
; /* Destination type (printer/class) */
6819 cups_ptype_t dmask
; /* Destination type mask */
6820 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6821 username
[HTTP_MAX_URI
], /* Username portion of URI */
6822 host
[HTTP_MAX_URI
], /* Host portion of URI */
6823 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6824 int port
; /* Port portion of URI */
6825 int completed
; /* Completed jobs? */
6826 int first_job_id
; /* First job ID */
6827 int limit
; /* Maximum number of jobs to return */
6828 int count
; /* Number of jobs that match */
6829 cupsd_job_t
*job
; /* Current job pointer */
6830 cupsd_printer_t
*printer
; /* Printer */
6831 cups_array_t
*list
; /* Which job list... */
6832 cups_array_t
*ra
; /* Requested attributes array */
6835 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6836 uri
->values
[0].string
.text
);
6839 * Is the destination valid?
6842 if (strcmp(uri
->name
, "printer-uri"))
6844 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request!"));
6848 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6849 sizeof(scheme
), username
, sizeof(username
), host
,
6850 sizeof(host
), &port
, resource
, sizeof(resource
));
6852 if (!strcmp(resource
, "/"))
6855 dtype
= (cups_ptype_t
)0;
6856 dmask
= (cups_ptype_t
)0;
6859 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6862 dtype
= (cups_ptype_t
)0;
6863 dmask
= CUPS_PRINTER_CLASS
;
6866 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6869 dtype
= CUPS_PRINTER_CLASS
;
6870 dmask
= CUPS_PRINTER_CLASS
;
6873 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6880 send_ipp_status(con
, IPP_NOT_FOUND
,
6881 _("The printer or class was not found."));
6886 dtype
&= CUPS_PRINTER_CLASS
;
6887 dmask
= CUPS_PRINTER_CLASS
;
6896 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6899 send_http_error(con
, status
, printer
);
6903 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6905 send_http_error(con
, status
, NULL
);
6910 * See if the "which-jobs" attribute have been specified...
6913 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6914 IPP_TAG_KEYWORD
)) != NULL
&&
6915 !strcmp(attr
->values
[0].string
.text
, "completed"))
6920 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
6925 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "processing"))
6928 list
= PrintingJobs
;
6937 * See if they want to limit the number of jobs reported...
6940 if ((attr
= ippFindAttribute(con
->request
, "limit",
6941 IPP_TAG_INTEGER
)) != NULL
)
6942 limit
= attr
->values
[0].integer
;
6946 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6947 IPP_TAG_INTEGER
)) != NULL
)
6948 first_job_id
= attr
->values
[0].integer
;
6953 * See if we only want to see jobs for a specific user...
6956 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6957 IPP_TAG_BOOLEAN
)) != NULL
&&
6958 attr
->values
[0].boolean
)
6959 strlcpy(username
, get_username(con
), sizeof(username
));
6963 ra
= create_requested_array(con
->request
);
6966 * OK, build a list of jobs for this printer...
6969 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6970 (limit
<= 0 || count
< limit
) && job
;
6971 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6974 * Filter out jobs that don't match...
6977 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6978 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6979 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6980 job
->username
, job
->state_value
, job
->attrs
);
6982 if (!job
->dest
|| !job
->username
)
6985 if (!job
->dest
|| !job
->username
)
6988 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6989 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6991 if ((job
->dtype
& dmask
) != dtype
&&
6992 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6994 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
6997 if (job
->id
< first_job_id
)
7004 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d!",
7009 if (username
[0] && strcasecmp(username
, job
->username
))
7013 ippAddSeparator(con
->response
);
7017 copy_job_attrs(con
, job
, ra
);
7020 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7022 cupsArrayDelete(ra
);
7024 con
->response
->request
.status
.status_code
= IPP_OK
;
7029 * 'get_notifications()' - Get events for a subscription.
7033 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7035 int i
, j
; /* Looping vars */
7036 http_status_t status
; /* Policy status */
7037 cupsd_subscription_t
*sub
; /* Subscription */
7038 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7039 *sequences
; /* notify-sequence-numbers */
7040 int min_seq
; /* Minimum sequence number */
7041 int interval
; /* Poll interval */
7044 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7048 * Get subscription attributes...
7051 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7053 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7058 send_ipp_status(con
, IPP_BAD_REQUEST
,
7059 _("Missing notify-subscription-ids attribute!"));
7064 * Are the subscription IDs valid?
7067 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7069 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7072 * Bad subscription ID...
7075 send_ipp_status(con
, IPP_NOT_FOUND
,
7076 _("notify-subscription-id %d no good!"),
7077 ids
->values
[i
].integer
);
7085 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7087 con
, sub
->owner
)) != HTTP_OK
)
7089 send_http_error(con
, status
, sub
->dest
);
7094 * Check the subscription type and update the interval accordingly.
7097 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7100 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7102 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7108 * Tell the client to poll again in N seconds...
7112 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7113 "notify-get-interval", interval
);
7115 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7116 "printer-up-time", time(NULL
));
7119 * Copy the subscription event attributes to the response.
7122 con
->response
->request
.status
.status_code
=
7123 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7125 for (i
= 0; i
< ids
->num_values
; i
++)
7128 * Get the subscription and sequence number...
7131 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7133 if (sequences
&& i
< sequences
->num_values
)
7134 min_seq
= sequences
->values
[i
].integer
;
7139 * If we don't have any new events, nothing to do here...
7142 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7146 * Otherwise copy all of the new events...
7149 if (sub
->first_event_id
> min_seq
)
7152 j
= min_seq
- sub
->first_event_id
;
7154 for (; j
< sub
->num_events
; j
++)
7156 ippAddSeparator(con
->response
);
7158 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7159 IPP_TAG_EVENT_NOTIFICATION
, 0);
7166 * 'get_ppd()' - Get a named PPD from the local system.
7170 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7171 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7173 http_status_t status
; /* Policy status */
7174 cupsd_printer_t
*dest
; /* Destination */
7175 cups_ptype_t dtype
; /* Destination type */
7178 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7179 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7181 if (!strcmp(uri
->name
, "ppd-name"))
7184 * Return a PPD file from cups-driverd...
7187 char command
[1024], /* cups-driverd command */
7188 options
[1024], /* Options to pass to command */
7189 ppd_name
[1024]; /* ppd-name */
7196 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7198 send_http_error(con
, status
, NULL
);
7203 * Run cups-driverd command with the given options...
7206 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7207 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7208 snprintf(options
, sizeof(options
), "get+%d+%s",
7209 con
->request
->request
.op
.request_id
, ppd_name
);
7211 if (cupsdSendCommand(con
, command
, options
, 0))
7214 * Command started successfully, don't send an IPP response here...
7217 ippDelete(con
->response
);
7218 con
->response
= NULL
;
7223 * Command failed, return "internal error" so the user knows something
7227 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7228 _("cups-driverd failed to execute."));
7231 else if (!strcmp(uri
->name
, "printer-uri") &&
7232 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7234 int i
; /* Looping var */
7235 char filename
[1024]; /* PPD filename */
7242 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7244 send_http_error(con
, status
, dest
);
7249 * See if we need the PPD for a class or remote printer...
7252 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7255 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7257 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7258 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7259 "printer-uri", NULL
, dest
->uri
);
7262 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7264 for (i
= 0; i
< dest
->num_printers
; i
++)
7265 if (!(dest
->printers
[i
]->type
&
7266 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7268 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7269 dest
->printers
[i
]->name
);
7271 if (!access(filename
, 0))
7275 if (i
< dest
->num_printers
)
7276 dest
= dest
->printers
[i
];
7279 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7280 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7281 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7287 * Found the printer with the PPD file, now see if there is one...
7290 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7292 send_ipp_status(con
, IPP_NOT_FOUND
,
7293 _("The PPD file \"%s\" could not be opened: %s"),
7294 uri
->values
[0].string
.text
, strerror(errno
));
7298 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7302 con
->response
->request
.status
.status_code
= IPP_OK
;
7305 send_ipp_status(con
, IPP_NOT_FOUND
,
7306 _("The PPD file \"%s\" could not be found."),
7307 uri
->values
[0].string
.text
);
7312 * 'get_ppds()' - Get the list of PPD files on the local system.
7316 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7318 http_status_t status
; /* Policy status */
7319 ipp_attribute_t
*limit
, /* Limit attribute */
7320 *device
, /* ppd-device-id attribute */
7321 *language
, /* ppd-natural-language attribute */
7322 *make
, /* ppd-make attribute */
7323 *model
, /* ppd-make-and-model attribute */
7324 *model_number
, /* ppd-model-number attribute */
7325 *product
, /* ppd-product attribute */
7326 *psversion
, /* ppd-psverion attribute */
7327 *type
, /* ppd-type attribute */
7328 *requested
, /* requested-attributes attribute */
7329 *exclude
, /* exclude-schemes attribute */
7330 *include
; /* include-schemes attribute */
7331 char command
[1024], /* cups-driverd command */
7332 options
[4096], /* Options to pass to command */
7333 device_str
[256],/* Escaped ppd-device-id string */
7335 /* Escaped ppd-natural-language */
7336 make_str
[256], /* Escaped ppd-make string */
7337 model_str
[256], /* Escaped ppd-make-and-model string */
7338 model_number_str
[256],
7339 /* ppd-model-number string */
7341 /* Escaped ppd-product string */
7343 /* Escaped ppd-psversion string */
7344 type_str
[256], /* Escaped ppd-type string */
7346 /* String for requested attributes */
7348 /* String for excluded schemes */
7350 /* String for included schemes */
7353 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7359 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7361 send_http_error(con
, status
, NULL
);
7366 * Run cups-driverd command with the given options...
7369 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7370 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7371 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7373 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7374 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7376 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7378 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7379 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7380 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7381 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7383 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7385 include
= ippFindAttribute(con
->request
, "include-schemes",
7389 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7391 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7394 url_encode_attr(device
, device_str
, sizeof(device_str
));
7396 device_str
[0] = '\0';
7399 url_encode_attr(language
, language_str
, sizeof(language_str
));
7401 language_str
[0] = '\0';
7404 url_encode_attr(make
, make_str
, sizeof(make_str
));
7409 url_encode_attr(model
, model_str
, sizeof(model_str
));
7411 model_str
[0] = '\0';
7414 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7415 model_number
->values
[0].integer
);
7417 model_number_str
[0] = '\0';
7420 url_encode_attr(product
, product_str
, sizeof(product_str
));
7422 product_str
[0] = '\0';
7425 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7427 psversion_str
[0] = '\0';
7430 url_encode_attr(type
, type_str
, sizeof(type_str
));
7435 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7437 exclude_str
[0] = '\0';
7440 url_encode_attr(include
, include_str
, sizeof(include_str
));
7442 include_str
[0] = '\0';
7444 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7445 snprintf(options
, sizeof(options
),
7446 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7447 con
->request
->request
.op
.request_id
,
7448 limit
? limit
->values
[0].integer
: 0,
7450 device
? "%20" : "", device_str
,
7451 language
? "%20" : "", language_str
,
7452 make
? "%20" : "", make_str
,
7453 model
? "%20" : "", model_str
,
7454 model_number
? "%20" : "", model_number_str
,
7455 product
? "%20" : "", product_str
,
7456 psversion
? "%20" : "", psversion_str
,
7457 type
? "%20" : "", type_str
,
7458 exclude_str
[0] ? "%20" : "", exclude_str
,
7459 include_str
[0] ? "%20" : "", include_str
);
7461 if (cupsdSendCommand(con
, command
, options
, 0))
7464 * Command started successfully, don't send an IPP response here...
7467 ippDelete(con
->response
);
7468 con
->response
= NULL
;
7473 * Command failed, return "internal error" so the user knows something
7477 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7478 _("cups-driverd failed to execute."));
7484 * 'get_printer_attrs()' - Get printer attributes.
7488 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7489 ipp_attribute_t
*uri
) /* I - Printer URI */
7491 http_status_t status
; /* Policy status */
7492 cups_ptype_t dtype
; /* Destination type (printer/class) */
7493 cupsd_printer_t
*printer
; /* Printer/class */
7494 cups_array_t
*ra
; /* Requested attributes array */
7497 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7498 con
->http
.fd
, uri
->values
[0].string
.text
);
7501 * Is the destination valid?
7504 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7510 send_ipp_status(con
, IPP_NOT_FOUND
,
7511 _("The printer or class was not found."));
7519 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7521 send_http_error(con
, status
, printer
);
7526 * Send the attributes...
7529 ra
= create_requested_array(con
->request
);
7531 copy_printer_attrs(con
, printer
, ra
);
7533 cupsArrayDelete(ra
);
7535 con
->response
->request
.status
.status_code
= IPP_OK
;
7540 * 'get_printer_supported()' - Get printer supported values.
7544 get_printer_supported(
7545 cupsd_client_t
*con
, /* I - Client connection */
7546 ipp_attribute_t
*uri
) /* I - Printer URI */
7548 http_status_t status
; /* Policy status */
7549 cups_ptype_t dtype
; /* Destination type (printer/class) */
7550 cupsd_printer_t
*printer
; /* Printer/class */
7553 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7554 con
->http
.fd
, uri
->values
[0].string
.text
);
7557 * Is the destination valid?
7560 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7566 send_ipp_status(con
, IPP_NOT_FOUND
,
7567 _("The printer or class was not found."));
7575 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7577 send_http_error(con
, status
, printer
);
7582 * Return a list of attributes that can be set via Set-Printer-Attributes.
7585 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7587 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7588 "printer-location", 0);
7590 con
->response
->request
.status
.status_code
= IPP_OK
;
7595 * 'get_printers()' - Get a list of printers or classes.
7599 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7600 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7602 http_status_t status
; /* Policy status */
7603 ipp_attribute_t
*attr
; /* Current attribute */
7604 int limit
; /* Max number of printers to return */
7605 int count
; /* Number of printers that match */
7606 cupsd_printer_t
*printer
; /* Current printer pointer */
7607 int printer_type
, /* printer-type attribute */
7608 printer_mask
; /* printer-type-mask attribute */
7609 char *location
; /* Location string */
7610 const char *username
; /* Current user */
7611 char *first_printer_name
; /* first-printer-name attribute */
7612 cups_array_t
*ra
; /* Requested attributes array */
7615 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7616 con
->http
.fd
, type
);
7622 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7624 send_http_error(con
, status
, NULL
);
7629 * Check for printers...
7632 if (!Printers
|| !cupsArrayCount(Printers
))
7634 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7639 * See if they want to limit the number of printers reported...
7642 if ((attr
= ippFindAttribute(con
->request
, "limit",
7643 IPP_TAG_INTEGER
)) != NULL
)
7644 limit
= attr
->values
[0].integer
;
7648 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7649 IPP_TAG_NAME
)) != NULL
)
7650 first_printer_name
= attr
->values
[0].string
.text
;
7652 first_printer_name
= NULL
;
7655 * Support filtering...
7658 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7659 IPP_TAG_ENUM
)) != NULL
)
7660 printer_type
= attr
->values
[0].integer
;
7664 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7665 IPP_TAG_ENUM
)) != NULL
)
7666 printer_mask
= attr
->values
[0].integer
;
7670 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7671 IPP_TAG_TEXT
)) != NULL
)
7672 location
= attr
->values
[0].string
.text
;
7676 if (con
->username
[0])
7677 username
= con
->username
;
7678 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7679 IPP_TAG_NAME
)) != NULL
)
7680 username
= attr
->values
[0].string
.text
;
7684 ra
= create_requested_array(con
->request
);
7687 * OK, build a list of printers for this printer...
7690 if (first_printer_name
)
7692 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7693 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7696 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7699 count
< limit
&& printer
;
7700 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7702 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7703 (printer
->type
& printer_mask
) == printer_type
&&
7705 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
7708 * If HideImplicitMembers is enabled, see if this printer or class
7709 * is a member of an implicit class...
7712 if (ImplicitClasses
&& HideImplicitMembers
&&
7713 printer
->in_implicit_class
)
7717 * If a username is specified, see if it is allowed or denied
7721 if (!(printer
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
7722 printer
->num_users
&& username
&& !user_allowed(printer
, username
))
7726 * Add the group separator as needed...
7730 ippAddSeparator(con
->response
);
7735 * Send the attributes...
7738 copy_printer_attrs(con
, printer
, ra
);
7742 cupsArrayDelete(ra
);
7744 con
->response
->request
.status
.status_code
= IPP_OK
;
7749 * 'get_subscription_attrs()' - Get subscription attributes.
7753 get_subscription_attrs(
7754 cupsd_client_t
*con
, /* I - Client connection */
7755 int sub_id
) /* I - Subscription ID */
7757 http_status_t status
; /* Policy status */
7758 cupsd_subscription_t
*sub
; /* Subscription */
7759 cups_array_t
*ra
; /* Requested attributes array */
7762 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7763 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7764 con
, con
->http
.fd
, sub_id
);
7767 * Is the subscription ID valid?
7770 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7773 * Bad subscription ID...
7776 send_ipp_status(con
, IPP_NOT_FOUND
,
7777 _("notify-subscription-id %d no good!"), sub_id
);
7785 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7787 con
, sub
->owner
)) != HTTP_OK
)
7789 send_http_error(con
, status
, sub
->dest
);
7794 * Copy the subscription attributes to the response using the
7795 * requested-attributes attribute that may be provided by the client.
7798 ra
= create_requested_array(con
->request
);
7800 copy_subscription_attrs(con
, sub
, ra
);
7802 cupsArrayDelete(ra
);
7804 con
->response
->request
.status
.status_code
= IPP_OK
;
7809 * 'get_subscriptions()' - Get subscriptions.
7813 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7814 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7816 http_status_t status
; /* Policy status */
7817 int count
; /* Number of subscriptions */
7818 int limit
; /* Limit */
7819 cupsd_subscription_t
*sub
; /* Subscription */
7820 cups_array_t
*ra
; /* Requested attributes array */
7821 ipp_attribute_t
*attr
; /* Attribute */
7822 cups_ptype_t dtype
; /* Destination type (printer/class) */
7823 char scheme
[HTTP_MAX_URI
],
7824 /* Scheme portion of URI */
7825 username
[HTTP_MAX_URI
],
7826 /* Username portion of URI */
7828 /* Host portion of URI */
7829 resource
[HTTP_MAX_URI
];
7830 /* Resource portion of URI */
7831 int port
; /* Port portion of URI */
7832 cupsd_job_t
*job
; /* Job pointer */
7833 cupsd_printer_t
*printer
; /* Printer */
7836 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7837 "get_subscriptions(con=%p[%d], uri=%s)",
7838 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7841 * Is the destination valid?
7844 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7845 sizeof(scheme
), username
, sizeof(username
), host
,
7846 sizeof(host
), &port
, resource
, sizeof(resource
));
7848 if (!strcmp(resource
, "/") ||
7849 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7850 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7851 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7856 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7859 job
= cupsdFindJob(atoi(resource
+ 6));
7863 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
7868 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7874 send_ipp_status(con
, IPP_NOT_FOUND
,
7875 _("The printer or class was not found."));
7878 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7879 IPP_TAG_INTEGER
)) != NULL
)
7881 job
= cupsdFindJob(attr
->values
[0].integer
);
7885 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
7886 attr
->values
[0].integer
);
7897 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
7899 con
, NULL
)) != HTTP_OK
)
7901 send_http_error(con
, status
, printer
);
7906 * Copy the subscription attributes to the response using the
7907 * requested-attributes attribute that may be provided by the client.
7910 ra
= create_requested_array(con
->request
);
7912 if ((attr
= ippFindAttribute(con
->request
, "limit",
7913 IPP_TAG_INTEGER
)) != NULL
)
7914 limit
= attr
->values
[0].integer
;
7919 * See if we only want to see subscriptions for a specific user...
7922 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7923 IPP_TAG_BOOLEAN
)) != NULL
&&
7924 attr
->values
[0].boolean
)
7925 strlcpy(username
, get_username(con
), sizeof(username
));
7929 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7931 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7932 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7933 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
7935 ippAddSeparator(con
->response
);
7936 copy_subscription_attrs(con
, sub
, ra
);
7939 if (limit
&& count
>= limit
)
7943 cupsArrayDelete(ra
);
7946 con
->response
->request
.status
.status_code
= IPP_OK
;
7948 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7953 * 'get_username()' - Get the username associated with a request.
7956 static const char * /* O - Username */
7957 get_username(cupsd_client_t
*con
) /* I - Connection */
7959 ipp_attribute_t
*attr
; /* Attribute */
7962 if (con
->username
[0])
7963 return (con
->username
);
7964 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7965 IPP_TAG_NAME
)) != NULL
)
7966 return (attr
->values
[0].string
.text
);
7968 return ("anonymous");
7973 * 'hold_job()' - Hold a print job.
7977 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7978 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7980 ipp_attribute_t
*attr
, /* Current job-hold-until */
7981 *newattr
; /* New job-hold-until */
7982 int jobid
; /* Job ID */
7983 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7984 username
[HTTP_MAX_URI
], /* Username portion of URI */
7985 host
[HTTP_MAX_URI
], /* Host portion of URI */
7986 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7987 int port
; /* Port portion of URI */
7988 cupsd_job_t
*job
; /* Job information */
7991 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
7992 uri
->values
[0].string
.text
);
7995 * See if we have a job URI or a printer URI...
7998 if (!strcmp(uri
->name
, "printer-uri"))
8001 * Got a printer URI; see if we also have a job-id attribute...
8004 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8005 IPP_TAG_INTEGER
)) == NULL
)
8007 send_ipp_status(con
, IPP_BAD_REQUEST
,
8008 _("Got a printer-uri attribute but no job-id!"));
8012 jobid
= attr
->values
[0].integer
;
8017 * Got a job URI; parse it to get the job ID...
8020 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8021 sizeof(scheme
), username
, sizeof(username
), host
,
8022 sizeof(host
), &port
, resource
, sizeof(resource
));
8024 if (strncmp(resource
, "/jobs/", 6))
8030 send_ipp_status(con
, IPP_BAD_REQUEST
,
8031 _("Bad job-uri attribute \"%s\"!"),
8032 uri
->values
[0].string
.text
);
8036 jobid
= atoi(resource
+ 6);
8040 * See if the job exists...
8043 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8046 * Nope - return a "not found" error...
8049 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8054 * See if the job is owned by the requesting user...
8057 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8059 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8064 * Hold the job and return...
8069 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8070 "Job held by user.");
8072 if ((newattr
= ippFindAttribute(con
->request
, "job-hold-until",
8073 IPP_TAG_KEYWORD
)) == NULL
)
8074 newattr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8076 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8077 IPP_TAG_KEYWORD
)) == NULL
)
8078 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8083 * Free the old hold value and copy the new one over...
8086 _cupsStrFree(attr
->values
[0].string
.text
);
8090 attr
->value_tag
= newattr
->value_tag
;
8091 attr
->values
[0].string
.text
=
8092 _cupsStrRetain(newattr
->values
[0].string
.text
);
8096 attr
->value_tag
= IPP_TAG_KEYWORD
;
8097 attr
->values
[0].string
.text
= _cupsStrAlloc("indefinite");
8101 * Hold job until specified time...
8104 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
8106 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8107 "Job job-hold-until value changed by user.");
8110 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Held by \"%s\".", username
);
8112 con
->response
->request
.status
.status_code
= IPP_OK
;
8117 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8121 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8122 ipp_attribute_t
*uri
) /* I - Printer URI */
8124 http_status_t status
; /* Policy status */
8125 cups_ptype_t dtype
; /* Destination type (printer/class) */
8126 cupsd_printer_t
*printer
; /* Printer data */
8129 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8130 con
->http
.fd
, uri
->values
[0].string
.text
);
8133 * Is the destination valid?
8136 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8142 send_ipp_status(con
, IPP_NOT_FOUND
,
8143 _("The printer or class was not found."));
8151 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8153 send_http_error(con
, status
, printer
);
8158 * Hold pending/new jobs sent to the printer...
8161 printer
->holding_new_jobs
= 1;
8163 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8164 cupsdAddPrinterHistory(printer
);
8166 if (dtype
& CUPS_PRINTER_CLASS
)
8167 cupsdLogMessage(CUPSD_LOG_INFO
,
8168 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8169 printer
->name
, get_username(con
));
8171 cupsdLogMessage(CUPSD_LOG_INFO
,
8172 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8173 printer
->name
, get_username(con
));
8176 * Everything was ok, so return OK status...
8179 con
->response
->request
.status
.status_code
= IPP_OK
;
8184 * 'move_job()' - Move a job to a new destination.
8188 move_job(cupsd_client_t
*con
, /* I - Client connection */
8189 ipp_attribute_t
*uri
) /* I - Job URI */
8191 http_status_t status
; /* Policy status */
8192 ipp_attribute_t
*attr
; /* Current attribute */
8193 int jobid
; /* Job ID */
8194 cupsd_job_t
*job
; /* Current job */
8195 const char *src
; /* Source printer/class */
8196 cups_ptype_t stype
, /* Source type (printer or class) */
8197 dtype
; /* Destination type (printer/class) */
8198 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8199 username
[HTTP_MAX_URI
], /* Username portion of URI */
8200 host
[HTTP_MAX_URI
], /* Host portion of URI */
8201 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8202 int port
; /* Port portion of URI */
8203 cupsd_printer_t
*sprinter
, /* Source printer */
8204 *dprinter
; /* Destination printer */
8207 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8208 uri
->values
[0].string
.text
);
8211 * Get the new printer or class...
8214 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8215 IPP_TAG_URI
)) == NULL
)
8218 * Need job-printer-uri...
8221 send_ipp_status(con
, IPP_BAD_REQUEST
,
8222 _("job-printer-uri attribute missing!"));
8226 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8232 send_ipp_status(con
, IPP_NOT_FOUND
,
8233 _("The printer or class was not found."));
8238 * See if we have a job URI or a printer URI...
8241 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8242 sizeof(scheme
), username
, sizeof(username
), host
,
8243 sizeof(host
), &port
, resource
, sizeof(resource
));
8245 if (!strcmp(uri
->name
, "printer-uri"))
8248 * Got a printer URI; see if we also have a job-id attribute...
8251 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8252 IPP_TAG_INTEGER
)) == NULL
)
8258 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8259 &sprinter
)) == NULL
)
8265 send_ipp_status(con
, IPP_NOT_FOUND
,
8266 _("The printer or class was not found."));
8275 * Otherwise, just move a single job...
8278 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8281 * Nope - return a "not found" error...
8284 send_ipp_status(con
, IPP_NOT_FOUND
,
8285 _("Job #%d does not exist!"), attr
->values
[0].integer
);
8291 * Job found, initialize source pointers...
8302 * Got a job URI; parse it to get the job ID...
8305 if (strncmp(resource
, "/jobs/", 6))
8311 send_ipp_status(con
, IPP_BAD_REQUEST
,
8312 _("Bad job-uri attribute \"%s\"!"),
8313 uri
->values
[0].string
.text
);
8318 * See if the job exists...
8321 jobid
= atoi(resource
+ 6);
8323 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8326 * Nope - return a "not found" error...
8329 send_ipp_status(con
, IPP_NOT_FOUND
,
8330 _("Job #%d does not exist!"), jobid
);
8336 * Job found, initialize source pointers...
8345 * Check the policy of the destination printer...
8348 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8349 job
? job
->username
: NULL
)) != HTTP_OK
)
8351 send_http_error(con
, status
, dprinter
);
8356 * Now move the job or jobs...
8362 * See if the job has been completed...
8365 if (job
->state_value
> IPP_JOB_STOPPED
)
8368 * Return a "not-possible" error...
8371 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8372 _("Job #%d is finished and cannot be altered!"),
8378 * See if the job is owned by the requesting user...
8381 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8383 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8388 * Move the job to a different printer or class...
8391 cupsdMoveJob(job
, dprinter
);
8396 * Got the source printer, now look through the jobs...
8399 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8401 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8404 * See if the job is pointing at the source printer or has not been
8408 if (strcasecmp(job
->dest
, src
) ||
8409 job
->state_value
> IPP_JOB_STOPPED
)
8413 * See if the job can be moved by the requesting user...
8416 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8420 * Move the job to a different printer or class...
8423 cupsdMoveJob(job
, dprinter
);
8428 * Start jobs if possible...
8434 * Return with "everything is OK" status...
8437 con
->response
->request
.status
.status_code
= IPP_OK
;
8442 * 'ppd_parse_line()' - Parse a PPD default line.
8445 static int /* O - 0 on success, -1 on failure */
8446 ppd_parse_line(const char *line
, /* I - Line */
8447 char *option
, /* O - Option name */
8448 int olen
, /* I - Size of option name */
8449 char *choice
, /* O - Choice name */
8450 int clen
) /* I - Size of choice name */
8453 * Verify this is a default option line...
8456 if (strncmp(line
, "*Default", 8))
8460 * Read the option name...
8463 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
8473 * Skip everything else up to the colon (:)...
8476 while (*line
&& *line
!= ':')
8485 * Now grab the option choice, skipping leading whitespace...
8488 while (isspace(*line
& 255))
8491 for (clen
--; isalnum(*line
& 255); line
++)
8501 * Return with no errors...
8509 * 'print_job()' - Print a file to a printer or class.
8513 print_job(cupsd_client_t
*con
, /* I - Client connection */
8514 ipp_attribute_t
*uri
) /* I - Printer URI */
8516 ipp_attribute_t
*attr
; /* Current attribute */
8517 ipp_attribute_t
*format
; /* Document-format attribute */
8518 const char *default_format
; /* document-format-default value */
8519 cupsd_job_t
*job
; /* New job */
8520 char filename
[1024]; /* Job filename */
8521 mime_type_t
*filetype
; /* Type of file */
8522 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8523 type
[MIME_MAX_TYPE
], /* Subtype of file */
8524 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8525 /* Textual name of mime type */
8526 cupsd_printer_t
*printer
; /* Printer data */
8527 struct stat fileinfo
; /* File information */
8528 int kbytes
; /* Size of file */
8529 int compression
; /* Document compression */
8532 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8533 uri
->values
[0].string
.text
);
8536 * Validate print file attributes, for now just document-format and
8537 * compression (CUPS only supports "none" and "gzip")...
8540 compression
= CUPS_FILE_NONE
;
8542 if ((attr
= ippFindAttribute(con
->request
, "compression",
8543 IPP_TAG_KEYWORD
)) != NULL
)
8545 if (strcmp(attr
->values
[0].string
.text
, "none")
8547 && strcmp(attr
->values
[0].string
.text
, "gzip")
8548 #endif /* HAVE_LIBZ */
8551 send_ipp_status(con
, IPP_ATTRIBUTES
,
8552 _("Unsupported compression \"%s\"!"),
8553 attr
->values
[0].string
.text
);
8554 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8555 "compression", NULL
, attr
->values
[0].string
.text
);
8560 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8561 compression
= CUPS_FILE_GZIP
;
8562 #endif /* HAVE_LIBZ */
8566 * Do we have a file to print?
8571 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8576 * Is the destination valid?
8579 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8585 send_ipp_status(con
, IPP_NOT_FOUND
,
8586 _("The printer or class was not found."));
8591 * Is it a format we support?
8594 if ((format
= ippFindAttribute(con
->request
, "document-format",
8595 IPP_TAG_MIMETYPE
)) != NULL
)
8598 * Grab format from client...
8601 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8604 send_ipp_status(con
, IPP_BAD_REQUEST
,
8605 _("Could not scan type \"%s\"!"),
8606 format
->values
[0].string
.text
);
8610 else if ((default_format
= cupsGetOption("document-format",
8611 printer
->num_options
,
8612 printer
->options
)) != NULL
)
8615 * Use default document format...
8618 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8620 send_ipp_status(con
, IPP_BAD_REQUEST
,
8621 _("Could not scan type \"%s\"!"),
8632 strcpy(super
, "application");
8633 strcpy(type
, "octet-stream");
8636 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8639 * Auto-type the file...
8642 ipp_attribute_t
*doc_name
; /* document-name attribute */
8645 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8647 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8648 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8649 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8653 filetype
= mimeType(MimeDatabase
, super
, type
);
8655 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8656 filetype
->super
, filetype
->type
);
8659 filetype
= mimeType(MimeDatabase
, super
, type
);
8663 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8666 * Replace the document-format attribute value with the auto-typed or
8670 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8675 _cupsStrFree(format
->values
[0].string
.text
);
8677 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8680 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8681 "document-format", NULL
, mimetype
);
8685 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8686 _("Unsupported format \'%s/%s\'!"), super
, type
);
8687 cupsdLogMessage(CUPSD_LOG_INFO
,
8688 "Hint: Do you have the raw file printing rules enabled?");
8691 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8692 "document-format", NULL
, format
->values
[0].string
.text
);
8698 * Read any embedded job ticket info from PS files...
8701 if (!strcasecmp(filetype
->super
, "application") &&
8702 (!strcasecmp(filetype
->type
, "postscript") ||
8703 !strcasecmp(filetype
->type
, "pdf")))
8704 read_job_ticket(con
);
8707 * Create the job object...
8710 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8714 * Update quota data...
8717 if (stat(con
->filename
, &fileinfo
))
8720 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8722 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8724 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8725 IPP_TAG_INTEGER
)) != NULL
)
8726 attr
->values
[0].integer
+= kbytes
;
8729 * Add the job file...
8732 if (add_file(con
, job
, filetype
, compression
))
8735 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8737 rename(con
->filename
, filename
);
8738 cupsdClearString(&con
->filename
);
8741 * See if we need to add the ending sheet...
8744 if (cupsdTimeoutJob(job
))
8748 * Log and save the job...
8751 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8752 "File of type %s/%s queued by \"%s\".",
8753 filetype
->super
, filetype
->type
, job
->username
);
8754 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8755 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8756 job
->dest
, job
->username
);
8759 * Start the job if possible...
8767 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8769 * This function only gets called when printing a single PDF or PostScript
8770 * file using the Print-Job operation. It doesn't work for Create-Job +
8771 * Send-File, since the job attributes need to be set at job creation
8772 * time for banners to work. The embedded job ticket stuff is here
8773 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8774 * options and IPP attributes which otherwise would be lost.
8776 * The format of a job ticket is simple:
8778 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8780 * %cupsJobTicket: attr1=value1
8781 * %cupsJobTicket: attr2=value2
8783 * %cupsJobTicket: attrN=valueN
8785 * Job ticket lines must appear immediately after the first line that
8786 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8787 * stops looking for job ticket info when it finds a line that does not begin
8788 * with "%cupsJobTicket:".
8790 * The maximum length of a job ticket line, including the prefix, is
8791 * 255 characters to conform with the Adobe DSC.
8793 * Read-only attributes are rejected with a notice to the error log in
8794 * case a malicious user tries anything. Since the job ticket is read
8795 * prior to attribute validation in print_job(), job ticket attributes
8796 * will go through the same validation as IPP attributes...
8800 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8802 cups_file_t
*fp
; /* File to read from */
8803 char line
[256]; /* Line data */
8804 int num_options
; /* Number of options */
8805 cups_option_t
*options
; /* Options */
8806 ipp_t
*ticket
; /* New attributes */
8807 ipp_attribute_t
*attr
, /* Current attribute */
8808 *attr2
, /* Job attribute */
8809 *prev2
; /* Previous job attribute */
8813 * First open the print file...
8816 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8818 cupsdLogMessage(CUPSD_LOG_ERROR
,
8819 "Unable to open print file for job ticket - %s",
8825 * Skip the first line...
8828 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8830 cupsdLogMessage(CUPSD_LOG_ERROR
,
8831 "Unable to read from print file for job ticket - %s",
8837 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8840 * Not a DSC-compliant file, so no job ticket info will be available...
8848 * Read job ticket info from the file...
8854 while (cupsFileGets(fp
, line
, sizeof(line
)))
8857 * Stop at the first non-ticket line...
8860 if (strncmp(line
, "%cupsJobTicket:", 15))
8864 * Add the options to the option array...
8867 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8871 * Done with the file; see if we have any options...
8876 if (num_options
== 0)
8880 * OK, convert the options to an attribute list, and apply them to
8885 cupsEncodeOptions(ticket
, num_options
, options
);
8888 * See what the user wants to change.
8891 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8893 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8896 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8897 !strcmp(attr
->name
, "job-originating-user-name") ||
8898 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8899 !strcmp(attr
->name
, "job-k-octets") ||
8900 !strcmp(attr
->name
, "job-id") ||
8901 !strncmp(attr
->name
, "job-state", 9) ||
8902 !strncmp(attr
->name
, "time-at-", 8))
8903 continue; /* Read-only attrs */
8905 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8906 IPP_TAG_ZERO
)) != NULL
)
8909 * Some other value; first free the old value...
8912 if (con
->request
->attrs
== attr2
)
8914 con
->request
->attrs
= attr2
->next
;
8919 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8920 if (prev2
->next
== attr2
)
8922 prev2
->next
= attr2
->next
;
8927 if (con
->request
->last
== attr2
)
8928 con
->request
->last
= prev2
;
8930 _ippFreeAttr(attr2
);
8934 * Add new option by copying it...
8937 copy_attribute(con
->request
, attr
, 0);
8941 * Then free the attribute list and option array...
8945 cupsFreeOptions(num_options
, options
);
8950 * 'reject_jobs()' - Reject print jobs to a printer.
8954 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8955 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8957 http_status_t status
; /* Policy status */
8958 cups_ptype_t dtype
; /* Destination type (printer/class) */
8959 cupsd_printer_t
*printer
; /* Printer data */
8960 ipp_attribute_t
*attr
; /* printer-state-message text */
8963 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8964 con
->http
.fd
, uri
->values
[0].string
.text
);
8967 * Is the destination valid?
8970 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8976 send_ipp_status(con
, IPP_NOT_FOUND
,
8977 _("The printer or class was not found."));
8985 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8987 send_http_error(con
, status
, printer
);
8992 * Reject jobs sent to the printer...
8995 printer
->accepting
= 0;
8997 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8998 IPP_TAG_TEXT
)) == NULL
)
8999 strcpy(printer
->state_message
, "Rejecting Jobs");
9001 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9002 sizeof(printer
->state_message
));
9004 cupsdAddPrinterHistory(printer
);
9006 if (dtype
& CUPS_PRINTER_CLASS
)
9008 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9010 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9011 printer
->name
, get_username(con
));
9015 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9017 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9018 printer
->name
, get_username(con
));
9022 * Everything was ok, so return OK status...
9025 con
->response
->request
.status
.status_code
= IPP_OK
;
9030 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9034 release_held_new_jobs(
9035 cupsd_client_t
*con
, /* I - Connection */
9036 ipp_attribute_t
*uri
) /* I - Printer URI */
9038 http_status_t status
; /* Policy status */
9039 cups_ptype_t dtype
; /* Destination type (printer/class) */
9040 cupsd_printer_t
*printer
; /* Printer data */
9043 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9044 con
->http
.fd
, uri
->values
[0].string
.text
);
9047 * Is the destination valid?
9050 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9056 send_ipp_status(con
, IPP_NOT_FOUND
,
9057 _("The printer or class was not found."));
9065 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9067 send_http_error(con
, status
, printer
);
9072 * Hold pending/new jobs sent to the printer...
9075 printer
->holding_new_jobs
= 0;
9077 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9078 cupsdAddPrinterHistory(printer
);
9080 if (dtype
& CUPS_PRINTER_CLASS
)
9081 cupsdLogMessage(CUPSD_LOG_INFO
,
9082 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9083 printer
->name
, get_username(con
));
9085 cupsdLogMessage(CUPSD_LOG_INFO
,
9086 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9087 printer
->name
, get_username(con
));
9090 * Everything was ok, so return OK status...
9093 con
->response
->request
.status
.status_code
= IPP_OK
;
9098 * 'release_job()' - Release a held print job.
9102 release_job(cupsd_client_t
*con
, /* I - Client connection */
9103 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9105 ipp_attribute_t
*attr
; /* Current attribute */
9106 int jobid
; /* Job ID */
9107 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9108 username
[HTTP_MAX_URI
], /* Username portion of URI */
9109 host
[HTTP_MAX_URI
], /* Host portion of URI */
9110 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9111 int port
; /* Port portion of URI */
9112 cupsd_job_t
*job
; /* Job information */
9115 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9116 con
->http
.fd
, uri
->values
[0].string
.text
);
9119 * See if we have a job URI or a printer URI...
9122 if (!strcmp(uri
->name
, "printer-uri"))
9125 * Got a printer URI; see if we also have a job-id attribute...
9128 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9129 IPP_TAG_INTEGER
)) == NULL
)
9131 send_ipp_status(con
, IPP_BAD_REQUEST
,
9132 _("Got a printer-uri attribute but no job-id!"));
9136 jobid
= attr
->values
[0].integer
;
9141 * Got a job URI; parse it to get the job ID...
9144 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9145 sizeof(scheme
), username
, sizeof(username
), host
,
9146 sizeof(host
), &port
, resource
, sizeof(resource
));
9148 if (strncmp(resource
, "/jobs/", 6))
9154 send_ipp_status(con
, IPP_BAD_REQUEST
,
9155 _("Bad job-uri attribute \"%s\"!"),
9156 uri
->values
[0].string
.text
);
9160 jobid
= atoi(resource
+ 6);
9164 * See if the job exists...
9167 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9170 * Nope - return a "not found" error...
9173 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9178 * See if job is "held"...
9181 if (job
->state_value
!= IPP_JOB_HELD
)
9184 * Nope - return a "not possible" error...
9187 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
9192 * See if the job is owned by the requesting user...
9195 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9197 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9202 * Reset the job-hold-until value to "no-hold"...
9205 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9206 IPP_TAG_KEYWORD
)) == NULL
)
9207 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9211 _cupsStrFree(attr
->values
[0].string
.text
);
9213 attr
->value_tag
= IPP_TAG_KEYWORD
;
9214 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9216 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9217 "Job job-hold-until value changed by user.");
9221 * Release the job and return...
9224 cupsdReleaseJob(job
);
9226 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9227 "Job released by user.");
9229 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9231 con
->response
->request
.status
.status_code
= IPP_OK
;
9238 * 'renew_subscription()' - Renew an existing subscription...
9243 cupsd_client_t
*con
, /* I - Client connection */
9244 int sub_id
) /* I - Subscription ID */
9246 http_status_t status
; /* Policy status */
9247 cupsd_subscription_t
*sub
; /* Subscription */
9248 ipp_attribute_t
*lease
; /* notify-lease-duration */
9251 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9252 "renew_subscription(con=%p[%d], sub_id=%d)",
9253 con
, con
->http
.fd
, sub_id
);
9256 * Is the subscription ID valid?
9259 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9262 * Bad subscription ID...
9265 send_ipp_status(con
, IPP_NOT_FOUND
,
9266 _("notify-subscription-id %d no good!"), sub_id
);
9273 * Job subscriptions cannot be renewed...
9276 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9277 _("Job subscriptions cannot be renewed!"));
9285 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9287 con
, sub
->owner
)) != HTTP_OK
)
9289 send_http_error(con
, status
, sub
->dest
);
9294 * Renew the subscription...
9297 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9300 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9302 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9304 cupsdLogMessage(CUPSD_LOG_INFO
,
9305 "renew_subscription: Limiting notify-lease-duration to "
9308 sub
->lease
= MaxLeaseDuration
;
9311 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9313 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9315 con
->response
->request
.status
.status_code
= IPP_OK
;
9317 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9318 "notify-lease-duration", sub
->lease
);
9323 * 'restart_job()' - Restart an old print job.
9327 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9328 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9330 ipp_attribute_t
*attr
; /* Current attribute */
9331 int jobid
; /* Job ID */
9332 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9333 username
[HTTP_MAX_URI
], /* Username portion of URI */
9334 host
[HTTP_MAX_URI
], /* Host portion of URI */
9335 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9336 int port
; /* Port portion of URI */
9337 cupsd_job_t
*job
; /* Job information */
9340 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9341 con
->http
.fd
, uri
->values
[0].string
.text
);
9344 * See if we have a job URI or a printer URI...
9347 if (!strcmp(uri
->name
, "printer-uri"))
9350 * Got a printer URI; see if we also have a job-id attribute...
9353 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9354 IPP_TAG_INTEGER
)) == NULL
)
9356 send_ipp_status(con
, IPP_BAD_REQUEST
,
9357 _("Got a printer-uri attribute but no job-id!"));
9361 jobid
= attr
->values
[0].integer
;
9366 * Got a job URI; parse it to get the job ID...
9369 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9370 sizeof(scheme
), username
, sizeof(username
), host
,
9371 sizeof(host
), &port
, resource
, sizeof(resource
));
9373 if (strncmp(resource
, "/jobs/", 6))
9379 send_ipp_status(con
, IPP_BAD_REQUEST
,
9380 _("Bad job-uri attribute \"%s\"!"),
9381 uri
->values
[0].string
.text
);
9385 jobid
= atoi(resource
+ 6);
9389 * See if the job exists...
9392 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9395 * Nope - return a "not found" error...
9398 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9403 * See if job is in any of the "completed" states...
9406 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9409 * Nope - return a "not possible" error...
9412 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
9418 * See if we have retained the job files...
9423 if (!job
->attrs
|| job
->num_files
== 0)
9426 * Nope - return a "not possible" error...
9429 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9430 _("Job #%d cannot be restarted - no files!"), jobid
);
9435 * See if the job is owned by the requesting user...
9438 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9440 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9445 * Restart the job and return...
9448 cupsdRestartJob(job
);
9450 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9452 con
->response
->request
.status
.status_code
= IPP_OK
;
9457 * 'save_auth_info()' - Save authentication information for a job.
9462 cupsd_client_t
*con
, /* I - Client connection */
9463 cupsd_job_t
*job
, /* I - Job */
9464 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9466 int i
; /* Looping var */
9467 char filename
[1024]; /* Job authentication filename */
9468 cups_file_t
*fp
; /* Job authentication file */
9469 char line
[2048]; /* Line for file */
9470 cupsd_printer_t
*dest
; /* Destination printer/class */
9474 * This function saves the in-memory authentication information for
9475 * a job so that it can be used to authenticate with a remote host.
9476 * The information is stored in a file that is readable only by the
9477 * root user. The fields are Base-64 encoded, each on a separate line,
9478 * followed by random number (up to 1024) of newlines to limit the
9479 * amount of information that is exposed.
9481 * Because of the potential for exposing of authentication information,
9482 * this functionality is only enabled when running cupsd as root.
9484 * This caching only works for the Basic and BasicDigest authentication
9485 * types. Digest authentication cannot be cached this way, and in
9486 * the future Kerberos authentication may make all of this obsolete.
9488 * Authentication information is saved whenever an authenticated
9489 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9492 * This information is deleted after a job is completed or canceled,
9493 * so reprints may require subsequent re-authentication.
9499 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9503 * Create the authentication file and change permissions...
9506 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9507 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9509 cupsdLogMessage(CUPSD_LOG_ERROR
,
9510 "Unable to save authentication info to \"%s\" - %s",
9511 filename
, strerror(errno
));
9515 fchown(cupsFileNumber(fp
), 0, 0);
9516 fchmod(cupsFileNumber(fp
), 0400);
9518 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9521 * Write 1 to 3 auth values...
9524 cupsdClearString(&job
->auth_username
);
9525 cupsdClearString(&job
->auth_domain
);
9526 cupsdClearString(&job
->auth_password
);
9528 for (i
= 0; i
< auth_info
->num_values
; i
++)
9530 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9531 strlen(auth_info
->values
[i
].string
.text
));
9532 cupsFilePrintf(fp
, "%s\n", line
);
9534 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9535 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9536 auth_info
->values
[i
].string
.text
);
9537 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9538 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9539 auth_info
->values
[i
].string
.text
);
9540 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9541 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9542 auth_info
->values
[i
].string
.text
);
9545 else if (con
->username
[0])
9548 * Write the authenticated username...
9551 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9552 cupsFilePrintf(fp
, "%s\n", line
);
9554 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9555 cupsdClearString(&job
->auth_domain
);
9558 * Write the authenticated password...
9561 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9562 cupsFilePrintf(fp
, "%s\n", line
);
9564 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
9568 * Write a random number of newlines to the end of the file...
9571 for (i
= (rand() % 1024); i
>= 0; i
--)
9572 cupsFilePutChar(fp
, '\n');
9575 * Close the file and return...
9580 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9581 if (con
->gss_have_creds
)
9582 save_krb5_creds(con
, job
);
9583 else if (job
->ccname
)
9584 cupsdClearString(&(job
->ccname
));
9585 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9589 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9591 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
9595 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
9596 cupsd_job_t
*job
) /* I - Job */
9598 # if !defined(HAVE_KRB5_CC_NEW_UNIQUE) && !defined(HAVE_HEIMDAL)
9599 cupsdLogMessage(CUPSD_LOG_INFO
,
9600 "Sorry, your version of Kerberos does not support delegated "
9605 krb5_error_code error
; /* Kerberos error code */
9606 OM_uint32 major_status
, /* Major status code */
9607 minor_status
; /* Minor status code */
9608 krb5_principal principal
; /* Kerberos principal */
9613 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
9617 if (krb5_init_context
== NULL
)
9619 # endif /* __APPLE__ */
9621 if (!KerberosInitialized
)
9624 * Setup a Kerberos context for the scheduler to use...
9627 KerberosInitialized
= 1;
9629 if (krb5_init_context(&KerberosContext
))
9631 KerberosContext
= NULL
;
9633 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to initialize Kerberos context");
9639 * We MUST create a file-based cache because memory-based caches are
9640 * only valid for the current process/address space.
9642 * Due to various bugs/features in different versions of Kerberos, we
9643 * need either the krb5_cc_new_unique() function or Heimdal's version
9644 * of krb5_cc_gen_new() to create a new FILE: credential cache that
9645 * can be passed to the backend. These functions create a temporary
9646 * file (typically in /tmp) containing the cached credentials, which
9647 * are removed when we have successfully printed a job.
9650 # ifdef HAVE_KRB5_CC_NEW_UNIQUE
9651 if ((error
= krb5_cc_new_unique(KerberosContext
, "FILE", NULL
,
9652 &(job
->ccache
))) != 0)
9653 # else /* HAVE_HEIMDAL */
9654 if ((error
= krb5_cc_gen_new(KerberosContext
, &krb5_fcc_ops
,
9655 &(job
->ccache
))) != 0)
9656 # endif /* HAVE_KRB5_CC_NEW_UNIQUE */
9658 cupsdLogMessage(CUPSD_LOG_ERROR
,
9659 "Unable to create new credentials cache (%d/%s)",
9660 error
, strerror(errno
));
9665 if ((error
= krb5_parse_name(KerberosContext
, con
->username
, &principal
)) != 0)
9667 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to parse kerberos username (%d/%s)",
9668 error
, strerror(errno
));
9669 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9674 if ((error
= krb5_cc_initialize(KerberosContext
, job
->ccache
, principal
)))
9676 cupsdLogMessage(CUPSD_LOG_ERROR
,
9677 "Unable to initialize credentials cache (%d/%s)", error
,
9679 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9680 krb5_free_principal(KerberosContext
, principal
);
9685 krb5_free_principal(KerberosContext
, principal
);
9688 * Copy the user's credentials to the new cache file...
9691 major_status
= gss_krb5_copy_ccache(&minor_status
, con
->gss_delegated_cred
,
9694 if (GSS_ERROR(major_status
))
9696 cupsdLogGSSMessage(CUPSD_LOG_ERROR
, major_status
, minor_status
,
9697 "Unable to import client credentials cache");
9698 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9704 * Add the KRB5CCNAME environment variable to the job so that the
9705 * backend can use the credentials when printing.
9708 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
9709 krb5_cc_get_name(KerberosContext
, job
->ccache
));
9711 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
9712 # endif /* HAVE_KRB5_CC_NEW_UNIQUE || HAVE_HEIMDAL */
9714 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9718 * 'send_document()' - Send a file to a printer or class.
9722 send_document(cupsd_client_t
*con
, /* I - Client connection */
9723 ipp_attribute_t
*uri
) /* I - Printer URI */
9725 ipp_attribute_t
*attr
; /* Current attribute */
9726 ipp_attribute_t
*format
; /* Request's document-format attribute */
9727 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9728 const char *default_format
;/* document-format-default value */
9729 int jobid
; /* Job ID number */
9730 cupsd_job_t
*job
; /* Current job */
9731 char job_uri
[HTTP_MAX_URI
],
9733 scheme
[HTTP_MAX_URI
],
9734 /* Method portion of URI */
9735 username
[HTTP_MAX_URI
],
9736 /* Username portion of URI */
9738 /* Host portion of URI */
9739 resource
[HTTP_MAX_URI
];
9740 /* Resource portion of URI */
9741 int port
; /* Port portion of URI */
9742 mime_type_t
*filetype
; /* Type of file */
9743 char super
[MIME_MAX_SUPER
],
9744 /* Supertype of file */
9745 type
[MIME_MAX_TYPE
],
9746 /* Subtype of file */
9747 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9748 /* Textual name of mime type */
9749 char filename
[1024]; /* Job filename */
9750 cupsd_printer_t
*printer
; /* Current printer */
9751 struct stat fileinfo
; /* File information */
9752 int kbytes
; /* Size of file */
9753 int compression
; /* Type of compression */
9754 int start_job
; /* Start the job? */
9757 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9758 con
->http
.fd
, uri
->values
[0].string
.text
);
9761 * See if we have a job URI or a printer URI...
9764 if (!strcmp(uri
->name
, "printer-uri"))
9767 * Got a printer URI; see if we also have a job-id attribute...
9770 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9771 IPP_TAG_INTEGER
)) == NULL
)
9773 send_ipp_status(con
, IPP_BAD_REQUEST
,
9774 _("Got a printer-uri attribute but no job-id!"));
9778 jobid
= attr
->values
[0].integer
;
9783 * Got a job URI; parse it to get the job ID...
9786 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9787 sizeof(scheme
), username
, sizeof(username
), host
,
9788 sizeof(host
), &port
, resource
, sizeof(resource
));
9790 if (strncmp(resource
, "/jobs/", 6))
9796 send_ipp_status(con
, IPP_BAD_REQUEST
,
9797 _("Bad job-uri attribute \"%s\"!"),
9798 uri
->values
[0].string
.text
);
9802 jobid
= atoi(resource
+ 6);
9806 * See if the job exists...
9809 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9812 * Nope - return a "not found" error...
9815 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9819 printer
= cupsdFindDest(job
->dest
);
9822 * See if the job is owned by the requesting user...
9825 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9827 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9832 * OK, see if the client is sending the document compressed - CUPS
9833 * only supports "none" and "gzip".
9836 compression
= CUPS_FILE_NONE
;
9838 if ((attr
= ippFindAttribute(con
->request
, "compression",
9839 IPP_TAG_KEYWORD
)) != NULL
)
9841 if (strcmp(attr
->values
[0].string
.text
, "none")
9843 && strcmp(attr
->values
[0].string
.text
, "gzip")
9844 #endif /* HAVE_LIBZ */
9847 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
9848 attr
->values
[0].string
.text
);
9849 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9850 "compression", NULL
, attr
->values
[0].string
.text
);
9855 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9856 compression
= CUPS_FILE_GZIP
;
9857 #endif /* HAVE_LIBZ */
9861 * Do we have a file to print?
9866 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
9871 * Is it a format we support?
9874 if ((format
= ippFindAttribute(con
->request
, "document-format",
9875 IPP_TAG_MIMETYPE
)) != NULL
)
9878 * Grab format from client...
9881 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9884 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9885 format
->values
[0].string
.text
);
9889 else if ((default_format
= cupsGetOption("document-format",
9890 printer
->num_options
,
9891 printer
->options
)) != NULL
)
9894 * Use default document format...
9897 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9899 send_ipp_status(con
, IPP_BAD_REQUEST
,
9900 _("Could not scan type \"%s\"!"),
9908 * No document format attribute? Auto-type it!
9911 strcpy(super
, "application");
9912 strcpy(type
, "octet-stream");
9915 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9918 * Auto-type the file...
9921 ipp_attribute_t
*doc_name
; /* document-name attribute */
9924 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9926 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9927 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9928 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9932 filetype
= mimeType(MimeDatabase
, super
, type
);
9934 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9935 filetype
->super
, filetype
->type
);
9938 filetype
= mimeType(MimeDatabase
, super
, type
);
9943 * Replace the document-format attribute value with the auto-typed or
9947 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9950 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9951 IPP_TAG_MIMETYPE
)) != NULL
)
9953 _cupsStrFree(jformat
->values
[0].string
.text
);
9955 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9958 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9959 "document-format", NULL
, mimetype
);
9963 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9964 _("Unsupported format \'%s/%s\'!"), super
, type
);
9965 cupsdLogMessage(CUPSD_LOG_INFO
,
9966 "Hint: Do you have the raw file printing rules enabled?");
9969 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9970 "document-format", NULL
, format
->values
[0].string
.text
);
9975 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9977 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9980 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9981 _("Unsupported format \'%s\'!"), mimetype
);
9983 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9984 "document-format", NULL
, mimetype
);
9990 * Add the file to the job...
9995 if (add_file(con
, job
, filetype
, compression
))
9998 if (stat(con
->filename
, &fileinfo
))
10001 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10003 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10005 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10006 IPP_TAG_INTEGER
)) != NULL
)
10007 attr
->values
[0].integer
+= kbytes
;
10009 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10011 rename(con
->filename
, filename
);
10013 cupsdClearString(&con
->filename
);
10015 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10016 filetype
->super
, filetype
->type
, job
->username
);
10019 * Start the job if this is the last document...
10022 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10023 IPP_TAG_BOOLEAN
)) != NULL
&&
10024 attr
->values
[0].boolean
)
10027 * See if we need to add the ending sheet...
10030 if (cupsdTimeoutJob(job
))
10033 if (job
->state_value
== IPP_JOB_STOPPED
)
10035 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10036 job
->state_value
= IPP_JOB_PENDING
;
10038 else if (job
->state_value
== IPP_JOB_HELD
)
10040 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10041 IPP_TAG_KEYWORD
)) == NULL
)
10042 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10044 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10046 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10047 job
->state_value
= IPP_JOB_PENDING
;
10052 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10058 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10059 IPP_TAG_KEYWORD
)) == NULL
)
10060 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10062 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10064 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10065 job
->state_value
= IPP_JOB_HELD
;
10066 job
->hold_until
= time(NULL
) + 60;
10069 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10076 * Fill in the response info...
10079 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10082 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10085 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10087 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10089 add_job_state_reasons(con
, job
);
10091 con
->response
->request
.status
.status_code
= IPP_OK
;
10094 * Start the job if necessary...
10103 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10108 cupsd_client_t
*con
, /* I - Client connection */
10109 http_status_t status
, /* I - HTTP status code */
10110 cupsd_printer_t
*printer
) /* I - Printer, if any */
10112 ipp_attribute_t
*uri
; /* Request URI, if any */
10115 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10116 IPP_TAG_URI
)) == NULL
)
10117 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10119 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10120 "Returning HTTP %s for %s (%s) from %s",
10121 httpStatus(status
),
10122 ippOpString(con
->request
->request
.op
.operation_id
),
10123 uri
? uri
->values
[0].string
.text
: "no URI",
10124 con
->http
.hostname
);
10128 int auth_type
; /* Type of authentication required */
10131 auth_type
= CUPSD_AUTH_NONE
;
10133 if (status
== HTTP_UNAUTHORIZED
&&
10134 printer
->num_auth_info_required
> 0 &&
10135 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10137 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10138 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10139 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10142 * Creating and authenticating jobs requires Kerberos...
10145 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10150 * Use policy/location-defined authentication requirements...
10153 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10154 cupsd_location_t
*auth
; /* Pointer to authentication element */
10157 if (printer
->type
& CUPS_PRINTER_CLASS
)
10158 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10160 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10162 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10163 auth
->type
== CUPSD_AUTH_NONE
)
10164 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10166 con
->request
->request
.op
.operation_id
:
10171 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10172 auth_type
= DefaultAuthType
;
10174 auth_type
= auth
->type
;
10178 cupsdSendError(con
, status
, auth_type
);
10181 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10183 ippDelete(con
->response
);
10184 con
->response
= NULL
;
10191 * 'send_ipp_status()' - Send a status back to the IPP client.
10195 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10196 ipp_status_t status
, /* I - IPP status code */
10197 const char *message
,/* I - Status message */
10198 ...) /* I - Additional args as needed */
10200 va_list ap
; /* Pointer to additional args */
10201 char formatted
[1024]; /* Formatted errror message */
10204 va_start(ap
, message
);
10205 vsnprintf(formatted
, sizeof(formatted
),
10206 _cupsLangString(con
->language
, message
), ap
);
10209 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10210 ippOpString(con
->request
->request
.op
.operation_id
),
10211 ippErrorString(status
), formatted
);
10213 con
->response
->request
.status
.status_code
= status
;
10215 if (ippFindAttribute(con
->response
, "attributes-charset",
10216 IPP_TAG_ZERO
) == NULL
)
10217 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10218 "attributes-charset", NULL
, DefaultCharset
);
10220 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10221 IPP_TAG_ZERO
) == NULL
)
10222 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10223 "attributes-natural-language", NULL
, DefaultLanguage
);
10225 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10226 "status-message", NULL
, formatted
);
10231 * 'set_default()' - Set the default destination...
10235 set_default(cupsd_client_t
*con
, /* I - Client connection */
10236 ipp_attribute_t
*uri
) /* I - Printer URI */
10238 http_status_t status
; /* Policy status */
10239 cups_ptype_t dtype
; /* Destination type (printer/class) */
10240 cupsd_printer_t
*printer
, /* Printer */
10241 *oldprinter
; /* Old default printer */
10244 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10245 con
->http
.fd
, uri
->values
[0].string
.text
);
10248 * Is the destination valid?
10251 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10257 send_ipp_status(con
, IPP_NOT_FOUND
,
10258 _("The printer or class was not found."));
10266 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10268 send_http_error(con
, status
, NULL
);
10273 * Set it as the default...
10276 oldprinter
= DefaultPrinter
;
10277 DefaultPrinter
= printer
;
10280 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10281 "%s is no longer the default printer.", oldprinter
->name
);
10283 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10284 "%s is now the default printer.", printer
->name
);
10286 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10287 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10289 cupsdLogMessage(CUPSD_LOG_INFO
,
10290 "Default destination set to \"%s\" by \"%s\".",
10291 printer
->name
, get_username(con
));
10294 * Everything was ok, so return OK status...
10297 con
->response
->request
.status
.status_code
= IPP_OK
;
10302 * 'set_job_attrs()' - Set job attributes.
10306 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10307 ipp_attribute_t
*uri
) /* I - Job URI */
10309 ipp_attribute_t
*attr
, /* Current attribute */
10310 *attr2
; /* Job attribute */
10311 int jobid
; /* Job ID */
10312 cupsd_job_t
*job
; /* Current job */
10313 char scheme
[HTTP_MAX_URI
],
10314 /* Method portion of URI */
10315 username
[HTTP_MAX_URI
],
10316 /* Username portion of URI */
10317 host
[HTTP_MAX_URI
],
10318 /* Host portion of URI */
10319 resource
[HTTP_MAX_URI
];
10320 /* Resource portion of URI */
10321 int port
; /* Port portion of URI */
10322 int event
; /* Events? */
10323 int check_jobs
; /* Check jobs? */
10326 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10327 con
->http
.fd
, uri
->values
[0].string
.text
);
10330 * Start with "everything is OK" status...
10333 con
->response
->request
.status
.status_code
= IPP_OK
;
10336 * See if we have a job URI or a printer URI...
10339 if (!strcmp(uri
->name
, "printer-uri"))
10342 * Got a printer URI; see if we also have a job-id attribute...
10345 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10346 IPP_TAG_INTEGER
)) == NULL
)
10348 send_ipp_status(con
, IPP_BAD_REQUEST
,
10349 _("Got a printer-uri attribute but no job-id!"));
10353 jobid
= attr
->values
[0].integer
;
10358 * Got a job URI; parse it to get the job ID...
10361 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10362 sizeof(scheme
), username
, sizeof(username
), host
,
10363 sizeof(host
), &port
, resource
, sizeof(resource
));
10365 if (strncmp(resource
, "/jobs/", 6))
10371 send_ipp_status(con
, IPP_BAD_REQUEST
,
10372 _("Bad job-uri attribute \"%s\"!"),
10373 uri
->values
[0].string
.text
);
10377 jobid
= atoi(resource
+ 6);
10381 * See if the job exists...
10384 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10387 * Nope - return a "not found" error...
10390 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
10395 * See if the job has been completed...
10398 if (job
->state_value
> IPP_JOB_STOPPED
)
10401 * Return a "not-possible" error...
10404 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10405 _("Job #%d is finished and cannot be altered!"), jobid
);
10410 * See if the job is owned by the requesting user...
10413 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10415 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
10420 * See what the user wants to change.
10428 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10430 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10433 if (!strcmp(attr
->name
, "attributes-charset") ||
10434 !strcmp(attr
->name
, "attributes-natural-language") ||
10435 !strcmp(attr
->name
, "document-compression") ||
10436 !strcmp(attr
->name
, "document-format") ||
10437 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10438 !strcmp(attr
->name
, "job-document-access-errors") ||
10439 !strcmp(attr
->name
, "job-id") ||
10440 !strcmp(attr
->name
, "job-impressions-completed") ||
10441 !strcmp(attr
->name
, "job-k-octets") ||
10442 !strcmp(attr
->name
, "job-originating-host-name") ||
10443 !strcmp(attr
->name
, "job-originating-user-name") ||
10444 !strcmp(attr
->name
, "job-printer-up-time") ||
10445 !strcmp(attr
->name
, "job-printer-uri") ||
10446 !strcmp(attr
->name
, "job-sheets") ||
10447 !strcmp(attr
->name
, "job-state-message") ||
10448 !strcmp(attr
->name
, "job-state-reasons") ||
10449 !strcmp(attr
->name
, "job-uri") ||
10450 !strcmp(attr
->name
, "number-of-documents") ||
10451 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10452 !strcmp(attr
->name
, "output-device-assigned") ||
10453 !strncmp(attr
->name
, "date-time-at-", 13) ||
10454 !strncmp(attr
->name
, "job-k-octets", 12) ||
10455 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10456 !strncmp(attr
->name
, "time-at-", 8))
10462 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10463 _("%s cannot be changed."), attr
->name
);
10465 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10466 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10471 if (!strcmp(attr
->name
, "job-priority"))
10474 * Change the job priority...
10477 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10479 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
10481 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10482 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10484 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10486 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10487 _("Job is completed and cannot be changed."));
10490 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10492 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10493 attr
->values
[0].integer
);
10494 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10497 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10498 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10501 else if (!strcmp(attr
->name
, "job-state"))
10504 * Change the job state...
10507 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10509 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
10511 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10512 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10516 switch (attr
->values
[0].integer
)
10518 case IPP_JOB_PENDING
:
10519 case IPP_JOB_HELD
:
10520 if (job
->state_value
> IPP_JOB_HELD
)
10522 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10523 _("Job state cannot be changed."));
10526 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10528 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10529 attr
->values
[0].integer
);
10531 job
->state
->values
[0].integer
= attr
->values
[0].integer
;
10532 job
->state_value
= (ipp_jstate_t
)attr
->values
[0].integer
;
10534 event
|= CUPSD_EVENT_JOB_STATE
;
10539 case IPP_JOB_PROCESSING
:
10540 case IPP_JOB_STOPPED
:
10541 if (job
->state_value
!= attr
->values
[0].integer
)
10543 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10544 _("Job state cannot be changed."));
10549 case IPP_JOB_CANCELED
:
10550 case IPP_JOB_ABORTED
:
10551 case IPP_JOB_COMPLETED
:
10552 if (job
->state_value
> IPP_JOB_PROCESSING
)
10554 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10555 _("Job state cannot be changed."));
10558 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10560 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10561 attr
->values
[0].integer
);
10562 cupsdCancelJob(job
, 0, (ipp_jstate_t
)attr
->values
[0].integer
);
10570 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10572 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10573 IPP_TAG_ZERO
)) != NULL
)
10576 * Some other value; first free the old value...
10579 if (job
->attrs
->prev
)
10580 job
->attrs
->prev
->next
= attr2
->next
;
10582 job
->attrs
->attrs
= attr2
->next
;
10584 if (job
->attrs
->last
== attr2
)
10585 job
->attrs
->last
= job
->attrs
->prev
;
10587 _ippFreeAttr(attr2
);
10590 * Then copy the attribute...
10593 copy_attribute(job
->attrs
, attr
, 0);
10596 * See if the job-name or job-hold-until is being changed.
10599 if (!strcmp(attr
->name
, "job-hold-until"))
10601 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10602 attr
->values
[0].string
.text
);
10603 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
10605 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10606 cupsdReleaseJob(job
);
10611 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10614 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10617 * Delete the attribute...
10620 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10621 IPP_TAG_ZERO
)) != NULL
)
10623 if (job
->attrs
->prev
)
10624 job
->attrs
->prev
->next
= attr2
->next
;
10626 job
->attrs
->attrs
= attr2
->next
;
10628 if (attr2
== job
->attrs
->last
)
10629 job
->attrs
->last
= job
->attrs
->prev
;
10631 _ippFreeAttr(attr2
);
10633 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10639 * Add new option by copying it...
10642 copy_attribute(job
->attrs
, attr
, 0);
10644 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10653 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10656 * Send events as needed...
10659 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10660 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10661 cupsdFindDest(job
->dest
), job
,
10662 "Job priority changed by user.");
10664 if (event
& CUPSD_EVENT_JOB_STATE
)
10665 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10666 job
->state_value
== IPP_JOB_HELD
?
10667 "Job held by user." : "Job restarted by user.");
10669 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10670 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10671 "Job options changed by user.");
10674 * Start jobs if possible...
10683 * 'set_printer_attrs()' - Set printer attributes.
10687 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10688 ipp_attribute_t
*uri
) /* I - Printer */
10690 http_status_t status
; /* Policy status */
10691 cups_ptype_t dtype
; /* Destination type (printer/class) */
10692 cupsd_printer_t
*printer
; /* Printer/class */
10693 ipp_attribute_t
*attr
; /* Printer attribute */
10694 int changed
; /* Was anything changed? */
10697 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10698 con
->http
.fd
, uri
->values
[0].string
.text
);
10701 * Is the destination valid?
10704 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10710 send_ipp_status(con
, IPP_NOT_FOUND
,
10711 _("The printer or class was not found."));
10719 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10721 send_http_error(con
, status
, printer
);
10726 * Return a list of attributes that can be set via Set-Printer-Attributes.
10729 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10730 IPP_TAG_TEXT
)) != NULL
)
10732 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10736 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10737 IPP_TAG_TEXT
)) != NULL
)
10739 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10744 * Update the printer attributes and return...
10749 cupsdSetPrinterAttrs(printer
);
10750 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10752 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10753 "Printer \"%s\" description or location changed by \"%s\".",
10754 printer
->name
, get_username(con
));
10756 cupsdLogMessage(CUPSD_LOG_INFO
,
10757 "Printer \"%s\" description or location changed by \"%s\".",
10758 printer
->name
, get_username(con
));
10761 con
->response
->request
.status
.status_code
= IPP_OK
;
10766 * 'set_printer_defaults()' - Set printer default options from a request.
10770 set_printer_defaults(
10771 cupsd_client_t
*con
, /* I - Client connection */
10772 cupsd_printer_t
*printer
) /* I - Printer */
10774 int i
; /* Looping var */
10775 ipp_attribute_t
*attr
; /* Current attribute */
10776 int namelen
; /* Length of attribute name */
10777 char name
[256], /* New attribute name */
10778 value
[256]; /* String version of integer attrs */
10781 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10784 * Skip non-printer attributes...
10787 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10790 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10792 if (!strcmp(attr
->name
, "job-sheets-default"))
10795 * Only allow keywords and names...
10798 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10802 * Only allow job-sheets-default to be set when running without a
10803 * system high classification level...
10806 if (Classification
)
10809 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10811 if (attr
->num_values
> 1)
10812 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10814 cupsdSetString(&printer
->job_sheets
[1], "none");
10816 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10818 cupsdFreePrinterUsers(printer
);
10820 printer
->deny_users
= 0;
10822 if (attr
->value_tag
== IPP_TAG_NAME
&&
10823 (attr
->num_values
> 1 ||
10824 strcmp(attr
->values
[0].string
.text
, "all")))
10826 for (i
= 0; i
< attr
->num_values
; i
++)
10827 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10830 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10832 cupsdFreePrinterUsers(printer
);
10834 printer
->deny_users
= 1;
10836 if (attr
->value_tag
== IPP_TAG_NAME
&&
10837 (attr
->num_values
> 1 ||
10838 strcmp(attr
->values
[0].string
.text
, "none")))
10840 for (i
= 0; i
< attr
->num_values
; i
++)
10841 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10844 else if (!strcmp(attr
->name
, "job-quota-period"))
10846 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10849 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10850 attr
->values
[0].integer
);
10851 cupsdFreeQuotas(printer
);
10853 printer
->quota_period
= attr
->values
[0].integer
;
10855 else if (!strcmp(attr
->name
, "job-k-limit"))
10857 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10860 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10861 attr
->values
[0].integer
);
10862 cupsdFreeQuotas(printer
);
10864 printer
->k_limit
= attr
->values
[0].integer
;
10866 else if (!strcmp(attr
->name
, "job-page-limit"))
10868 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10871 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10872 attr
->values
[0].integer
);
10873 cupsdFreeQuotas(printer
);
10875 printer
->page_limit
= attr
->values
[0].integer
;
10877 else if (!strcmp(attr
->name
, "printer-op-policy"))
10879 cupsd_policy_t
*p
; /* Policy */
10882 if (attr
->value_tag
!= IPP_TAG_NAME
)
10885 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10887 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10888 "Setting printer-op-policy to \"%s\"...",
10889 attr
->values
[0].string
.text
);
10890 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10891 printer
->op_policy_ptr
= p
;
10895 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10896 _("Unknown printer-op-policy \"%s\"."),
10897 attr
->values
[0].string
.text
);
10901 else if (!strcmp(attr
->name
, "printer-error-policy"))
10903 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10906 if (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10907 strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10908 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10909 strcmp(attr
->values
[0].string
.text
, "stop-printer"))
10911 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10912 _("Unknown printer-error-policy \"%s\"."),
10913 attr
->values
[0].string
.text
);
10917 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10918 "Setting printer-error-policy to \"%s\"...",
10919 attr
->values
[0].string
.text
);
10920 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10924 * Skip any other non-default attributes...
10927 namelen
= strlen(attr
->name
);
10928 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10929 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10933 * OK, anything else must be a user-defined default...
10936 strlcpy(name
, attr
->name
, sizeof(name
));
10937 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10939 switch (attr
->value_tag
)
10941 case IPP_TAG_DELETEATTR
:
10942 printer
->num_options
= cupsRemoveOption(name
,
10943 printer
->num_options
,
10944 &(printer
->options
));
10945 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10946 "Deleting %s", attr
->name
);
10949 case IPP_TAG_NAME
:
10950 case IPP_TAG_KEYWORD
:
10952 printer
->num_options
= cupsAddOption(name
,
10953 attr
->values
[0].string
.text
,
10954 printer
->num_options
,
10955 &(printer
->options
));
10956 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10957 "Setting %s to \"%s\"...", attr
->name
,
10958 attr
->values
[0].string
.text
);
10961 case IPP_TAG_BOOLEAN
:
10962 printer
->num_options
= cupsAddOption(name
,
10963 attr
->values
[0].boolean
?
10965 printer
->num_options
,
10966 &(printer
->options
));
10967 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10968 "Setting %s to %s...", attr
->name
,
10969 attr
->values
[0].boolean
? "true" : "false");
10972 case IPP_TAG_INTEGER
:
10973 case IPP_TAG_ENUM
:
10974 sprintf(value
, "%d", attr
->values
[0].integer
);
10975 printer
->num_options
= cupsAddOption(name
, value
,
10976 printer
->num_options
,
10977 &(printer
->options
));
10978 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10979 "Setting %s to %s...", attr
->name
, value
);
10982 case IPP_TAG_RANGE
:
10983 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10984 attr
->values
[0].range
.upper
);
10985 printer
->num_options
= cupsAddOption(name
, value
,
10986 printer
->num_options
,
10987 &(printer
->options
));
10988 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10989 "Setting %s to %s...", attr
->name
, value
);
10992 case IPP_TAG_RESOLUTION
:
10993 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10994 attr
->values
[0].resolution
.yres
,
10995 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10997 printer
->num_options
= cupsAddOption(name
, value
,
10998 printer
->num_options
,
10999 &(printer
->options
));
11000 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11001 "Setting %s to %s...", attr
->name
, value
);
11005 /* Do nothing for other values */
11013 * 'start_printer()' - Start a printer.
11017 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11018 ipp_attribute_t
*uri
) /* I - Printer URI */
11020 http_status_t status
; /* Policy status */
11021 cups_ptype_t dtype
; /* Destination type (printer/class) */
11022 cupsd_printer_t
*printer
; /* Printer data */
11025 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11026 con
->http
.fd
, uri
->values
[0].string
.text
);
11029 * Is the destination valid?
11032 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11038 send_ipp_status(con
, IPP_NOT_FOUND
,
11039 _("The printer or class was not found."));
11047 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11049 send_http_error(con
, status
, printer
);
11054 * Start the printer...
11057 printer
->state_message
[0] = '\0';
11059 cupsdStartPrinter(printer
, 1);
11061 if (dtype
& CUPS_PRINTER_CLASS
)
11062 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11063 printer
->name
, get_username(con
));
11065 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11066 printer
->name
, get_username(con
));
11071 * Everything was ok, so return OK status...
11074 con
->response
->request
.status
.status_code
= IPP_OK
;
11079 * 'stop_printer()' - Stop a printer.
11083 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11084 ipp_attribute_t
*uri
) /* I - Printer URI */
11086 http_status_t status
; /* Policy status */
11087 cups_ptype_t dtype
; /* Destination type (printer/class) */
11088 cupsd_printer_t
*printer
; /* Printer data */
11089 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11092 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11093 con
->http
.fd
, uri
->values
[0].string
.text
);
11096 * Is the destination valid?
11099 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11105 send_ipp_status(con
, IPP_NOT_FOUND
,
11106 _("The printer or class was not found."));
11114 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11116 send_http_error(con
, status
, printer
);
11121 * Stop the printer...
11124 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11125 IPP_TAG_TEXT
)) == NULL
)
11126 strcpy(printer
->state_message
, "Paused");
11129 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11130 sizeof(printer
->state_message
));
11133 cupsdStopPrinter(printer
, 1);
11135 if (dtype
& CUPS_PRINTER_CLASS
)
11136 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11137 printer
->name
, get_username(con
));
11139 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11140 printer
->name
, get_username(con
));
11143 * Everything was ok, so return OK status...
11146 con
->response
->request
.status
.status_code
= IPP_OK
;
11151 * 'url_encode_attr()' - URL-encode a string attribute.
11155 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11156 char *buffer
,/* I - String buffer */
11157 int bufsize
)/* I - Size of buffer */
11159 int i
; /* Looping var */
11160 char *bufptr
, /* Pointer into buffer */
11161 *bufend
; /* End of buffer */
11164 strlcpy(buffer
, attr
->name
, bufsize
);
11165 bufptr
= buffer
+ strlen(buffer
);
11166 bufend
= buffer
+ bufsize
- 1;
11168 for (i
= 0; i
< attr
->num_values
; i
++)
11170 if (bufptr
>= bufend
)
11178 if (bufptr
>= bufend
)
11183 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11184 bufptr
, bufend
- bufptr
+ 1);
11186 if (bufptr
>= bufend
)
11197 * 'url_encode_string()' - URL-encode a string.
11200 static char * /* O - End of string */
11201 url_encode_string(const char *s
, /* I - String */
11202 char *buffer
, /* I - String buffer */
11203 int bufsize
) /* I - Size of buffer */
11205 char *bufptr
, /* Pointer into buffer */
11206 *bufend
; /* End of buffer */
11207 static const char *hex
= "0123456789ABCDEF";
11212 bufend
= buffer
+ bufsize
- 1;
11214 while (*s
&& bufptr
< bufend
)
11216 if (*s
== ' ' || *s
== '%')
11218 if (bufptr
>= (bufend
- 2))
11222 *bufptr
++ = hex
[(*s
>> 4) & 15];
11223 *bufptr
++ = hex
[*s
& 15];
11227 else if (*s
== '\'' || *s
== '\\')
11229 if (bufptr
>= (bufend
- 1))
11246 * 'user_allowed()' - See if a user is allowed to print to a queue.
11249 static int /* O - 0 if not allowed, 1 if allowed */
11250 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11251 const char *username
) /* I - Username */
11253 int i
; /* Looping var */
11254 struct passwd
*pw
; /* User password data */
11255 char baseuser
[256], /* Base username */
11256 *baseptr
; /* Pointer to "@" in base username */
11259 if (p
->num_users
== 0)
11262 if (!strcmp(username
, "root"))
11265 if (strchr(username
, '@'))
11268 * Strip @REALM for username check...
11271 strlcpy(baseuser
, username
, sizeof(baseuser
));
11273 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11276 username
= baseuser
;
11279 pw
= getpwnam(username
);
11282 for (i
= 0; i
< p
->num_users
; i
++)
11284 if (p
->users
[i
][0] == '@')
11287 * Check group membership...
11290 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
11293 else if (p
->users
[i
][0] == '#')
11299 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
11302 else if (!strcasecmp(username
, p
->users
[i
]))
11306 return ((i
< p
->num_users
) != p
->deny_users
);
11311 * 'validate_job()' - Validate printer options and destination.
11315 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11316 ipp_attribute_t
*uri
) /* I - Printer URI */
11318 http_status_t status
; /* Policy status */
11319 ipp_attribute_t
*attr
; /* Current attribute */
11320 ipp_attribute_t
*format
; /* Document-format attribute */
11321 cups_ptype_t dtype
; /* Destination type (printer/class) */
11322 char super
[MIME_MAX_SUPER
],
11323 /* Supertype of file */
11324 type
[MIME_MAX_TYPE
];
11325 /* Subtype of file */
11326 cupsd_printer_t
*printer
; /* Printer */
11329 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11330 con
->http
.fd
, uri
->values
[0].string
.text
);
11333 * OK, see if the client is sending the document compressed - CUPS
11334 * doesn't support compression yet...
11337 if ((attr
= ippFindAttribute(con
->request
, "compression",
11338 IPP_TAG_KEYWORD
)) != NULL
&&
11339 !strcmp(attr
->values
[0].string
.text
, "none"))
11341 send_ipp_status(con
, IPP_ATTRIBUTES
,
11342 _("Unsupported compression attribute %s!"),
11343 attr
->values
[0].string
.text
);
11344 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11345 "compression", NULL
, attr
->values
[0].string
.text
);
11350 * Is it a format we support?
11353 if ((format
= ippFindAttribute(con
->request
, "document-format",
11354 IPP_TAG_MIMETYPE
)) != NULL
)
11356 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11359 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
11360 format
->values
[0].string
.text
);
11364 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11365 !mimeType(MimeDatabase
, super
, type
))
11367 cupsdLogMessage(CUPSD_LOG_INFO
,
11368 "Hint: Do you have the raw file printing rules enabled?");
11369 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11370 _("Unsupported format \"%s\"!"),
11371 format
->values
[0].string
.text
);
11372 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11373 "document-format", NULL
, format
->values
[0].string
.text
);
11379 * Is the destination valid?
11382 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11388 send_ipp_status(con
, IPP_NOT_FOUND
,
11389 _("The printer or class was not found."));
11397 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11399 send_http_error(con
, status
, printer
);
11404 * Everything was ok, so return OK status...
11407 con
->response
->request
.status
.status_code
= IPP_OK
;
11412 * 'validate_name()' - Make sure the printer name only contains valid chars.
11415 static int /* O - 0 if name is no good, 1 if good */
11416 validate_name(const char *name
) /* I - Name to check */
11418 const char *ptr
; /* Pointer into name */
11422 * Scan the whole name...
11425 for (ptr
= name
; *ptr
; ptr
++)
11426 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11430 * All the characters are good; validate the length, too...
11433 return ((ptr
- name
) < 128);
11438 * 'validate_user()' - Validate the user for the request.
11441 static int /* O - 1 if permitted, 0 otherwise */
11442 validate_user(cupsd_job_t
*job
, /* I - Job */
11443 cupsd_client_t
*con
, /* I - Client connection */
11444 const char *owner
, /* I - Owner of job/resource */
11445 char *username
, /* O - Authenticated username */
11446 int userlen
) /* I - Length of username */
11448 cupsd_printer_t
*printer
; /* Printer for job */
11451 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11452 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11454 job
->id
, con
? con
->http
.fd
: 0,
11455 owner
? owner
: "(null)", username
, userlen
);
11458 * Validate input...
11461 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11465 * Get the best authenticated username that is available.
11468 strlcpy(username
, get_username(con
), userlen
);
11471 * Check the username against the owner...
11474 printer
= cupsdFindDest(job
->dest
);
11476 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11477 con
, owner
) == HTTP_OK
);
11482 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".