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 (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
716 #ifdef CUPSD_USE_CHUNKING
718 * Because older versions of CUPS (1.1.17 and older) and some IPP
719 * clients do not implement chunking properly, we cannot use
720 * chunking by default. This may become the default in future
721 * CUPS releases, or we might add a configuration directive for
725 if (con
->http
.version
== HTTP_1_1
)
727 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
730 if (cupsdFlushHeader(con
) < 0)
733 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
736 #endif /* CUPSD_USE_CHUNKING */
738 size_t length
; /* Length of response */
741 length
= ippLength(con
->response
);
743 if (con
->file
>= 0 && !con
->pipe_pid
)
745 struct stat fileinfo
; /* File information */
748 if (!fstat(con
->file
, &fileinfo
))
749 length
+= fileinfo
.st_size
;
752 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
753 CUPS_LLCAST length
) < 0)
756 if (cupsdFlushHeader(con
) < 0)
759 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
760 con
->http
.data_remaining
= length
;
762 if (con
->http
.data_remaining
<= INT_MAX
)
763 con
->http
._data_remaining
= con
->http
.data_remaining
;
765 con
->http
._data_remaining
= INT_MAX
;
768 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
769 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
772 * Tell the caller the response header was sent successfully...
780 * Tell the caller the response header could not be sent...
789 * Sending data from a subprocess like cups-deviced; tell the caller
790 * everything is A-OK so far...
799 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
802 int /* O - 0 on success, -1 on error */
803 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
805 cupsd_printer_t
*printer
; /* Destination printer or class */
806 ipp_attribute_t
*attr
; /* job-sheets attribute */
807 int kbytes
; /* Kilobytes in banner */
810 job
->pending_timeout
= 0;
813 * See if we need to add the ending sheet...
816 printer
= cupsdFindDest(job
->dest
);
817 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
820 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
821 attr
&& attr
->num_values
> 1)
827 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
828 attr
->values
[1].string
.text
);
830 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
833 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
841 * 'accept_jobs()' - Accept print jobs to a printer.
845 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
846 ipp_attribute_t
*uri
) /* I - Printer or class URI */
848 http_status_t status
; /* Policy status */
849 cups_ptype_t dtype
; /* Destination type (printer/class) */
850 cupsd_printer_t
*printer
; /* Printer data */
853 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
854 con
->http
.fd
, uri
->values
[0].string
.text
);
857 * Is the destination valid?
860 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
866 send_ipp_status(con
, IPP_NOT_FOUND
,
867 _("The printer or class was not found."));
875 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
877 send_http_error(con
, status
, printer
);
882 * Accept jobs sent to the printer...
885 printer
->accepting
= 1;
886 printer
->state_message
[0] = '\0';
888 cupsdAddPrinterHistory(printer
);
890 if (dtype
& CUPS_PRINTER_CLASS
)
892 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
894 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
895 printer
->name
, get_username(con
));
899 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
901 cupsdLogMessage(CUPSD_LOG_INFO
,
902 "Printer \"%s\" now accepting jobs (\"%s\").",
903 printer
->name
, get_username(con
));
907 * Everything was ok, so return OK status...
910 con
->response
->request
.status
.status_code
= IPP_OK
;
915 * 'add_class()' - Add a class to the system.
919 add_class(cupsd_client_t
*con
, /* I - Client connection */
920 ipp_attribute_t
*uri
) /* I - URI of class */
922 http_status_t status
; /* Policy status */
923 int i
; /* Looping var */
924 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
925 username
[HTTP_MAX_URI
], /* Username portion of URI */
926 host
[HTTP_MAX_URI
], /* Host portion of URI */
927 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
928 int port
; /* Port portion of URI */
929 cupsd_printer_t
*pclass
, /* Class */
930 *member
; /* Member printer/class */
931 cups_ptype_t dtype
; /* Destination type */
932 ipp_attribute_t
*attr
; /* Printer attribute */
933 int modify
; /* Non-zero if we just modified */
934 char newname
[IPP_MAX_NAME
]; /* New class name */
935 int need_restart_job
; /* Need to restart job? */
938 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
939 con
->http
.fd
, uri
->values
[0].string
.text
);
942 * Do we have a valid URI?
945 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
946 sizeof(scheme
), username
, sizeof(username
), host
,
947 sizeof(host
), &port
, resource
, sizeof(resource
));
950 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
953 * No, return an error...
956 send_ipp_status(con
, IPP_BAD_REQUEST
,
957 _("The printer-uri must be of the form "
958 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
963 * Do we have a valid printer name?
966 if (!validate_name(resource
+ 9))
969 * No, return an error...
972 send_ipp_status(con
, IPP_BAD_REQUEST
,
973 _("The printer-uri \"%s\" contains invalid characters."),
974 uri
->values
[0].string
.text
);
979 * See if the class already exists; if not, create a new class...
982 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
985 * Class doesn't exist; see if we have a printer of the same name...
988 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
989 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
992 * Yes, return an error...
995 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
996 _("A printer named \"%s\" already exists!"),
1002 * No, check the default policy and then add the class...
1005 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1007 send_http_error(con
, status
, NULL
);
1011 pclass
= cupsdAddClass(resource
+ 9);
1014 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1017 * Check the default policy, then rename the implicit class to "AnyClass"
1021 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1023 send_http_error(con
, status
, NULL
);
1027 if (ImplicitAnyClasses
)
1029 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1030 cupsdRenamePrinter(pclass
, newname
);
1033 cupsdDeletePrinter(pclass
, 1);
1036 * Add the class as a new local class...
1039 pclass
= cupsdAddClass(resource
+ 9);
1042 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1045 * Check the default policy, then rename the remote class to "Class"...
1048 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1050 send_http_error(con
, status
, NULL
);
1054 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1055 cupsdRenamePrinter(pclass
, newname
);
1058 * Add the class as a new local class...
1061 pclass
= cupsdAddClass(resource
+ 9);
1064 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1067 send_http_error(con
, status
, pclass
);
1074 * Look for attributes and copy them over as needed...
1077 need_restart_job
= 0;
1079 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1080 IPP_TAG_TEXT
)) != NULL
)
1081 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1083 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1084 IPP_TAG_TEXT
)) != NULL
)
1085 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1087 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1088 IPP_TAG_BOOLEAN
)) != NULL
)
1090 cupsdLogMessage(CUPSD_LOG_INFO
,
1091 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1092 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1094 pclass
->accepting
= attr
->values
[0].boolean
;
1095 cupsdAddPrinterHistory(pclass
);
1098 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1099 IPP_TAG_BOOLEAN
)) != NULL
)
1101 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1102 cupsdDeregisterPrinter(pclass
, 1);
1104 cupsdLogMessage(CUPSD_LOG_INFO
,
1105 "Setting %s printer-is-shared to %d (was %d.)",
1106 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1108 pclass
->shared
= attr
->values
[0].boolean
;
1111 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1112 IPP_TAG_ENUM
)) != NULL
)
1114 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1115 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1117 send_ipp_status(con
, IPP_BAD_REQUEST
,
1118 _("Attempt to set %s printer-state to bad value %d!"),
1119 pclass
->name
, attr
->values
[0].integer
);
1123 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1124 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1126 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1127 cupsdStopPrinter(pclass
, 0);
1130 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1131 need_restart_job
= 1;
1134 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1135 IPP_TAG_TEXT
)) != NULL
)
1137 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1138 sizeof(pclass
->state_message
));
1139 cupsdAddPrinterHistory(pclass
);
1141 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1142 IPP_TAG_URI
)) != NULL
)
1145 * Clear the printer array as needed...
1148 need_restart_job
= 1;
1150 if (pclass
->num_printers
> 0)
1152 free(pclass
->printers
);
1153 pclass
->num_printers
= 0;
1157 * Add each printer or class that is listed...
1160 for (i
= 0; i
< attr
->num_values
; i
++)
1163 * Search for the printer or class URI...
1166 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1172 send_ipp_status(con
, IPP_NOT_FOUND
,
1173 _("The printer or class was not found."));
1178 * Add it to the class...
1181 cupsdAddPrinterToClass(pclass
, member
);
1185 set_printer_defaults(con
, pclass
);
1187 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1188 IPP_TAG_KEYWORD
)) != NULL
)
1189 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1192 * Update the printer class attributes and return...
1195 cupsdSetPrinterAttrs(pclass
);
1196 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1198 if (need_restart_job
&& pclass
->job
)
1203 * Stop the current job and then restart it below...
1206 job
= (cupsd_job_t
*)pclass
->job
;
1208 cupsdStopJob(job
, 1);
1210 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1211 job
->state_value
= IPP_JOB_PENDING
;
1214 if (need_restart_job
)
1217 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1221 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, pclass
, NULL
,
1222 "Class \"%s\" modified by \"%s\".", pclass
->name
,
1225 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1226 pclass
->name
, get_username(con
));
1230 cupsdAddPrinterHistory(pclass
);
1232 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, pclass
, NULL
,
1233 "New class \"%s\" added by \"%s\".", pclass
->name
,
1236 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1237 pclass
->name
, get_username(con
));
1240 con
->response
->request
.status
.status_code
= IPP_OK
;
1245 * 'add_file()' - Add a file to a job.
1248 static int /* O - 0 on success, -1 on error */
1249 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1250 cupsd_job_t
*job
, /* I - Job to add to */
1251 mime_type_t
*filetype
, /* I - Type of file */
1252 int compression
) /* I - Compression */
1254 mime_type_t
**filetypes
; /* New filetypes array... */
1255 int *compressions
; /* New compressions array... */
1258 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1259 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1260 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1261 filetype
->super
, filetype
->type
, compression
);
1264 * Add the file to the job...
1267 if (job
->num_files
== 0)
1269 compressions
= (int *)malloc(sizeof(int));
1270 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1274 compressions
= (int *)realloc(job
->compressions
,
1275 (job
->num_files
+ 1) * sizeof(int));
1276 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1277 (job
->num_files
+ 1) *
1278 sizeof(mime_type_t
*));
1281 if (!compressions
|| !filetypes
)
1283 cupsdCancelJob(job
, 1, IPP_JOB_ABORTED
);
1286 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1287 _("Unable to allocate memory for file types!"));
1292 job
->compressions
= compressions
;
1293 job
->compressions
[job
->num_files
] = compression
;
1294 job
->filetypes
= filetypes
;
1295 job
->filetypes
[job
->num_files
] = filetype
;
1300 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1307 * 'add_job()' - Add a job to a print queue.
1310 static cupsd_job_t
* /* O - Job object */
1311 add_job(cupsd_client_t
*con
, /* I - Client connection */
1312 cupsd_printer_t
*printer
, /* I - Destination printer */
1313 mime_type_t
*filetype
) /* I - First print file type, if any */
1315 http_status_t status
; /* Policy status */
1316 ipp_attribute_t
*attr
, /* Current attribute */
1317 *auth_info
; /* auth-info attribute */
1318 const char *val
; /* Default option value */
1319 int priority
; /* Job priority */
1320 char *title
; /* Job name/title */
1321 cupsd_job_t
*job
; /* Current job */
1322 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1323 int kbytes
; /* Size of print file */
1324 int i
; /* Looping var */
1325 int lowerpagerange
; /* Page range bound */
1328 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1329 con
, con
->http
.fd
, printer
, printer
->name
,
1330 filetype
, filetype
? filetype
->super
: "none",
1331 filetype
? filetype
->type
: "none");
1334 * Check remote printing to non-shared printer...
1337 if (!printer
->shared
&&
1338 strcasecmp(con
->http
.hostname
, "localhost") &&
1339 strcasecmp(con
->http
.hostname
, ServerName
))
1341 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1342 _("The printer or class is not shared!"));
1350 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1352 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1354 send_http_error(con
, status
, printer
);
1357 else if (printer
->num_auth_info_required
> 0 &&
1358 strcmp(printer
->auth_info_required
[0], "none") &&
1359 !con
->username
[0] && !auth_info
)
1361 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1365 else if (auth_info
&& !con
->http
.tls
&&
1366 !httpAddrLocalhost(con
->http
.hostaddr
))
1369 * Require encryption of auth-info over non-local connections...
1372 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1375 #endif /* HAVE_SSL */
1378 * See if the printer is accepting jobs...
1381 if (!printer
->accepting
)
1383 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1384 _("Destination \"%s\" is not accepting jobs."),
1390 * Validate job template attributes; for now just document-format,
1391 * copies, number-up, and page-ranges...
1394 if (filetype
&& printer
->filetypes
&&
1395 !cupsArrayFind(printer
->filetypes
, filetype
))
1397 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1398 /* MIME media type string */
1401 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1404 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1405 _("Unsupported format \'%s\'!"), mimetype
);
1407 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1408 "document-format", NULL
, mimetype
);
1413 if ((attr
= ippFindAttribute(con
->request
, "copies",
1414 IPP_TAG_INTEGER
)) != NULL
)
1416 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1418 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1419 attr
->values
[0].integer
);
1420 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1421 "copies", attr
->values
[0].integer
);
1426 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1427 IPP_TAG_ZERO
)) != NULL
)
1429 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1430 attr
->value_tag
!= IPP_TAG_NAME
)
1432 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type!"));
1436 if (attr
->num_values
> 2)
1438 send_ipp_status(con
, IPP_BAD_REQUEST
,
1439 _("Too many job-sheets values (%d > 2)!"),
1444 for (i
= 0; i
< attr
->num_values
; i
++)
1445 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1446 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1448 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"!"),
1449 attr
->values
[i
].string
.text
);
1454 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1455 IPP_TAG_INTEGER
)) != NULL
)
1457 if (attr
->values
[0].integer
!= 1 &&
1458 attr
->values
[0].integer
!= 2 &&
1459 attr
->values
[0].integer
!= 4 &&
1460 attr
->values
[0].integer
!= 6 &&
1461 attr
->values
[0].integer
!= 9 &&
1462 attr
->values
[0].integer
!= 16)
1464 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1465 attr
->values
[0].integer
);
1466 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1467 "number-up", attr
->values
[0].integer
);
1472 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1473 IPP_TAG_RANGE
)) != NULL
)
1475 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1477 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1478 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1480 send_ipp_status(con
, IPP_BAD_REQUEST
,
1481 _("Bad page-ranges values %d-%d."),
1482 attr
->values
[i
].range
.lower
,
1483 attr
->values
[i
].range
.upper
);
1487 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1492 * Make sure we aren't over our limit...
1495 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1498 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1500 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1501 _("Too many active jobs."));
1505 if ((i
= check_quotas(con
, printer
)) < 0)
1507 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1512 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1517 * Create the job and set things up...
1520 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1521 IPP_TAG_INTEGER
)) != NULL
)
1522 priority
= attr
->values
[0].integer
;
1525 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1526 printer
->options
)) != NULL
)
1527 priority
= atoi(val
);
1531 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1535 if ((attr
= ippFindAttribute(con
->request
, "job-name",
1536 IPP_TAG_NAME
)) != NULL
)
1537 title
= attr
->values
[0].string
.text
;
1539 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1540 title
= "Untitled");
1542 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1544 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1545 _("Unable to add job for destination \"%s\"!"),
1550 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1551 CUPS_PRINTER_REMOTE
);
1552 job
->attrs
= con
->request
;
1554 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1556 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1558 add_job_uuid(con
, job
);
1559 apply_printer_defaults(printer
, job
);
1561 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1563 if (con
->username
[0])
1565 cupsdSetString(&job
->username
, con
->username
);
1568 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1572 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1573 "add_job: requesting-user-name=\"%s\"",
1574 attr
->values
[0].string
.text
);
1576 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1579 cupsdSetString(&job
->username
, "anonymous");
1582 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1583 "job-originating-user-name", NULL
, job
->username
);
1586 attr
->group_tag
= IPP_TAG_JOB
;
1587 _cupsStrFree(attr
->name
);
1588 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1591 if (con
->username
[0] || auth_info
)
1593 save_auth_info(con
, job
, auth_info
);
1596 * Remove the auth-info attribute from the attribute data...
1600 ippDeleteAttribute(job
->attrs
, auth_info
);
1603 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1604 IPP_TAG_ZERO
)) != NULL
)
1607 * Request contains a job-originating-host-name attribute; validate it...
1610 if (attr
->value_tag
!= IPP_TAG_NAME
||
1611 attr
->num_values
!= 1 ||
1612 strcmp(con
->http
.hostname
, "localhost"))
1615 * Can't override the value if we aren't connected via localhost.
1616 * Also, we can only have 1 value and it must be a name value.
1619 switch (attr
->value_tag
)
1621 case IPP_TAG_STRING
:
1622 case IPP_TAG_TEXTLANG
:
1623 case IPP_TAG_NAMELANG
:
1626 case IPP_TAG_KEYWORD
:
1628 case IPP_TAG_URISCHEME
:
1629 case IPP_TAG_CHARSET
:
1630 case IPP_TAG_LANGUAGE
:
1631 case IPP_TAG_MIMETYPE
:
1633 * Free old strings...
1636 for (i
= 0; i
< attr
->num_values
; i
++)
1638 _cupsStrFree(attr
->values
[i
].string
.text
);
1639 attr
->values
[i
].string
.text
= NULL
;
1640 if (attr
->values
[i
].string
.charset
)
1642 _cupsStrFree(attr
->values
[i
].string
.charset
);
1643 attr
->values
[i
].string
.charset
= NULL
;
1652 * Use the default connection hostname instead...
1655 attr
->value_tag
= IPP_TAG_NAME
;
1656 attr
->num_values
= 1;
1657 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1660 attr
->group_tag
= IPP_TAG_JOB
;
1665 * No job-originating-host-name attribute, so use the hostname from
1669 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1670 "job-originating-host-name", NULL
, con
->http
.hostname
);
1673 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1675 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1676 "time-at-processing", 0);
1677 attr
->value_tag
= IPP_TAG_NOVALUE
;
1678 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1679 "time-at-completed", 0);
1680 attr
->value_tag
= IPP_TAG_NOVALUE
;
1683 * Add remaining job attributes...
1686 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1687 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1688 "job-state", IPP_JOB_STOPPED
);
1689 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1690 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1691 "job-media-sheets-completed", 0);
1692 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1694 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1697 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1698 IPP_TAG_INTEGER
)) != NULL
)
1699 attr
->values
[0].integer
= 0;
1701 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1703 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1704 IPP_TAG_KEYWORD
)) == NULL
)
1705 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1708 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1709 printer
->options
)) == NULL
)
1712 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1713 "job-hold-until", NULL
, val
);
1715 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold") &&
1716 !(printer
->type
& CUPS_PRINTER_REMOTE
))
1719 * Hold job until specified time...
1722 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
1724 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1725 job
->state_value
= IPP_JOB_HELD
;
1727 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1729 job
->hold_until
= time(NULL
) + 60;
1730 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1731 job
->state_value
= IPP_JOB_HELD
;
1735 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1736 job
->state_value
= IPP_JOB_PENDING
;
1739 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1743 * Add job sheets options...
1746 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1747 IPP_TAG_ZERO
)) == NULL
)
1749 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1750 "Adding default job-sheets values \"%s,%s\"...",
1751 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1753 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1755 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1756 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1759 job
->job_sheets
= attr
;
1762 * Enforce classification level if set...
1767 cupsdLogMessage(CUPSD_LOG_INFO
,
1768 "Classification=\"%s\", ClassifyOverride=%d",
1769 Classification
? Classification
: "(null)",
1772 if (ClassifyOverride
)
1774 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1775 (attr
->num_values
== 1 ||
1776 !strcmp(attr
->values
[1].string
.text
, "none")))
1779 * Force the leading banner to have the classification on it...
1782 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1784 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1785 "job-sheets=\"%s,none\", "
1786 "job-originating-user-name=\"%s\"",
1787 Classification
, job
->username
);
1789 else if (attr
->num_values
== 2 &&
1790 strcmp(attr
->values
[0].string
.text
,
1791 attr
->values
[1].string
.text
) &&
1792 strcmp(attr
->values
[0].string
.text
, "none") &&
1793 strcmp(attr
->values
[1].string
.text
, "none"))
1796 * Can't put two different security markings on the same document!
1799 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1801 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1802 "job-sheets=\"%s,%s\", "
1803 "job-originating-user-name=\"%s\"",
1804 attr
->values
[0].string
.text
,
1805 attr
->values
[1].string
.text
, job
->username
);
1807 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1808 strcmp(attr
->values
[0].string
.text
, "none") &&
1809 (attr
->num_values
== 1 ||
1810 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1811 strcmp(attr
->values
[1].string
.text
, "none"))))
1813 if (attr
->num_values
== 1)
1814 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1815 "CLASSIFICATION OVERRIDDEN "
1816 "job-sheets=\"%s\", "
1817 "job-originating-user-name=\"%s\"",
1818 attr
->values
[0].string
.text
, job
->username
);
1820 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1821 "CLASSIFICATION OVERRIDDEN "
1822 "job-sheets=\"%s,%s\",fffff "
1823 "job-originating-user-name=\"%s\"",
1824 attr
->values
[0].string
.text
,
1825 attr
->values
[1].string
.text
, job
->username
);
1828 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1829 (attr
->num_values
== 1 ||
1830 strcmp(attr
->values
[1].string
.text
, Classification
)))
1833 * Force the banner to have the classification on it...
1836 if (attr
->num_values
> 1 &&
1837 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1839 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1840 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1844 if (attr
->num_values
== 1 ||
1845 strcmp(attr
->values
[0].string
.text
, "none"))
1846 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1848 if (attr
->num_values
> 1 &&
1849 strcmp(attr
->values
[1].string
.text
, "none"))
1850 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1853 if (attr
->num_values
> 1)
1854 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1855 "CLASSIFICATION FORCED "
1856 "job-sheets=\"%s,%s\", "
1857 "job-originating-user-name=\"%s\"",
1858 attr
->values
[0].string
.text
,
1859 attr
->values
[1].string
.text
, job
->username
);
1861 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1862 "CLASSIFICATION FORCED "
1863 "job-sheets=\"%s\", "
1864 "job-originating-user-name=\"%s\"",
1865 Classification
, job
->username
);
1870 * See if we need to add the starting sheet...
1873 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1875 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1876 attr
->values
[0].string
.text
);
1878 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1880 cupsdDeleteJob(job
);
1884 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1887 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1888 IPP_TAG_ZERO
)) != NULL
)
1892 * Fill in the response info...
1895 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1896 LocalPort
, job
->id
);
1898 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1901 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1903 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1905 add_job_state_reasons(con
, job
);
1907 con
->response
->request
.status
.status_code
= IPP_OK
;
1910 * Add any job subscriptions...
1913 add_job_subscriptions(con
, job
);
1916 * Set all but the first two attributes to the job attributes group...
1919 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1920 attr
->group_tag
= IPP_TAG_JOB
;
1923 * Fire the "job created" event...
1926 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1929 * Return the new job...
1937 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1938 * upon the job and printer state...
1942 add_job_state_reasons(
1943 cupsd_client_t
*con
, /* I - Client connection */
1944 cupsd_job_t
*job
) /* I - Job info */
1946 cupsd_printer_t
*dest
; /* Destination printer */
1949 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1950 con
, con
->http
.fd
, job
? job
->id
: 0);
1952 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1954 case IPP_JOB_PENDING
:
1955 dest
= cupsdFindDest(job
->dest
);
1957 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1958 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1959 "job-state-reasons", NULL
, "printer-stopped");
1961 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1962 "job-state-reasons", NULL
, "none");
1966 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1967 IPP_TAG_KEYWORD
) != NULL
||
1968 ippFindAttribute(job
->attrs
, "job-hold-until",
1969 IPP_TAG_NAME
) != NULL
)
1970 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1971 "job-state-reasons", NULL
, "job-hold-until-specified");
1973 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1974 "job-state-reasons", NULL
, "job-incoming");
1977 case IPP_JOB_PROCESSING
:
1978 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1979 "job-state-reasons", NULL
, "job-printing");
1982 case IPP_JOB_STOPPED
:
1983 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1984 "job-state-reasons", NULL
, "job-stopped");
1987 case IPP_JOB_CANCELED
:
1988 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1989 "job-state-reasons", NULL
, "job-canceled-by-user");
1992 case IPP_JOB_ABORTED
:
1993 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1994 "job-state-reasons", NULL
, "aborted-by-system");
1997 case IPP_JOB_COMPLETED
:
1998 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1999 "job-state-reasons", NULL
, "job-completed-successfully");
2006 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2010 add_job_subscriptions(
2011 cupsd_client_t
*con
, /* I - Client connection */
2012 cupsd_job_t
*job
) /* I - Newly created job */
2014 int i
; /* Looping var */
2015 ipp_attribute_t
*prev
, /* Previous attribute */
2016 *next
, /* Next attribute */
2017 *attr
; /* Current attribute */
2018 cupsd_subscription_t
*sub
; /* Subscription object */
2019 const char *recipient
, /* notify-recipient-uri */
2020 *pullmethod
; /* notify-pull-method */
2021 ipp_attribute_t
*user_data
; /* notify-user-data */
2022 int interval
; /* notify-time-interval */
2023 unsigned mask
; /* notify-events */
2027 * Find the first subscription group attribute; return if we have
2031 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2032 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2039 * Process the subscription attributes in the request...
2048 mask
= CUPSD_EVENT_NONE
;
2050 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2052 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2053 attr
->value_tag
== IPP_TAG_URI
)
2056 * Validate the recipient scheme against the ServerBin/notifier
2060 char notifier
[1024], /* Notifier filename */
2061 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2062 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2063 host
[HTTP_MAX_URI
], /* Host portion of URI */
2064 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2065 int port
; /* Port portion of URI */
2068 recipient
= attr
->values
[0].string
.text
;
2070 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2071 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2072 host
, sizeof(host
), &port
,
2073 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2075 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2076 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
2077 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2078 "notify-status-code", IPP_URI_SCHEME
);
2082 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2084 if (access(notifier
, X_OK
))
2086 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2087 _("notify-recipient-uri URI \"%s\" uses unknown "
2088 "scheme!"), recipient
);
2089 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2090 "notify-status-code", IPP_URI_SCHEME
);
2094 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2096 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2097 _("notify-recipient-uri URI \"%s\" is already used!"),
2099 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2100 "notify-status-code", IPP_ATTRIBUTES
);
2104 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2105 attr
->value_tag
== IPP_TAG_KEYWORD
)
2107 pullmethod
= attr
->values
[0].string
.text
;
2109 if (strcmp(pullmethod
, "ippget"))
2111 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2112 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
2113 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2114 "notify-status-code", IPP_ATTRIBUTES
);
2118 else if (!strcmp(attr
->name
, "notify-charset") &&
2119 attr
->value_tag
== IPP_TAG_CHARSET
&&
2120 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2121 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2123 send_ipp_status(con
, IPP_CHARSET
,
2124 _("Character set \"%s\" not supported!"),
2125 attr
->values
[0].string
.text
);
2128 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2129 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2130 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2132 send_ipp_status(con
, IPP_CHARSET
,
2133 _("Language \"%s\" not supported!"),
2134 attr
->values
[0].string
.text
);
2137 else if (!strcmp(attr
->name
, "notify-user-data") &&
2138 attr
->value_tag
== IPP_TAG_STRING
)
2140 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2142 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2143 _("The notify-user-data value is too large "
2144 "(%d > 63 octets)!"),
2145 attr
->values
[0].unknown
.length
);
2151 else if (!strcmp(attr
->name
, "notify-events") &&
2152 attr
->value_tag
== IPP_TAG_KEYWORD
)
2154 for (i
= 0; i
< attr
->num_values
; i
++)
2155 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2157 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2159 send_ipp_status(con
, IPP_BAD_REQUEST
,
2160 _("The notify-lease-duration attribute cannot be "
2161 "used with job subscriptions."));
2164 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2165 attr
->value_tag
== IPP_TAG_INTEGER
)
2166 interval
= attr
->values
[0].integer
;
2171 if (!recipient
&& !pullmethod
)
2174 if (mask
== CUPSD_EVENT_NONE
)
2175 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2177 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2178 recipient
, 0)) != NULL
)
2180 sub
->interval
= interval
;
2182 cupsdSetString(&sub
->owner
, job
->username
);
2186 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2187 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2188 sub
->user_data_len
);
2191 ippAddSeparator(con
->response
);
2192 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2193 "notify-subscription-id", sub
->id
);
2200 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2203 * Remove all of the subscription attributes from the job request...
2205 * TODO: Optimize this since subscription groups have to come at the
2206 * end of the request...
2209 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2213 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2214 attr
->group_tag
== IPP_TAG_ZERO
)
2217 * Free and remove this attribute...
2225 job
->attrs
->attrs
= next
;
2231 job
->attrs
->last
= prev
;
2232 job
->attrs
->current
= prev
;
2237 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2239 * See RFC 4122 for the definition of UUIDs and the format.
2243 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2244 cupsd_job_t
*job
) /* I - Job */
2246 char uuid
[1024]; /* job-uuid string */
2247 _cups_md5_state_t md5state
; /* MD5 state */
2248 unsigned char md5sum
[16]; /* MD5 digest/sum */
2252 * First see if the job already has a job-uuid attribute; if so, return...
2255 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2259 * No job-uuid attribute, so build a version 3 UUID with the local job
2260 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2261 * the ServerName, server name and port that the client connected to,
2262 * and local job ID...
2265 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2266 con
->serverport
, job
->id
);
2268 _cupsMD5Init(&md5state
);
2269 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2270 _cupsMD5Finish(&md5state
, md5sum
);
2273 * Format the UUID URI using the MD5 sum and job ID.
2276 snprintf(uuid
, sizeof(uuid
),
2277 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2278 "%02x%02x%02x%02x%02x%02x",
2279 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2280 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2281 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2282 md5sum
[14], md5sum
[15]);
2284 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2289 * 'add_printer()' - Add a printer to the system.
2293 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2294 ipp_attribute_t
*uri
) /* I - URI of printer */
2296 http_status_t status
; /* Policy status */
2297 int i
; /* Looping var */
2298 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2299 username
[HTTP_MAX_URI
], /* Username portion of URI */
2300 host
[HTTP_MAX_URI
], /* Host portion of URI */
2301 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2302 int port
; /* Port portion of URI */
2303 cupsd_printer_t
*printer
; /* Printer/class */
2304 ipp_attribute_t
*attr
; /* Printer attribute */
2305 cups_file_t
*fp
; /* Script/PPD file */
2306 char line
[1024]; /* Line from file... */
2307 char srcfile
[1024], /* Source Script/PPD file */
2308 dstfile
[1024]; /* Destination Script/PPD file */
2309 int modify
; /* Non-zero if we are modifying */
2310 char newname
[IPP_MAX_NAME
]; /* New printer name */
2311 int need_restart_job
; /* Need to restart job? */
2312 int set_device_uri
, /* Did we set the device URI? */
2313 set_port_monitor
; /* Did we set the port monitor? */
2316 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2317 con
->http
.fd
, uri
->values
[0].string
.text
);
2320 * Do we have a valid URI?
2323 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2324 sizeof(scheme
), username
, sizeof(username
), host
,
2325 sizeof(host
), &port
, resource
, sizeof(resource
));
2327 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2330 * No, return an error...
2333 send_ipp_status(con
, IPP_BAD_REQUEST
,
2334 _("The printer-uri must be of the form "
2335 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2340 * Do we have a valid printer name?
2343 if (!validate_name(resource
+ 10))
2346 * No, return an error...
2349 send_ipp_status(con
, IPP_BAD_REQUEST
,
2350 _("The printer-uri \"%s\" contains invalid characters."),
2351 uri
->values
[0].string
.text
);
2356 * See if the printer already exists; if not, create a new printer...
2359 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2362 * Printer doesn't exist; see if we have a class of the same name...
2365 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2366 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2369 * Yes, return an error...
2372 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2373 _("A class named \"%s\" already exists!"),
2379 * No, check the default policy then add the printer...
2382 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2384 send_http_error(con
, status
, NULL
);
2388 printer
= cupsdAddPrinter(resource
+ 10);
2391 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2394 * Check the default policy, then rename the implicit printer to
2395 * "AnyPrinter" or delete it...
2398 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2400 send_http_error(con
, status
, NULL
);
2404 if (ImplicitAnyClasses
)
2406 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2407 cupsdRenamePrinter(printer
, newname
);
2410 cupsdDeletePrinter(printer
, 1);
2413 * Add the printer as a new local printer...
2416 printer
= cupsdAddPrinter(resource
+ 10);
2419 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2422 * Check the default policy, then rename the remote printer to
2423 * "Printer@server"...
2426 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2428 send_http_error(con
, status
, NULL
);
2432 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2434 cupsdRenamePrinter(printer
, newname
);
2437 * Add the printer as a new local printer...
2440 printer
= cupsdAddPrinter(resource
+ 10);
2443 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2446 send_http_error(con
, status
, printer
);
2453 * Look for attributes and copy them over as needed...
2456 need_restart_job
= 0;
2458 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2459 IPP_TAG_TEXT
)) != NULL
)
2460 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2462 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2463 IPP_TAG_TEXT
)) != NULL
)
2464 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2468 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2469 IPP_TAG_URI
)) != NULL
)
2472 * Do we have a valid device URI?
2475 http_uri_status_t uri_status
; /* URI separation status */
2476 char old_device_uri
[1024];
2477 /* Old device URI */
2480 need_restart_job
= 1;
2482 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2483 attr
->values
[0].string
.text
,
2484 scheme
, sizeof(scheme
),
2485 username
, sizeof(username
),
2486 host
, sizeof(host
), &port
,
2487 resource
, sizeof(resource
));
2489 if (uri_status
< HTTP_URI_OK
)
2491 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"!"),
2492 attr
->values
[0].string
.text
);
2493 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2494 "add_printer: httpSeparateURI returned %d", uri_status
);
2498 if (!strcmp(scheme
, "file"))
2501 * See if the administrator has enabled file devices...
2504 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2507 * File devices are disabled and the URL is not file:/dev/null...
2510 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2511 _("File device URIs have been disabled! "
2512 "To enable, see the FileDevice directive in "
2513 "\"%s/cupsd.conf\"."),
2521 * See if the backend exists and is executable...
2524 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2525 if (access(srcfile
, X_OK
))
2528 * Could not find device in list!
2531 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\"!"),
2537 if (printer
->sanitized_device_uri
)
2538 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2539 sizeof(old_device_uri
));
2541 old_device_uri
[0] = '\0';
2543 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2545 cupsdLogMessage(CUPSD_LOG_INFO
,
2546 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2547 printer
->name
, printer
->sanitized_device_uri
,
2553 set_port_monitor
= 0;
2555 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2556 IPP_TAG_NAME
)) != NULL
)
2558 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2561 need_restart_job
= 1;
2563 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2567 for (i
= 0; i
< supported
->num_values
; i
++)
2568 if (!strcmp(supported
->values
[i
].string
.text
,
2569 attr
->values
[0].string
.text
))
2573 if (!supported
|| i
>= supported
->num_values
)
2575 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"!"),
2576 attr
->values
[0].string
.text
);
2580 cupsdLogMessage(CUPSD_LOG_INFO
,
2581 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2582 printer
->name
, attr
->values
[0].string
.text
,
2583 printer
->port_monitor
? printer
->port_monitor
: "none");
2585 if (strcmp(attr
->values
[0].string
.text
, "none"))
2586 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2588 cupsdClearString(&printer
->port_monitor
);
2590 set_port_monitor
= 1;
2593 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2594 IPP_TAG_BOOLEAN
)) != NULL
)
2596 cupsdLogMessage(CUPSD_LOG_INFO
,
2597 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2598 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2600 printer
->accepting
= attr
->values
[0].boolean
;
2601 cupsdAddPrinterHistory(printer
);
2604 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2605 IPP_TAG_BOOLEAN
)) != NULL
)
2607 if (printer
->shared
&& !attr
->values
[0].boolean
)
2608 cupsdDeregisterPrinter(printer
, 1);
2610 cupsdLogMessage(CUPSD_LOG_INFO
,
2611 "Setting %s printer-is-shared to %d (was %d.)",
2612 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2614 printer
->shared
= attr
->values
[0].boolean
;
2617 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2618 IPP_TAG_ENUM
)) != NULL
)
2620 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2621 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2623 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d!"),
2624 attr
->values
[0].integer
);
2628 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2629 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2631 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2632 cupsdStopPrinter(printer
, 0);
2635 need_restart_job
= 1;
2636 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2639 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2640 IPP_TAG_TEXT
)) != NULL
)
2642 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2643 sizeof(printer
->state_message
));
2644 cupsdAddPrinterHistory(printer
);
2647 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2648 IPP_TAG_KEYWORD
)) != NULL
)
2650 if (attr
->num_values
>
2651 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2653 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2654 _("Too many printer-state-reasons values (%d > %d)!"),
2656 (int)(sizeof(printer
->reasons
) /
2657 sizeof(printer
->reasons
[0])));
2661 for (i
= 0; i
< printer
->num_reasons
; i
++)
2662 _cupsStrFree(printer
->reasons
[i
]);
2664 printer
->num_reasons
= 0;
2665 for (i
= 0; i
< attr
->num_values
; i
++)
2667 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2670 printer
->reasons
[printer
->num_reasons
] =
2671 _cupsStrRetain(attr
->values
[i
].string
.text
);
2673 if (!strcmp(printer
->reasons
[printer
->num_reasons
], "paused") &&
2674 printer
->state
!= IPP_PRINTER_STOPPED
)
2676 cupsdLogMessage(CUPSD_LOG_INFO
,
2677 "Setting %s printer-state to %d (was %d.)",
2678 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2679 cupsdStopPrinter(printer
, 0);
2682 printer
->num_reasons
++;
2685 if (PrintcapFormat
== PRINTCAP_PLIST
)
2686 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2689 set_printer_defaults(con
, printer
);
2691 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2692 IPP_TAG_KEYWORD
)) != NULL
)
2693 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2696 * See if we have all required attributes...
2699 if (!printer
->device_uri
)
2700 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2703 * See if we have an interface script or PPD file attached to the request...
2708 need_restart_job
= 1;
2710 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2712 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2715 * Yes; get the first line from it...
2719 cupsFileGets(fp
, line
, sizeof(line
));
2723 * Then see what kind of file it is...
2726 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2729 if (!strncmp(line
, "*PPD-Adobe", 10))
2732 * The new file is a PPD file, so remove any old interface script
2733 * that might be lying around...
2741 * This must be an interface script, so move the file over to the
2742 * interfaces directory and make it executable...
2745 if (copy_file(srcfile
, dstfile
))
2747 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2748 _("Unable to copy interface script - %s!"),
2753 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2754 "Copied interface script successfully!");
2755 chmod(dstfile
, 0755);
2758 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2761 if (!strncmp(line
, "*PPD-Adobe", 10))
2764 * The new file is a PPD file, so move the file over to the
2765 * ppd directory and make it readable by all...
2768 if (copy_file(srcfile
, dstfile
))
2770 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2771 _("Unable to copy PPD file - %s!"),
2776 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2777 "Copied PPD file successfully!");
2778 chmod(dstfile
, 0644);
2782 * (Re)register color profiles...
2787 apple_unregister_profiles(printer
);
2788 apple_register_profiles(printer
);
2790 #endif /* __APPLE__ */
2795 * This must be an interface script, so remove any old PPD file that
2796 * may be lying around...
2803 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2804 IPP_TAG_NAME
)) != NULL
)
2806 need_restart_job
= 1;
2808 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2811 * Raw driver, remove any existing PPD or interface script files.
2814 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2818 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2828 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2832 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2835 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2837 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file!"));
2841 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2842 "Copied PPD file successfully!");
2843 chmod(dstfile
, 0644);
2847 * (Re)register color profiles...
2852 apple_unregister_profiles(printer
);
2853 apple_register_profiles(printer
);
2855 #endif /* __APPLE__ */
2860 * If we set the device URI but not the port monitor, check which port
2861 * monitor to use by default...
2864 if (set_device_uri
&& !set_port_monitor
)
2866 ppd_file_t
*ppd
; /* PPD file */
2867 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2870 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2871 sizeof(scheme
), username
, sizeof(username
), host
,
2872 sizeof(host
), &port
, resource
, sizeof(resource
));
2874 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2876 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2878 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2880 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2881 if (!strcmp(scheme
, ppdattr
->spec
))
2883 cupsdLogMessage(CUPSD_LOG_INFO
,
2884 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2885 printer
->name
, ppdattr
->value
,
2886 printer
->port_monitor
? printer
->port_monitor
2889 if (strcmp(ppdattr
->value
, "none"))
2890 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2892 cupsdClearString(&printer
->port_monitor
);
2902 * Update the printer attributes and return...
2905 cupsdSetPrinterAttrs(printer
);
2906 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2908 if (need_restart_job
&& printer
->job
)
2913 * Stop the current job and then restart it below...
2916 job
= (cupsd_job_t
*)printer
->job
;
2918 cupsdStopJob(job
, 1);
2920 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2921 job
->state_value
= IPP_JOB_PENDING
;
2924 if (need_restart_job
)
2927 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2931 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2932 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2935 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2936 printer
->name
, get_username(con
));
2940 cupsdAddPrinterHistory(printer
);
2942 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2943 "New printer \"%s\" added by \"%s\".", printer
->name
,
2946 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2947 printer
->name
, get_username(con
));
2950 con
->response
->request
.status
.status_code
= IPP_OK
;
2955 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2956 * based upon the printer state...
2960 add_printer_state_reasons(
2961 cupsd_client_t
*con
, /* I - Client connection */
2962 cupsd_printer_t
*p
) /* I - Printer info */
2964 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2965 "add_printer_state_reasons(%p[%d], %p[%s])",
2966 con
, con
->http
.fd
, p
, p
->name
);
2968 if (p
->num_reasons
== 0)
2969 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2970 "printer-state-reasons", NULL
,
2971 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
2973 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2974 "printer-state-reasons", p
->num_reasons
, NULL
,
2975 (const char * const *)p
->reasons
);
2980 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2981 * the specified printer or class.
2985 add_queued_job_count(
2986 cupsd_client_t
*con
, /* I - Client connection */
2987 cupsd_printer_t
*p
) /* I - Printer or class */
2989 int count
; /* Number of jobs on destination */
2992 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2993 con
, con
->http
.fd
, p
, p
->name
);
2995 count
= cupsdGetPrinterJobCount(p
->name
);
2997 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2998 "queued-job-count", count
);
3004 * 'apple_init_profile()' - Initialize a color profile.
3009 ppd_file_t
*ppd
, /* I - PPD file */
3010 cups_array_t
*languages
, /* I - Languages in the PPD file */
3011 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3012 unsigned id
, /* I - Profile ID */
3013 const char *name
, /* I - Profile name */
3014 const char *text
, /* I - Profile UI text */
3015 const char *iccfile
) /* I - ICC filename */
3017 char url
[1024]; /* URL for profile filename */
3018 CFMutableDictionaryRef dict
; /* Dictionary for name */
3019 char *language
; /* Current language */
3020 ppd_attr_t
*attr
; /* Profile attribute */
3021 CFStringRef cflang
, /* Language string */
3022 cftext
; /* Localized text */
3026 * Build the profile name dictionary...
3029 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3030 &kCFTypeDictionaryKeyCallBacks
,
3031 &kCFTypeDictionaryValueCallBacks
);
3033 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3034 kCFStringEncodingUTF8
);
3038 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
3045 * Find localized names for the color profiles...
3048 cupsArraySave(ppd
->sorted_attrs
);
3050 for (language
= (char *)cupsArrayFirst(languages
);
3052 language
= (char *)cupsArrayNext(languages
))
3056 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3058 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3061 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3063 if (attr
&& attr
->text
[0])
3065 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3066 kCFStringEncodingUTF8
);
3067 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3068 kCFStringEncodingUTF8
);
3070 if (cflang
&& cftext
)
3071 CFDictionarySetValue(dict
, cflang
, cftext
);
3081 cupsArrayRestore(ppd
->sorted_attrs
);
3085 * Fill in the profile data...
3089 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3092 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3093 profile
->profileID
= id
;
3094 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3095 profile
->profileName
= dict
;
3098 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3099 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3104 * 'apple_register_profiles()' - Register color profiles for a printer.
3108 apple_register_profiles(
3109 cupsd_printer_t
*p
) /* I - Printer */
3111 int i
; /* Looping var */
3112 char ppdfile
[1024], /* PPD filename */
3113 iccfile
[1024], /* ICC filename */
3114 selector
[PPD_MAX_NAME
];
3115 /* Profile selection string */
3116 ppd_file_t
*ppd
; /* PPD file */
3117 ppd_attr_t
*attr
, /* Profile attributes */
3118 *profileid_attr
,/* cupsProfileID attribute */
3119 *q1_attr
, /* ColorModel (or other) qualifier */
3120 *q2_attr
, /* MediaType (or other) qualifier */
3121 *q3_attr
; /* Resolution (or other) qualifier */
3122 char q_keyword
[PPD_MAX_NAME
];
3123 /* Qualifier keyword */
3124 const char *q1_choice
, /* ColorModel (or other) choice */
3125 *q2_choice
, /* MediaType (or other) choice */
3126 *q3_choice
; /* Resolution (or other) choice */
3127 const char *profile_key
; /* Profile keyword */
3128 ppd_option_t
*cm_option
; /* Color model option */
3129 ppd_choice_t
*cm_choice
; /* Color model choice */
3130 int num_profiles
; /* Number of profiles */
3131 CMError error
; /* Last error */
3132 unsigned device_id
, /* Printer device ID */
3133 profile_id
, /* Profile ID */
3134 default_profile_id
= 0;
3135 /* Default profile ID */
3136 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3137 CFStringRef printer_name
; /* Printer name string */
3138 CMDeviceScope scope
= /* Scope of the registration */
3140 kCFPreferencesAnyUser
,
3141 kCFPreferencesCurrentHost
3143 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3144 CMDeviceProfileInfo
*profile
; /* Current profile */
3145 cups_array_t
*languages
; /* Languages array */
3149 * Make sure ColorSync is available...
3152 if (CMRegisterColorDevice
== NULL
)
3156 * Try opening the PPD file for this printer...
3159 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3160 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3164 * See if we have any profiles...
3167 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3168 profile_key
= "APTiogaProfile";
3171 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3172 profile_key
= "cupsICCProfile";
3175 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3176 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3178 if (attr
->value
[0] != '/')
3179 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3182 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3184 if (access(iccfile
, 0))
3192 * If we have profiles, add them...
3195 if (num_profiles
> 0)
3197 if (profile_key
[0] == 'A')
3200 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3204 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3206 default_profile_id
= atoi(attr
->value
);
3208 q1_choice
= q2_choice
= q3_choice
= NULL
;
3213 * For CUPS PPDs, figure out the default profile selector values...
3216 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3217 attr
->value
&& attr
->value
[0])
3219 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3220 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3222 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3223 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3225 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3226 q1_choice
= q1_attr
->value
;
3230 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3231 attr
->value
&& attr
->value
[0])
3233 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3234 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3237 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3239 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3240 q2_choice
= q2_attr
->value
;
3244 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3245 attr
->value
&& attr
->value
[0])
3247 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3248 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3251 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3253 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3254 q3_choice
= q3_attr
->value
;
3260 * Build the array of profiles...
3262 * Note: This calloc actually requests slightly more memory than needed.
3265 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3267 cupsdLogMessage(CUPSD_LOG_ERROR
,
3268 "Unable to allocate memory for %d profiles!",
3274 profiles
->profileCount
= num_profiles
;
3275 languages
= _ppdGetLanguages(ppd
);
3277 for (profile
= profiles
->profiles
,
3278 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3280 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3281 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3284 * Add this profile...
3287 if (attr
->value
[0] != '/')
3288 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3291 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3293 if (access(iccfile
, 0))
3296 if (profile_key
[0] == 'c')
3298 cupsArraySave(ppd
->sorted_attrs
);
3300 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3301 attr
->spec
)) != NULL
&&
3302 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3303 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3305 profile_id
= _ppdHashName(attr
->spec
);
3307 cupsArrayRestore(ppd
->sorted_attrs
);
3310 profile_id
= atoi(attr
->spec
);
3312 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3313 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3318 * See if this is the default profile...
3321 if (!default_profile_id
)
3327 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3328 q1_choice
, q2_choice
, q3_choice
);
3329 if (!strcmp(selector
, attr
->spec
))
3330 default_profile_id
= profile_id
;
3333 if (!default_profile_id
)
3335 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3337 if (!strcmp(selector
, attr
->spec
))
3338 default_profile_id
= profile_id
;
3342 if (!default_profile_id
&& q3_choice
)
3344 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3346 if (!strcmp(selector
, attr
->spec
))
3347 default_profile_id
= profile_id
;
3350 if (!default_profile_id
)
3352 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3353 if (!strcmp(selector
, attr
->spec
))
3354 default_profile_id
= profile_id
;
3359 _ppdFreeLanguages(languages
);
3361 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3364 * Extract profiles from ColorModel option...
3367 const char *profile_name
; /* Name of generic profile */
3370 num_profiles
= cm_option
->num_choices
;
3372 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3374 cupsdLogMessage(CUPSD_LOG_ERROR
,
3375 "Unable to allocate memory for %d profiles!",
3381 profiles
->profileCount
= num_profiles
;
3383 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3384 cm_choice
= cm_option
->choices
;
3386 i
--, cm_choice
++, profile
++)
3388 if (!strcmp(cm_choice
->choice
, "Gray") ||
3389 !strcmp(cm_choice
->choice
, "Black"))
3390 profile_name
= "Gray";
3391 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3392 !strcmp(cm_choice
->choice
, "CMY"))
3393 profile_name
= "RGB";
3394 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3395 !strcmp(cm_choice
->choice
, "KCMY"))
3396 profile_name
= "CMYK";
3398 profile_name
= "DeviceN";
3400 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3401 profile_id
= _ppdHashName(selector
);
3403 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3404 cm_choice
->text
, NULL
);
3406 if (cm_choice
->marked
)
3407 default_profile_id
= profile_id
;
3413 * Use the default colorspace...
3416 num_profiles
= 1 + ppd
->colorspace
!= PPD_CS_GRAY
;
3418 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3420 cupsdLogMessage(CUPSD_LOG_ERROR
,
3421 "Unable to allocate memory for %d profiles!",
3427 profiles
->profileCount
= num_profiles
;
3429 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3430 "Gray", "Gray", NULL
);
3432 switch (ppd
->colorspace
)
3436 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3437 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3441 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3442 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3446 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3447 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3456 if (num_profiles
> 0)
3459 * Make sure we have a default profile ID...
3462 if (!default_profile_id
)
3463 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3466 * Get the device ID hash and pathelogical name dictionary.
3469 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3472 device_id
= _ppdHashName(p
->name
);
3473 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3474 &kCFTypeDictionaryKeyCallBacks
,
3475 &kCFTypeDictionaryValueCallBacks
);
3476 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3477 p
->name
, kCFStringEncodingUTF8
);
3479 if (device_name
&& printer_name
)
3481 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3484 * Register the device with ColorSync...
3487 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3488 device_name
, &scope
);
3491 * Register the profiles...
3495 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3496 default_profile_id
, profiles
);
3506 cupsdLogMessage(CUPSD_LOG_ERROR
,
3507 "Unable to register ICC color profiles for \"%s\" - %d",
3508 p
->name
, (int)error
);
3510 for (profile
= profiles
->profiles
;
3512 profile
++, num_profiles
--)
3513 CFRelease(profile
->profileName
);
3518 CFRelease(printer_name
);
3521 CFRelease(device_name
);
3529 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3534 apple_unregister_profiles(
3535 cupsd_printer_t
*p
) /* I - Printer */
3538 * Make sure ColorSync is available...
3541 if (CMUnregisterColorDevice
!= NULL
)
3542 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3544 #endif /* __APPLE__ */
3547 * 'apply_printer_defaults()' - Apply printer default options to a job.
3551 apply_printer_defaults(
3552 cupsd_printer_t
*printer
, /* I - Printer */
3553 cupsd_job_t
*job
) /* I - Job */
3555 int i
, /* Looping var */
3556 num_options
; /* Number of default options */
3557 cups_option_t
*options
, /* Default options */
3558 *option
; /* Current option */
3562 * Collect all of the default options and add the missing ones to the
3566 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3567 option
= printer
->options
;
3570 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3572 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3577 * Encode these options as attributes in the job object...
3580 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3581 cupsFreeOptions(num_options
, options
);
3586 * 'authenticate_job()' - Set job authentication info.
3590 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3591 ipp_attribute_t
*uri
) /* I - Job URI */
3593 ipp_attribute_t
*attr
, /* job-id attribute */
3594 *auth_info
; /* auth-info attribute */
3595 int jobid
; /* Job ID */
3596 cupsd_job_t
*job
; /* Current job */
3597 char scheme
[HTTP_MAX_URI
],
3598 /* Method portion of URI */
3599 username
[HTTP_MAX_URI
],
3600 /* Username portion of URI */
3602 /* Host portion of URI */
3603 resource
[HTTP_MAX_URI
];
3604 /* Resource portion of URI */
3605 int port
; /* Port portion of URI */
3608 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3609 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3612 * Start with "everything is OK" status...
3615 con
->response
->request
.status
.status_code
= IPP_OK
;
3618 * See if we have a job URI or a printer URI...
3621 if (!strcmp(uri
->name
, "printer-uri"))
3624 * Got a printer URI; see if we also have a job-id attribute...
3627 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3628 IPP_TAG_INTEGER
)) == NULL
)
3630 send_ipp_status(con
, IPP_BAD_REQUEST
,
3631 _("Got a printer-uri attribute but no job-id!"));
3635 jobid
= attr
->values
[0].integer
;
3640 * Got a job URI; parse it to get the job ID...
3643 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3644 sizeof(scheme
), username
, sizeof(username
), host
,
3645 sizeof(host
), &port
, resource
, sizeof(resource
));
3647 if (strncmp(resource
, "/jobs/", 6))
3653 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
3654 uri
->values
[0].string
.text
);
3658 jobid
= atoi(resource
+ 6);
3662 * See if the job exists...
3665 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3668 * Nope - return a "not found" error...
3671 send_ipp_status(con
, IPP_NOT_FOUND
,
3672 _("Job #%d does not exist!"), jobid
);
3677 * See if the job has been completed...
3680 if (job
->state_value
!= IPP_JOB_HELD
)
3683 * Return a "not-possible" error...
3686 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3687 _("Job #%d is not held for authentication!"),
3693 * See if we have already authenticated...
3696 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3698 if (!con
->username
[0] && !auth_info
)
3700 cupsd_printer_t
*printer
; /* Job destination */
3704 * No auth data. If we need to authenticate via Kerberos, send a
3705 * HTTP auth challenge, otherwise just return an IPP error...
3708 printer
= cupsdFindDest(job
->dest
);
3710 if (printer
&& printer
->num_auth_info_required
> 0 &&
3711 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3712 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3714 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3715 _("No authentication information provided!"));
3720 * See if the job is owned by the requesting user...
3723 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3725 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
3730 * Save the authentication information for this job...
3733 save_auth_info(con
, job
, auth_info
);
3736 * Reset the job-hold-until value to "no-hold"...
3739 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3740 IPP_TAG_KEYWORD
)) == NULL
)
3741 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3745 attr
->value_tag
= IPP_TAG_KEYWORD
;
3746 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3750 * Release the job and return...
3753 cupsdReleaseJob(job
);
3755 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3760 * 'cancel_all_jobs()' - Cancel all print jobs.
3764 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3765 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3767 http_status_t status
; /* Policy status */
3768 cups_ptype_t dtype
; /* Destination type */
3769 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3770 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3771 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3772 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3773 int port
; /* Port portion of URI */
3774 ipp_attribute_t
*attr
; /* Attribute in request */
3775 const char *username
; /* Username */
3776 int purge
; /* Purge? */
3777 cupsd_printer_t
*printer
; /* Printer */
3780 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3781 con
->http
.fd
, uri
->values
[0].string
.text
);
3784 * See if we have a printer URI...
3787 if (strcmp(uri
->name
, "printer-uri"))
3789 send_ipp_status(con
, IPP_BAD_REQUEST
,
3790 _("The printer-uri attribute is required!"));
3795 * Get the username (if any) for the jobs we want to cancel (only if
3796 * "my-jobs" is specified...
3799 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3800 IPP_TAG_BOOLEAN
)) != NULL
&&
3801 attr
->values
[0].boolean
)
3803 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3804 IPP_TAG_NAME
)) != NULL
)
3805 username
= attr
->values
[0].string
.text
;
3808 send_ipp_status(con
, IPP_BAD_REQUEST
,
3809 _("Missing requesting-user-name attribute!"));
3817 * Look for the "purge-jobs" attribute...
3820 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3821 IPP_TAG_BOOLEAN
)) != NULL
)
3822 purge
= attr
->values
[0].boolean
;
3827 * And if the destination is valid...
3830 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3836 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3837 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3838 hostname
, sizeof(hostname
), &port
,
3839 resource
, sizeof(resource
));
3841 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3842 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3844 send_ipp_status(con
, IPP_NOT_FOUND
,
3845 _("The printer or class was not found."));
3853 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3855 send_http_error(con
, status
, NULL
);
3860 * Cancel all jobs on all printers...
3863 cupsdCancelJobs(NULL
, username
, purge
);
3865 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3866 purge
? "purged" : "canceled", get_username(con
));
3874 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3877 send_http_error(con
, status
, printer
);
3882 * Cancel all of the jobs on the named printer...
3885 cupsdCancelJobs(printer
->name
, username
, purge
);
3887 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3888 printer
->name
, purge
? "purged" : "canceled",
3892 con
->response
->request
.status
.status_code
= IPP_OK
;
3897 * 'cancel_job()' - Cancel a print job.
3901 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3902 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3904 ipp_attribute_t
*attr
; /* Current attribute */
3905 int jobid
; /* Job ID */
3906 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3907 username
[HTTP_MAX_URI
], /* Username portion of URI */
3908 host
[HTTP_MAX_URI
], /* Host portion of URI */
3909 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3910 int port
; /* Port portion of URI */
3911 cupsd_job_t
*job
; /* Job information */
3912 cups_ptype_t dtype
; /* Destination type (printer/class) */
3913 cupsd_printer_t
*printer
; /* Printer data */
3914 int purge
; /* Purge the job? */
3917 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3918 con
->http
.fd
, uri
->values
[0].string
.text
);
3921 * See if we have a job URI or a printer URI...
3924 if (!strcmp(uri
->name
, "printer-uri"))
3927 * Got a printer URI; see if we also have a job-id attribute...
3930 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3931 IPP_TAG_INTEGER
)) == NULL
)
3933 send_ipp_status(con
, IPP_BAD_REQUEST
,
3934 _("Got a printer-uri attribute but no job-id!"));
3938 if ((jobid
= attr
->values
[0].integer
) == 0)
3941 * Find the current job on the specified printer...
3944 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3950 send_ipp_status(con
, IPP_NOT_FOUND
,
3951 _("The printer or class was not found."));
3956 * See if the printer is currently printing a job...
3960 jobid
= ((cupsd_job_t
*)printer
->job
)->id
;
3964 * No, see if there are any pending jobs...
3967 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3969 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3970 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3971 !strcasecmp(job
->dest
, printer
->name
))
3978 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3980 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3981 if (job
->state_value
== IPP_JOB_STOPPED
&&
3982 !strcasecmp(job
->dest
, printer
->name
))
3989 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s!"),
4000 * Got a job URI; parse it to get the job ID...
4003 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4004 sizeof(scheme
), username
, sizeof(username
), host
,
4005 sizeof(host
), &port
, resource
, sizeof(resource
));
4007 if (strncmp(resource
, "/jobs/", 6))
4013 send_ipp_status(con
, IPP_BAD_REQUEST
,
4014 _("Bad job-uri attribute \"%s\"!"),
4015 uri
->values
[0].string
.text
);
4019 jobid
= atoi(resource
+ 6);
4023 * Look for the "purge-job" attribute...
4026 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4027 IPP_TAG_BOOLEAN
)) != NULL
)
4028 purge
= attr
->values
[0].boolean
;
4033 * See if the job exists...
4036 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4039 * Nope - return a "not found" error...
4042 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
4047 * See if the job is owned by the requesting user...
4050 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4052 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
4057 * See if the job is already completed, canceled, or aborted; if so,
4058 * we can't cancel...
4061 if (job
->state_value
>= IPP_JOB_CANCELED
&& !purge
)
4063 switch (job
->state_value
)
4065 case IPP_JOB_CANCELED
:
4066 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4067 _("Job #%d is already canceled - can\'t cancel."),
4071 case IPP_JOB_ABORTED
:
4072 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4073 _("Job #%d is already aborted - can\'t cancel."),
4078 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4079 _("Job #%d is already completed - can\'t cancel."),
4088 * Cancel the job and return...
4091 cupsdCancelJob(job
, purge
, IPP_JOB_CANCELED
);
4095 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4098 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4101 con
->response
->request
.status
.status_code
= IPP_OK
;
4106 * 'cancel_subscription()' - Cancel a subscription.
4110 cancel_subscription(
4111 cupsd_client_t
*con
, /* I - Client connection */
4112 int sub_id
) /* I - Subscription ID */
4114 http_status_t status
; /* Policy status */
4115 cupsd_subscription_t
*sub
; /* Subscription */
4118 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4119 "cancel_subscription(con=%p[%d], sub_id=%d)",
4120 con
, con
->http
.fd
, sub_id
);
4123 * Is the subscription ID valid?
4126 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4129 * Bad subscription ID...
4132 send_ipp_status(con
, IPP_NOT_FOUND
,
4133 _("notify-subscription-id %d no good!"), sub_id
);
4141 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4143 con
, sub
->owner
)) != HTTP_OK
)
4145 send_http_error(con
, status
, sub
->dest
);
4150 * Cancel the subscription...
4153 cupsdDeleteSubscription(sub
, 1);
4155 con
->response
->request
.status
.status_code
= IPP_OK
;
4160 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4163 static int /* O - 1 if OK, 0 if not */
4164 check_rss_recipient(
4165 const char *recipient
) /* I - Recipient URI */
4167 cupsd_subscription_t
*sub
; /* Current subscription */
4170 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4172 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4176 * Compare the URIs up to the first ?...
4179 const char *r1
, *r2
;
4181 for (r1
= recipient
, r2
= sub
->recipient
;
4182 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4194 * 'check_quotas()' - Check quotas for a printer and user.
4197 static int /* O - 1 if OK, 0 if not */
4198 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4199 cupsd_printer_t
*p
) /* I - Printer or class */
4201 int i
; /* Looping var */
4202 char username
[33]; /* Username */
4203 cupsd_quota_t
*q
; /* Quota data */
4204 #ifdef HAVE_MBR_UID_TO_UUID
4206 * Use Apple membership APIs which require that all names represent
4207 * valid user account or group records accessible by the server.
4210 uuid_t usr_uuid
; /* UUID for job requesting user */
4211 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4212 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4213 int mbr_err
; /* Error from membership function */
4214 int is_member
; /* Is this user a member? */
4217 * Use standard POSIX APIs for checking users and groups...
4220 struct passwd
*pw
; /* User password data */
4221 #endif /* HAVE_MBR_UID_TO_UUID */
4224 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4225 con
, con
->http
.fd
, p
, p
->name
);
4228 * Figure out who is printing...
4231 strlcpy(username
, get_username(con
), sizeof(username
));
4234 * Check global active job limits for printers and users...
4237 if (MaxJobsPerPrinter
)
4240 * Check if there are too many pending jobs on this printer...
4243 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4245 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4254 * Check if there are too many pending jobs for this user...
4257 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4259 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4266 * Check against users...
4269 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4274 #ifdef HAVE_MBR_UID_TO_UUID
4276 * Get UUID for job requesting user...
4279 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4285 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4286 "check_quotas: UUID lookup failed for user \"%s\"",
4288 cupsdLogMessage(CUPSD_LOG_INFO
,
4289 "Denying user \"%s\" access to printer \"%s\" "
4290 "(unknown user)...",
4296 * Get UID and GID of requesting user...
4299 pw
= getpwnam(username
);
4301 #endif /* HAVE_MBR_UID_TO_UUID */
4303 for (i
= 0; i
< p
->num_users
; i
++)
4304 if (p
->users
[i
][0] == '@')
4307 * Check group membership...
4310 #ifdef HAVE_MBR_UID_TO_UUID
4311 if (p
->users
[i
][1] == '#')
4313 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4314 uuid_clear(grp_uuid
);
4316 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4320 * Invalid ACL entries are ignored for matching; just record a
4321 * warning in the log...
4324 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4325 "check_quotas: UUID lookup failed for ACL entry "
4326 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4327 cupsdLogMessage(CUPSD_LOG_WARN
,
4328 "Access control entry \"%s\" not a valid group name; "
4329 "entry ignored", p
->users
[i
]);
4332 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4336 * At this point, there should be no errors, but check anyways...
4339 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4340 "check_quotas: group \"%s\" membership check "
4341 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4346 * Stop if we found a match...
4353 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4355 #endif /* HAVE_MBR_UID_TO_UUID */
4357 #ifdef HAVE_MBR_UID_TO_UUID
4360 if (p
->users
[i
][0] == '#')
4362 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4363 uuid_clear(usr2_uuid
);
4365 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4369 * Invalid ACL entries are ignored for matching; just record a
4370 * warning in the log...
4373 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4374 "check_quotas: UUID lookup failed for ACL entry "
4375 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4376 cupsdLogMessage(CUPSD_LOG_WARN
,
4377 "Access control entry \"%s\" not a valid user name; "
4378 "entry ignored", p
->users
[i
]);
4381 if ((mbr_err
= mbr_check_membership(usr_uuid
, usr2_uuid
,
4384 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4385 "check_quotas: User \"%s\" identity check failed "
4386 "(err=%d)", p
->users
[i
], mbr_err
);
4394 else if (!strcasecmp(username
, p
->users
[i
]))
4396 #endif /* HAVE_MBR_UID_TO_UUID */
4398 if ((i
< p
->num_users
) == p
->deny_users
)
4400 cupsdLogMessage(CUPSD_LOG_INFO
,
4401 "Denying user \"%s\" access to printer \"%s\"...",
4412 if (AppleQuotas
&& (q
= cupsdFindQuota(p
, username
)) != NULL
)
4415 * TODO: Define these special page count values as constants!
4418 if (q
->page_count
== -4) /* special case: unlimited user */
4420 cupsdLogMessage(CUPSD_LOG_INFO
,
4421 "User \"%s\" request approved for printer %s (%s): "
4423 username
, p
->name
, p
->info
);
4424 q
->page_count
= 0; /* allow user to print */
4427 else if (q
->page_count
== -3) /* quota exceeded */
4429 cupsdLogMessage(CUPSD_LOG_INFO
,
4430 "User \"%s\" request denied for printer %s (%s): "
4431 "quota limit exceeded.",
4432 username
, p
->name
, p
->info
);
4433 q
->page_count
= 2; /* force quota exceeded failure */
4436 else if (q
->page_count
== -2) /* quota disabled for user */
4438 cupsdLogMessage(CUPSD_LOG_INFO
,
4439 "User \"%s\" request denied for printer %s (%s): "
4440 "printing disabled for user.",
4441 username
, p
->name
, p
->info
);
4442 q
->page_count
= 2; /* force quota exceeded failure */
4445 else if (q
->page_count
== -1) /* quota access error */
4447 cupsdLogMessage(CUPSD_LOG_INFO
,
4448 "User \"%s\" request denied for printer %s (%s): "
4449 "unable to determine quota limit.",
4450 username
, p
->name
, p
->info
);
4451 q
->page_count
= 2; /* force quota exceeded failure */
4454 else if (q
->page_count
< 0) /* user not found or other error */
4456 cupsdLogMessage(CUPSD_LOG_INFO
,
4457 "User \"%s\" request denied for printer %s (%s): "
4458 "user disabled / missing quota.",
4459 username
, p
->name
, p
->info
);
4460 q
->page_count
= 2; /* force quota exceeded failure */
4463 else /* page within user limits */
4465 q
->page_count
= 0; /* allow user to print */
4470 #endif /* __APPLE__ */
4471 if (p
->k_limit
|| p
->page_limit
)
4473 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4475 cupsdLogMessage(CUPSD_LOG_ERROR
,
4476 "Unable to allocate quota data for user \"%s\"!",
4481 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4482 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4484 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4491 * If we have gotten this far, we're done!
4499 * 'copy_attribute()' - Copy a single attribute.
4502 static ipp_attribute_t
* /* O - New attribute */
4504 ipp_t
*to
, /* O - Destination request/response */
4505 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4506 int quickcopy
) /* I - Do a quick copy? */
4508 int i
; /* Looping var */
4509 ipp_attribute_t
*toattr
; /* Destination attribute */
4512 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4513 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4514 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4517 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4520 toattr
= ippAddSeparator(to
);
4523 case IPP_TAG_INTEGER
:
4525 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4526 attr
->name
, attr
->num_values
, NULL
);
4528 for (i
= 0; i
< attr
->num_values
; i
++)
4529 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4532 case IPP_TAG_BOOLEAN
:
4533 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4534 attr
->num_values
, NULL
);
4536 for (i
= 0; i
< attr
->num_values
; i
++)
4537 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4540 case IPP_TAG_STRING
:
4543 case IPP_TAG_KEYWORD
:
4545 case IPP_TAG_URISCHEME
:
4546 case IPP_TAG_CHARSET
:
4547 case IPP_TAG_LANGUAGE
:
4548 case IPP_TAG_MIMETYPE
:
4549 toattr
= ippAddStrings(to
, attr
->group_tag
,
4550 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4551 attr
->name
, attr
->num_values
, NULL
, NULL
);
4555 for (i
= 0; i
< attr
->num_values
; i
++)
4556 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4558 else if (attr
->value_tag
& IPP_TAG_COPY
)
4560 for (i
= 0; i
< attr
->num_values
; i
++)
4561 toattr
->values
[i
].string
.text
=
4562 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4566 for (i
= 0; i
< attr
->num_values
; i
++)
4567 toattr
->values
[i
].string
.text
=
4568 _cupsStrRetain(attr
->values
[i
].string
.text
);
4573 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4574 attr
->values
[0].date
);
4577 case IPP_TAG_RESOLUTION
:
4578 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4579 attr
->num_values
, IPP_RES_PER_INCH
,
4582 for (i
= 0; i
< attr
->num_values
; i
++)
4584 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4585 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4586 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4590 case IPP_TAG_RANGE
:
4591 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4592 attr
->num_values
, NULL
, NULL
);
4594 for (i
= 0; i
< attr
->num_values
; i
++)
4596 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4597 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4601 case IPP_TAG_TEXTLANG
:
4602 case IPP_TAG_NAMELANG
:
4603 toattr
= ippAddStrings(to
, attr
->group_tag
,
4604 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4605 attr
->name
, attr
->num_values
, NULL
, NULL
);
4609 for (i
= 0; i
< attr
->num_values
; i
++)
4611 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4612 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4615 else if (attr
->value_tag
& IPP_TAG_COPY
)
4617 for (i
= 0; i
< attr
->num_values
; i
++)
4620 toattr
->values
[i
].string
.charset
=
4621 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4623 toattr
->values
[i
].string
.charset
=
4624 toattr
->values
[0].string
.charset
;
4626 toattr
->values
[i
].string
.text
=
4627 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4632 for (i
= 0; i
< attr
->num_values
; i
++)
4635 toattr
->values
[i
].string
.charset
=
4636 _cupsStrRetain(attr
->values
[i
].string
.charset
);
4638 toattr
->values
[i
].string
.charset
=
4639 toattr
->values
[0].string
.charset
;
4641 toattr
->values
[i
].string
.text
=
4642 _cupsStrRetain(attr
->values
[i
].string
.text
);
4647 case IPP_TAG_BEGIN_COLLECTION
:
4648 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4649 attr
->num_values
, NULL
);
4651 for (i
= 0; i
< attr
->num_values
; i
++)
4653 toattr
->values
[i
].collection
= ippNew();
4654 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
4655 NULL
, IPP_TAG_ZERO
, 0);
4660 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4661 attr
->name
, attr
->num_values
, NULL
);
4663 for (i
= 0; i
< attr
->num_values
; i
++)
4665 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4667 if (toattr
->values
[i
].unknown
.length
> 0)
4669 if ((toattr
->values
[i
].unknown
.data
=
4670 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4671 toattr
->values
[i
].unknown
.length
= 0;
4673 memcpy(toattr
->values
[i
].unknown
.data
,
4674 attr
->values
[i
].unknown
.data
,
4675 toattr
->values
[i
].unknown
.length
);
4678 break; /* anti-compiler-warning-code */
4686 * 'copy_attrs()' - Copy attributes from one request to another.
4690 copy_attrs(ipp_t
*to
, /* I - Destination request */
4691 ipp_t
*from
, /* I - Source request */
4692 cups_array_t
*ra
, /* I - Requested attributes */
4693 ipp_tag_t group
, /* I - Group to copy */
4694 int quickcopy
) /* I - Do a quick copy? */
4696 ipp_attribute_t
*fromattr
; /* Source attribute */
4699 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4700 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4701 to
, from
, ra
, group
, quickcopy
);
4706 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4709 * Filter attributes as needed...
4712 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4713 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4716 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4719 * Don't send collection attributes by default to IPP/1.x clients
4720 * since many do not support collections...
4723 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4724 !ra
&& to
->request
.status
.version
[0] == 1)
4727 copy_attribute(to
, fromattr
, quickcopy
);
4734 * 'copy_banner()' - Copy a banner file to the requests directory for the
4738 static int /* O - Size of banner file in kbytes */
4739 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4740 cupsd_job_t
*job
, /* I - Job information */
4741 const char *name
) /* I - Name of banner */
4743 int i
; /* Looping var */
4744 int kbytes
; /* Size of banner file in kbytes */
4745 char filename
[1024]; /* Job filename */
4746 cupsd_banner_t
*banner
; /* Pointer to banner */
4747 cups_file_t
*in
; /* Input file */
4748 cups_file_t
*out
; /* Output file */
4749 int ch
; /* Character from file */
4750 char attrname
[255], /* Name of attribute */
4751 *s
; /* Pointer into name */
4752 ipp_attribute_t
*attr
; /* Attribute */
4755 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4756 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4757 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4758 name
? name
: "(null)");
4761 * Find the banner; return if not found or "none"...
4764 if (!name
|| !strcmp(name
, "none") ||
4765 (banner
= cupsdFindBanner(name
)) == NULL
)
4769 * Open the banner and job files...
4772 if (add_file(con
, job
, banner
->filetype
, 0))
4775 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4777 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4779 cupsdLogMessage(CUPSD_LOG_ERROR
,
4780 "Unable to create banner job file %s - %s",
4781 filename
, strerror(errno
));
4786 fchmod(cupsFileNumber(out
), 0640);
4787 fchown(cupsFileNumber(out
), RunUser
, Group
);
4790 * Try the localized banner file under the subdirectory...
4793 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4795 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4798 * Convert ll-cc to ll_CC...
4802 attrname
[3] = toupper(attrname
[3] & 255);
4803 attrname
[4] = toupper(attrname
[4] & 255);
4806 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4809 if (access(filename
, 0) && strlen(attrname
) > 2)
4812 * Wasn't able to find "ll_CC" locale file; try the non-national
4813 * localization banner directory.
4818 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4822 if (access(filename
, 0))
4825 * Use the non-localized banner file.
4828 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4831 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4835 cupsdLogMessage(CUPSD_LOG_ERROR
,
4836 "Unable to open banner template file %s - %s",
4837 filename
, strerror(errno
));
4843 * Parse the file to the end...
4846 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4850 * Get an attribute name...
4853 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4854 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4856 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4866 * Ignore { followed by stuff that is not an attribute name...
4869 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4874 * See if it is defined...
4877 if (attrname
[0] == '?')
4882 if (!strcmp(s
, "printer-name"))
4884 cupsFilePuts(out
, job
->dest
);
4887 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4890 * See if we have a leading question mark...
4893 if (attrname
[0] != '?')
4896 * Nope, write to file as-is; probably a PostScript procedure...
4899 cupsFilePrintf(out
, "{%s}", attrname
);
4906 * Output value(s)...
4909 for (i
= 0; i
< attr
->num_values
; i
++)
4912 cupsFilePutChar(out
, ',');
4914 switch (attr
->value_tag
)
4916 case IPP_TAG_INTEGER
:
4918 if (!strncmp(s
, "time-at-", 8))
4919 cupsFilePuts(out
, cupsdGetDateTime(attr
->values
[i
].integer
));
4921 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4924 case IPP_TAG_BOOLEAN
:
4925 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4928 case IPP_TAG_NOVALUE
:
4929 cupsFilePuts(out
, "novalue");
4932 case IPP_TAG_RANGE
:
4933 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4934 attr
->values
[i
].range
.upper
);
4937 case IPP_TAG_RESOLUTION
:
4938 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4939 attr
->values
[i
].resolution
.yres
,
4940 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4945 case IPP_TAG_STRING
:
4948 case IPP_TAG_KEYWORD
:
4949 case IPP_TAG_CHARSET
:
4950 case IPP_TAG_LANGUAGE
:
4951 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
4954 * Need to quote strings for PS banners...
4959 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4961 if (*p
== '(' || *p
== ')' || *p
== '\\')
4963 cupsFilePutChar(out
, '\\');
4964 cupsFilePutChar(out
, *p
);
4966 else if (*p
< 32 || *p
> 126)
4967 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4969 cupsFilePutChar(out
, *p
);
4973 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4977 break; /* anti-compiler-warning-code */
4981 else if (ch
== '\\') /* Quoted char */
4983 ch
= cupsFileGetChar(in
);
4985 if (ch
!= '{') /* Only do special handling for \{ */
4986 cupsFilePutChar(out
, '\\');
4988 cupsFilePutChar(out
, ch
);
4991 cupsFilePutChar(out
, ch
);
4995 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4997 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4998 IPP_TAG_INTEGER
)) != NULL
)
4999 attr
->values
[0].integer
+= kbytes
;
5008 * 'copy_file()' - Copy a PPD file or interface script...
5011 static int /* O - 0 = success, -1 = error */
5012 copy_file(const char *from
, /* I - Source file */
5013 const char *to
) /* I - Destination file */
5015 cups_file_t
*src
, /* Source file */
5016 *dst
; /* Destination file */
5017 int bytes
; /* Bytes to read/write */
5018 char buffer
[2048]; /* Copy buffer */
5021 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5024 * Open the source and destination file for a copy...
5027 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5030 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5037 * Copy the source file to the destination...
5040 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5041 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5049 * Close both files and return...
5054 return (cupsFileClose(dst
));
5059 * 'copy_model()' - Copy a PPD model file, substituting default values
5063 static int /* O - 0 = success, -1 = error */
5064 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5065 const char *from
, /* I - Source file */
5066 const char *to
) /* I - Destination file */
5068 fd_set input
; /* select() input set */
5069 struct timeval timeout
; /* select() timeout */
5070 int maxfd
; /* Max file descriptor for select() */
5071 char tempfile
[1024]; /* Temporary PPD file */
5072 int tempfd
; /* Temporary PPD file descriptor */
5073 int temppid
; /* Process ID of cups-driverd */
5074 int temppipe
[2]; /* Temporary pipes */
5075 char *argv
[4], /* Command-line arguments */
5076 *envp
[MAX_ENV
]; /* Environment */
5077 cups_file_t
*src
, /* Source file */
5078 *dst
; /* Destination file */
5079 ppd_file_t
*ppd
; /* PPD file */
5080 int bytes
, /* Bytes from pipe */
5081 total
; /* Total bytes from pipe */
5082 char buffer
[2048]; /* Copy buffer */
5083 int i
; /* Looping var */
5084 char option
[PPD_MAX_NAME
], /* Option name */
5085 choice
[PPD_MAX_NAME
]; /* Choice name */
5086 int num_defaults
; /* Number of default options */
5087 cups_option_t
*defaults
; /* Default options */
5088 char cups_protocol
[PPD_MAX_LINE
];
5089 /* cupsProtocol attribute */
5092 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5093 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5097 * Run cups-driverd to get the PPD file...
5100 argv
[0] = "cups-driverd";
5102 argv
[2] = (char *)from
;
5105 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5107 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5108 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5109 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5113 cupsdOpenPipe(temppipe
);
5115 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5116 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5118 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5119 -1, -1, 0, DefaultProfile
, &temppid
))
5130 * Wait up to 30 seconds for the PPD file to be copied...
5135 if (temppipe
[0] > CGIPipes
[0])
5136 maxfd
= temppipe
[0] + 1;
5138 maxfd
= CGIPipes
[0] + 1;
5143 * See if we have data ready...
5147 FD_SET(temppipe
[0], &input
);
5148 FD_SET(CGIPipes
[0], &input
);
5150 timeout
.tv_sec
= 30;
5151 timeout
.tv_usec
= 0;
5153 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5163 * We have timed out...
5169 if (FD_ISSET(temppipe
[0], &input
))
5172 * Read the PPD file from the pipe, and write it to the PPD file.
5175 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5177 if (write(tempfd
, buffer
, bytes
) < bytes
)
5186 if (FD_ISSET(CGIPipes
[0], &input
))
5196 * No data from cups-deviced...
5199 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
5205 * Read the source file and see what page sizes are supported...
5208 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5215 * Open the destination (if possible) and set the default options...
5220 cups_protocol
[0] = '\0';
5222 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5225 * Read all of the default lines from the old PPD...
5228 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5229 if (!strncmp(buffer
, "*Default", 8))
5232 * Add the default option...
5235 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5236 choice
, sizeof(choice
)))
5238 ppd_option_t
*ppdo
; /* PPD option */
5242 * Only add the default if the default hasn't already been
5243 * set and the choice exists in the new PPD...
5246 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5247 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5248 ppdFindChoice(ppdo
, choice
))
5249 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5253 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5254 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5258 else if (ppdPageSize(ppd
, DefaultPaperSize
))
5261 * Add the default media sizes...
5264 num_defaults
= cupsAddOption("PageSize", DefaultPaperSize
,
5265 num_defaults
, &defaults
);
5266 num_defaults
= cupsAddOption("PageRegion", DefaultPaperSize
,
5267 num_defaults
, &defaults
);
5268 num_defaults
= cupsAddOption("PaperDimension", DefaultPaperSize
,
5269 num_defaults
, &defaults
);
5270 num_defaults
= cupsAddOption("ImageableArea", DefaultPaperSize
,
5271 num_defaults
, &defaults
);
5277 * Open the source file for a copy...
5280 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5282 cupsFreeOptions(num_defaults
, defaults
);
5288 * Open the destination file for a copy...
5291 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5293 cupsFreeOptions(num_defaults
, defaults
);
5300 * Copy the source file to the destination...
5303 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5305 if (!strncmp(buffer
, "*Default", 8))
5308 * Check for an previous default option choice...
5311 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5312 choice
, sizeof(choice
)))
5314 const char *val
; /* Default option value */
5317 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5320 * Substitute the previous choice...
5323 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5328 cupsFilePrintf(dst
, "%s\n", buffer
);
5331 if (cups_protocol
[0])
5332 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5334 cupsFreeOptions(num_defaults
, defaults
);
5337 * Close both files and return...
5344 return (cupsFileClose(dst
));
5349 * 'copy_job_attrs()' - Copy job attributes.
5353 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5354 cupsd_job_t
*job
, /* I - Job */
5355 cups_array_t
*ra
) /* I - Requested attributes array */
5357 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5361 * Send the requested attributes for each job...
5364 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5365 con
->servername
, con
->serverport
, "/jobs/%d",
5368 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5369 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5370 "document-count", job
->num_files
);
5372 if (!ra
|| cupsArrayFind(ra
, "job-media-progress"))
5373 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5374 "job-media-progress", job
->progress
);
5376 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5377 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5378 "job-more-info", NULL
, job_uri
);
5380 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5381 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5382 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5383 job
->num_files
> 0);
5385 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5386 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5387 "job-printer-up-time", time(NULL
));
5389 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5390 add_job_state_reasons(con
, job
);
5392 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5393 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5394 "job-uri", NULL
, job_uri
);
5396 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5401 * 'copy_printer_attrs()' - Copy printer attributes.
5406 cupsd_client_t
*con
, /* I - Client connection */
5407 cupsd_printer_t
*printer
, /* I - Printer */
5408 cups_array_t
*ra
) /* I - Requested attributes array */
5410 char printer_uri
[HTTP_MAX_URI
];
5412 time_t curtime
; /* Current time */
5413 int i
; /* Looping var */
5414 ipp_attribute_t
*history
; /* History collection */
5418 * Copy the printer attributes to the response using requested-attributes
5419 * and document-format attributes that may be provided by the client.
5422 curtime
= time(NULL
);
5425 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
5426 printer
->recoverable
)
5427 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5428 "com.apple.print.recoverable-message", NULL
,
5429 printer
->recoverable
);
5430 #endif /* __APPLE__ */
5432 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5433 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5434 "marker-change-time", printer
->marker_time
);
5436 if (printer
->num_printers
> 0 &&
5437 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5439 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5440 cupsd_printer_t
*p2
; /* Printer in class */
5441 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5444 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5445 IPP_TAG_URI
, "member-uris",
5446 printer
->num_printers
, NULL
,
5449 for (i
= 0; i
< printer
->num_printers
; i
++)
5451 p2
= printer
->printers
[i
];
5453 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5454 IPP_TAG_URI
)) != NULL
)
5455 member_uris
->values
[i
].string
.text
=
5456 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5459 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5460 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5462 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5463 "/classes/%s" : "/printers/%s", p2
->name
);
5464 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5470 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5471 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5472 "printer-alert", NULL
, printer
->alert
);
5474 if (printer
->alert_description
&&
5475 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5476 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5477 "printer-alert-description", NULL
,
5478 printer
->alert_description
);
5480 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5481 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5482 ippTimeToDate(curtime
));
5485 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5487 if (printer
->reg_name
)
5488 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5489 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5491 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5492 "printer-dns-sd-name", 0);
5494 #endif /* HAVE_DNSSD */
5496 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5497 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5498 "printer-error-policy", NULL
, printer
->error_policy
);
5500 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5501 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5502 printer
->accepting
);
5504 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5505 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5508 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5509 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5511 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5512 "http", NULL
, con
->servername
, con
->serverport
,
5513 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5514 "/classes/%s" : "/printers/%s", printer
->name
);
5515 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5516 "printer-more-info", NULL
, printer_uri
);
5519 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5520 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5521 "printer-op-policy", NULL
, printer
->op_policy
);
5523 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5524 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5527 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5528 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5529 "printer-state-change-time", printer
->state_time
);
5531 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5532 cupsArrayFind(ra
, "printer-state-history"))
5535 * Printer history is only sent if specifically requested, so that
5536 * older CUPS/IPP clients won't barf on the collection attributes.
5539 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5540 "printer-state-history",
5541 printer
->num_history
, NULL
);
5543 for (i
= 0; i
< printer
->num_history
; i
++)
5544 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5545 NULL
, IPP_TAG_ZERO
, 0);
5548 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5549 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5550 "printer-state-message", NULL
, printer
->state_message
);
5552 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5553 add_printer_state_reasons(con
, printer
);
5555 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5557 int type
; /* printer-type value */
5561 * Add the CUPS-specific printer-type attribute...
5564 type
= printer
->type
;
5566 if (printer
== DefaultPrinter
)
5567 type
|= CUPS_PRINTER_DEFAULT
;
5569 if (!printer
->accepting
)
5570 type
|= CUPS_PRINTER_REJECTING
;
5572 if (!printer
->shared
)
5573 type
|= CUPS_PRINTER_NOT_SHARED
;
5575 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5579 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5580 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5581 "printer-up-time", curtime
);
5583 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5584 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5586 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5587 "ipp", NULL
, con
->servername
, con
->serverport
,
5588 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5589 "/classes/%s" : "/printers/%s", printer
->name
);
5590 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5591 "printer-uri-supported", NULL
, printer_uri
);
5592 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5596 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5597 add_queued_job_count(con
, printer
);
5599 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5600 if (printer
->ppd_attrs
)
5601 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0);
5602 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5607 * 'copy_subscription_attrs()' - Copy subscription attributes.
5611 copy_subscription_attrs(
5612 cupsd_client_t
*con
, /* I - Client connection */
5613 cupsd_subscription_t
*sub
, /* I - Subscription */
5614 cups_array_t
*ra
) /* I - Requested attributes array */
5616 ipp_attribute_t
*attr
; /* Current attribute */
5617 char printer_uri
[HTTP_MAX_URI
];
5619 int count
; /* Number of events */
5620 unsigned mask
; /* Current event mask */
5621 const char *name
; /* Current event name */
5625 * Copy the subscription attributes to the response using the
5626 * requested-attributes attribute that may be provided by the client.
5629 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5631 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5634 * Simple event list...
5637 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5638 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5639 "notify-events", NULL
, name
);
5644 * Complex event list...
5647 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5648 if (sub
->mask
& mask
)
5651 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5652 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5653 "notify-events", count
, NULL
, NULL
);
5655 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5656 if (sub
->mask
& mask
)
5658 attr
->values
[count
].string
.text
=
5659 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5666 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5667 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5668 "notify-job-id", sub
->job
->id
);
5670 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5671 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5672 "notify-lease-duration", sub
->lease
);
5674 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5676 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5677 "ipp", NULL
, con
->servername
, con
->serverport
,
5678 "/printers/%s", sub
->dest
->name
);
5679 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5680 "notify-printer-uri", NULL
, printer_uri
);
5683 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5684 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5685 "notify-recipient-uri", NULL
, sub
->recipient
);
5686 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5687 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5688 "notify-pull-method", NULL
, "ippget");
5690 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5691 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5692 "notify-subscriber-user-name", NULL
, sub
->owner
);
5694 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5695 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5696 "notify-subscription-id", sub
->id
);
5698 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5699 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5700 "notify-time-interval", sub
->interval
);
5702 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5703 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5704 sub
->user_data
, sub
->user_data_len
);
5709 * 'create_job()' - Print a file to a printer or class.
5713 create_job(cupsd_client_t
*con
, /* I - Client connection */
5714 ipp_attribute_t
*uri
) /* I - Printer URI */
5716 cupsd_printer_t
*printer
; /* Printer */
5717 cupsd_job_t
*job
; /* New job */
5720 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5721 con
->http
.fd
, uri
->values
[0].string
.text
);
5724 * Is the destination valid?
5727 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5733 send_ipp_status(con
, IPP_NOT_FOUND
,
5734 _("The printer or class was not found."));
5739 * Create the job object...
5742 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5745 job
->pending_timeout
= 1;
5748 * Save and log the job...
5751 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5752 job
->dest
, job
->username
);
5757 * 'create_requested_array()' - Create an array for the requested-attributes.
5760 static cups_array_t
* /* O - Array of attributes or NULL */
5761 create_requested_array(ipp_t
*request
) /* I - IPP request */
5763 int i
; /* Looping var */
5764 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5765 cups_array_t
*ra
; /* Requested attributes array */
5766 char *value
; /* Current value */
5770 * Get the requested-attributes attribute, and return NULL if we don't
5774 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5775 IPP_TAG_KEYWORD
)) == NULL
)
5779 * If the attribute contains a single "all" keyword, return NULL...
5782 if (requested
->num_values
== 1 &&
5783 !strcmp(requested
->values
[0].string
.text
, "all"))
5787 * Create an array using "strcmp" as the comparison function...
5790 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5792 for (i
= 0; i
< requested
->num_values
; i
++)
5794 value
= requested
->values
[i
].string
.text
;
5796 if (!strcmp(value
, "job-template"))
5798 cupsArrayAdd(ra
, "copies");
5799 cupsArrayAdd(ra
, "copies-default");
5800 cupsArrayAdd(ra
, "copies-supported");
5801 cupsArrayAdd(ra
, "finishings");
5802 cupsArrayAdd(ra
, "finishings-default");
5803 cupsArrayAdd(ra
, "finishings-supported");
5804 cupsArrayAdd(ra
, "job-hold-until");
5805 cupsArrayAdd(ra
, "job-hold-until-default");
5806 cupsArrayAdd(ra
, "job-hold-until-supported");
5807 cupsArrayAdd(ra
, "job-priority");
5808 cupsArrayAdd(ra
, "job-priority-default");
5809 cupsArrayAdd(ra
, "job-priority-supported");
5810 cupsArrayAdd(ra
, "job-sheets");
5811 cupsArrayAdd(ra
, "job-sheets-default");
5812 cupsArrayAdd(ra
, "job-sheets-supported");
5813 cupsArrayAdd(ra
, "media");
5814 cupsArrayAdd(ra
, "media-default");
5815 cupsArrayAdd(ra
, "media-supported");
5816 cupsArrayAdd(ra
, "multiple-document-handling");
5817 cupsArrayAdd(ra
, "multiple-document-handling-default");
5818 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5819 cupsArrayAdd(ra
, "number-up");
5820 cupsArrayAdd(ra
, "number-up-default");
5821 cupsArrayAdd(ra
, "number-up-supported");
5822 cupsArrayAdd(ra
, "orientation-requested");
5823 cupsArrayAdd(ra
, "orientation-requested-default");
5824 cupsArrayAdd(ra
, "orientation-requested-supported");
5825 cupsArrayAdd(ra
, "page-ranges");
5826 cupsArrayAdd(ra
, "page-ranges-supported");
5827 cupsArrayAdd(ra
, "printer-resolution");
5828 cupsArrayAdd(ra
, "printer-resolution-default");
5829 cupsArrayAdd(ra
, "printer-resolution-supported");
5830 cupsArrayAdd(ra
, "print-quality");
5831 cupsArrayAdd(ra
, "print-quality-default");
5832 cupsArrayAdd(ra
, "print-quality-supported");
5833 cupsArrayAdd(ra
, "sides");
5834 cupsArrayAdd(ra
, "sides-default");
5835 cupsArrayAdd(ra
, "sides-supported");
5837 else if (!strcmp(value
, "job-description"))
5839 cupsArrayAdd(ra
, "date-time-at-completed");
5840 cupsArrayAdd(ra
, "date-time-at-creation");
5841 cupsArrayAdd(ra
, "date-time-at-processing");
5842 cupsArrayAdd(ra
, "job-detailed-status-message");
5843 cupsArrayAdd(ra
, "job-document-access-errors");
5844 cupsArrayAdd(ra
, "job-id");
5845 cupsArrayAdd(ra
, "job-impressions");
5846 cupsArrayAdd(ra
, "job-impressions-completed");
5847 cupsArrayAdd(ra
, "job-k-octets");
5848 cupsArrayAdd(ra
, "job-k-octets-processed");
5849 cupsArrayAdd(ra
, "job-media-progress");
5850 cupsArrayAdd(ra
, "job-media-sheets");
5851 cupsArrayAdd(ra
, "job-media-sheets-completed");
5852 cupsArrayAdd(ra
, "job-message-from-operator");
5853 cupsArrayAdd(ra
, "job-more-info");
5854 cupsArrayAdd(ra
, "job-name");
5855 cupsArrayAdd(ra
, "job-originating-user-name");
5856 cupsArrayAdd(ra
, "job-printer-up-time");
5857 cupsArrayAdd(ra
, "job-printer-uri");
5858 cupsArrayAdd(ra
, "job-state");
5859 cupsArrayAdd(ra
, "job-state-message");
5860 cupsArrayAdd(ra
, "job-state-reasons");
5861 cupsArrayAdd(ra
, "job-uri");
5862 cupsArrayAdd(ra
, "number-of-documents");
5863 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5864 cupsArrayAdd(ra
, "output-device-assigned");
5865 cupsArrayAdd(ra
, "time-at-completed");
5866 cupsArrayAdd(ra
, "time-at-creation");
5867 cupsArrayAdd(ra
, "time-at-processing");
5869 else if (!strcmp(value
, "printer-description"))
5871 cupsArrayAdd(ra
, "charset-configured");
5872 cupsArrayAdd(ra
, "charset-supported");
5873 cupsArrayAdd(ra
, "color-supported");
5874 cupsArrayAdd(ra
, "compression-supported");
5875 cupsArrayAdd(ra
, "document-format-default");
5876 cupsArrayAdd(ra
, "document-format-supported");
5877 cupsArrayAdd(ra
, "generated-natural-language-supported");
5878 cupsArrayAdd(ra
, "ipp-versions-supported");
5879 cupsArrayAdd(ra
, "job-impressions-supported");
5880 cupsArrayAdd(ra
, "job-k-octets-supported");
5881 cupsArrayAdd(ra
, "job-media-sheets-supported");
5882 cupsArrayAdd(ra
, "job-settable-attributes-supported");
5883 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5884 cupsArrayAdd(ra
, "multiple-operation-time-out");
5885 cupsArrayAdd(ra
, "natural-language-configured");
5886 cupsArrayAdd(ra
, "notify-attributes-supported");
5887 cupsArrayAdd(ra
, "notify-lease-duration-default");
5888 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5889 cupsArrayAdd(ra
, "notify-max-events-supported");
5890 cupsArrayAdd(ra
, "notify-events-default");
5891 cupsArrayAdd(ra
, "notify-events-supported");
5892 cupsArrayAdd(ra
, "notify-pull-method-supported");
5893 cupsArrayAdd(ra
, "notify-schemes-supported");
5894 cupsArrayAdd(ra
, "operations-supported");
5895 cupsArrayAdd(ra
, "pages-per-minute");
5896 cupsArrayAdd(ra
, "pages-per-minute-color");
5897 cupsArrayAdd(ra
, "pdl-override-supported");
5898 cupsArrayAdd(ra
, "printer-alert");
5899 cupsArrayAdd(ra
, "printer-alert-description");
5900 cupsArrayAdd(ra
, "printer-commands");
5901 cupsArrayAdd(ra
, "printer-current-time");
5902 cupsArrayAdd(ra
, "printer-driver-installer");
5903 cupsArrayAdd(ra
, "printer-dns-sd-name");
5904 cupsArrayAdd(ra
, "printer-info");
5905 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5906 cupsArrayAdd(ra
, "printer-location");
5907 cupsArrayAdd(ra
, "printer-make-and-model");
5908 cupsArrayAdd(ra
, "printer-message-from-operator");
5909 cupsArrayAdd(ra
, "printer-more-info");
5910 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5911 cupsArrayAdd(ra
, "printer-name");
5912 cupsArrayAdd(ra
, "printer-state");
5913 cupsArrayAdd(ra
, "printer-state-message");
5914 cupsArrayAdd(ra
, "printer-state-reasons");
5915 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
5916 cupsArrayAdd(ra
, "printer-type");
5917 cupsArrayAdd(ra
, "printer-up-time");
5918 cupsArrayAdd(ra
, "printer-uri-supported");
5919 cupsArrayAdd(ra
, "queued-job-count");
5920 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5921 cupsArrayAdd(ra
, "uri-authentication-supported");
5922 cupsArrayAdd(ra
, "uri-security-supported");
5924 else if (!strcmp(value
, "printer-defaults"))
5926 char *name
; /* Option name */
5929 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5931 name
= (char *)cupsArrayNext(CommonDefaults
))
5932 cupsArrayAdd(ra
, name
);
5934 else if (!strcmp(value
, "subscription-template"))
5936 cupsArrayAdd(ra
, "notify-attributes");
5937 cupsArrayAdd(ra
, "notify-charset");
5938 cupsArrayAdd(ra
, "notify-events");
5939 cupsArrayAdd(ra
, "notify-lease-duration");
5940 cupsArrayAdd(ra
, "notify-natural-language");
5941 cupsArrayAdd(ra
, "notify-pull-method");
5942 cupsArrayAdd(ra
, "notify-recipient-uri");
5943 cupsArrayAdd(ra
, "notify-time-interval");
5944 cupsArrayAdd(ra
, "notify-user-data");
5947 cupsArrayAdd(ra
, value
);
5955 * 'create_subscription()' - Create a notification subscription.
5959 create_subscription(
5960 cupsd_client_t
*con
, /* I - Client connection */
5961 ipp_attribute_t
*uri
) /* I - Printer URI */
5963 http_status_t status
; /* Policy status */
5964 int i
; /* Looping var */
5965 ipp_attribute_t
*attr
; /* Current attribute */
5966 cups_ptype_t dtype
; /* Destination type (printer/class) */
5967 char scheme
[HTTP_MAX_URI
],
5968 /* Scheme portion of URI */
5969 userpass
[HTTP_MAX_URI
],
5970 /* Username portion of URI */
5972 /* Host portion of URI */
5973 resource
[HTTP_MAX_URI
];
5974 /* Resource portion of URI */
5975 int port
; /* Port portion of URI */
5976 cupsd_printer_t
*printer
; /* Printer/class */
5977 cupsd_job_t
*job
; /* Job */
5978 int jobid
; /* Job ID */
5979 cupsd_subscription_t
*sub
; /* Subscription object */
5980 const char *username
, /* requesting-user-name or
5981 authenticated username */
5982 *recipient
, /* notify-recipient-uri */
5983 *pullmethod
; /* notify-pull-method */
5984 ipp_attribute_t
*user_data
; /* notify-user-data */
5985 int interval
, /* notify-time-interval */
5986 lease
; /* notify-lease-duration */
5987 unsigned mask
; /* notify-events */
5988 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5989 *notify_lease
; /* notify-lease-duration(-default) */
5993 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5995 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5996 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5997 attr
->value_tag
, attr
->name
);
5999 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6004 * Is the destination valid?
6007 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6008 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6009 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6011 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6012 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6013 sizeof(host
), &port
, resource
, sizeof(resource
));
6015 if (!strcmp(resource
, "/"))
6017 dtype
= (cups_ptype_t
)0;
6020 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6022 dtype
= (cups_ptype_t
)0;
6025 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6027 dtype
= CUPS_PRINTER_CLASS
;
6030 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6036 send_ipp_status(con
, IPP_NOT_FOUND
,
6037 _("The printer or class was not found."));
6047 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6050 send_http_error(con
, status
, printer
);
6054 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6056 send_http_error(con
, status
, NULL
);
6061 * Get the user that is requesting the subscription...
6064 username
= get_username(con
);
6067 * Find the first subscription group attribute; return if we have
6071 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6072 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6077 send_ipp_status(con
, IPP_BAD_REQUEST
,
6078 _("No subscription attributes in request!"));
6083 * Process the subscription attributes in the request...
6086 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6094 lease
= DefaultLeaseDuration
;
6096 mask
= CUPSD_EVENT_NONE
;
6100 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6102 notify_lease
= ippFindAttribute(printer
->attrs
,
6103 "notify-lease-duration-default",
6107 lease
= notify_lease
->values
[0].integer
;
6111 notify_events
= NULL
;
6112 notify_lease
= NULL
;
6115 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6117 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6118 attr
->value_tag
== IPP_TAG_URI
)
6121 * Validate the recipient scheme against the ServerBin/notifier
6125 char notifier
[1024]; /* Notifier filename */
6128 recipient
= attr
->values
[0].string
.text
;
6130 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6131 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6132 host
, sizeof(host
), &port
,
6133 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6135 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6136 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
6137 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6138 "notify-status-code", IPP_URI_SCHEME
);
6142 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6144 if (access(notifier
, X_OK
))
6146 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6147 _("notify-recipient-uri URI \"%s\" uses unknown "
6148 "scheme!"), recipient
);
6149 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6150 "notify-status-code", IPP_URI_SCHEME
);
6154 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6156 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6157 _("notify-recipient-uri URI \"%s\" is already used!"),
6159 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6160 "notify-status-code", IPP_ATTRIBUTES
);
6164 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6165 attr
->value_tag
== IPP_TAG_KEYWORD
)
6167 pullmethod
= attr
->values
[0].string
.text
;
6169 if (strcmp(pullmethod
, "ippget"))
6171 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6172 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
6173 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6174 "notify-status-code", IPP_ATTRIBUTES
);
6178 else if (!strcmp(attr
->name
, "notify-charset") &&
6179 attr
->value_tag
== IPP_TAG_CHARSET
&&
6180 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6181 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6183 send_ipp_status(con
, IPP_CHARSET
,
6184 _("Character set \"%s\" not supported!"),
6185 attr
->values
[0].string
.text
);
6188 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6189 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6190 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6192 send_ipp_status(con
, IPP_CHARSET
,
6193 _("Language \"%s\" not supported!"),
6194 attr
->values
[0].string
.text
);
6197 else if (!strcmp(attr
->name
, "notify-user-data") &&
6198 attr
->value_tag
== IPP_TAG_STRING
)
6200 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6202 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6203 _("The notify-user-data value is too large "
6204 "(%d > 63 octets)!"),
6205 attr
->values
[0].unknown
.length
);
6211 else if (!strcmp(attr
->name
, "notify-events") &&
6212 attr
->value_tag
== IPP_TAG_KEYWORD
)
6213 notify_events
= attr
;
6214 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6215 attr
->value_tag
== IPP_TAG_INTEGER
)
6216 lease
= attr
->values
[0].integer
;
6217 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6218 attr
->value_tag
== IPP_TAG_INTEGER
)
6219 interval
= attr
->values
[0].integer
;
6220 else if (!strcmp(attr
->name
, "notify-job-id") &&
6221 attr
->value_tag
== IPP_TAG_INTEGER
)
6222 jobid
= attr
->values
[0].integer
;
6229 for (i
= 0; i
< notify_events
->num_values
; i
++)
6230 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6234 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6236 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6237 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6238 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6240 if (!recipient
&& !pullmethod
)
6243 if (mask
== CUPSD_EVENT_NONE
)
6246 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6248 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6251 send_ipp_status(con
, IPP_BAD_REQUEST
,
6252 _("notify-events not specified!"));
6257 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6259 cupsdLogMessage(CUPSD_LOG_INFO
,
6260 "create_subscription: Limiting notify-lease-duration to "
6263 lease
= MaxLeaseDuration
;
6268 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6270 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
6277 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6279 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6280 _("There are too many subscriptions."));
6285 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6288 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6289 "Added subscription %d for printer \"%s\"",
6290 sub
->id
, printer
->name
);
6292 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6295 sub
->interval
= interval
;
6297 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6299 cupsdSetString(&sub
->owner
, username
);
6303 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6304 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6305 sub
->user_data_len
);
6308 ippAddSeparator(con
->response
);
6309 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6310 "notify-subscription-id", sub
->id
);
6312 con
->response
->request
.status
.status_code
= IPP_OK
;
6318 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6323 * 'delete_printer()' - Remove a printer or class from the system.
6327 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6328 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6330 http_status_t status
; /* Policy status */
6331 cups_ptype_t dtype
; /* Destination type (printer/class) */
6332 cupsd_printer_t
*printer
; /* Printer/class */
6333 char filename
[1024]; /* Script/PPD filename */
6336 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6337 con
->http
.fd
, uri
->values
[0].string
.text
);
6340 * Do we have a valid URI?
6343 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6349 send_ipp_status(con
, IPP_NOT_FOUND
,
6350 _("The printer or class was not found."));
6358 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6360 send_http_error(con
, status
, NULL
);
6365 * Remove old jobs...
6368 cupsdCancelJobs(printer
->name
, NULL
, 1);
6371 * Remove old subscriptions and send a "deleted printer" event...
6374 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6375 "%s \"%s\" deleted by \"%s\".",
6376 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6377 printer
->name
, get_username(con
));
6379 cupsdExpireSubscriptions(printer
, NULL
);
6382 * Remove any old PPD or script files...
6385 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6389 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6393 snprintf(filename
, sizeof(filename
), "%s/%s.ipp", CacheDir
, printer
->name
);
6398 * Unregister color profiles...
6401 apple_unregister_profiles(printer
);
6402 #endif /* __APPLE__ */
6404 if (dtype
& CUPS_PRINTER_CLASS
)
6406 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6407 printer
->name
, get_username(con
));
6409 cupsdDeletePrinter(printer
, 0);
6410 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6414 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6415 printer
->name
, get_username(con
));
6417 cupsdDeletePrinter(printer
, 0);
6418 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6421 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6424 * Return with no errors...
6427 con
->response
->request
.status
.status_code
= IPP_OK
;
6432 * 'get_default()' - Get the default destination.
6436 get_default(cupsd_client_t
*con
) /* I - Client connection */
6438 http_status_t status
; /* Policy status */
6439 cups_array_t
*ra
; /* Requested attributes array */
6442 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6448 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6450 send_http_error(con
, status
, NULL
);
6456 ra
= create_requested_array(con
->request
);
6458 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6460 cupsArrayDelete(ra
);
6462 con
->response
->request
.status
.status_code
= IPP_OK
;
6465 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6470 * 'get_devices()' - Get the list of available devices on the local system.
6474 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6476 http_status_t status
; /* Policy status */
6477 ipp_attribute_t
*limit
, /* limit attribute */
6478 *timeout
, /* timeout attribute */
6479 *requested
, /* requested-attributes attribute */
6480 *exclude
, /* exclude-schemes attribute */
6481 *include
; /* include-schemes attribute */
6482 char command
[1024], /* cups-deviced command */
6483 options
[2048], /* Options to pass to command */
6485 /* String for requested attributes */
6487 /* String for excluded schemes */
6489 /* String for included schemes */
6492 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6498 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6500 send_http_error(con
, status
, NULL
);
6505 * Run cups-deviced command with the given options...
6508 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6509 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6510 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6512 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6513 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6516 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6518 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6521 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6523 exclude_str
[0] = '\0';
6526 url_encode_attr(include
, include_str
, sizeof(include_str
));
6528 include_str
[0] = '\0';
6530 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6531 snprintf(options
, sizeof(options
),
6532 "%d+%d+%d+%d+%s%s%s%s%s",
6533 con
->request
->request
.op
.request_id
,
6534 limit
? limit
->values
[0].integer
: 0,
6535 timeout
? timeout
->values
[0].integer
: 10,
6538 exclude_str
[0] ? "%20" : "", exclude_str
,
6539 include_str
[0] ? "%20" : "", include_str
);
6541 if (cupsdSendCommand(con
, command
, options
, 1))
6544 * Command started successfully, don't send an IPP response here...
6547 ippDelete(con
->response
);
6548 con
->response
= NULL
;
6553 * Command failed, return "internal error" so the user knows something
6557 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6558 _("cups-deviced failed to execute."));
6564 * 'get_document()' - Get a copy of a job file.
6568 get_document(cupsd_client_t
*con
, /* I - Client connection */
6569 ipp_attribute_t
*uri
) /* I - Job URI */
6571 http_status_t status
; /* Policy status */
6572 ipp_attribute_t
*attr
; /* Current attribute */
6573 int jobid
; /* Job ID */
6574 int docnum
; /* Document number */
6575 cupsd_job_t
*job
; /* Current job */
6576 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6577 username
[HTTP_MAX_URI
], /* Username portion of URI */
6578 host
[HTTP_MAX_URI
], /* Host portion of URI */
6579 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6580 int port
; /* Port portion of URI */
6581 char filename
[1024], /* Filename for document */
6582 format
[1024]; /* Format for document */
6585 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6586 con
->http
.fd
, uri
->values
[0].string
.text
);
6589 * See if we have a job URI or a printer URI...
6592 if (!strcmp(uri
->name
, "printer-uri"))
6595 * Got a printer URI; see if we also have a job-id attribute...
6598 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6599 IPP_TAG_INTEGER
)) == NULL
)
6601 send_ipp_status(con
, IPP_BAD_REQUEST
,
6602 _("Got a printer-uri attribute but no job-id!"));
6606 jobid
= attr
->values
[0].integer
;
6611 * Got a job URI; parse it to get the job ID...
6614 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6615 sizeof(scheme
), username
, sizeof(username
), host
,
6616 sizeof(host
), &port
, resource
, sizeof(resource
));
6618 if (strncmp(resource
, "/jobs/", 6))
6624 send_ipp_status(con
, IPP_BAD_REQUEST
,
6625 _("Bad job-uri attribute \"%s\"!"),
6626 uri
->values
[0].string
.text
);
6630 jobid
= atoi(resource
+ 6);
6634 * See if the job exists...
6637 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6640 * Nope - return a "not found" error...
6643 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6651 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6653 send_http_error(con
, status
, NULL
);
6658 * Get the document number...
6661 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6662 IPP_TAG_INTEGER
)) == NULL
)
6664 send_ipp_status(con
, IPP_BAD_REQUEST
,
6665 _("Missing document-number attribute!"));
6669 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6670 attr
->num_values
> 1)
6672 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6677 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6679 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6681 cupsdLogMessage(CUPSD_LOG_ERROR
,
6682 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6684 send_ipp_status(con
, IPP_NOT_FOUND
,
6685 _("Unable to open document %d in job %d!"), docnum
, jobid
);
6689 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6693 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6694 job
->filetypes
[docnum
- 1]->type
);
6696 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6698 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6700 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6701 IPP_TAG_NAME
)) != NULL
)
6702 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6703 NULL
, attr
->values
[0].string
.text
);
6708 * 'get_job_attrs()' - Get job attributes.
6712 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6713 ipp_attribute_t
*uri
) /* I - Job URI */
6715 http_status_t status
; /* Policy status */
6716 ipp_attribute_t
*attr
; /* Current attribute */
6717 int jobid
; /* Job ID */
6718 cupsd_job_t
*job
; /* Current job */
6719 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6720 username
[HTTP_MAX_URI
], /* Username portion of URI */
6721 host
[HTTP_MAX_URI
], /* Host portion of URI */
6722 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6723 int port
; /* Port portion of URI */
6724 cups_array_t
*ra
; /* Requested attributes array */
6727 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6728 con
->http
.fd
, uri
->values
[0].string
.text
);
6731 * See if we have a job URI or a printer URI...
6734 if (!strcmp(uri
->name
, "printer-uri"))
6737 * Got a printer URI; see if we also have a job-id attribute...
6740 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6741 IPP_TAG_INTEGER
)) == NULL
)
6743 send_ipp_status(con
, IPP_BAD_REQUEST
,
6744 _("Got a printer-uri attribute but no job-id!"));
6748 jobid
= attr
->values
[0].integer
;
6753 * Got a job URI; parse it to get the job ID...
6756 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6757 sizeof(scheme
), username
, sizeof(username
), host
,
6758 sizeof(host
), &port
, resource
, sizeof(resource
));
6760 if (strncmp(resource
, "/jobs/", 6))
6766 send_ipp_status(con
, IPP_BAD_REQUEST
,
6767 _("Bad job-uri attribute \"%s\"!"),
6768 uri
->values
[0].string
.text
);
6772 jobid
= atoi(resource
+ 6);
6776 * See if the job exists...
6779 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6782 * Nope - return a "not found" error...
6785 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6793 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6795 send_http_error(con
, status
, NULL
);
6800 * Copy attributes...
6805 ra
= create_requested_array(con
->request
);
6806 copy_job_attrs(con
, job
, ra
);
6807 cupsArrayDelete(ra
);
6809 con
->response
->request
.status
.status_code
= IPP_OK
;
6814 * 'get_jobs()' - Get a list of jobs for the specified printer.
6818 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6819 ipp_attribute_t
*uri
) /* I - Printer URI */
6821 http_status_t status
; /* Policy status */
6822 ipp_attribute_t
*attr
; /* Current attribute */
6823 const char *dest
; /* Destination */
6824 cups_ptype_t dtype
; /* Destination type (printer/class) */
6825 cups_ptype_t dmask
; /* Destination type mask */
6826 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6827 username
[HTTP_MAX_URI
], /* Username portion of URI */
6828 host
[HTTP_MAX_URI
], /* Host portion of URI */
6829 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6830 int port
; /* Port portion of URI */
6831 int completed
; /* Completed jobs? */
6832 int first_job_id
; /* First job ID */
6833 int limit
; /* Maximum number of jobs to return */
6834 int count
; /* Number of jobs that match */
6835 cupsd_job_t
*job
; /* Current job pointer */
6836 cupsd_printer_t
*printer
; /* Printer */
6837 cups_array_t
*list
; /* Which job list... */
6838 cups_array_t
*ra
; /* Requested attributes array */
6841 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6842 uri
->values
[0].string
.text
);
6845 * Is the destination valid?
6848 if (strcmp(uri
->name
, "printer-uri"))
6850 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request!"));
6854 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6855 sizeof(scheme
), username
, sizeof(username
), host
,
6856 sizeof(host
), &port
, resource
, sizeof(resource
));
6858 if (!strcmp(resource
, "/"))
6861 dtype
= (cups_ptype_t
)0;
6862 dmask
= (cups_ptype_t
)0;
6865 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6868 dtype
= (cups_ptype_t
)0;
6869 dmask
= CUPS_PRINTER_CLASS
;
6872 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6875 dtype
= CUPS_PRINTER_CLASS
;
6876 dmask
= CUPS_PRINTER_CLASS
;
6879 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6886 send_ipp_status(con
, IPP_NOT_FOUND
,
6887 _("The printer or class was not found."));
6892 dtype
&= CUPS_PRINTER_CLASS
;
6893 dmask
= CUPS_PRINTER_CLASS
;
6902 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6905 send_http_error(con
, status
, printer
);
6909 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6911 send_http_error(con
, status
, NULL
);
6916 * See if the "which-jobs" attribute have been specified...
6919 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6920 IPP_TAG_KEYWORD
)) != NULL
&&
6921 !strcmp(attr
->values
[0].string
.text
, "completed"))
6926 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
6931 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "printing"))
6934 list
= PrintingJobs
;
6943 * See if they want to limit the number of jobs reported...
6946 if ((attr
= ippFindAttribute(con
->request
, "limit",
6947 IPP_TAG_INTEGER
)) != NULL
)
6948 limit
= attr
->values
[0].integer
;
6952 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6953 IPP_TAG_INTEGER
)) != NULL
)
6954 first_job_id
= attr
->values
[0].integer
;
6959 * See if we only want to see jobs for a specific user...
6962 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6963 IPP_TAG_BOOLEAN
)) != NULL
&&
6964 attr
->values
[0].boolean
)
6965 strlcpy(username
, get_username(con
), sizeof(username
));
6969 ra
= create_requested_array(con
->request
);
6972 * OK, build a list of jobs for this printer...
6975 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6976 (limit
<= 0 || count
< limit
) && job
;
6977 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6980 * Filter out jobs that don't match...
6983 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: job->id = %d", job
->id
);
6985 if (!job
->dest
|| !job
->username
)
6988 if (!job
->dest
|| !job
->username
)
6991 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6992 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6994 if ((job
->dtype
& dmask
) != dtype
&&
6995 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6997 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
7000 if (job
->id
< first_job_id
)
7008 if (username
[0] && strcasecmp(username
, job
->username
))
7012 ippAddSeparator(con
->response
);
7016 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count = %d", count
);
7018 copy_job_attrs(con
, job
, ra
);
7021 cupsArrayDelete(ra
);
7023 con
->response
->request
.status
.status_code
= IPP_OK
;
7028 * 'get_notifications()' - Get events for a subscription.
7032 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7034 int i
, j
; /* Looping vars */
7035 http_status_t status
; /* Policy status */
7036 cupsd_subscription_t
*sub
; /* Subscription */
7037 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7038 *sequences
; /* notify-sequence-numbers */
7039 int min_seq
; /* Minimum sequence number */
7040 int interval
; /* Poll interval */
7043 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7047 * Get subscription attributes...
7050 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7052 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7057 send_ipp_status(con
, IPP_BAD_REQUEST
,
7058 _("Missing notify-subscription-ids attribute!"));
7063 * Are the subscription IDs valid?
7066 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7068 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7071 * Bad subscription ID...
7074 send_ipp_status(con
, IPP_NOT_FOUND
,
7075 _("notify-subscription-id %d no good!"),
7076 ids
->values
[i
].integer
);
7084 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7086 con
, sub
->owner
)) != HTTP_OK
)
7088 send_http_error(con
, status
, sub
->dest
);
7093 * Check the subscription type and update the interval accordingly.
7096 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7099 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7101 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7107 * Tell the client to poll again in N seconds...
7111 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7112 "notify-get-interval", interval
);
7114 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7115 "printer-up-time", time(NULL
));
7118 * Copy the subscription event attributes to the response.
7121 con
->response
->request
.status
.status_code
=
7122 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7124 for (i
= 0; i
< ids
->num_values
; i
++)
7127 * Get the subscription and sequence number...
7130 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7132 if (sequences
&& i
< sequences
->num_values
)
7133 min_seq
= sequences
->values
[i
].integer
;
7138 * If we don't have any new events, nothing to do here...
7141 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7145 * Otherwise copy all of the new events...
7148 if (sub
->first_event_id
> min_seq
)
7151 j
= min_seq
- sub
->first_event_id
;
7153 for (; j
< sub
->num_events
; j
++)
7155 ippAddSeparator(con
->response
);
7157 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7158 IPP_TAG_EVENT_NOTIFICATION
, 0);
7165 * 'get_ppd()' - Get a named PPD from the local system.
7169 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7170 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7172 http_status_t status
; /* Policy status */
7173 cupsd_printer_t
*dest
; /* Destination */
7174 cups_ptype_t dtype
; /* Destination type */
7177 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7178 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7180 if (!strcmp(uri
->name
, "ppd-name"))
7183 * Return a PPD file from cups-driverd...
7186 char command
[1024], /* cups-driverd command */
7187 options
[1024], /* Options to pass to command */
7188 ppd_name
[1024]; /* ppd-name */
7195 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7197 send_http_error(con
, status
, NULL
);
7202 * Run cups-driverd command with the given options...
7205 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7206 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7207 snprintf(options
, sizeof(options
), "get+%d+%s",
7208 con
->request
->request
.op
.request_id
, ppd_name
);
7210 if (cupsdSendCommand(con
, command
, options
, 0))
7213 * Command started successfully, don't send an IPP response here...
7216 ippDelete(con
->response
);
7217 con
->response
= NULL
;
7222 * Command failed, return "internal error" so the user knows something
7226 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7227 _("cups-driverd failed to execute."));
7230 else if (!strcmp(uri
->name
, "printer-uri") &&
7231 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7233 int i
; /* Looping var */
7234 char filename
[1024]; /* PPD filename */
7241 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7243 send_http_error(con
, status
, dest
);
7248 * See if we need the PPD for a class or remote printer...
7251 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7254 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7256 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7257 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7258 "printer-uri", NULL
, dest
->uri
);
7261 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7263 for (i
= 0; i
< dest
->num_printers
; i
++)
7264 if (!(dest
->printers
[i
]->type
&
7265 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7267 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7268 dest
->printers
[i
]->name
);
7270 if (!access(filename
, 0))
7274 if (i
< dest
->num_printers
)
7275 dest
= dest
->printers
[i
];
7278 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7279 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7280 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7286 * Found the printer with the PPD file, now see if there is one...
7289 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7291 send_ipp_status(con
, IPP_NOT_FOUND
,
7292 _("The PPD file \"%s\" could not be opened: %s"),
7293 uri
->values
[0].string
.text
, strerror(errno
));
7297 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7301 con
->response
->request
.status
.status_code
= IPP_OK
;
7304 send_ipp_status(con
, IPP_NOT_FOUND
,
7305 _("The PPD file \"%s\" could not be found."),
7306 uri
->values
[0].string
.text
);
7311 * 'get_ppds()' - Get the list of PPD files on the local system.
7315 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7317 http_status_t status
; /* Policy status */
7318 ipp_attribute_t
*limit
, /* Limit attribute */
7319 *device
, /* ppd-device-id attribute */
7320 *language
, /* ppd-natural-language attribute */
7321 *make
, /* ppd-make attribute */
7322 *model
, /* ppd-make-and-model attribute */
7323 *model_number
, /* ppd-model-number attribute */
7324 *product
, /* ppd-product attribute */
7325 *psversion
, /* ppd-psverion attribute */
7326 *type
, /* ppd-type attribute */
7327 *requested
, /* requested-attributes attribute */
7328 *exclude
, /* exclude-schemes attribute */
7329 *include
; /* include-schemes attribute */
7330 char command
[1024], /* cups-driverd command */
7331 options
[4096], /* Options to pass to command */
7332 device_str
[256],/* Escaped ppd-device-id string */
7334 /* Escaped ppd-natural-language */
7335 make_str
[256], /* Escaped ppd-make string */
7336 model_str
[256], /* Escaped ppd-make-and-model string */
7337 model_number_str
[256],
7338 /* ppd-model-number string */
7340 /* Escaped ppd-product string */
7342 /* Escaped ppd-psversion string */
7343 type_str
[256], /* Escaped ppd-type string */
7345 /* String for requested attributes */
7347 /* String for excluded schemes */
7349 /* String for included schemes */
7352 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7358 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7360 send_http_error(con
, status
, NULL
);
7365 * Run cups-driverd command with the given options...
7368 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7369 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7370 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7372 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7373 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7375 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7377 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7378 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7379 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7380 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7382 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7384 include
= ippFindAttribute(con
->request
, "include-schemes",
7388 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7390 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7393 url_encode_attr(device
, device_str
, sizeof(device_str
));
7395 device_str
[0] = '\0';
7398 url_encode_attr(language
, language_str
, sizeof(language_str
));
7400 language_str
[0] = '\0';
7403 url_encode_attr(make
, make_str
, sizeof(make_str
));
7408 url_encode_attr(model
, model_str
, sizeof(model_str
));
7410 model_str
[0] = '\0';
7413 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7414 model_number
->values
[0].integer
);
7416 model_number_str
[0] = '\0';
7419 url_encode_attr(product
, product_str
, sizeof(product_str
));
7421 product_str
[0] = '\0';
7424 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7426 psversion_str
[0] = '\0';
7429 url_encode_attr(type
, type_str
, sizeof(type_str
));
7434 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7436 exclude_str
[0] = '\0';
7439 url_encode_attr(include
, include_str
, sizeof(include_str
));
7441 include_str
[0] = '\0';
7443 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7444 snprintf(options
, sizeof(options
),
7445 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7446 con
->request
->request
.op
.request_id
,
7447 limit
? limit
->values
[0].integer
: 0,
7449 device
? "%20" : "", device_str
,
7450 language
? "%20" : "", language_str
,
7451 make
? "%20" : "", make_str
,
7452 model
? "%20" : "", model_str
,
7453 model_number
? "%20" : "", model_number_str
,
7454 product
? "%20" : "", product_str
,
7455 psversion
? "%20" : "", psversion_str
,
7456 type
? "%20" : "", type_str
,
7457 exclude_str
[0] ? "%20" : "", exclude_str
,
7458 include_str
[0] ? "%20" : "", include_str
);
7460 if (cupsdSendCommand(con
, command
, options
, 0))
7463 * Command started successfully, don't send an IPP response here...
7466 ippDelete(con
->response
);
7467 con
->response
= NULL
;
7472 * Command failed, return "internal error" so the user knows something
7476 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7477 _("cups-driverd failed to execute."));
7483 * 'get_printer_attrs()' - Get printer attributes.
7487 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7488 ipp_attribute_t
*uri
) /* I - Printer URI */
7490 http_status_t status
; /* Policy status */
7491 cups_ptype_t dtype
; /* Destination type (printer/class) */
7492 cupsd_printer_t
*printer
; /* Printer/class */
7493 cups_array_t
*ra
; /* Requested attributes array */
7496 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7497 con
->http
.fd
, uri
->values
[0].string
.text
);
7500 * Is the destination valid?
7503 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7509 send_ipp_status(con
, IPP_NOT_FOUND
,
7510 _("The printer or class was not found."));
7518 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7520 send_http_error(con
, status
, printer
);
7525 * Send the attributes...
7528 ra
= create_requested_array(con
->request
);
7530 copy_printer_attrs(con
, printer
, ra
);
7532 cupsArrayDelete(ra
);
7534 con
->response
->request
.status
.status_code
= IPP_OK
;
7539 * 'get_printer_supported()' - Get printer supported values.
7543 get_printer_supported(
7544 cupsd_client_t
*con
, /* I - Client connection */
7545 ipp_attribute_t
*uri
) /* I - Printer URI */
7547 http_status_t status
; /* Policy status */
7548 cups_ptype_t dtype
; /* Destination type (printer/class) */
7549 cupsd_printer_t
*printer
; /* Printer/class */
7552 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7553 con
->http
.fd
, uri
->values
[0].string
.text
);
7556 * Is the destination valid?
7559 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7565 send_ipp_status(con
, IPP_NOT_FOUND
,
7566 _("The printer or class was not found."));
7574 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7576 send_http_error(con
, status
, printer
);
7581 * Return a list of attributes that can be set via Set-Printer-Attributes.
7584 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7586 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7587 "printer-location", 0);
7589 con
->response
->request
.status
.status_code
= IPP_OK
;
7594 * 'get_printers()' - Get a list of printers or classes.
7598 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7599 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7601 http_status_t status
; /* Policy status */
7602 ipp_attribute_t
*attr
; /* Current attribute */
7603 int limit
; /* Max number of printers to return */
7604 int count
; /* Number of printers that match */
7605 cupsd_printer_t
*printer
; /* Current printer pointer */
7606 int printer_type
, /* printer-type attribute */
7607 printer_mask
; /* printer-type-mask attribute */
7608 char *location
; /* Location string */
7609 const char *username
; /* Current user */
7610 char *first_printer_name
; /* first-printer-name attribute */
7611 cups_array_t
*ra
; /* Requested attributes array */
7614 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7615 con
->http
.fd
, type
);
7621 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7623 send_http_error(con
, status
, NULL
);
7628 * Check for printers...
7631 if (!Printers
|| !cupsArrayCount(Printers
))
7633 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7638 * See if they want to limit the number of printers reported...
7641 if ((attr
= ippFindAttribute(con
->request
, "limit",
7642 IPP_TAG_INTEGER
)) != NULL
)
7643 limit
= attr
->values
[0].integer
;
7647 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7648 IPP_TAG_NAME
)) != NULL
)
7649 first_printer_name
= attr
->values
[0].string
.text
;
7651 first_printer_name
= NULL
;
7654 * Support filtering...
7657 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7658 IPP_TAG_ENUM
)) != NULL
)
7659 printer_type
= attr
->values
[0].integer
;
7663 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7664 IPP_TAG_ENUM
)) != NULL
)
7665 printer_mask
= attr
->values
[0].integer
;
7669 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7670 IPP_TAG_TEXT
)) != NULL
)
7671 location
= attr
->values
[0].string
.text
;
7675 if (con
->username
[0])
7676 username
= con
->username
;
7677 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7678 IPP_TAG_NAME
)) != NULL
)
7679 username
= attr
->values
[0].string
.text
;
7683 ra
= create_requested_array(con
->request
);
7686 * OK, build a list of printers for this printer...
7689 if (first_printer_name
)
7691 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7692 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7695 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7698 count
< limit
&& printer
;
7699 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7701 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7702 (printer
->type
& printer_mask
) == printer_type
&&
7704 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
7707 * If HideImplicitMembers is enabled, see if this printer or class
7708 * is a member of an implicit class...
7711 if (ImplicitClasses
&& HideImplicitMembers
&&
7712 printer
->in_implicit_class
)
7716 * If a username is specified, see if it is allowed or denied
7720 if (!(printer
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
7721 printer
->num_users
&& username
&& !user_allowed(printer
, username
))
7725 * Add the group separator as needed...
7729 ippAddSeparator(con
->response
);
7734 * Send the attributes...
7737 copy_printer_attrs(con
, printer
, ra
);
7741 cupsArrayDelete(ra
);
7743 con
->response
->request
.status
.status_code
= IPP_OK
;
7748 * 'get_subscription_attrs()' - Get subscription attributes.
7752 get_subscription_attrs(
7753 cupsd_client_t
*con
, /* I - Client connection */
7754 int sub_id
) /* I - Subscription ID */
7756 http_status_t status
; /* Policy status */
7757 cupsd_subscription_t
*sub
; /* Subscription */
7758 cups_array_t
*ra
; /* Requested attributes array */
7761 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7762 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7763 con
, con
->http
.fd
, sub_id
);
7766 * Is the subscription ID valid?
7769 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7772 * Bad subscription ID...
7775 send_ipp_status(con
, IPP_NOT_FOUND
,
7776 _("notify-subscription-id %d no good!"), sub_id
);
7784 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7786 con
, sub
->owner
)) != HTTP_OK
)
7788 send_http_error(con
, status
, sub
->dest
);
7793 * Copy the subscription attributes to the response using the
7794 * requested-attributes attribute that may be provided by the client.
7797 ra
= create_requested_array(con
->request
);
7799 copy_subscription_attrs(con
, sub
, ra
);
7801 cupsArrayDelete(ra
);
7803 con
->response
->request
.status
.status_code
= IPP_OK
;
7808 * 'get_subscriptions()' - Get subscriptions.
7812 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7813 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7815 http_status_t status
; /* Policy status */
7816 int count
; /* Number of subscriptions */
7817 int limit
; /* Limit */
7818 cupsd_subscription_t
*sub
; /* Subscription */
7819 cups_array_t
*ra
; /* Requested attributes array */
7820 ipp_attribute_t
*attr
; /* Attribute */
7821 cups_ptype_t dtype
; /* Destination type (printer/class) */
7822 char scheme
[HTTP_MAX_URI
],
7823 /* Scheme portion of URI */
7824 username
[HTTP_MAX_URI
],
7825 /* Username portion of URI */
7827 /* Host portion of URI */
7828 resource
[HTTP_MAX_URI
];
7829 /* Resource portion of URI */
7830 int port
; /* Port portion of URI */
7831 cupsd_job_t
*job
; /* Job pointer */
7832 cupsd_printer_t
*printer
; /* Printer */
7835 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7836 "get_subscriptions(con=%p[%d], uri=%s)",
7837 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7840 * Is the destination valid?
7843 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7844 sizeof(scheme
), username
, sizeof(username
), host
,
7845 sizeof(host
), &port
, resource
, sizeof(resource
));
7847 if (!strcmp(resource
, "/") ||
7848 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7849 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7850 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7855 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7858 job
= cupsdFindJob(atoi(resource
+ 6));
7862 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
7867 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7873 send_ipp_status(con
, IPP_NOT_FOUND
,
7874 _("The printer or class was not found."));
7877 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7878 IPP_TAG_INTEGER
)) != NULL
)
7880 job
= cupsdFindJob(attr
->values
[0].integer
);
7884 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
7885 attr
->values
[0].integer
);
7896 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
7898 con
, NULL
)) != HTTP_OK
)
7900 send_http_error(con
, status
, printer
);
7905 * Copy the subscription attributes to the response using the
7906 * requested-attributes attribute that may be provided by the client.
7909 ra
= create_requested_array(con
->request
);
7911 if ((attr
= ippFindAttribute(con
->request
, "limit",
7912 IPP_TAG_INTEGER
)) != NULL
)
7913 limit
= attr
->values
[0].integer
;
7918 * See if we only want to see subscriptions for a specific user...
7921 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7922 IPP_TAG_BOOLEAN
)) != NULL
&&
7923 attr
->values
[0].boolean
)
7924 strlcpy(username
, get_username(con
), sizeof(username
));
7928 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7930 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7931 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7932 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
7934 ippAddSeparator(con
->response
);
7935 copy_subscription_attrs(con
, sub
, ra
);
7938 if (limit
&& count
>= limit
)
7942 cupsArrayDelete(ra
);
7945 con
->response
->request
.status
.status_code
= IPP_OK
;
7947 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7952 * 'get_username()' - Get the username associated with a request.
7955 static const char * /* O - Username */
7956 get_username(cupsd_client_t
*con
) /* I - Connection */
7958 ipp_attribute_t
*attr
; /* Attribute */
7961 if (con
->username
[0])
7962 return (con
->username
);
7963 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7964 IPP_TAG_NAME
)) != NULL
)
7965 return (attr
->values
[0].string
.text
);
7967 return ("anonymous");
7972 * 'hold_job()' - Hold a print job.
7976 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7977 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7979 ipp_attribute_t
*attr
, /* Current job-hold-until */
7980 *newattr
; /* New job-hold-until */
7981 int jobid
; /* Job ID */
7982 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7983 username
[HTTP_MAX_URI
], /* Username portion of URI */
7984 host
[HTTP_MAX_URI
], /* Host portion of URI */
7985 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7986 int port
; /* Port portion of URI */
7987 cupsd_job_t
*job
; /* Job information */
7990 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
7991 uri
->values
[0].string
.text
);
7994 * See if we have a job URI or a printer URI...
7997 if (!strcmp(uri
->name
, "printer-uri"))
8000 * Got a printer URI; see if we also have a job-id attribute...
8003 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8004 IPP_TAG_INTEGER
)) == NULL
)
8006 send_ipp_status(con
, IPP_BAD_REQUEST
,
8007 _("Got a printer-uri attribute but no job-id!"));
8011 jobid
= attr
->values
[0].integer
;
8016 * Got a job URI; parse it to get the job ID...
8019 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8020 sizeof(scheme
), username
, sizeof(username
), host
,
8021 sizeof(host
), &port
, resource
, sizeof(resource
));
8023 if (strncmp(resource
, "/jobs/", 6))
8029 send_ipp_status(con
, IPP_BAD_REQUEST
,
8030 _("Bad job-uri attribute \"%s\"!"),
8031 uri
->values
[0].string
.text
);
8035 jobid
= atoi(resource
+ 6);
8039 * See if the job exists...
8042 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8045 * Nope - return a "not found" error...
8048 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8053 * See if the job is owned by the requesting user...
8056 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8058 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8063 * Hold the job and return...
8068 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8069 "Job held by user.");
8071 if ((newattr
= ippFindAttribute(con
->request
, "job-hold-until",
8072 IPP_TAG_KEYWORD
)) == NULL
)
8073 newattr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8075 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8076 IPP_TAG_KEYWORD
)) == NULL
)
8077 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8082 * Free the old hold value and copy the new one over...
8085 _cupsStrFree(attr
->values
[0].string
.text
);
8089 attr
->value_tag
= newattr
->value_tag
;
8090 attr
->values
[0].string
.text
=
8091 _cupsStrRetain(newattr
->values
[0].string
.text
);
8095 attr
->value_tag
= IPP_TAG_KEYWORD
;
8096 attr
->values
[0].string
.text
= _cupsStrAlloc("indefinite");
8100 * Hold job until specified time...
8103 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
8105 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8106 "Job job-hold-until value changed by user.");
8109 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Held by \"%s\".", username
);
8111 con
->response
->request
.status
.status_code
= IPP_OK
;
8116 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8120 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8121 ipp_attribute_t
*uri
) /* I - Printer URI */
8123 http_status_t status
; /* Policy status */
8124 cups_ptype_t dtype
; /* Destination type (printer/class) */
8125 cupsd_printer_t
*printer
; /* Printer data */
8128 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8129 con
->http
.fd
, uri
->values
[0].string
.text
);
8132 * Is the destination valid?
8135 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8141 send_ipp_status(con
, IPP_NOT_FOUND
,
8142 _("The printer or class was not found."));
8150 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8152 send_http_error(con
, status
, printer
);
8157 * Hold pending/new jobs sent to the printer...
8160 printer
->holding_new_jobs
= 1;
8162 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8163 cupsdAddPrinterHistory(printer
);
8165 if (dtype
& CUPS_PRINTER_CLASS
)
8166 cupsdLogMessage(CUPSD_LOG_INFO
,
8167 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8168 printer
->name
, get_username(con
));
8170 cupsdLogMessage(CUPSD_LOG_INFO
,
8171 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8172 printer
->name
, get_username(con
));
8175 * Everything was ok, so return OK status...
8178 con
->response
->request
.status
.status_code
= IPP_OK
;
8183 * 'move_job()' - Move a job to a new destination.
8187 move_job(cupsd_client_t
*con
, /* I - Client connection */
8188 ipp_attribute_t
*uri
) /* I - Job URI */
8190 http_status_t status
; /* Policy status */
8191 ipp_attribute_t
*attr
; /* Current attribute */
8192 int jobid
; /* Job ID */
8193 cupsd_job_t
*job
; /* Current job */
8194 const char *src
; /* Source printer/class */
8195 cups_ptype_t stype
, /* Source type (printer or class) */
8196 dtype
; /* Destination type (printer/class) */
8197 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8198 username
[HTTP_MAX_URI
], /* Username portion of URI */
8199 host
[HTTP_MAX_URI
], /* Host portion of URI */
8200 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8201 int port
; /* Port portion of URI */
8202 cupsd_printer_t
*sprinter
, /* Source printer */
8203 *dprinter
; /* Destination printer */
8206 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8207 uri
->values
[0].string
.text
);
8210 * Get the new printer or class...
8213 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8214 IPP_TAG_URI
)) == NULL
)
8217 * Need job-printer-uri...
8220 send_ipp_status(con
, IPP_BAD_REQUEST
,
8221 _("job-printer-uri attribute missing!"));
8225 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8231 send_ipp_status(con
, IPP_NOT_FOUND
,
8232 _("The printer or class was not found."));
8237 * See if we have a job URI or a printer URI...
8240 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8241 sizeof(scheme
), username
, sizeof(username
), host
,
8242 sizeof(host
), &port
, resource
, sizeof(resource
));
8244 if (!strcmp(uri
->name
, "printer-uri"))
8247 * Got a printer URI; see if we also have a job-id attribute...
8250 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8251 IPP_TAG_INTEGER
)) == NULL
)
8257 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8258 &sprinter
)) == NULL
)
8264 send_ipp_status(con
, IPP_NOT_FOUND
,
8265 _("The printer or class was not found."));
8274 * Otherwise, just move a single job...
8277 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8280 * Nope - return a "not found" error...
8283 send_ipp_status(con
, IPP_NOT_FOUND
,
8284 _("Job #%d does not exist!"), attr
->values
[0].integer
);
8290 * Job found, initialize source pointers...
8301 * Got a job URI; parse it to get the job ID...
8304 if (strncmp(resource
, "/jobs/", 6))
8310 send_ipp_status(con
, IPP_BAD_REQUEST
,
8311 _("Bad job-uri attribute \"%s\"!"),
8312 uri
->values
[0].string
.text
);
8317 * See if the job exists...
8320 jobid
= atoi(resource
+ 6);
8322 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8325 * Nope - return a "not found" error...
8328 send_ipp_status(con
, IPP_NOT_FOUND
,
8329 _("Job #%d does not exist!"), jobid
);
8335 * Job found, initialize source pointers...
8344 * Check the policy of the destination printer...
8347 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8348 job
? job
->username
: NULL
)) != HTTP_OK
)
8350 send_http_error(con
, status
, dprinter
);
8355 * Now move the job or jobs...
8361 * See if the job has been completed...
8364 if (job
->state_value
> IPP_JOB_STOPPED
)
8367 * Return a "not-possible" error...
8370 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8371 _("Job #%d is finished and cannot be altered!"),
8377 * See if the job is owned by the requesting user...
8380 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8382 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8387 * Move the job to a different printer or class...
8390 cupsdMoveJob(job
, dprinter
);
8395 * Got the source printer, now look through the jobs...
8398 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8400 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8403 * See if the job is pointing at the source printer or has not been
8407 if (strcasecmp(job
->dest
, src
) ||
8408 job
->state_value
> IPP_JOB_STOPPED
)
8412 * See if the job can be moved by the requesting user...
8415 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8419 * Move the job to a different printer or class...
8422 cupsdMoveJob(job
, dprinter
);
8427 * Start jobs if possible...
8433 * Return with "everything is OK" status...
8436 con
->response
->request
.status
.status_code
= IPP_OK
;
8441 * 'ppd_parse_line()' - Parse a PPD default line.
8444 static int /* O - 0 on success, -1 on failure */
8445 ppd_parse_line(const char *line
, /* I - Line */
8446 char *option
, /* O - Option name */
8447 int olen
, /* I - Size of option name */
8448 char *choice
, /* O - Choice name */
8449 int clen
) /* I - Size of choice name */
8452 * Verify this is a default option line...
8455 if (strncmp(line
, "*Default", 8))
8459 * Read the option name...
8462 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
8472 * Skip everything else up to the colon (:)...
8475 while (*line
&& *line
!= ':')
8484 * Now grab the option choice, skipping leading whitespace...
8487 while (isspace(*line
& 255))
8490 for (clen
--; isalnum(*line
& 255); line
++)
8500 * Return with no errors...
8508 * 'print_job()' - Print a file to a printer or class.
8512 print_job(cupsd_client_t
*con
, /* I - Client connection */
8513 ipp_attribute_t
*uri
) /* I - Printer URI */
8515 ipp_attribute_t
*attr
; /* Current attribute */
8516 ipp_attribute_t
*format
; /* Document-format attribute */
8517 const char *default_format
; /* document-format-default value */
8518 cupsd_job_t
*job
; /* New job */
8519 char filename
[1024]; /* Job filename */
8520 mime_type_t
*filetype
; /* Type of file */
8521 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8522 type
[MIME_MAX_TYPE
], /* Subtype of file */
8523 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8524 /* Textual name of mime type */
8525 cupsd_printer_t
*printer
; /* Printer data */
8526 struct stat fileinfo
; /* File information */
8527 int kbytes
; /* Size of file */
8528 int compression
; /* Document compression */
8531 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8532 uri
->values
[0].string
.text
);
8535 * Validate print file attributes, for now just document-format and
8536 * compression (CUPS only supports "none" and "gzip")...
8539 compression
= CUPS_FILE_NONE
;
8541 if ((attr
= ippFindAttribute(con
->request
, "compression",
8542 IPP_TAG_KEYWORD
)) != NULL
)
8544 if (strcmp(attr
->values
[0].string
.text
, "none")
8546 && strcmp(attr
->values
[0].string
.text
, "gzip")
8547 #endif /* HAVE_LIBZ */
8550 send_ipp_status(con
, IPP_ATTRIBUTES
,
8551 _("Unsupported compression \"%s\"!"),
8552 attr
->values
[0].string
.text
);
8553 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8554 "compression", NULL
, attr
->values
[0].string
.text
);
8559 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8560 compression
= CUPS_FILE_GZIP
;
8561 #endif /* HAVE_LIBZ */
8565 * Do we have a file to print?
8570 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8575 * Is the destination valid?
8578 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8584 send_ipp_status(con
, IPP_NOT_FOUND
,
8585 _("The printer or class was not found."));
8590 * Is it a format we support?
8593 if ((format
= ippFindAttribute(con
->request
, "document-format",
8594 IPP_TAG_MIMETYPE
)) != NULL
)
8597 * Grab format from client...
8600 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8603 send_ipp_status(con
, IPP_BAD_REQUEST
,
8604 _("Could not scan type \"%s\"!"),
8605 format
->values
[0].string
.text
);
8609 else if ((default_format
= cupsGetOption("document-format",
8610 printer
->num_options
,
8611 printer
->options
)) != NULL
)
8614 * Use default document format...
8617 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8619 send_ipp_status(con
, IPP_BAD_REQUEST
,
8620 _("Could not scan type \"%s\"!"),
8631 strcpy(super
, "application");
8632 strcpy(type
, "octet-stream");
8635 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8638 * Auto-type the file...
8641 ipp_attribute_t
*doc_name
; /* document-name attribute */
8644 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8646 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8647 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8648 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8652 filetype
= mimeType(MimeDatabase
, super
, type
);
8654 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8655 filetype
->super
, filetype
->type
);
8658 filetype
= mimeType(MimeDatabase
, super
, type
);
8662 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8665 * Replace the document-format attribute value with the auto-typed or
8669 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8674 _cupsStrFree(format
->values
[0].string
.text
);
8676 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8679 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8680 "document-format", NULL
, mimetype
);
8684 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8685 _("Unsupported format \'%s/%s\'!"), super
, type
);
8686 cupsdLogMessage(CUPSD_LOG_INFO
,
8687 "Hint: Do you have the raw file printing rules enabled?");
8690 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8691 "document-format", NULL
, format
->values
[0].string
.text
);
8697 * Read any embedded job ticket info from PS files...
8700 if (!strcasecmp(filetype
->super
, "application") &&
8701 (!strcasecmp(filetype
->type
, "postscript") ||
8702 !strcasecmp(filetype
->type
, "pdf")))
8703 read_job_ticket(con
);
8706 * Create the job object...
8709 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8713 * Update quota data...
8716 if (stat(con
->filename
, &fileinfo
))
8719 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8721 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8723 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8724 IPP_TAG_INTEGER
)) != NULL
)
8725 attr
->values
[0].integer
+= kbytes
;
8728 * Add the job file...
8731 if (add_file(con
, job
, filetype
, compression
))
8734 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8736 rename(con
->filename
, filename
);
8737 cupsdClearString(&con
->filename
);
8740 * See if we need to add the ending sheet...
8743 if (cupsdTimeoutJob(job
))
8747 * Log and save the job...
8750 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8751 "File of type %s/%s queued by \"%s\".",
8752 filetype
->super
, filetype
->type
, job
->username
);
8753 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8754 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8755 job
->dest
, job
->username
);
8758 * Start the job if possible...
8766 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8768 * This function only gets called when printing a single PDF or PostScript
8769 * file using the Print-Job operation. It doesn't work for Create-Job +
8770 * Send-File, since the job attributes need to be set at job creation
8771 * time for banners to work. The embedded job ticket stuff is here
8772 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8773 * options and IPP attributes which otherwise would be lost.
8775 * The format of a job ticket is simple:
8777 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8779 * %cupsJobTicket: attr1=value1
8780 * %cupsJobTicket: attr2=value2
8782 * %cupsJobTicket: attrN=valueN
8784 * Job ticket lines must appear immediately after the first line that
8785 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8786 * stops looking for job ticket info when it finds a line that does not begin
8787 * with "%cupsJobTicket:".
8789 * The maximum length of a job ticket line, including the prefix, is
8790 * 255 characters to conform with the Adobe DSC.
8792 * Read-only attributes are rejected with a notice to the error log in
8793 * case a malicious user tries anything. Since the job ticket is read
8794 * prior to attribute validation in print_job(), job ticket attributes
8795 * will go through the same validation as IPP attributes...
8799 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8801 cups_file_t
*fp
; /* File to read from */
8802 char line
[256]; /* Line data */
8803 int num_options
; /* Number of options */
8804 cups_option_t
*options
; /* Options */
8805 ipp_t
*ticket
; /* New attributes */
8806 ipp_attribute_t
*attr
, /* Current attribute */
8807 *attr2
, /* Job attribute */
8808 *prev2
; /* Previous job attribute */
8812 * First open the print file...
8815 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8817 cupsdLogMessage(CUPSD_LOG_ERROR
,
8818 "Unable to open print file for job ticket - %s",
8824 * Skip the first line...
8827 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8829 cupsdLogMessage(CUPSD_LOG_ERROR
,
8830 "Unable to read from print file for job ticket - %s",
8836 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8839 * Not a DSC-compliant file, so no job ticket info will be available...
8847 * Read job ticket info from the file...
8853 while (cupsFileGets(fp
, line
, sizeof(line
)))
8856 * Stop at the first non-ticket line...
8859 if (strncmp(line
, "%cupsJobTicket:", 15))
8863 * Add the options to the option array...
8866 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8870 * Done with the file; see if we have any options...
8875 if (num_options
== 0)
8879 * OK, convert the options to an attribute list, and apply them to
8884 cupsEncodeOptions(ticket
, num_options
, options
);
8887 * See what the user wants to change.
8890 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8892 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8895 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8896 !strcmp(attr
->name
, "job-originating-user-name") ||
8897 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8898 !strcmp(attr
->name
, "job-k-octets") ||
8899 !strcmp(attr
->name
, "job-id") ||
8900 !strncmp(attr
->name
, "job-state", 9) ||
8901 !strncmp(attr
->name
, "time-at-", 8))
8902 continue; /* Read-only attrs */
8904 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8905 IPP_TAG_ZERO
)) != NULL
)
8908 * Some other value; first free the old value...
8911 if (con
->request
->attrs
== attr2
)
8913 con
->request
->attrs
= attr2
->next
;
8918 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8919 if (prev2
->next
== attr2
)
8921 prev2
->next
= attr2
->next
;
8926 if (con
->request
->last
== attr2
)
8927 con
->request
->last
= prev2
;
8929 _ippFreeAttr(attr2
);
8933 * Add new option by copying it...
8936 copy_attribute(con
->request
, attr
, 0);
8940 * Then free the attribute list and option array...
8944 cupsFreeOptions(num_options
, options
);
8949 * 'reject_jobs()' - Reject print jobs to a printer.
8953 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8954 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8956 http_status_t status
; /* Policy status */
8957 cups_ptype_t dtype
; /* Destination type (printer/class) */
8958 cupsd_printer_t
*printer
; /* Printer data */
8959 ipp_attribute_t
*attr
; /* printer-state-message text */
8962 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8963 con
->http
.fd
, uri
->values
[0].string
.text
);
8966 * Is the destination valid?
8969 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8975 send_ipp_status(con
, IPP_NOT_FOUND
,
8976 _("The printer or class was not found."));
8984 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8986 send_http_error(con
, status
, printer
);
8991 * Reject jobs sent to the printer...
8994 printer
->accepting
= 0;
8996 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8997 IPP_TAG_TEXT
)) == NULL
)
8998 strcpy(printer
->state_message
, "Rejecting Jobs");
9000 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9001 sizeof(printer
->state_message
));
9003 cupsdAddPrinterHistory(printer
);
9005 if (dtype
& CUPS_PRINTER_CLASS
)
9007 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9009 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9010 printer
->name
, get_username(con
));
9014 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9016 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9017 printer
->name
, get_username(con
));
9021 * Everything was ok, so return OK status...
9024 con
->response
->request
.status
.status_code
= IPP_OK
;
9029 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9033 release_held_new_jobs(
9034 cupsd_client_t
*con
, /* I - Connection */
9035 ipp_attribute_t
*uri
) /* I - Printer URI */
9037 http_status_t status
; /* Policy status */
9038 cups_ptype_t dtype
; /* Destination type (printer/class) */
9039 cupsd_printer_t
*printer
; /* Printer data */
9042 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9043 con
->http
.fd
, uri
->values
[0].string
.text
);
9046 * Is the destination valid?
9049 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9055 send_ipp_status(con
, IPP_NOT_FOUND
,
9056 _("The printer or class was not found."));
9064 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9066 send_http_error(con
, status
, printer
);
9071 * Hold pending/new jobs sent to the printer...
9074 printer
->holding_new_jobs
= 0;
9076 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9077 cupsdAddPrinterHistory(printer
);
9079 if (dtype
& CUPS_PRINTER_CLASS
)
9080 cupsdLogMessage(CUPSD_LOG_INFO
,
9081 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9082 printer
->name
, get_username(con
));
9084 cupsdLogMessage(CUPSD_LOG_INFO
,
9085 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9086 printer
->name
, get_username(con
));
9089 * Everything was ok, so return OK status...
9092 con
->response
->request
.status
.status_code
= IPP_OK
;
9097 * 'release_job()' - Release a held print job.
9101 release_job(cupsd_client_t
*con
, /* I - Client connection */
9102 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9104 ipp_attribute_t
*attr
; /* Current attribute */
9105 int jobid
; /* Job ID */
9106 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9107 username
[HTTP_MAX_URI
], /* Username portion of URI */
9108 host
[HTTP_MAX_URI
], /* Host portion of URI */
9109 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9110 int port
; /* Port portion of URI */
9111 cupsd_job_t
*job
; /* Job information */
9114 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9115 con
->http
.fd
, uri
->values
[0].string
.text
);
9118 * See if we have a job URI or a printer URI...
9121 if (!strcmp(uri
->name
, "printer-uri"))
9124 * Got a printer URI; see if we also have a job-id attribute...
9127 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9128 IPP_TAG_INTEGER
)) == NULL
)
9130 send_ipp_status(con
, IPP_BAD_REQUEST
,
9131 _("Got a printer-uri attribute but no job-id!"));
9135 jobid
= attr
->values
[0].integer
;
9140 * Got a job URI; parse it to get the job ID...
9143 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9144 sizeof(scheme
), username
, sizeof(username
), host
,
9145 sizeof(host
), &port
, resource
, sizeof(resource
));
9147 if (strncmp(resource
, "/jobs/", 6))
9153 send_ipp_status(con
, IPP_BAD_REQUEST
,
9154 _("Bad job-uri attribute \"%s\"!"),
9155 uri
->values
[0].string
.text
);
9159 jobid
= atoi(resource
+ 6);
9163 * See if the job exists...
9166 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9169 * Nope - return a "not found" error...
9172 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9177 * See if job is "held"...
9180 if (job
->state_value
!= IPP_JOB_HELD
)
9183 * Nope - return a "not possible" error...
9186 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
9191 * See if the job is owned by the requesting user...
9194 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9196 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9201 * Reset the job-hold-until value to "no-hold"...
9204 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9205 IPP_TAG_KEYWORD
)) == NULL
)
9206 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9210 _cupsStrFree(attr
->values
[0].string
.text
);
9212 attr
->value_tag
= IPP_TAG_KEYWORD
;
9213 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9215 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9216 "Job job-hold-until value changed by user.");
9220 * Release the job and return...
9223 cupsdReleaseJob(job
);
9225 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9226 "Job released by user.");
9228 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9230 con
->response
->request
.status
.status_code
= IPP_OK
;
9237 * 'renew_subscription()' - Renew an existing subscription...
9242 cupsd_client_t
*con
, /* I - Client connection */
9243 int sub_id
) /* I - Subscription ID */
9245 http_status_t status
; /* Policy status */
9246 cupsd_subscription_t
*sub
; /* Subscription */
9247 ipp_attribute_t
*lease
; /* notify-lease-duration */
9250 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9251 "renew_subscription(con=%p[%d], sub_id=%d)",
9252 con
, con
->http
.fd
, sub_id
);
9255 * Is the subscription ID valid?
9258 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9261 * Bad subscription ID...
9264 send_ipp_status(con
, IPP_NOT_FOUND
,
9265 _("notify-subscription-id %d no good!"), sub_id
);
9272 * Job subscriptions cannot be renewed...
9275 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9276 _("Job subscriptions cannot be renewed!"));
9284 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9286 con
, sub
->owner
)) != HTTP_OK
)
9288 send_http_error(con
, status
, sub
->dest
);
9293 * Renew the subscription...
9296 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9299 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9301 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9303 cupsdLogMessage(CUPSD_LOG_INFO
,
9304 "renew_subscription: Limiting notify-lease-duration to "
9307 sub
->lease
= MaxLeaseDuration
;
9310 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9312 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9314 con
->response
->request
.status
.status_code
= IPP_OK
;
9316 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9317 "notify-lease-duration", sub
->lease
);
9322 * 'restart_job()' - Restart an old print job.
9326 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9327 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9329 ipp_attribute_t
*attr
; /* Current attribute */
9330 int jobid
; /* Job ID */
9331 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9332 username
[HTTP_MAX_URI
], /* Username portion of URI */
9333 host
[HTTP_MAX_URI
], /* Host portion of URI */
9334 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9335 int port
; /* Port portion of URI */
9336 cupsd_job_t
*job
; /* Job information */
9339 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9340 con
->http
.fd
, uri
->values
[0].string
.text
);
9343 * See if we have a job URI or a printer URI...
9346 if (!strcmp(uri
->name
, "printer-uri"))
9349 * Got a printer URI; see if we also have a job-id attribute...
9352 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9353 IPP_TAG_INTEGER
)) == NULL
)
9355 send_ipp_status(con
, IPP_BAD_REQUEST
,
9356 _("Got a printer-uri attribute but no job-id!"));
9360 jobid
= attr
->values
[0].integer
;
9365 * Got a job URI; parse it to get the job ID...
9368 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9369 sizeof(scheme
), username
, sizeof(username
), host
,
9370 sizeof(host
), &port
, resource
, sizeof(resource
));
9372 if (strncmp(resource
, "/jobs/", 6))
9378 send_ipp_status(con
, IPP_BAD_REQUEST
,
9379 _("Bad job-uri attribute \"%s\"!"),
9380 uri
->values
[0].string
.text
);
9384 jobid
= atoi(resource
+ 6);
9388 * See if the job exists...
9391 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9394 * Nope - return a "not found" error...
9397 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9402 * See if job is in any of the "completed" states...
9405 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9408 * Nope - return a "not possible" error...
9411 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
9417 * See if we have retained the job files...
9422 if (!job
->attrs
|| job
->num_files
== 0)
9425 * Nope - return a "not possible" error...
9428 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9429 _("Job #%d cannot be restarted - no files!"), jobid
);
9434 * See if the job is owned by the requesting user...
9437 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9439 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9444 * Restart the job and return...
9447 cupsdRestartJob(job
);
9449 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9451 con
->response
->request
.status
.status_code
= IPP_OK
;
9456 * 'save_auth_info()' - Save authentication information for a job.
9461 cupsd_client_t
*con
, /* I - Client connection */
9462 cupsd_job_t
*job
, /* I - Job */
9463 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9465 int i
; /* Looping var */
9466 char filename
[1024]; /* Job authentication filename */
9467 cups_file_t
*fp
; /* Job authentication file */
9468 char line
[2048]; /* Line for file */
9469 cupsd_printer_t
*dest
; /* Destination printer/class */
9473 * This function saves the in-memory authentication information for
9474 * a job so that it can be used to authenticate with a remote host.
9475 * The information is stored in a file that is readable only by the
9476 * root user. The fields are Base-64 encoded, each on a separate line,
9477 * followed by random number (up to 1024) of newlines to limit the
9478 * amount of information that is exposed.
9480 * Because of the potential for exposing of authentication information,
9481 * this functionality is only enabled when running cupsd as root.
9483 * This caching only works for the Basic and BasicDigest authentication
9484 * types. Digest authentication cannot be cached this way, and in
9485 * the future Kerberos authentication may make all of this obsolete.
9487 * Authentication information is saved whenever an authenticated
9488 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9491 * This information is deleted after a job is completed or canceled,
9492 * so reprints may require subsequent re-authentication.
9498 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9502 * Create the authentication file and change permissions...
9505 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9506 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9508 cupsdLogMessage(CUPSD_LOG_ERROR
,
9509 "Unable to save authentication info to \"%s\" - %s",
9510 filename
, strerror(errno
));
9514 fchown(cupsFileNumber(fp
), 0, 0);
9515 fchmod(cupsFileNumber(fp
), 0400);
9517 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9520 * Write 1 to 3 auth values...
9523 cupsdClearString(&job
->auth_username
);
9524 cupsdClearString(&job
->auth_domain
);
9525 cupsdClearString(&job
->auth_password
);
9527 for (i
= 0; i
< auth_info
->num_values
; i
++)
9529 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9530 strlen(auth_info
->values
[i
].string
.text
));
9531 cupsFilePrintf(fp
, "%s\n", line
);
9533 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9534 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9535 auth_info
->values
[i
].string
.text
);
9536 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9537 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9538 auth_info
->values
[i
].string
.text
);
9539 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9540 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9541 auth_info
->values
[i
].string
.text
);
9544 else if (con
->username
[0])
9547 * Write the authenticated username...
9550 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9551 cupsFilePrintf(fp
, "%s\n", line
);
9553 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9554 cupsdClearString(&job
->auth_domain
);
9557 * Write the authenticated password...
9560 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9561 cupsFilePrintf(fp
, "%s\n", line
);
9563 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
9567 * Write a random number of newlines to the end of the file...
9570 for (i
= (rand() % 1024); i
>= 0; i
--)
9571 cupsFilePutChar(fp
, '\n');
9574 * Close the file and return...
9579 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9580 if (con
->gss_have_creds
)
9581 save_krb5_creds(con
, job
);
9582 else if (job
->ccname
)
9583 cupsdClearString(&(job
->ccname
));
9584 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9588 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9590 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
9594 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
9595 cupsd_job_t
*job
) /* I - Job */
9597 # if !defined(HAVE_KRB5_CC_NEW_UNIQUE) && !defined(HAVE_HEIMDAL)
9598 cupsdLogMessage(CUPSD_LOG_INFO
,
9599 "Sorry, your version of Kerberos does not support delegated "
9604 krb5_error_code error
; /* Kerberos error code */
9605 OM_uint32 major_status
, /* Major status code */
9606 minor_status
; /* Minor status code */
9607 krb5_principal principal
; /* Kerberos principal */
9612 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
9616 if (krb5_init_context
== NULL
)
9618 # endif /* __APPLE__ */
9620 if (!KerberosInitialized
)
9623 * Setup a Kerberos context for the scheduler to use...
9626 KerberosInitialized
= 1;
9628 if (krb5_init_context(&KerberosContext
))
9630 KerberosContext
= NULL
;
9632 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to initialize Kerberos context");
9638 * We MUST create a file-based cache because memory-based caches are
9639 * only valid for the current process/address space.
9641 * Due to various bugs/features in different versions of Kerberos, we
9642 * need either the krb5_cc_new_unique() function or Heimdal's version
9643 * of krb5_cc_gen_new() to create a new FILE: credential cache that
9644 * can be passed to the backend. These functions create a temporary
9645 * file (typically in /tmp) containing the cached credentials, which
9646 * are removed when we have successfully printed a job.
9649 # ifdef HAVE_KRB5_CC_NEW_UNIQUE
9650 if ((error
= krb5_cc_new_unique(KerberosContext
, "FILE", NULL
,
9651 &(job
->ccache
))) != 0)
9652 # else /* HAVE_HEIMDAL */
9653 if ((error
= krb5_cc_gen_new(KerberosContext
, &krb5_fcc_ops
,
9654 &(job
->ccache
))) != 0)
9655 # endif /* HAVE_KRB5_CC_NEW_UNIQUE */
9657 cupsdLogMessage(CUPSD_LOG_ERROR
,
9658 "Unable to create new credentials cache (%d/%s)",
9659 error
, strerror(errno
));
9664 if ((error
= krb5_parse_name(KerberosContext
, con
->username
, &principal
)) != 0)
9666 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to parse kerberos username (%d/%s)",
9667 error
, strerror(errno
));
9668 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9673 if ((error
= krb5_cc_initialize(KerberosContext
, job
->ccache
, principal
)))
9675 cupsdLogMessage(CUPSD_LOG_ERROR
,
9676 "Unable to initialize credentials cache (%d/%s)", error
,
9678 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9679 krb5_free_principal(KerberosContext
, principal
);
9684 krb5_free_principal(KerberosContext
, principal
);
9687 * Copy the user's credentials to the new cache file...
9690 major_status
= gss_krb5_copy_ccache(&minor_status
, con
->gss_delegated_cred
,
9693 if (GSS_ERROR(major_status
))
9695 cupsdLogGSSMessage(CUPSD_LOG_ERROR
, major_status
, minor_status
,
9696 "Unable to import client credentials cache");
9697 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9703 * Add the KRB5CCNAME environment variable to the job so that the
9704 * backend can use the credentials when printing.
9707 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
9708 krb5_cc_get_name(KerberosContext
, job
->ccache
));
9710 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
9711 # endif /* HAVE_KRB5_CC_NEW_UNIQUE || HAVE_HEIMDAL */
9713 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9717 * 'send_document()' - Send a file to a printer or class.
9721 send_document(cupsd_client_t
*con
, /* I - Client connection */
9722 ipp_attribute_t
*uri
) /* I - Printer URI */
9724 ipp_attribute_t
*attr
; /* Current attribute */
9725 ipp_attribute_t
*format
; /* Request's document-format attribute */
9726 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9727 const char *default_format
;/* document-format-default value */
9728 int jobid
; /* Job ID number */
9729 cupsd_job_t
*job
; /* Current job */
9730 char job_uri
[HTTP_MAX_URI
],
9732 scheme
[HTTP_MAX_URI
],
9733 /* Method portion of URI */
9734 username
[HTTP_MAX_URI
],
9735 /* Username portion of URI */
9737 /* Host portion of URI */
9738 resource
[HTTP_MAX_URI
];
9739 /* Resource portion of URI */
9740 int port
; /* Port portion of URI */
9741 mime_type_t
*filetype
; /* Type of file */
9742 char super
[MIME_MAX_SUPER
],
9743 /* Supertype of file */
9744 type
[MIME_MAX_TYPE
],
9745 /* Subtype of file */
9746 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9747 /* Textual name of mime type */
9748 char filename
[1024]; /* Job filename */
9749 cupsd_printer_t
*printer
; /* Current printer */
9750 struct stat fileinfo
; /* File information */
9751 int kbytes
; /* Size of file */
9752 int compression
; /* Type of compression */
9753 int start_job
; /* Start the job? */
9756 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9757 con
->http
.fd
, uri
->values
[0].string
.text
);
9760 * See if we have a job URI or a printer URI...
9763 if (!strcmp(uri
->name
, "printer-uri"))
9766 * Got a printer URI; see if we also have a job-id attribute...
9769 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9770 IPP_TAG_INTEGER
)) == NULL
)
9772 send_ipp_status(con
, IPP_BAD_REQUEST
,
9773 _("Got a printer-uri attribute but no job-id!"));
9777 jobid
= attr
->values
[0].integer
;
9782 * Got a job URI; parse it to get the job ID...
9785 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9786 sizeof(scheme
), username
, sizeof(username
), host
,
9787 sizeof(host
), &port
, resource
, sizeof(resource
));
9789 if (strncmp(resource
, "/jobs/", 6))
9795 send_ipp_status(con
, IPP_BAD_REQUEST
,
9796 _("Bad job-uri attribute \"%s\"!"),
9797 uri
->values
[0].string
.text
);
9801 jobid
= atoi(resource
+ 6);
9805 * See if the job exists...
9808 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9811 * Nope - return a "not found" error...
9814 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9818 printer
= cupsdFindDest(job
->dest
);
9821 * See if the job is owned by the requesting user...
9824 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9826 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9831 * OK, see if the client is sending the document compressed - CUPS
9832 * only supports "none" and "gzip".
9835 compression
= CUPS_FILE_NONE
;
9837 if ((attr
= ippFindAttribute(con
->request
, "compression",
9838 IPP_TAG_KEYWORD
)) != NULL
)
9840 if (strcmp(attr
->values
[0].string
.text
, "none")
9842 && strcmp(attr
->values
[0].string
.text
, "gzip")
9843 #endif /* HAVE_LIBZ */
9846 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
9847 attr
->values
[0].string
.text
);
9848 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9849 "compression", NULL
, attr
->values
[0].string
.text
);
9854 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9855 compression
= CUPS_FILE_GZIP
;
9856 #endif /* HAVE_LIBZ */
9860 * Do we have a file to print?
9865 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
9870 * Is it a format we support?
9873 if ((format
= ippFindAttribute(con
->request
, "document-format",
9874 IPP_TAG_MIMETYPE
)) != NULL
)
9877 * Grab format from client...
9880 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9883 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9884 format
->values
[0].string
.text
);
9888 else if ((default_format
= cupsGetOption("document-format",
9889 printer
->num_options
,
9890 printer
->options
)) != NULL
)
9893 * Use default document format...
9896 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9898 send_ipp_status(con
, IPP_BAD_REQUEST
,
9899 _("Could not scan type \"%s\"!"),
9907 * No document format attribute? Auto-type it!
9910 strcpy(super
, "application");
9911 strcpy(type
, "octet-stream");
9914 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9917 * Auto-type the file...
9920 ipp_attribute_t
*doc_name
; /* document-name attribute */
9923 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9925 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9926 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9927 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9931 filetype
= mimeType(MimeDatabase
, super
, type
);
9933 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9934 filetype
->super
, filetype
->type
);
9937 filetype
= mimeType(MimeDatabase
, super
, type
);
9942 * Replace the document-format attribute value with the auto-typed or
9946 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9949 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9950 IPP_TAG_MIMETYPE
)) != NULL
)
9952 _cupsStrFree(jformat
->values
[0].string
.text
);
9954 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9957 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9958 "document-format", NULL
, mimetype
);
9962 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9963 _("Unsupported format \'%s/%s\'!"), super
, type
);
9964 cupsdLogMessage(CUPSD_LOG_INFO
,
9965 "Hint: Do you have the raw file printing rules enabled?");
9968 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9969 "document-format", NULL
, format
->values
[0].string
.text
);
9974 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9976 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9979 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9980 _("Unsupported format \'%s\'!"), mimetype
);
9982 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9983 "document-format", NULL
, mimetype
);
9989 * Add the file to the job...
9994 if (add_file(con
, job
, filetype
, compression
))
9997 if (stat(con
->filename
, &fileinfo
))
10000 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10002 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10004 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10005 IPP_TAG_INTEGER
)) != NULL
)
10006 attr
->values
[0].integer
+= kbytes
;
10008 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10010 rename(con
->filename
, filename
);
10012 cupsdClearString(&con
->filename
);
10014 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10015 filetype
->super
, filetype
->type
, job
->username
);
10018 * Start the job if this is the last document...
10021 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10022 IPP_TAG_BOOLEAN
)) != NULL
&&
10023 attr
->values
[0].boolean
)
10026 * See if we need to add the ending sheet...
10029 if (cupsdTimeoutJob(job
))
10032 if (job
->state_value
== IPP_JOB_STOPPED
)
10034 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10035 job
->state_value
= IPP_JOB_PENDING
;
10037 else if (job
->state_value
== IPP_JOB_HELD
)
10039 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10040 IPP_TAG_KEYWORD
)) == NULL
)
10041 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10043 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10045 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10046 job
->state_value
= IPP_JOB_PENDING
;
10051 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10057 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10058 IPP_TAG_KEYWORD
)) == NULL
)
10059 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10061 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10063 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10064 job
->state_value
= IPP_JOB_HELD
;
10065 job
->hold_until
= time(NULL
) + 60;
10068 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10075 * Fill in the response info...
10078 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10081 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10084 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10086 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10088 add_job_state_reasons(con
, job
);
10090 con
->response
->request
.status
.status_code
= IPP_OK
;
10093 * Start the job if necessary...
10102 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10107 cupsd_client_t
*con
, /* I - Client connection */
10108 http_status_t status
, /* I - HTTP status code */
10109 cupsd_printer_t
*printer
) /* I - Printer, if any */
10111 ipp_attribute_t
*uri
; /* Request URI, if any */
10114 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10115 IPP_TAG_URI
)) == NULL
)
10116 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10118 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10119 "Returning HTTP %s for %s (%s) from %s",
10120 httpStatus(status
),
10121 ippOpString(con
->request
->request
.op
.operation_id
),
10122 uri
? uri
->values
[0].string
.text
: "no URI",
10123 con
->http
.hostname
);
10127 int auth_type
; /* Type of authentication required */
10130 auth_type
= CUPSD_AUTH_NONE
;
10132 if (status
== HTTP_UNAUTHORIZED
&&
10133 printer
->num_auth_info_required
> 0 &&
10134 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10136 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10137 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10138 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10141 * Creating and authenticating jobs requires Kerberos...
10144 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10149 * Use policy/location-defined authentication requirements...
10152 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10153 cupsd_location_t
*auth
; /* Pointer to authentication element */
10156 if (printer
->type
& CUPS_PRINTER_CLASS
)
10157 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10159 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10161 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10162 auth
->type
== CUPSD_AUTH_NONE
)
10163 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10165 con
->request
->request
.op
.operation_id
:
10170 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10171 auth_type
= DefaultAuthType
;
10173 auth_type
= auth
->type
;
10177 cupsdSendError(con
, status
, auth_type
);
10180 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10182 ippDelete(con
->response
);
10183 con
->response
= NULL
;
10190 * 'send_ipp_status()' - Send a status back to the IPP client.
10194 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10195 ipp_status_t status
, /* I - IPP status code */
10196 const char *message
,/* I - Status message */
10197 ...) /* I - Additional args as needed */
10199 va_list ap
; /* Pointer to additional args */
10200 char formatted
[1024]; /* Formatted errror message */
10203 va_start(ap
, message
);
10204 vsnprintf(formatted
, sizeof(formatted
),
10205 _cupsLangString(con
->language
, message
), ap
);
10208 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10209 ippOpString(con
->request
->request
.op
.operation_id
),
10210 ippErrorString(status
), formatted
);
10212 con
->response
->request
.status
.status_code
= status
;
10214 if (ippFindAttribute(con
->response
, "attributes-charset",
10215 IPP_TAG_ZERO
) == NULL
)
10216 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10217 "attributes-charset", NULL
, DefaultCharset
);
10219 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10220 IPP_TAG_ZERO
) == NULL
)
10221 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10222 "attributes-natural-language", NULL
, DefaultLanguage
);
10224 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10225 "status-message", NULL
, formatted
);
10230 * 'set_default()' - Set the default destination...
10234 set_default(cupsd_client_t
*con
, /* I - Client connection */
10235 ipp_attribute_t
*uri
) /* I - Printer URI */
10237 http_status_t status
; /* Policy status */
10238 cups_ptype_t dtype
; /* Destination type (printer/class) */
10239 cupsd_printer_t
*printer
, /* Printer */
10240 *oldprinter
; /* Old default printer */
10243 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10244 con
->http
.fd
, uri
->values
[0].string
.text
);
10247 * Is the destination valid?
10250 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10256 send_ipp_status(con
, IPP_NOT_FOUND
,
10257 _("The printer or class was not found."));
10265 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10267 send_http_error(con
, status
, NULL
);
10272 * Set it as the default...
10275 oldprinter
= DefaultPrinter
;
10276 DefaultPrinter
= printer
;
10279 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10280 "%s is no longer the default printer.", oldprinter
->name
);
10282 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10283 "%s is now the default printer.", printer
->name
);
10285 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10286 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10288 cupsdLogMessage(CUPSD_LOG_INFO
,
10289 "Default destination set to \"%s\" by \"%s\".",
10290 printer
->name
, get_username(con
));
10293 * Everything was ok, so return OK status...
10296 con
->response
->request
.status
.status_code
= IPP_OK
;
10301 * 'set_job_attrs()' - Set job attributes.
10305 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10306 ipp_attribute_t
*uri
) /* I - Job URI */
10308 ipp_attribute_t
*attr
, /* Current attribute */
10309 *attr2
; /* Job attribute */
10310 int jobid
; /* Job ID */
10311 cupsd_job_t
*job
; /* Current job */
10312 char scheme
[HTTP_MAX_URI
],
10313 /* Method portion of URI */
10314 username
[HTTP_MAX_URI
],
10315 /* Username portion of URI */
10316 host
[HTTP_MAX_URI
],
10317 /* Host portion of URI */
10318 resource
[HTTP_MAX_URI
];
10319 /* Resource portion of URI */
10320 int port
; /* Port portion of URI */
10321 int event
; /* Events? */
10322 int check_jobs
; /* Check jobs? */
10325 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10326 con
->http
.fd
, uri
->values
[0].string
.text
);
10329 * Start with "everything is OK" status...
10332 con
->response
->request
.status
.status_code
= IPP_OK
;
10335 * See if we have a job URI or a printer URI...
10338 if (!strcmp(uri
->name
, "printer-uri"))
10341 * Got a printer URI; see if we also have a job-id attribute...
10344 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10345 IPP_TAG_INTEGER
)) == NULL
)
10347 send_ipp_status(con
, IPP_BAD_REQUEST
,
10348 _("Got a printer-uri attribute but no job-id!"));
10352 jobid
= attr
->values
[0].integer
;
10357 * Got a job URI; parse it to get the job ID...
10360 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10361 sizeof(scheme
), username
, sizeof(username
), host
,
10362 sizeof(host
), &port
, resource
, sizeof(resource
));
10364 if (strncmp(resource
, "/jobs/", 6))
10370 send_ipp_status(con
, IPP_BAD_REQUEST
,
10371 _("Bad job-uri attribute \"%s\"!"),
10372 uri
->values
[0].string
.text
);
10376 jobid
= atoi(resource
+ 6);
10380 * See if the job exists...
10383 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10386 * Nope - return a "not found" error...
10389 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
10394 * See if the job has been completed...
10397 if (job
->state_value
> IPP_JOB_STOPPED
)
10400 * Return a "not-possible" error...
10403 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10404 _("Job #%d is finished and cannot be altered!"), jobid
);
10409 * See if the job is owned by the requesting user...
10412 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10414 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
10419 * See what the user wants to change.
10427 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10429 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10432 if (!strcmp(attr
->name
, "attributes-charset") ||
10433 !strcmp(attr
->name
, "attributes-natural-language") ||
10434 !strcmp(attr
->name
, "document-compression") ||
10435 !strcmp(attr
->name
, "document-format") ||
10436 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10437 !strcmp(attr
->name
, "job-document-access-errors") ||
10438 !strcmp(attr
->name
, "job-id") ||
10439 !strcmp(attr
->name
, "job-impressions-completed") ||
10440 !strcmp(attr
->name
, "job-k-octets") ||
10441 !strcmp(attr
->name
, "job-originating-host-name") ||
10442 !strcmp(attr
->name
, "job-originating-user-name") ||
10443 !strcmp(attr
->name
, "job-printer-up-time") ||
10444 !strcmp(attr
->name
, "job-printer-uri") ||
10445 !strcmp(attr
->name
, "job-sheets") ||
10446 !strcmp(attr
->name
, "job-state-message") ||
10447 !strcmp(attr
->name
, "job-state-reasons") ||
10448 !strcmp(attr
->name
, "job-uri") ||
10449 !strcmp(attr
->name
, "number-of-documents") ||
10450 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10451 !strcmp(attr
->name
, "output-device-assigned") ||
10452 !strncmp(attr
->name
, "date-time-at-", 13) ||
10453 !strncmp(attr
->name
, "job-k-octets", 12) ||
10454 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10455 !strncmp(attr
->name
, "time-at-", 8))
10461 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10462 _("%s cannot be changed."), attr
->name
);
10464 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10465 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10470 if (!strcmp(attr
->name
, "job-priority"))
10473 * Change the job priority...
10476 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10478 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
10480 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10481 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10483 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10485 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10486 _("Job is completed and cannot be changed."));
10489 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10491 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10492 attr
->values
[0].integer
);
10493 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10496 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10497 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10500 else if (!strcmp(attr
->name
, "job-state"))
10503 * Change the job state...
10506 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10508 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
10510 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10511 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10515 switch (attr
->values
[0].integer
)
10517 case IPP_JOB_PENDING
:
10518 case IPP_JOB_HELD
:
10519 if (job
->state_value
> IPP_JOB_HELD
)
10521 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10522 _("Job state cannot be changed."));
10525 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10527 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10528 attr
->values
[0].integer
);
10530 job
->state
->values
[0].integer
= attr
->values
[0].integer
;
10531 job
->state_value
= (ipp_jstate_t
)attr
->values
[0].integer
;
10533 event
|= CUPSD_EVENT_JOB_STATE
;
10538 case IPP_JOB_PROCESSING
:
10539 case IPP_JOB_STOPPED
:
10540 if (job
->state_value
!= attr
->values
[0].integer
)
10542 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10543 _("Job state cannot be changed."));
10548 case IPP_JOB_CANCELED
:
10549 case IPP_JOB_ABORTED
:
10550 case IPP_JOB_COMPLETED
:
10551 if (job
->state_value
> IPP_JOB_PROCESSING
)
10553 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10554 _("Job state cannot be changed."));
10557 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10559 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10560 attr
->values
[0].integer
);
10561 cupsdCancelJob(job
, 0, (ipp_jstate_t
)attr
->values
[0].integer
);
10569 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10571 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10572 IPP_TAG_ZERO
)) != NULL
)
10575 * Some other value; first free the old value...
10578 if (job
->attrs
->prev
)
10579 job
->attrs
->prev
->next
= attr2
->next
;
10581 job
->attrs
->attrs
= attr2
->next
;
10583 if (job
->attrs
->last
== attr2
)
10584 job
->attrs
->last
= job
->attrs
->prev
;
10586 _ippFreeAttr(attr2
);
10589 * Then copy the attribute...
10592 copy_attribute(job
->attrs
, attr
, 0);
10595 * See if the job-name or job-hold-until is being changed.
10598 if (!strcmp(attr
->name
, "job-hold-until"))
10600 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10601 attr
->values
[0].string
.text
);
10602 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
10604 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10605 cupsdReleaseJob(job
);
10610 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10613 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10616 * Delete the attribute...
10619 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10620 IPP_TAG_ZERO
)) != NULL
)
10622 if (job
->attrs
->prev
)
10623 job
->attrs
->prev
->next
= attr2
->next
;
10625 job
->attrs
->attrs
= attr2
->next
;
10627 if (attr2
== job
->attrs
->last
)
10628 job
->attrs
->last
= job
->attrs
->prev
;
10630 _ippFreeAttr(attr2
);
10632 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10638 * Add new option by copying it...
10641 copy_attribute(job
->attrs
, attr
, 0);
10643 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10652 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10655 * Send events as needed...
10658 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10659 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10660 cupsdFindDest(job
->dest
), job
,
10661 "Job priority changed by user.");
10663 if (event
& CUPSD_EVENT_JOB_STATE
)
10664 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10665 job
->state_value
== IPP_JOB_HELD
?
10666 "Job held by user." : "Job restarted by user.");
10668 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10669 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10670 "Job options changed by user.");
10673 * Start jobs if possible...
10682 * 'set_printer_attrs()' - Set printer attributes.
10686 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10687 ipp_attribute_t
*uri
) /* I - Printer */
10689 http_status_t status
; /* Policy status */
10690 cups_ptype_t dtype
; /* Destination type (printer/class) */
10691 cupsd_printer_t
*printer
; /* Printer/class */
10692 ipp_attribute_t
*attr
; /* Printer attribute */
10693 int changed
; /* Was anything changed? */
10696 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10697 con
->http
.fd
, uri
->values
[0].string
.text
);
10700 * Is the destination valid?
10703 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10709 send_ipp_status(con
, IPP_NOT_FOUND
,
10710 _("The printer or class was not found."));
10718 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10720 send_http_error(con
, status
, printer
);
10725 * Return a list of attributes that can be set via Set-Printer-Attributes.
10728 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10729 IPP_TAG_TEXT
)) != NULL
)
10731 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10735 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10736 IPP_TAG_TEXT
)) != NULL
)
10738 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10743 * Update the printer attributes and return...
10748 cupsdSetPrinterAttrs(printer
);
10749 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10751 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10752 "Printer \"%s\" description or location changed by \"%s\".",
10753 printer
->name
, get_username(con
));
10755 cupsdLogMessage(CUPSD_LOG_INFO
,
10756 "Printer \"%s\" description or location changed by \"%s\".",
10757 printer
->name
, get_username(con
));
10760 con
->response
->request
.status
.status_code
= IPP_OK
;
10765 * 'set_printer_defaults()' - Set printer default options from a request.
10769 set_printer_defaults(
10770 cupsd_client_t
*con
, /* I - Client connection */
10771 cupsd_printer_t
*printer
) /* I - Printer */
10773 int i
; /* Looping var */
10774 ipp_attribute_t
*attr
; /* Current attribute */
10775 int namelen
; /* Length of attribute name */
10776 char name
[256], /* New attribute name */
10777 value
[256]; /* String version of integer attrs */
10780 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10783 * Skip non-printer attributes...
10786 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10789 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10791 if (!strcmp(attr
->name
, "job-sheets-default"))
10794 * Only allow keywords and names...
10797 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10801 * Only allow job-sheets-default to be set when running without a
10802 * system high classification level...
10805 if (Classification
)
10808 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10810 if (attr
->num_values
> 1)
10811 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10813 cupsdSetString(&printer
->job_sheets
[1], "none");
10815 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10817 cupsdFreePrinterUsers(printer
);
10819 printer
->deny_users
= 0;
10821 if (attr
->value_tag
== IPP_TAG_NAME
&&
10822 (attr
->num_values
> 1 ||
10823 strcmp(attr
->values
[0].string
.text
, "all")))
10825 for (i
= 0; i
< attr
->num_values
; i
++)
10826 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10829 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10831 cupsdFreePrinterUsers(printer
);
10833 printer
->deny_users
= 1;
10835 if (attr
->value_tag
== IPP_TAG_NAME
&&
10836 (attr
->num_values
> 1 ||
10837 strcmp(attr
->values
[0].string
.text
, "none")))
10839 for (i
= 0; i
< attr
->num_values
; i
++)
10840 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10843 else if (!strcmp(attr
->name
, "job-quota-period"))
10845 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10848 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10849 attr
->values
[0].integer
);
10850 cupsdFreeQuotas(printer
);
10852 printer
->quota_period
= attr
->values
[0].integer
;
10854 else if (!strcmp(attr
->name
, "job-k-limit"))
10856 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10859 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10860 attr
->values
[0].integer
);
10861 cupsdFreeQuotas(printer
);
10863 printer
->k_limit
= attr
->values
[0].integer
;
10865 else if (!strcmp(attr
->name
, "job-page-limit"))
10867 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10870 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10871 attr
->values
[0].integer
);
10872 cupsdFreeQuotas(printer
);
10874 printer
->page_limit
= attr
->values
[0].integer
;
10876 else if (!strcmp(attr
->name
, "printer-op-policy"))
10878 cupsd_policy_t
*p
; /* Policy */
10881 if (attr
->value_tag
!= IPP_TAG_NAME
)
10884 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10886 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10887 "Setting printer-op-policy to \"%s\"...",
10888 attr
->values
[0].string
.text
);
10889 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10890 printer
->op_policy_ptr
= p
;
10894 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10895 _("Unknown printer-op-policy \"%s\"."),
10896 attr
->values
[0].string
.text
);
10900 else if (!strcmp(attr
->name
, "printer-error-policy"))
10902 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10905 if (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10906 strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10907 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10908 strcmp(attr
->values
[0].string
.text
, "stop-printer"))
10910 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10911 _("Unknown printer-error-policy \"%s\"."),
10912 attr
->values
[0].string
.text
);
10916 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10917 "Setting printer-error-policy to \"%s\"...",
10918 attr
->values
[0].string
.text
);
10919 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10923 * Skip any other non-default attributes...
10926 namelen
= strlen(attr
->name
);
10927 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10928 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10932 * OK, anything else must be a user-defined default...
10935 strlcpy(name
, attr
->name
, sizeof(name
));
10936 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10938 switch (attr
->value_tag
)
10940 case IPP_TAG_DELETEATTR
:
10941 printer
->num_options
= cupsRemoveOption(name
,
10942 printer
->num_options
,
10943 &(printer
->options
));
10944 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10945 "Deleting %s", attr
->name
);
10948 case IPP_TAG_NAME
:
10949 case IPP_TAG_KEYWORD
:
10951 printer
->num_options
= cupsAddOption(name
,
10952 attr
->values
[0].string
.text
,
10953 printer
->num_options
,
10954 &(printer
->options
));
10955 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10956 "Setting %s to \"%s\"...", attr
->name
,
10957 attr
->values
[0].string
.text
);
10960 case IPP_TAG_BOOLEAN
:
10961 printer
->num_options
= cupsAddOption(name
,
10962 attr
->values
[0].boolean
?
10964 printer
->num_options
,
10965 &(printer
->options
));
10966 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10967 "Setting %s to %s...", attr
->name
,
10968 attr
->values
[0].boolean
? "true" : "false");
10971 case IPP_TAG_INTEGER
:
10972 case IPP_TAG_ENUM
:
10973 sprintf(value
, "%d", attr
->values
[0].integer
);
10974 printer
->num_options
= cupsAddOption(name
, value
,
10975 printer
->num_options
,
10976 &(printer
->options
));
10977 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10978 "Setting %s to %s...", attr
->name
, value
);
10981 case IPP_TAG_RANGE
:
10982 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10983 attr
->values
[0].range
.upper
);
10984 printer
->num_options
= cupsAddOption(name
, value
,
10985 printer
->num_options
,
10986 &(printer
->options
));
10987 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10988 "Setting %s to %s...", attr
->name
, value
);
10991 case IPP_TAG_RESOLUTION
:
10992 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10993 attr
->values
[0].resolution
.yres
,
10994 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10996 printer
->num_options
= cupsAddOption(name
, value
,
10997 printer
->num_options
,
10998 &(printer
->options
));
10999 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11000 "Setting %s to %s...", attr
->name
, value
);
11004 /* Do nothing for other values */
11012 * 'start_printer()' - Start a printer.
11016 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11017 ipp_attribute_t
*uri
) /* I - Printer URI */
11019 http_status_t status
; /* Policy status */
11020 cups_ptype_t dtype
; /* Destination type (printer/class) */
11021 cupsd_printer_t
*printer
; /* Printer data */
11024 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11025 con
->http
.fd
, uri
->values
[0].string
.text
);
11028 * Is the destination valid?
11031 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11037 send_ipp_status(con
, IPP_NOT_FOUND
,
11038 _("The printer or class was not found."));
11046 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11048 send_http_error(con
, status
, printer
);
11053 * Start the printer...
11056 printer
->state_message
[0] = '\0';
11058 cupsdStartPrinter(printer
, 1);
11060 if (dtype
& CUPS_PRINTER_CLASS
)
11061 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11062 printer
->name
, get_username(con
));
11064 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11065 printer
->name
, get_username(con
));
11070 * Everything was ok, so return OK status...
11073 con
->response
->request
.status
.status_code
= IPP_OK
;
11078 * 'stop_printer()' - Stop a printer.
11082 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11083 ipp_attribute_t
*uri
) /* I - Printer URI */
11085 http_status_t status
; /* Policy status */
11086 cups_ptype_t dtype
; /* Destination type (printer/class) */
11087 cupsd_printer_t
*printer
; /* Printer data */
11088 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11091 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11092 con
->http
.fd
, uri
->values
[0].string
.text
);
11095 * Is the destination valid?
11098 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11104 send_ipp_status(con
, IPP_NOT_FOUND
,
11105 _("The printer or class was not found."));
11113 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11115 send_http_error(con
, status
, printer
);
11120 * Stop the printer...
11123 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11124 IPP_TAG_TEXT
)) == NULL
)
11125 strcpy(printer
->state_message
, "Paused");
11128 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11129 sizeof(printer
->state_message
));
11132 cupsdStopPrinter(printer
, 1);
11134 if (dtype
& CUPS_PRINTER_CLASS
)
11135 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11136 printer
->name
, get_username(con
));
11138 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11139 printer
->name
, get_username(con
));
11142 * Everything was ok, so return OK status...
11145 con
->response
->request
.status
.status_code
= IPP_OK
;
11150 * 'url_encode_attr()' - URL-encode a string attribute.
11154 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11155 char *buffer
,/* I - String buffer */
11156 int bufsize
)/* I - Size of buffer */
11158 int i
; /* Looping var */
11159 char *bufptr
, /* Pointer into buffer */
11160 *bufend
; /* End of buffer */
11163 strlcpy(buffer
, attr
->name
, bufsize
);
11164 bufptr
= buffer
+ strlen(buffer
);
11165 bufend
= buffer
+ bufsize
- 1;
11167 for (i
= 0; i
< attr
->num_values
; i
++)
11169 if (bufptr
>= bufend
)
11177 if (bufptr
>= bufend
)
11182 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11183 bufptr
, bufend
- bufptr
+ 1);
11185 if (bufptr
>= bufend
)
11196 * 'url_encode_string()' - URL-encode a string.
11199 static char * /* O - End of string */
11200 url_encode_string(const char *s
, /* I - String */
11201 char *buffer
, /* I - String buffer */
11202 int bufsize
) /* I - Size of buffer */
11204 char *bufptr
, /* Pointer into buffer */
11205 *bufend
; /* End of buffer */
11206 static const char *hex
= "0123456789ABCDEF";
11211 bufend
= buffer
+ bufsize
- 1;
11213 while (*s
&& bufptr
< bufend
)
11215 if (*s
== ' ' || *s
== '%')
11217 if (bufptr
>= (bufend
- 2))
11221 *bufptr
++ = hex
[(*s
>> 4) & 15];
11222 *bufptr
++ = hex
[*s
& 15];
11226 else if (*s
== '\'' || *s
== '\\')
11228 if (bufptr
>= (bufend
- 1))
11245 * 'user_allowed()' - See if a user is allowed to print to a queue.
11248 static int /* O - 0 if not allowed, 1 if allowed */
11249 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11250 const char *username
) /* I - Username */
11252 int i
; /* Looping var */
11253 struct passwd
*pw
; /* User password data */
11254 char baseuser
[256], /* Base username */
11255 *baseptr
; /* Pointer to "@" in base username */
11258 if (p
->num_users
== 0)
11261 if (!strcmp(username
, "root"))
11264 if (strchr(username
, '@'))
11267 * Strip @REALM for username check...
11270 strlcpy(baseuser
, username
, sizeof(baseuser
));
11272 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11275 username
= baseuser
;
11278 pw
= getpwnam(username
);
11281 for (i
= 0; i
< p
->num_users
; i
++)
11283 if (p
->users
[i
][0] == '@')
11286 * Check group membership...
11289 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
11292 else if (p
->users
[i
][0] == '#')
11298 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
11301 else if (!strcasecmp(username
, p
->users
[i
]))
11305 return ((i
< p
->num_users
) != p
->deny_users
);
11310 * 'validate_job()' - Validate printer options and destination.
11314 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11315 ipp_attribute_t
*uri
) /* I - Printer URI */
11317 http_status_t status
; /* Policy status */
11318 ipp_attribute_t
*attr
; /* Current attribute */
11319 ipp_attribute_t
*format
; /* Document-format attribute */
11320 cups_ptype_t dtype
; /* Destination type (printer/class) */
11321 char super
[MIME_MAX_SUPER
],
11322 /* Supertype of file */
11323 type
[MIME_MAX_TYPE
];
11324 /* Subtype of file */
11325 cupsd_printer_t
*printer
; /* Printer */
11328 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11329 con
->http
.fd
, uri
->values
[0].string
.text
);
11332 * OK, see if the client is sending the document compressed - CUPS
11333 * doesn't support compression yet...
11336 if ((attr
= ippFindAttribute(con
->request
, "compression",
11337 IPP_TAG_KEYWORD
)) != NULL
&&
11338 !strcmp(attr
->values
[0].string
.text
, "none"))
11340 send_ipp_status(con
, IPP_ATTRIBUTES
,
11341 _("Unsupported compression attribute %s!"),
11342 attr
->values
[0].string
.text
);
11343 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11344 "compression", NULL
, attr
->values
[0].string
.text
);
11349 * Is it a format we support?
11352 if ((format
= ippFindAttribute(con
->request
, "document-format",
11353 IPP_TAG_MIMETYPE
)) != NULL
)
11355 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11358 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
11359 format
->values
[0].string
.text
);
11363 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11364 !mimeType(MimeDatabase
, super
, type
))
11366 cupsdLogMessage(CUPSD_LOG_INFO
,
11367 "Hint: Do you have the raw file printing rules enabled?");
11368 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11369 _("Unsupported format \"%s\"!"),
11370 format
->values
[0].string
.text
);
11371 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11372 "document-format", NULL
, format
->values
[0].string
.text
);
11378 * Is the destination valid?
11381 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11387 send_ipp_status(con
, IPP_NOT_FOUND
,
11388 _("The printer or class was not found."));
11396 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11398 send_http_error(con
, status
, printer
);
11403 * Everything was ok, so return OK status...
11406 con
->response
->request
.status
.status_code
= IPP_OK
;
11411 * 'validate_name()' - Make sure the printer name only contains valid chars.
11414 static int /* O - 0 if name is no good, 1 if good */
11415 validate_name(const char *name
) /* I - Name to check */
11417 const char *ptr
; /* Pointer into name */
11421 * Scan the whole name...
11424 for (ptr
= name
; *ptr
; ptr
++)
11425 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11429 * All the characters are good; validate the length, too...
11432 return ((ptr
- name
) < 128);
11437 * 'validate_user()' - Validate the user for the request.
11440 static int /* O - 1 if permitted, 0 otherwise */
11441 validate_user(cupsd_job_t
*job
, /* I - Job */
11442 cupsd_client_t
*con
, /* I - Client connection */
11443 const char *owner
, /* I - Owner of job/resource */
11444 char *username
, /* O - Authenticated username */
11445 int userlen
) /* I - Length of username */
11447 cupsd_printer_t
*printer
; /* Printer for job */
11450 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11451 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11453 job
->id
, con
? con
->http
.fd
: 0,
11454 owner
? owner
: "(null)", username
, userlen
);
11457 * Validate input...
11460 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11464 * Get the best authenticated username that is available.
11467 strlcpy(username
, get_username(con
), userlen
);
11470 * Check the username against the owner...
11473 printer
= cupsdFindDest(job
->dest
);
11475 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11476 con
, owner
) == HTTP_OK
);
11481 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".