2 * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
4 * IPP routines for the Common UNIX Printing System (CUPS) scheduler.
6 * Copyright 2007-2009 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * This file contains Kerberos support code, copyright 2006 by
12 * These coded instructions, statements, and computer programs are the
13 * property of Apple Inc. and are protected by Federal copyright
14 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 * which should have been included with this file. If this file is
16 * file is missing or damaged, see the license at "http://www.cups.org/".
20 * cupsdProcessIPPRequest() - Process an incoming IPP request.
21 * cupsdTimeoutJob() - Timeout a job waiting on job files.
22 * accept_jobs() - Accept print jobs to a printer.
23 * add_class() - Add a class to the system.
24 * add_file() - Add a file to a job.
25 * add_job() - Add a job to a print queue.
26 * add_job_state_reasons() - Add the "job-state-reasons" attribute based
27 * upon the job and printer state...
28 * add_job_subscriptions() - Add any subscriptions for a job.
29 * add_job_uuid() - Add job-uuid attribute to a job.
30 * add_printer() - Add a printer to the system.
31 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
32 * based upon the printer state...
33 * add_queued_job_count() - Add the "queued-job-count" attribute for the
34 * specified printer or class.
35 * apple_init_profile() - Initialize a color profile.
36 * apple_register_profiles() - Register color profiles for a printer.
37 * apple_unregister_profiles() - Remove color profiles for the specified
39 * apply_printer_defaults() - Apply printer default options to a job.
40 * authenticate_job() - Set job authentication info.
41 * cancel_all_jobs() - Cancel all print jobs.
42 * cancel_job() - Cancel a print job.
43 * cancel_subscription() - Cancel a subscription.
44 * check_quotas() - Check quotas for a printer and user.
45 * check_rss_recipient() - Check that we do not have a duplicate RSS
47 * copy_attribute() - Copy a single attribute.
48 * copy_attrs() - Copy attributes from one request to another.
49 * copy_banner() - Copy a banner file to the requests directory
50 * for the specified job.
51 * copy_file() - Copy a PPD file or interface script...
52 * copy_model() - Copy a PPD model file, substituting default
54 * copy_job_attrs() - Copy job attributes.
55 * copy_printer_attrs() - Copy printer attributes.
56 * copy_subscription_attrs() - Copy subscription attributes.
57 * create_job() - Print a file to a printer or class.
58 * create_requested_array() - Create an array for the requested-attributes.
59 * create_subscription() - Create a notification subscription.
60 * delete_printer() - Remove a printer or class from the system.
61 * get_default() - Get the default destination.
62 * get_devices() - Get the list of available devices on the
64 * get_document() - Get a copy of a job file.
65 * get_job_attrs() - Get job attributes.
66 * get_jobs() - Get a list of jobs for the specified printer.
67 * get_notifications() - Get events for a subscription.
68 * get_ppd() - Get a named PPD from the local system.
69 * get_ppds() - Get the list of PPD files on the local
71 * get_printer_attrs() - Get printer attributes.
72 * get_printers() - Get a list of printers or classes.
73 * get_subscription_attrs() - Get subscription attributes.
74 * get_subscriptions() - Get subscriptions.
75 * get_username() - Get the username associated with a request.
76 * hold_job() - Hold a print job.
77 * move_job() - Move a job to a new destination.
78 * ppd_parse_line() - Parse a PPD default line.
79 * print_job() - Print a file to a printer or class.
80 * read_job_ticket() - Read a job ticket embedded in a print file.
81 * reject_jobs() - Reject print jobs to a printer.
82 * release_job() - Release a held print job.
83 * renew_subscription() - Renew an existing subscription...
84 * restart_job() - Restart an old print job.
85 * save_auth_info() - Save authentication information for a job.
86 * save_krb5_creds() - Save Kerberos credentials for the job.
87 * send_document() - Send a file to a printer or class.
88 * send_http_error() - Send a HTTP error back to the IPP client.
89 * send_ipp_status() - Send a status back to the IPP client.
90 * set_default() - Set the default destination...
91 * set_job_attrs() - Set job attributes.
92 * set_printer_attrs() - Set printer attributes.
93 * set_printer_defaults() - Set printer default options from a request.
94 * start_printer() - Start a printer.
95 * stop_printer() - Stop a printer.
96 * url_encode_attr() - URL-encode a string attribute.
97 * url_encode_string() - URL-encode a string.
98 * user_allowed() - See if a user is allowed to print to a queue.
99 * validate_job() - Validate printer options and destination.
100 * validate_name() - Make sure the printer name only contains
102 * validate_user() - Validate the user for the request.
106 * Include necessary headers...
110 #include <cups/ppd-private.h>
113 # include <ApplicationServices/ApplicationServices.h>
114 # include <CoreFoundation/CoreFoundation.h>
115 # ifdef HAVE_MEMBERSHIP_H
116 # include <membership.h>
117 # endif /* HAVE_MEMBERSHIP_H */
118 # ifdef HAVE_MEMBERSHIPPRIV_H
119 # include <membershipPriv.h>
121 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
122 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
123 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
124 # endif /* HAVE_MEMBERSHIPPRIV_H */
125 #endif /* __APPLE__ */
132 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
133 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
134 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
135 mime_type_t
*filetype
, int compression
);
136 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
137 mime_type_t
*filetype
);
138 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
139 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
140 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
141 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
142 static void add_printer_state_reasons(cupsd_client_t
*con
,
144 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
146 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
147 CMDeviceProfileInfo
*profile
, unsigned id
,
148 const char *name
, const char *text
,
149 const char *iccfile
);
150 static void apple_register_profiles(cupsd_printer_t
*p
);
151 static void apple_unregister_profiles(cupsd_printer_t
*p
);
152 #endif /* __APPLE__ */
153 static void apply_printer_defaults(cupsd_printer_t
*printer
,
155 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
156 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
157 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
158 static void cancel_subscription(cupsd_client_t
*con
, int id
);
159 static int check_rss_recipient(const char *recipient
);
160 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
161 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
163 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
164 ipp_tag_t group
, int quickcopy
);
165 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
167 static int copy_file(const char *from
, const char *to
);
168 static int copy_model(cupsd_client_t
*con
, const char *from
,
170 static void copy_job_attrs(cupsd_client_t
*con
,
173 static void copy_printer_attrs(cupsd_client_t
*con
,
174 cupsd_printer_t
*printer
,
176 static void copy_subscription_attrs(cupsd_client_t
*con
,
177 cupsd_subscription_t
*sub
,
179 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
180 static cups_array_t
*create_requested_array(ipp_t
*request
);
181 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
182 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
183 static void get_default(cupsd_client_t
*con
);
184 static void get_devices(cupsd_client_t
*con
);
185 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
187 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
188 static void get_notifications(cupsd_client_t
*con
);
189 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static void get_ppds(cupsd_client_t
*con
);
191 static void get_printers(cupsd_client_t
*con
, int type
);
192 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
193 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
194 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
195 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
196 static const char *get_username(cupsd_client_t
*con
);
197 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
199 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
200 static int ppd_parse_line(const char *line
, char *option
, int olen
,
201 char *choice
, int clen
);
202 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
203 static void read_job_ticket(cupsd_client_t
*con
);
204 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
205 static void release_held_new_jobs(cupsd_client_t
*con
,
206 ipp_attribute_t
*uri
);
207 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
208 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
209 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
210 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
211 ipp_attribute_t
*auth_info
);
212 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
213 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
214 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
215 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
216 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
217 cupsd_printer_t
*printer
);
218 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
219 const char *message
, ...)
221 __attribute__ ((__format__ (__printf__
, 3, 4)))
222 # endif /* __GNUC__ */
224 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
225 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
226 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
227 static void set_printer_defaults(cupsd_client_t
*con
,
228 cupsd_printer_t
*printer
);
229 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
230 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
231 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
233 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
234 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
235 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
236 static int validate_name(const char *name
);
237 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
238 const char *owner
, char *username
,
243 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
246 int /* O - 1 on success, 0 on failure */
247 cupsdProcessIPPRequest(
248 cupsd_client_t
*con
) /* I - Client connection */
250 ipp_tag_t group
; /* Current group tag */
251 ipp_attribute_t
*attr
; /* Current attribute */
252 ipp_attribute_t
*charset
; /* Character set attribute */
253 ipp_attribute_t
*language
; /* Language attribute */
254 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
255 ipp_attribute_t
*username
; /* requesting-user-name attr */
256 int sub_id
; /* Subscription ID */
259 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
260 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
261 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
264 * First build an empty response message for this request...
267 con
->response
= ippNew();
269 con
->response
->request
.status
.version
[0] =
270 con
->request
->request
.op
.version
[0];
271 con
->response
->request
.status
.version
[1] =
272 con
->request
->request
.op
.version
[1];
273 con
->response
->request
.status
.request_id
=
274 con
->request
->request
.op
.request_id
;
277 * Then validate the request header and required attributes...
280 if (con
->request
->request
.any
.version
[0] != 1 &&
281 con
->request
->request
.any
.version
[0] != 2)
284 * Return an error, since we only support IPP 1.x and 2.x.
287 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
288 "%04X %s Bad request version number %d.%d",
289 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
290 con
->request
->request
.any
.version
[0],
291 con
->request
->request
.any
.version
[1]);
293 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
294 _("Bad request version number %d.%d!"),
295 con
->request
->request
.any
.version
[0],
296 con
->request
->request
.any
.version
[1]);
298 else if (con
->request
->request
.any
.request_id
< 1)
301 * Return an error, since request IDs must be between 1 and 2^31-1
304 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
305 "%04X %s Bad request ID %d",
306 IPP_BAD_REQUEST
, con
->http
.hostname
,
307 con
->request
->request
.any
.request_id
);
309 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d!"),
310 con
->request
->request
.any
.request_id
);
312 else if (!con
->request
->attrs
)
314 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
315 "%04X %s No attributes in request",
316 IPP_BAD_REQUEST
, con
->http
.hostname
);
318 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request!"));
323 * Make sure that the attributes are provided in the correct order and
324 * don't repeat groups...
327 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
330 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
333 * Out of order; return an error...
336 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
337 "%04X %s Attribute groups are out of order",
338 IPP_BAD_REQUEST
, con
->http
.hostname
);
340 send_ipp_status(con
, IPP_BAD_REQUEST
,
341 _("Attribute groups are out of order (%x < %x)!"),
342 attr
->group_tag
, group
);
346 group
= attr
->group_tag
;
351 * Then make sure that the first three attributes are:
354 * attributes-natural-language
355 * printer-uri/job-uri
358 attr
= con
->request
->attrs
;
359 if (attr
&& attr
->name
&&
360 !strcmp(attr
->name
, "attributes-charset") &&
361 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
369 if (attr
&& attr
->name
&&
370 !strcmp(attr
->name
, "attributes-natural-language") &&
371 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
376 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
377 IPP_TAG_URI
)) != NULL
)
379 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
380 IPP_TAG_URI
)) != NULL
)
382 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
383 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
388 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
389 "attributes-charset", NULL
,
390 charset
->values
[0].string
.text
);
392 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
393 "attributes-charset", NULL
, DefaultCharset
);
396 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
397 "attributes-natural-language", NULL
,
398 language
->values
[0].string
.text
);
400 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
401 "attributes-natural-language", NULL
, DefaultLanguage
);
404 strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
405 strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
408 * Bad character set...
411 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"!",
412 charset
->values
[0].string
.text
);
413 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
414 "%04X %s Unsupported attributes-charset value \"%s\"",
415 IPP_CHARSET
, con
->http
.hostname
,
416 charset
->values
[0].string
.text
);
417 send_ipp_status(con
, IPP_BAD_REQUEST
,
418 _("Unsupported character set \"%s\"!"),
419 charset
->values
[0].string
.text
);
421 else if (!charset
|| !language
||
423 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
424 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
425 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
426 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
427 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
430 * Return an error, since attributes-charset,
431 * attributes-natural-language, and printer-uri/job-uri are required
432 * for all operations.
437 cupsdLogMessage(CUPSD_LOG_ERROR
,
438 "Missing attributes-charset attribute!");
440 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
441 "%04X %s Missing attributes-charset attribute",
442 IPP_BAD_REQUEST
, con
->http
.hostname
);
447 cupsdLogMessage(CUPSD_LOG_ERROR
,
448 "Missing attributes-natural-language attribute!");
450 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
451 "%04X %s Missing attributes-natural-language attribute",
452 IPP_BAD_REQUEST
, con
->http
.hostname
);
457 cupsdLogMessage(CUPSD_LOG_ERROR
,
458 "Missing printer-uri, job-uri, or ppd-name "
461 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
462 "%04X %s Missing printer-uri, job-uri, or ppd-name "
463 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
466 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
468 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
469 cupsdLogMessage(CUPSD_LOG_DEBUG
,
470 "attr \"%s\": group_tag = %x, value_tag = %x",
471 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
474 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
476 send_ipp_status(con
, IPP_BAD_REQUEST
,
477 _("Missing required attributes!"));
482 * OK, all the checks pass so far; make sure requesting-user-name is
483 * not "root" from a remote host...
486 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
487 IPP_TAG_NAME
)) != NULL
)
490 * Check for root user...
493 if (!strcmp(username
->values
[0].string
.text
, "root") &&
494 strcasecmp(con
->http
.hostname
, "localhost") &&
495 strcmp(con
->username
, "root"))
498 * Remote unauthenticated user masquerading as local root...
501 _cupsStrFree(username
->values
[0].string
.text
);
502 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
506 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
507 IPP_TAG_INTEGER
)) != NULL
)
508 sub_id
= attr
->values
[0].integer
;
513 * Then try processing the operation...
517 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
518 ippOpString(con
->request
->request
.op
.operation_id
),
519 uri
->values
[0].string
.text
);
521 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
522 ippOpString(con
->request
->request
.op
.operation_id
));
524 switch (con
->request
->request
.op
.operation_id
)
530 case IPP_VALIDATE_JOB
:
531 validate_job(con
, uri
);
534 case IPP_CREATE_JOB
:
535 create_job(con
, uri
);
538 case IPP_SEND_DOCUMENT
:
539 send_document(con
, uri
);
542 case IPP_CANCEL_JOB
:
543 cancel_job(con
, uri
);
546 case IPP_GET_JOB_ATTRIBUTES
:
547 get_job_attrs(con
, uri
);
554 case IPP_GET_PRINTER_ATTRIBUTES
:
555 get_printer_attrs(con
, uri
);
558 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
559 get_printer_supported(con
, uri
);
566 case IPP_RELEASE_JOB
:
567 release_job(con
, uri
);
570 case IPP_RESTART_JOB
:
571 restart_job(con
, uri
);
574 case IPP_PAUSE_PRINTER
:
575 stop_printer(con
, uri
);
578 case IPP_RESUME_PRINTER
:
579 start_printer(con
, uri
);
582 case IPP_PURGE_JOBS
:
583 cancel_all_jobs(con
, uri
);
586 case IPP_SET_JOB_ATTRIBUTES
:
587 set_job_attrs(con
, uri
);
590 case IPP_SET_PRINTER_ATTRIBUTES
:
591 set_printer_attrs(con
, uri
);
594 case IPP_HOLD_NEW_JOBS
:
595 hold_new_jobs(con
, uri
);
598 case IPP_RELEASE_HELD_NEW_JOBS
:
599 release_held_new_jobs(con
, uri
);
602 case CUPS_GET_DEFAULT
:
606 case CUPS_GET_PRINTERS
:
607 get_printers(con
, 0);
610 case CUPS_GET_CLASSES
:
611 get_printers(con
, CUPS_PRINTER_CLASS
);
614 case CUPS_ADD_PRINTER
:
615 add_printer(con
, uri
);
618 case CUPS_DELETE_PRINTER
:
619 delete_printer(con
, uri
);
622 case CUPS_ADD_CLASS
:
626 case CUPS_DELETE_CLASS
:
627 delete_printer(con
, uri
);
630 case CUPS_ACCEPT_JOBS
:
631 case IPP_ENABLE_PRINTER
:
632 accept_jobs(con
, uri
);
635 case CUPS_REJECT_JOBS
:
636 case IPP_DISABLE_PRINTER
:
637 reject_jobs(con
, uri
);
640 case CUPS_SET_DEFAULT
:
641 set_default(con
, uri
);
644 case CUPS_GET_DEVICES
:
648 case CUPS_GET_DOCUMENT
:
649 get_document(con
, uri
);
664 case CUPS_AUTHENTICATE_JOB
:
665 authenticate_job(con
, uri
);
668 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
669 case IPP_CREATE_JOB_SUBSCRIPTION
:
670 create_subscription(con
, uri
);
673 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
674 get_subscription_attrs(con
, sub_id
);
677 case IPP_GET_SUBSCRIPTIONS
:
678 get_subscriptions(con
, uri
);
681 case IPP_RENEW_SUBSCRIPTION
:
682 renew_subscription(con
, sub_id
);
685 case IPP_CANCEL_SUBSCRIPTION
:
686 cancel_subscription(con
, sub_id
);
689 case IPP_GET_NOTIFICATIONS
:
690 get_notifications(con
);
694 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
695 "%04X %s Operation %04X (%s) not supported",
696 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
697 con
->request
->request
.op
.operation_id
,
698 ippOpString(con
->request
->request
.op
.operation_id
));
700 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
701 _("%s not supported!"),
703 con
->request
->request
.op
.operation_id
));
713 * Sending data from the scheduler...
716 cupsdLogMessage(con
->response
->request
.status
.status_code
717 >= IPP_BAD_REQUEST
&&
718 con
->response
->request
.status
.status_code
719 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
720 "Returning IPP %s for %s (%s) from %s",
721 ippErrorString(con
->response
->request
.status
.status_code
),
722 ippOpString(con
->request
->request
.op
.operation_id
),
723 uri
? uri
->values
[0].string
.text
: "no URI",
726 if (LogLevel
== CUPSD_LOG_DEBUG2
)
727 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
728 "cupsdProcessIPPRequest: ippLength(response)=%ld",
729 (long)ippLength(con
->response
));
731 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
733 #ifdef CUPSD_USE_CHUNKING
735 * Because older versions of CUPS (1.1.17 and older) and some IPP
736 * clients do not implement chunking properly, we cannot use
737 * chunking by default. This may become the default in future
738 * CUPS releases, or we might add a configuration directive for
742 if (con
->http
.version
== HTTP_1_1
)
744 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
747 if (cupsdFlushHeader(con
) < 0)
750 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
753 #endif /* CUPSD_USE_CHUNKING */
755 size_t length
; /* Length of response */
758 length
= ippLength(con
->response
);
760 if (con
->file
>= 0 && !con
->pipe_pid
)
762 struct stat fileinfo
; /* File information */
765 if (!fstat(con
->file
, &fileinfo
))
766 length
+= fileinfo
.st_size
;
769 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
770 CUPS_LLCAST length
) < 0)
773 if (cupsdFlushHeader(con
) < 0)
776 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
777 con
->http
.data_remaining
= length
;
779 if (con
->http
.data_remaining
<= INT_MAX
)
780 con
->http
._data_remaining
= con
->http
.data_remaining
;
782 con
->http
._data_remaining
= INT_MAX
;
785 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
786 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
789 * Tell the caller the response header was sent successfully...
797 * Tell the caller the response header could not be sent...
806 * Sending data from a subprocess like cups-deviced; tell the caller
807 * everything is A-OK so far...
816 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
819 int /* O - 0 on success, -1 on error */
820 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
822 cupsd_printer_t
*printer
; /* Destination printer or class */
823 ipp_attribute_t
*attr
; /* job-sheets attribute */
824 int kbytes
; /* Kilobytes in banner */
827 job
->pending_timeout
= 0;
830 * See if we need to add the ending sheet...
833 printer
= cupsdFindDest(job
->dest
);
834 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
837 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
838 attr
&& attr
->num_values
> 1)
844 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
845 attr
->values
[1].string
.text
);
847 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
850 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
858 * 'accept_jobs()' - Accept print jobs to a printer.
862 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
863 ipp_attribute_t
*uri
) /* I - Printer or class URI */
865 http_status_t status
; /* Policy status */
866 cups_ptype_t dtype
; /* Destination type (printer/class) */
867 cupsd_printer_t
*printer
; /* Printer data */
870 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
871 con
->http
.fd
, uri
->values
[0].string
.text
);
874 * Is the destination valid?
877 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
883 send_ipp_status(con
, IPP_NOT_FOUND
,
884 _("The printer or class was not found."));
892 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
894 send_http_error(con
, status
, printer
);
899 * Accept jobs sent to the printer...
902 printer
->accepting
= 1;
903 printer
->state_message
[0] = '\0';
905 cupsdAddPrinterHistory(printer
);
907 if (dtype
& CUPS_PRINTER_CLASS
)
909 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
911 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
912 printer
->name
, get_username(con
));
916 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
918 cupsdLogMessage(CUPSD_LOG_INFO
,
919 "Printer \"%s\" now accepting jobs (\"%s\").",
920 printer
->name
, get_username(con
));
924 * Everything was ok, so return OK status...
927 con
->response
->request
.status
.status_code
= IPP_OK
;
932 * 'add_class()' - Add a class to the system.
936 add_class(cupsd_client_t
*con
, /* I - Client connection */
937 ipp_attribute_t
*uri
) /* I - URI of class */
939 http_status_t status
; /* Policy status */
940 int i
; /* Looping var */
941 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
942 username
[HTTP_MAX_URI
], /* Username portion of URI */
943 host
[HTTP_MAX_URI
], /* Host portion of URI */
944 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
945 int port
; /* Port portion of URI */
946 cupsd_printer_t
*pclass
, /* Class */
947 *member
; /* Member printer/class */
948 cups_ptype_t dtype
; /* Destination type */
949 ipp_attribute_t
*attr
; /* Printer attribute */
950 int modify
; /* Non-zero if we just modified */
951 char newname
[IPP_MAX_NAME
]; /* New class name */
952 int need_restart_job
; /* Need to restart job? */
955 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
956 con
->http
.fd
, uri
->values
[0].string
.text
);
959 * Do we have a valid URI?
962 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
963 sizeof(scheme
), username
, sizeof(username
), host
,
964 sizeof(host
), &port
, resource
, sizeof(resource
));
967 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
970 * No, return an error...
973 send_ipp_status(con
, IPP_BAD_REQUEST
,
974 _("The printer-uri must be of the form "
975 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
980 * Do we have a valid printer name?
983 if (!validate_name(resource
+ 9))
986 * No, return an error...
989 send_ipp_status(con
, IPP_BAD_REQUEST
,
990 _("The printer-uri \"%s\" contains invalid characters."),
991 uri
->values
[0].string
.text
);
996 * See if the class already exists; if not, create a new class...
999 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1002 * Class doesn't exist; see if we have a printer of the same name...
1005 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
1006 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
1009 * Yes, return an error...
1012 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1013 _("A printer named \"%s\" already exists!"),
1019 * No, check the default policy and then add the class...
1022 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1024 send_http_error(con
, status
, NULL
);
1028 pclass
= cupsdAddClass(resource
+ 9);
1031 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1034 * Check the default policy, then rename the implicit class to "AnyClass"
1038 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1040 send_http_error(con
, status
, NULL
);
1044 if (ImplicitAnyClasses
)
1046 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1047 cupsdRenamePrinter(pclass
, newname
);
1050 cupsdDeletePrinter(pclass
, 1);
1053 * Add the class as a new local class...
1056 pclass
= cupsdAddClass(resource
+ 9);
1059 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1062 * Check the default policy, then rename the remote class to "Class"...
1065 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1067 send_http_error(con
, status
, NULL
);
1071 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1072 cupsdRenamePrinter(pclass
, newname
);
1075 * Add the class as a new local class...
1078 pclass
= cupsdAddClass(resource
+ 9);
1081 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1084 send_http_error(con
, status
, pclass
);
1091 * Look for attributes and copy them over as needed...
1094 need_restart_job
= 0;
1096 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1097 IPP_TAG_TEXT
)) != NULL
)
1098 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1100 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1101 IPP_TAG_TEXT
)) != NULL
)
1102 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1104 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1105 IPP_TAG_BOOLEAN
)) != NULL
)
1107 cupsdLogMessage(CUPSD_LOG_INFO
,
1108 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1109 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1111 pclass
->accepting
= attr
->values
[0].boolean
;
1112 cupsdAddPrinterHistory(pclass
);
1115 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1116 IPP_TAG_BOOLEAN
)) != NULL
)
1118 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1119 cupsdDeregisterPrinter(pclass
, 1);
1121 cupsdLogMessage(CUPSD_LOG_INFO
,
1122 "Setting %s printer-is-shared to %d (was %d.)",
1123 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1125 pclass
->shared
= attr
->values
[0].boolean
;
1128 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1129 IPP_TAG_ENUM
)) != NULL
)
1131 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1132 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1134 send_ipp_status(con
, IPP_BAD_REQUEST
,
1135 _("Attempt to set %s printer-state to bad value %d!"),
1136 pclass
->name
, attr
->values
[0].integer
);
1140 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1141 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1143 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1144 cupsdStopPrinter(pclass
, 0);
1147 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1148 need_restart_job
= 1;
1151 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1152 IPP_TAG_TEXT
)) != NULL
)
1154 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1155 sizeof(pclass
->state_message
));
1156 cupsdAddPrinterHistory(pclass
);
1158 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1159 IPP_TAG_URI
)) != NULL
)
1162 * Clear the printer array as needed...
1165 need_restart_job
= 1;
1167 if (pclass
->num_printers
> 0)
1169 free(pclass
->printers
);
1170 pclass
->num_printers
= 0;
1174 * Add each printer or class that is listed...
1177 for (i
= 0; i
< attr
->num_values
; i
++)
1180 * Search for the printer or class URI...
1183 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1189 send_ipp_status(con
, IPP_NOT_FOUND
,
1190 _("The printer or class was not found."));
1193 else if (dtype
& CUPS_PRINTER_CLASS
)
1195 send_ipp_status(con
, IPP_BAD_REQUEST
,
1196 _("Nested classes are not allowed!"));
1201 * Add it to the class...
1204 cupsdAddPrinterToClass(pclass
, member
);
1208 set_printer_defaults(con
, pclass
);
1210 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1211 IPP_TAG_KEYWORD
)) != NULL
)
1212 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1215 * Update the printer class attributes and return...
1218 cupsdSetPrinterAttrs(pclass
);
1219 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1221 if (need_restart_job
&& pclass
->job
)
1224 * Reset the current job to a "pending" status...
1227 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1228 "Job restarted because the class was modified.");
1231 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1235 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, pclass
, NULL
,
1236 "Class \"%s\" modified by \"%s\".", pclass
->name
,
1239 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1240 pclass
->name
, get_username(con
));
1244 cupsdAddPrinterHistory(pclass
);
1246 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, pclass
, NULL
,
1247 "New class \"%s\" added by \"%s\".", pclass
->name
,
1250 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1251 pclass
->name
, get_username(con
));
1254 con
->response
->request
.status
.status_code
= IPP_OK
;
1259 * 'add_file()' - Add a file to a job.
1262 static int /* O - 0 on success, -1 on error */
1263 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1264 cupsd_job_t
*job
, /* I - Job to add to */
1265 mime_type_t
*filetype
, /* I - Type of file */
1266 int compression
) /* I - Compression */
1268 mime_type_t
**filetypes
; /* New filetypes array... */
1269 int *compressions
; /* New compressions array... */
1272 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1273 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1274 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1275 filetype
->super
, filetype
->type
, compression
);
1278 * Add the file to the job...
1281 if (job
->num_files
== 0)
1283 compressions
= (int *)malloc(sizeof(int));
1284 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1288 compressions
= (int *)realloc(job
->compressions
,
1289 (job
->num_files
+ 1) * sizeof(int));
1290 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1291 (job
->num_files
+ 1) *
1292 sizeof(mime_type_t
*));
1295 if (!compressions
|| !filetypes
)
1297 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1298 "Job aborted because the scheduler ran out of memory.");
1301 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1302 _("Unable to allocate memory for file types!"));
1307 job
->compressions
= compressions
;
1308 job
->compressions
[job
->num_files
] = compression
;
1309 job
->filetypes
= filetypes
;
1310 job
->filetypes
[job
->num_files
] = filetype
;
1315 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1322 * 'add_job()' - Add a job to a print queue.
1325 static cupsd_job_t
* /* O - Job object */
1326 add_job(cupsd_client_t
*con
, /* I - Client connection */
1327 cupsd_printer_t
*printer
, /* I - Destination printer */
1328 mime_type_t
*filetype
) /* I - First print file type, if any */
1330 http_status_t status
; /* Policy status */
1331 ipp_attribute_t
*attr
, /* Current attribute */
1332 *auth_info
; /* auth-info attribute */
1333 const char *val
; /* Default option value */
1334 int priority
; /* Job priority */
1335 char *title
; /* Job name/title */
1336 cupsd_job_t
*job
; /* Current job */
1337 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1338 int kbytes
; /* Size of print file */
1339 int i
; /* Looping var */
1340 int lowerpagerange
; /* Page range bound */
1343 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1344 con
, con
->http
.fd
, printer
, printer
->name
,
1345 filetype
, filetype
? filetype
->super
: "none",
1346 filetype
? filetype
->type
: "none");
1349 * Check remote printing to non-shared printer...
1352 if (!printer
->shared
&&
1353 strcasecmp(con
->http
.hostname
, "localhost") &&
1354 strcasecmp(con
->http
.hostname
, ServerName
))
1356 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1357 _("The printer or class is not shared!"));
1365 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1367 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1369 send_http_error(con
, status
, printer
);
1372 else if (printer
->num_auth_info_required
== 1 &&
1373 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1376 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1380 else if (auth_info
&& !con
->http
.tls
&&
1381 !httpAddrLocalhost(con
->http
.hostaddr
))
1384 * Require encryption of auth-info over non-local connections...
1387 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1390 #endif /* HAVE_SSL */
1393 * See if the printer is accepting jobs...
1396 if (!printer
->accepting
)
1398 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1399 _("Destination \"%s\" is not accepting jobs."),
1405 * Validate job template attributes; for now just document-format,
1406 * copies, number-up, and page-ranges...
1409 if (filetype
&& printer
->filetypes
&&
1410 !cupsArrayFind(printer
->filetypes
, filetype
))
1412 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1413 /* MIME media type string */
1416 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1419 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1420 _("Unsupported format \'%s\'!"), mimetype
);
1422 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1423 "document-format", NULL
, mimetype
);
1428 if ((attr
= ippFindAttribute(con
->request
, "copies",
1429 IPP_TAG_INTEGER
)) != NULL
)
1431 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1433 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1434 attr
->values
[0].integer
);
1435 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1436 "copies", attr
->values
[0].integer
);
1441 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1442 IPP_TAG_ZERO
)) != NULL
)
1444 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1445 attr
->value_tag
!= IPP_TAG_NAME
)
1447 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type!"));
1451 if (attr
->num_values
> 2)
1453 send_ipp_status(con
, IPP_BAD_REQUEST
,
1454 _("Too many job-sheets values (%d > 2)!"),
1459 for (i
= 0; i
< attr
->num_values
; i
++)
1460 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1461 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1463 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"!"),
1464 attr
->values
[i
].string
.text
);
1469 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1470 IPP_TAG_INTEGER
)) != NULL
)
1472 if (attr
->values
[0].integer
!= 1 &&
1473 attr
->values
[0].integer
!= 2 &&
1474 attr
->values
[0].integer
!= 4 &&
1475 attr
->values
[0].integer
!= 6 &&
1476 attr
->values
[0].integer
!= 9 &&
1477 attr
->values
[0].integer
!= 16)
1479 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1480 attr
->values
[0].integer
);
1481 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1482 "number-up", attr
->values
[0].integer
);
1487 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1488 IPP_TAG_RANGE
)) != NULL
)
1490 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1492 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1493 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1495 send_ipp_status(con
, IPP_BAD_REQUEST
,
1496 _("Bad page-ranges values %d-%d."),
1497 attr
->values
[i
].range
.lower
,
1498 attr
->values
[i
].range
.upper
);
1502 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1507 * Make sure we aren't over our limit...
1510 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1513 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1515 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1516 _("Too many active jobs."));
1520 if ((i
= check_quotas(con
, printer
)) < 0)
1522 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1527 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1532 * Create the job and set things up...
1535 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1536 IPP_TAG_INTEGER
)) != NULL
)
1537 priority
= attr
->values
[0].integer
;
1540 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1541 printer
->options
)) != NULL
)
1542 priority
= atoi(val
);
1546 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1550 if ((attr
= ippFindAttribute(con
->request
, "job-name",
1551 IPP_TAG_NAME
)) != NULL
)
1552 title
= attr
->values
[0].string
.text
;
1554 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1555 title
= "Untitled");
1557 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1559 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1560 _("Unable to add job for destination \"%s\"!"),
1565 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1566 CUPS_PRINTER_REMOTE
);
1567 job
->attrs
= con
->request
;
1569 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1571 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1573 add_job_uuid(con
, job
);
1574 apply_printer_defaults(printer
, job
);
1576 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1578 if (con
->username
[0])
1580 cupsdSetString(&job
->username
, con
->username
);
1583 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1587 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1588 "add_job: requesting-user-name=\"%s\"",
1589 attr
->values
[0].string
.text
);
1591 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1594 cupsdSetString(&job
->username
, "anonymous");
1597 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1598 "job-originating-user-name", NULL
, job
->username
);
1601 attr
->group_tag
= IPP_TAG_JOB
;
1602 _cupsStrFree(attr
->name
);
1603 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1606 if (con
->username
[0] || auth_info
)
1608 save_auth_info(con
, job
, auth_info
);
1611 * Remove the auth-info attribute from the attribute data...
1615 ippDeleteAttribute(job
->attrs
, auth_info
);
1618 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1619 IPP_TAG_ZERO
)) != NULL
)
1622 * Request contains a job-originating-host-name attribute; validate it...
1625 if (attr
->value_tag
!= IPP_TAG_NAME
||
1626 attr
->num_values
!= 1 ||
1627 strcmp(con
->http
.hostname
, "localhost"))
1630 * Can't override the value if we aren't connected via localhost.
1631 * Also, we can only have 1 value and it must be a name value.
1634 switch (attr
->value_tag
)
1636 case IPP_TAG_STRING
:
1637 case IPP_TAG_TEXTLANG
:
1638 case IPP_TAG_NAMELANG
:
1641 case IPP_TAG_KEYWORD
:
1643 case IPP_TAG_URISCHEME
:
1644 case IPP_TAG_CHARSET
:
1645 case IPP_TAG_LANGUAGE
:
1646 case IPP_TAG_MIMETYPE
:
1648 * Free old strings...
1651 for (i
= 0; i
< attr
->num_values
; i
++)
1653 _cupsStrFree(attr
->values
[i
].string
.text
);
1654 attr
->values
[i
].string
.text
= NULL
;
1655 if (attr
->values
[i
].string
.charset
)
1657 _cupsStrFree(attr
->values
[i
].string
.charset
);
1658 attr
->values
[i
].string
.charset
= NULL
;
1667 * Use the default connection hostname instead...
1670 attr
->value_tag
= IPP_TAG_NAME
;
1671 attr
->num_values
= 1;
1672 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1675 attr
->group_tag
= IPP_TAG_JOB
;
1680 * No job-originating-host-name attribute, so use the hostname from
1684 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1685 "job-originating-host-name", NULL
, con
->http
.hostname
);
1688 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1690 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1691 "time-at-processing", 0);
1692 attr
->value_tag
= IPP_TAG_NOVALUE
;
1693 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1694 "time-at-completed", 0);
1695 attr
->value_tag
= IPP_TAG_NOVALUE
;
1698 * Add remaining job attributes...
1701 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1702 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1703 "job-state", IPP_JOB_STOPPED
);
1704 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1705 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1706 "job-media-sheets-completed", 0);
1707 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1709 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1712 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1713 IPP_TAG_INTEGER
)) != NULL
)
1714 attr
->values
[0].integer
= 0;
1716 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1718 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1719 IPP_TAG_KEYWORD
)) == NULL
)
1720 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1723 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1724 printer
->options
)) == NULL
)
1727 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1728 "job-hold-until", NULL
, val
);
1730 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold") &&
1731 !(printer
->type
& CUPS_PRINTER_REMOTE
))
1734 * Hold job until specified time...
1737 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1739 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1740 job
->state_value
= IPP_JOB_HELD
;
1742 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1744 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1745 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1746 job
->state_value
= IPP_JOB_HELD
;
1750 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1751 job
->state_value
= IPP_JOB_PENDING
;
1754 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1758 * Add job sheets options...
1761 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1762 IPP_TAG_ZERO
)) == NULL
)
1764 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1765 "Adding default job-sheets values \"%s,%s\"...",
1766 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1768 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1770 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1771 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1774 job
->job_sheets
= attr
;
1777 * Enforce classification level if set...
1782 cupsdLogMessage(CUPSD_LOG_INFO
,
1783 "Classification=\"%s\", ClassifyOverride=%d",
1784 Classification
? Classification
: "(null)",
1787 if (ClassifyOverride
)
1789 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1790 (attr
->num_values
== 1 ||
1791 !strcmp(attr
->values
[1].string
.text
, "none")))
1794 * Force the leading banner to have the classification on it...
1797 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1799 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1800 "job-sheets=\"%s,none\", "
1801 "job-originating-user-name=\"%s\"",
1802 Classification
, job
->username
);
1804 else if (attr
->num_values
== 2 &&
1805 strcmp(attr
->values
[0].string
.text
,
1806 attr
->values
[1].string
.text
) &&
1807 strcmp(attr
->values
[0].string
.text
, "none") &&
1808 strcmp(attr
->values
[1].string
.text
, "none"))
1811 * Can't put two different security markings on the same document!
1814 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1816 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1817 "job-sheets=\"%s,%s\", "
1818 "job-originating-user-name=\"%s\"",
1819 attr
->values
[0].string
.text
,
1820 attr
->values
[1].string
.text
, job
->username
);
1822 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1823 strcmp(attr
->values
[0].string
.text
, "none") &&
1824 (attr
->num_values
== 1 ||
1825 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1826 strcmp(attr
->values
[1].string
.text
, "none"))))
1828 if (attr
->num_values
== 1)
1829 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1830 "CLASSIFICATION OVERRIDDEN "
1831 "job-sheets=\"%s\", "
1832 "job-originating-user-name=\"%s\"",
1833 attr
->values
[0].string
.text
, job
->username
);
1835 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1836 "CLASSIFICATION OVERRIDDEN "
1837 "job-sheets=\"%s,%s\",fffff "
1838 "job-originating-user-name=\"%s\"",
1839 attr
->values
[0].string
.text
,
1840 attr
->values
[1].string
.text
, job
->username
);
1843 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1844 (attr
->num_values
== 1 ||
1845 strcmp(attr
->values
[1].string
.text
, Classification
)))
1848 * Force the banner to have the classification on it...
1851 if (attr
->num_values
> 1 &&
1852 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1854 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1855 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1859 if (attr
->num_values
== 1 ||
1860 strcmp(attr
->values
[0].string
.text
, "none"))
1861 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1863 if (attr
->num_values
> 1 &&
1864 strcmp(attr
->values
[1].string
.text
, "none"))
1865 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1868 if (attr
->num_values
> 1)
1869 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1870 "CLASSIFICATION FORCED "
1871 "job-sheets=\"%s,%s\", "
1872 "job-originating-user-name=\"%s\"",
1873 attr
->values
[0].string
.text
,
1874 attr
->values
[1].string
.text
, job
->username
);
1876 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1877 "CLASSIFICATION FORCED "
1878 "job-sheets=\"%s\", "
1879 "job-originating-user-name=\"%s\"",
1880 Classification
, job
->username
);
1885 * See if we need to add the starting sheet...
1888 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1890 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1891 attr
->values
[0].string
.text
);
1893 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1895 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1896 "Aborting job because the start banner could not be "
1901 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1904 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1905 IPP_TAG_ZERO
)) != NULL
)
1909 * Fill in the response info...
1912 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1913 LocalPort
, job
->id
);
1915 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1918 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1920 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1922 add_job_state_reasons(con
, job
);
1924 con
->response
->request
.status
.status_code
= IPP_OK
;
1927 * Add any job subscriptions...
1930 add_job_subscriptions(con
, job
);
1933 * Set all but the first two attributes to the job attributes group...
1936 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1937 attr
->group_tag
= IPP_TAG_JOB
;
1940 * Fire the "job created" event...
1943 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1946 * Return the new job...
1954 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1955 * upon the job and printer state...
1959 add_job_state_reasons(
1960 cupsd_client_t
*con
, /* I - Client connection */
1961 cupsd_job_t
*job
) /* I - Job info */
1963 cupsd_printer_t
*dest
; /* Destination printer */
1966 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1967 con
, con
->http
.fd
, job
? job
->id
: 0);
1969 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1971 case IPP_JOB_PENDING
:
1972 dest
= cupsdFindDest(job
->dest
);
1974 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1975 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1976 "job-state-reasons", NULL
, "printer-stopped");
1978 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1979 "job-state-reasons", NULL
, "none");
1983 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1984 IPP_TAG_KEYWORD
) != NULL
||
1985 ippFindAttribute(job
->attrs
, "job-hold-until",
1986 IPP_TAG_NAME
) != NULL
)
1987 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1988 "job-state-reasons", NULL
, "job-hold-until-specified");
1990 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1991 "job-state-reasons", NULL
, "job-incoming");
1994 case IPP_JOB_PROCESSING
:
1995 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1996 "job-state-reasons", NULL
, "job-printing");
1999 case IPP_JOB_STOPPED
:
2000 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2001 "job-state-reasons", NULL
, "job-stopped");
2004 case IPP_JOB_CANCELED
:
2005 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2006 "job-state-reasons", NULL
, "job-canceled-by-user");
2009 case IPP_JOB_ABORTED
:
2010 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2011 "job-state-reasons", NULL
, "aborted-by-system");
2014 case IPP_JOB_COMPLETED
:
2015 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2016 "job-state-reasons", NULL
, "job-completed-successfully");
2023 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2027 add_job_subscriptions(
2028 cupsd_client_t
*con
, /* I - Client connection */
2029 cupsd_job_t
*job
) /* I - Newly created job */
2031 int i
; /* Looping var */
2032 ipp_attribute_t
*prev
, /* Previous attribute */
2033 *next
, /* Next attribute */
2034 *attr
; /* Current attribute */
2035 cupsd_subscription_t
*sub
; /* Subscription object */
2036 const char *recipient
, /* notify-recipient-uri */
2037 *pullmethod
; /* notify-pull-method */
2038 ipp_attribute_t
*user_data
; /* notify-user-data */
2039 int interval
; /* notify-time-interval */
2040 unsigned mask
; /* notify-events */
2044 * Find the first subscription group attribute; return if we have
2048 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2049 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2056 * Process the subscription attributes in the request...
2065 mask
= CUPSD_EVENT_NONE
;
2067 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2069 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2070 attr
->value_tag
== IPP_TAG_URI
)
2073 * Validate the recipient scheme against the ServerBin/notifier
2077 char notifier
[1024], /* Notifier filename */
2078 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2079 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2080 host
[HTTP_MAX_URI
], /* Host portion of URI */
2081 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2082 int port
; /* Port portion of URI */
2085 recipient
= attr
->values
[0].string
.text
;
2087 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2088 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2089 host
, sizeof(host
), &port
,
2090 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2092 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2093 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
2094 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2095 "notify-status-code", IPP_URI_SCHEME
);
2099 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2101 if (access(notifier
, X_OK
))
2103 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2104 _("notify-recipient-uri URI \"%s\" uses unknown "
2105 "scheme!"), recipient
);
2106 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2107 "notify-status-code", IPP_URI_SCHEME
);
2111 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2113 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2114 _("notify-recipient-uri URI \"%s\" is already used!"),
2116 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2117 "notify-status-code", IPP_ATTRIBUTES
);
2121 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2122 attr
->value_tag
== IPP_TAG_KEYWORD
)
2124 pullmethod
= attr
->values
[0].string
.text
;
2126 if (strcmp(pullmethod
, "ippget"))
2128 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2129 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
2130 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2131 "notify-status-code", IPP_ATTRIBUTES
);
2135 else if (!strcmp(attr
->name
, "notify-charset") &&
2136 attr
->value_tag
== IPP_TAG_CHARSET
&&
2137 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2138 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2140 send_ipp_status(con
, IPP_CHARSET
,
2141 _("Character set \"%s\" not supported!"),
2142 attr
->values
[0].string
.text
);
2145 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2146 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2147 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2149 send_ipp_status(con
, IPP_CHARSET
,
2150 _("Language \"%s\" not supported!"),
2151 attr
->values
[0].string
.text
);
2154 else if (!strcmp(attr
->name
, "notify-user-data") &&
2155 attr
->value_tag
== IPP_TAG_STRING
)
2157 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2159 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2160 _("The notify-user-data value is too large "
2161 "(%d > 63 octets)!"),
2162 attr
->values
[0].unknown
.length
);
2168 else if (!strcmp(attr
->name
, "notify-events") &&
2169 attr
->value_tag
== IPP_TAG_KEYWORD
)
2171 for (i
= 0; i
< attr
->num_values
; i
++)
2172 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2174 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2176 send_ipp_status(con
, IPP_BAD_REQUEST
,
2177 _("The notify-lease-duration attribute cannot be "
2178 "used with job subscriptions."));
2181 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2182 attr
->value_tag
== IPP_TAG_INTEGER
)
2183 interval
= attr
->values
[0].integer
;
2188 if (!recipient
&& !pullmethod
)
2191 if (mask
== CUPSD_EVENT_NONE
)
2192 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2194 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2195 recipient
, 0)) != NULL
)
2197 sub
->interval
= interval
;
2199 cupsdSetString(&sub
->owner
, job
->username
);
2203 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2204 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2205 sub
->user_data_len
);
2208 ippAddSeparator(con
->response
);
2209 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2210 "notify-subscription-id", sub
->id
);
2217 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2220 * Remove all of the subscription attributes from the job request...
2222 * TODO: Optimize this since subscription groups have to come at the
2223 * end of the request...
2226 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2230 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2231 attr
->group_tag
== IPP_TAG_ZERO
)
2234 * Free and remove this attribute...
2242 job
->attrs
->attrs
= next
;
2248 job
->attrs
->last
= prev
;
2249 job
->attrs
->current
= prev
;
2254 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2256 * See RFC 4122 for the definition of UUIDs and the format.
2260 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2261 cupsd_job_t
*job
) /* I - Job */
2263 char uuid
[1024]; /* job-uuid string */
2264 _cups_md5_state_t md5state
; /* MD5 state */
2265 unsigned char md5sum
[16]; /* MD5 digest/sum */
2269 * First see if the job already has a job-uuid attribute; if so, return...
2272 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2276 * No job-uuid attribute, so build a version 3 UUID with the local job
2277 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2278 * the ServerName, server name and port that the client connected to,
2279 * and local job ID...
2282 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2283 con
->serverport
, job
->id
);
2285 _cupsMD5Init(&md5state
);
2286 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2287 _cupsMD5Finish(&md5state
, md5sum
);
2290 * Format the UUID URI using the MD5 sum and job ID.
2293 snprintf(uuid
, sizeof(uuid
),
2294 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2295 "%02x%02x%02x%02x%02x%02x",
2296 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2297 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2298 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2299 md5sum
[14], md5sum
[15]);
2301 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2306 * 'add_printer()' - Add a printer to the system.
2310 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2311 ipp_attribute_t
*uri
) /* I - URI of printer */
2313 http_status_t status
; /* Policy status */
2314 int i
; /* Looping var */
2315 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2316 username
[HTTP_MAX_URI
], /* Username portion of URI */
2317 host
[HTTP_MAX_URI
], /* Host portion of URI */
2318 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2319 int port
; /* Port portion of URI */
2320 cupsd_printer_t
*printer
; /* Printer/class */
2321 ipp_attribute_t
*attr
; /* Printer attribute */
2322 cups_file_t
*fp
; /* Script/PPD file */
2323 char line
[1024]; /* Line from file... */
2324 char srcfile
[1024], /* Source Script/PPD file */
2325 dstfile
[1024]; /* Destination Script/PPD file */
2326 int modify
; /* Non-zero if we are modifying */
2327 char newname
[IPP_MAX_NAME
]; /* New printer name */
2328 int need_restart_job
; /* Need to restart job? */
2329 int set_device_uri
, /* Did we set the device URI? */
2330 set_port_monitor
; /* Did we set the port monitor? */
2333 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2334 con
->http
.fd
, uri
->values
[0].string
.text
);
2337 * Do we have a valid URI?
2340 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2341 sizeof(scheme
), username
, sizeof(username
), host
,
2342 sizeof(host
), &port
, resource
, sizeof(resource
));
2344 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2347 * No, return an error...
2350 send_ipp_status(con
, IPP_BAD_REQUEST
,
2351 _("The printer-uri must be of the form "
2352 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2357 * Do we have a valid printer name?
2360 if (!validate_name(resource
+ 10))
2363 * No, return an error...
2366 send_ipp_status(con
, IPP_BAD_REQUEST
,
2367 _("The printer-uri \"%s\" contains invalid characters."),
2368 uri
->values
[0].string
.text
);
2373 * See if the printer already exists; if not, create a new printer...
2376 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2379 * Printer doesn't exist; see if we have a class of the same name...
2382 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2383 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2386 * Yes, return an error...
2389 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2390 _("A class named \"%s\" already exists!"),
2396 * No, check the default policy then add the printer...
2399 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2401 send_http_error(con
, status
, NULL
);
2405 printer
= cupsdAddPrinter(resource
+ 10);
2408 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2411 * Check the default policy, then rename the implicit printer to
2412 * "AnyPrinter" or delete it...
2415 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2417 send_http_error(con
, status
, NULL
);
2421 if (ImplicitAnyClasses
)
2423 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2424 cupsdRenamePrinter(printer
, newname
);
2427 cupsdDeletePrinter(printer
, 1);
2430 * Add the printer as a new local printer...
2433 printer
= cupsdAddPrinter(resource
+ 10);
2436 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2439 * Check the default policy, then rename the remote printer to
2440 * "Printer@server"...
2443 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2445 send_http_error(con
, status
, NULL
);
2449 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2451 cupsdRenamePrinter(printer
, newname
);
2454 * Add the printer as a new local printer...
2457 printer
= cupsdAddPrinter(resource
+ 10);
2460 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2463 send_http_error(con
, status
, printer
);
2470 * Look for attributes and copy them over as needed...
2473 need_restart_job
= 0;
2475 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2476 IPP_TAG_TEXT
)) != NULL
)
2477 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2479 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2480 IPP_TAG_TEXT
)) != NULL
)
2481 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2485 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2486 IPP_TAG_URI
)) != NULL
)
2489 * Do we have a valid device URI?
2492 http_uri_status_t uri_status
; /* URI separation status */
2493 char old_device_uri
[1024];
2494 /* Old device URI */
2497 need_restart_job
= 1;
2499 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2500 attr
->values
[0].string
.text
,
2501 scheme
, sizeof(scheme
),
2502 username
, sizeof(username
),
2503 host
, sizeof(host
), &port
,
2504 resource
, sizeof(resource
));
2506 if (uri_status
< HTTP_URI_OK
)
2508 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"!"),
2509 attr
->values
[0].string
.text
);
2510 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2511 "add_printer: httpSeparateURI returned %d", uri_status
);
2515 if (!strcmp(scheme
, "file"))
2518 * See if the administrator has enabled file devices...
2521 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2524 * File devices are disabled and the URL is not file:/dev/null...
2527 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2528 _("File device URIs have been disabled! "
2529 "To enable, see the FileDevice directive in "
2530 "\"%s/cupsd.conf\"."),
2538 * See if the backend exists and is executable...
2541 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2542 if (access(srcfile
, X_OK
))
2545 * Could not find device in list!
2548 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\"!"),
2554 if (printer
->sanitized_device_uri
)
2555 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2556 sizeof(old_device_uri
));
2558 old_device_uri
[0] = '\0';
2560 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2562 cupsdLogMessage(CUPSD_LOG_INFO
,
2563 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2564 printer
->name
, printer
->sanitized_device_uri
,
2570 set_port_monitor
= 0;
2572 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2573 IPP_TAG_NAME
)) != NULL
)
2575 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2578 need_restart_job
= 1;
2580 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2584 for (i
= 0; i
< supported
->num_values
; i
++)
2585 if (!strcmp(supported
->values
[i
].string
.text
,
2586 attr
->values
[0].string
.text
))
2590 if (!supported
|| i
>= supported
->num_values
)
2592 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"!"),
2593 attr
->values
[0].string
.text
);
2597 cupsdLogMessage(CUPSD_LOG_INFO
,
2598 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2599 printer
->name
, attr
->values
[0].string
.text
,
2600 printer
->port_monitor
? printer
->port_monitor
: "none");
2602 if (strcmp(attr
->values
[0].string
.text
, "none"))
2603 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2605 cupsdClearString(&printer
->port_monitor
);
2607 set_port_monitor
= 1;
2610 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2611 IPP_TAG_BOOLEAN
)) != NULL
)
2613 cupsdLogMessage(CUPSD_LOG_INFO
,
2614 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2615 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2617 printer
->accepting
= attr
->values
[0].boolean
;
2618 cupsdAddPrinterHistory(printer
);
2621 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2622 IPP_TAG_BOOLEAN
)) != NULL
)
2624 if (printer
->shared
&& !attr
->values
[0].boolean
)
2625 cupsdDeregisterPrinter(printer
, 1);
2627 cupsdLogMessage(CUPSD_LOG_INFO
,
2628 "Setting %s printer-is-shared to %d (was %d.)",
2629 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2631 printer
->shared
= attr
->values
[0].boolean
;
2634 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2635 IPP_TAG_ENUM
)) != NULL
)
2637 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2638 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2640 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d!"),
2641 attr
->values
[0].integer
);
2645 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2646 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2648 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2649 cupsdStopPrinter(printer
, 0);
2652 need_restart_job
= 1;
2653 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2657 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2658 IPP_TAG_TEXT
)) != NULL
)
2660 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2661 sizeof(printer
->state_message
));
2662 cupsdAddPrinterHistory(printer
);
2665 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2666 IPP_TAG_KEYWORD
)) != NULL
)
2668 if (attr
->num_values
>
2669 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2671 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2672 _("Too many printer-state-reasons values (%d > %d)!"),
2674 (int)(sizeof(printer
->reasons
) /
2675 sizeof(printer
->reasons
[0])));
2679 for (i
= 0; i
< printer
->num_reasons
; i
++)
2680 _cupsStrFree(printer
->reasons
[i
]);
2682 printer
->num_reasons
= 0;
2683 for (i
= 0; i
< attr
->num_values
; i
++)
2685 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2688 printer
->reasons
[printer
->num_reasons
] =
2689 _cupsStrRetain(attr
->values
[i
].string
.text
);
2690 printer
->num_reasons
++;
2692 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2693 printer
->state
!= IPP_PRINTER_STOPPED
)
2695 cupsdLogMessage(CUPSD_LOG_INFO
,
2696 "Setting %s printer-state to %d (was %d.)",
2697 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2698 cupsdStopPrinter(printer
, 0);
2702 if (PrintcapFormat
== PRINTCAP_PLIST
)
2703 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2706 set_printer_defaults(con
, printer
);
2708 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2709 IPP_TAG_KEYWORD
)) != NULL
)
2710 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2713 * See if we have all required attributes...
2716 if (!printer
->device_uri
)
2717 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2720 * See if we have an interface script or PPD file attached to the request...
2725 need_restart_job
= 1;
2727 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2729 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2732 * Yes; get the first line from it...
2736 cupsFileGets(fp
, line
, sizeof(line
));
2740 * Then see what kind of file it is...
2743 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2746 if (!strncmp(line
, "*PPD-Adobe", 10))
2749 * The new file is a PPD file, so remove any old interface script
2750 * that might be lying around...
2758 * This must be an interface script, so move the file over to the
2759 * interfaces directory and make it executable...
2762 if (copy_file(srcfile
, dstfile
))
2764 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2765 _("Unable to copy interface script - %s!"),
2770 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2771 "Copied interface script successfully!");
2772 chmod(dstfile
, 0755);
2775 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2778 if (!strncmp(line
, "*PPD-Adobe", 10))
2781 * The new file is a PPD file, so move the file over to the
2782 * ppd directory and make it readable by all...
2785 if (copy_file(srcfile
, dstfile
))
2787 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2788 _("Unable to copy PPD file - %s!"),
2793 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2794 "Copied PPD file successfully!");
2795 chmod(dstfile
, 0644);
2799 * (Re)register color profiles...
2804 apple_unregister_profiles(printer
);
2805 apple_register_profiles(printer
);
2807 #endif /* __APPLE__ */
2812 * This must be an interface script, so remove any old PPD file that
2813 * may be lying around...
2820 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2821 IPP_TAG_NAME
)) != NULL
)
2823 need_restart_job
= 1;
2825 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2828 * Raw driver, remove any existing PPD or interface script files.
2831 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2835 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2845 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2849 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2852 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2854 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file!"));
2858 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2859 "Copied PPD file successfully!");
2860 chmod(dstfile
, 0644);
2864 * (Re)register color profiles...
2869 apple_unregister_profiles(printer
);
2870 apple_register_profiles(printer
);
2872 #endif /* __APPLE__ */
2877 * If we set the device URI but not the port monitor, check which port
2878 * monitor to use by default...
2881 if (set_device_uri
&& !set_port_monitor
)
2883 ppd_file_t
*ppd
; /* PPD file */
2884 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2887 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2888 sizeof(scheme
), username
, sizeof(username
), host
,
2889 sizeof(host
), &port
, resource
, sizeof(resource
));
2891 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2893 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2895 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2897 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2898 if (!strcmp(scheme
, ppdattr
->spec
))
2900 cupsdLogMessage(CUPSD_LOG_INFO
,
2901 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2902 printer
->name
, ppdattr
->value
,
2903 printer
->port_monitor
? printer
->port_monitor
2906 if (strcmp(ppdattr
->value
, "none"))
2907 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2909 cupsdClearString(&printer
->port_monitor
);
2919 * Update the printer attributes and return...
2922 cupsdSetPrinterAttrs(printer
);
2923 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2925 if (need_restart_job
&& printer
->job
)
2928 * Restart the current job...
2931 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2932 "Job restarted because the printer was modified.");
2935 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2939 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2940 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2943 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2944 printer
->name
, get_username(con
));
2948 cupsdAddPrinterHistory(printer
);
2950 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2951 "New printer \"%s\" added by \"%s\".", printer
->name
,
2954 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2955 printer
->name
, get_username(con
));
2958 con
->response
->request
.status
.status_code
= IPP_OK
;
2963 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2964 * based upon the printer state...
2968 add_printer_state_reasons(
2969 cupsd_client_t
*con
, /* I - Client connection */
2970 cupsd_printer_t
*p
) /* I - Printer info */
2972 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2973 "add_printer_state_reasons(%p[%d], %p[%s])",
2974 con
, con
->http
.fd
, p
, p
->name
);
2976 if (p
->num_reasons
== 0)
2977 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2978 "printer-state-reasons", NULL
, "none");
2980 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2981 "printer-state-reasons", p
->num_reasons
, NULL
,
2982 (const char * const *)p
->reasons
);
2987 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2988 * the specified printer or class.
2992 add_queued_job_count(
2993 cupsd_client_t
*con
, /* I - Client connection */
2994 cupsd_printer_t
*p
) /* I - Printer or class */
2996 int count
; /* Number of jobs on destination */
2999 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3000 con
, con
->http
.fd
, p
, p
->name
);
3002 count
= cupsdGetPrinterJobCount(p
->name
);
3004 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3005 "queued-job-count", count
);
3011 * 'apple_init_profile()' - Initialize a color profile.
3016 ppd_file_t
*ppd
, /* I - PPD file */
3017 cups_array_t
*languages
, /* I - Languages in the PPD file */
3018 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3019 unsigned id
, /* I - Profile ID */
3020 const char *name
, /* I - Profile name */
3021 const char *text
, /* I - Profile UI text */
3022 const char *iccfile
) /* I - ICC filename */
3024 char url
[1024]; /* URL for profile filename */
3025 CFMutableDictionaryRef dict
; /* Dictionary for name */
3026 char *language
; /* Current language */
3027 ppd_attr_t
*attr
; /* Profile attribute */
3028 CFStringRef cflang
, /* Language string */
3029 cftext
; /* Localized text */
3033 * Build the profile name dictionary...
3036 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3037 &kCFTypeDictionaryKeyCallBacks
,
3038 &kCFTypeDictionaryValueCallBacks
);
3040 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3041 kCFStringEncodingUTF8
);
3045 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
3052 * Find localized names for the color profiles...
3055 cupsArraySave(ppd
->sorted_attrs
);
3057 for (language
= (char *)cupsArrayFirst(languages
);
3059 language
= (char *)cupsArrayNext(languages
))
3063 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3065 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3068 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3070 if (attr
&& attr
->text
[0])
3072 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3073 kCFStringEncodingUTF8
);
3074 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3075 kCFStringEncodingUTF8
);
3077 if (cflang
&& cftext
)
3078 CFDictionarySetValue(dict
, cflang
, cftext
);
3088 cupsArrayRestore(ppd
->sorted_attrs
);
3092 * Fill in the profile data...
3096 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3099 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3100 profile
->profileID
= id
;
3101 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3102 profile
->profileName
= dict
;
3105 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3106 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3111 * 'apple_register_profiles()' - Register color profiles for a printer.
3115 apple_register_profiles(
3116 cupsd_printer_t
*p
) /* I - Printer */
3118 int i
; /* Looping var */
3119 char ppdfile
[1024], /* PPD filename */
3120 iccfile
[1024], /* ICC filename */
3121 selector
[PPD_MAX_NAME
];
3122 /* Profile selection string */
3123 ppd_file_t
*ppd
; /* PPD file */
3124 ppd_attr_t
*attr
, /* Profile attributes */
3125 *profileid_attr
,/* cupsProfileID attribute */
3126 *q1_attr
, /* ColorModel (or other) qualifier */
3127 *q2_attr
, /* MediaType (or other) qualifier */
3128 *q3_attr
; /* Resolution (or other) qualifier */
3129 char q_keyword
[PPD_MAX_NAME
];
3130 /* Qualifier keyword */
3131 const char *q1_choice
, /* ColorModel (or other) choice */
3132 *q2_choice
, /* MediaType (or other) choice */
3133 *q3_choice
; /* Resolution (or other) choice */
3134 const char *profile_key
; /* Profile keyword */
3135 ppd_option_t
*cm_option
; /* Color model option */
3136 ppd_choice_t
*cm_choice
; /* Color model choice */
3137 int num_profiles
; /* Number of profiles */
3138 CMError error
; /* Last error */
3139 unsigned device_id
, /* Printer device ID */
3140 profile_id
, /* Profile ID */
3141 default_profile_id
= 0;
3142 /* Default profile ID */
3143 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3144 CFStringRef printer_name
; /* Printer name string */
3145 CMDeviceScope scope
= /* Scope of the registration */
3147 kCFPreferencesAnyUser
,
3148 kCFPreferencesCurrentHost
3150 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3151 CMDeviceProfileInfo
*profile
; /* Current profile */
3152 cups_array_t
*languages
; /* Languages array */
3156 * Make sure ColorSync is available...
3159 if (CMRegisterColorDevice
== NULL
)
3163 * Try opening the PPD file for this printer...
3166 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3167 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3171 * See if we have any profiles...
3174 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3175 profile_key
= "APTiogaProfile";
3178 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3179 profile_key
= "cupsICCProfile";
3182 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3183 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3185 if (attr
->value
[0] != '/')
3186 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3189 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3191 if (access(iccfile
, 0))
3199 * If we have profiles, add them...
3202 if (num_profiles
> 0)
3204 if (profile_key
[0] == 'A')
3207 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3211 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3213 default_profile_id
= atoi(attr
->value
);
3215 q1_choice
= q2_choice
= q3_choice
= NULL
;
3220 * For CUPS PPDs, figure out the default profile selector values...
3223 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3224 attr
->value
&& attr
->value
[0])
3226 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3227 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3229 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3230 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3232 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3233 q1_choice
= q1_attr
->value
;
3237 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3238 attr
->value
&& attr
->value
[0])
3240 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3241 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3244 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3246 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3247 q2_choice
= q2_attr
->value
;
3251 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3252 attr
->value
&& attr
->value
[0])
3254 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3255 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3258 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3260 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3261 q3_choice
= q3_attr
->value
;
3267 * Build the array of profiles...
3269 * Note: This calloc actually requests slightly more memory than needed.
3272 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3274 cupsdLogMessage(CUPSD_LOG_ERROR
,
3275 "Unable to allocate memory for %d profiles!",
3281 profiles
->profileCount
= num_profiles
;
3282 languages
= _ppdGetLanguages(ppd
);
3284 for (profile
= profiles
->profiles
,
3285 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3287 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3288 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3291 * Add this profile...
3294 if (attr
->value
[0] != '/')
3295 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3298 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3300 if (access(iccfile
, 0))
3303 if (profile_key
[0] == 'c')
3305 cupsArraySave(ppd
->sorted_attrs
);
3307 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3308 attr
->spec
)) != NULL
&&
3309 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3310 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3312 profile_id
= _ppdHashName(attr
->spec
);
3314 cupsArrayRestore(ppd
->sorted_attrs
);
3317 profile_id
= atoi(attr
->spec
);
3319 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3320 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3325 * See if this is the default profile...
3328 if (!default_profile_id
)
3334 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3335 q1_choice
, q2_choice
, q3_choice
);
3336 if (!strcmp(selector
, attr
->spec
))
3337 default_profile_id
= profile_id
;
3340 if (!default_profile_id
)
3342 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3344 if (!strcmp(selector
, attr
->spec
))
3345 default_profile_id
= profile_id
;
3349 if (!default_profile_id
&& q3_choice
)
3351 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3353 if (!strcmp(selector
, attr
->spec
))
3354 default_profile_id
= profile_id
;
3357 if (!default_profile_id
)
3359 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3360 if (!strcmp(selector
, attr
->spec
))
3361 default_profile_id
= profile_id
;
3366 _ppdFreeLanguages(languages
);
3368 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3371 * Extract profiles from ColorModel option...
3374 const char *profile_name
; /* Name of generic profile */
3377 num_profiles
= cm_option
->num_choices
;
3379 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3381 cupsdLogMessage(CUPSD_LOG_ERROR
,
3382 "Unable to allocate memory for %d profiles!",
3388 profiles
->profileCount
= num_profiles
;
3390 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3391 cm_choice
= cm_option
->choices
;
3393 i
--, cm_choice
++, profile
++)
3395 if (!strcmp(cm_choice
->choice
, "Gray") ||
3396 !strcmp(cm_choice
->choice
, "Black"))
3397 profile_name
= "Gray";
3398 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3399 !strcmp(cm_choice
->choice
, "CMY"))
3400 profile_name
= "RGB";
3401 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3402 !strcmp(cm_choice
->choice
, "KCMY"))
3403 profile_name
= "CMYK";
3405 profile_name
= "DeviceN";
3407 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3408 profile_id
= _ppdHashName(selector
);
3410 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3411 cm_choice
->text
, NULL
);
3413 if (cm_choice
->marked
)
3414 default_profile_id
= profile_id
;
3420 * Use the default colorspace...
3423 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3425 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3427 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3429 cupsdLogMessage(CUPSD_LOG_ERROR
,
3430 "Unable to allocate memory for %d profiles!",
3436 profiles
->profileCount
= num_profiles
;
3438 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3439 "Gray", "Gray", NULL
);
3441 switch (ppd
->colorspace
)
3445 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3446 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3450 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3451 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3459 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3460 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3466 if (num_profiles
> 0)
3469 * Make sure we have a default profile ID...
3472 if (!default_profile_id
)
3473 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3476 * Get the device ID hash and pathelogical name dictionary.
3479 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3482 device_id
= _ppdHashName(p
->name
);
3483 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3484 &kCFTypeDictionaryKeyCallBacks
,
3485 &kCFTypeDictionaryValueCallBacks
);
3486 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3487 p
->name
, kCFStringEncodingUTF8
);
3489 if (device_name
&& printer_name
)
3491 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3494 * Register the device with ColorSync...
3497 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3498 device_name
, &scope
);
3501 * Register the profiles...
3505 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3506 default_profile_id
, profiles
);
3516 cupsdLogMessage(CUPSD_LOG_ERROR
,
3517 "Unable to register ICC color profiles for \"%s\" - %d",
3518 p
->name
, (int)error
);
3520 for (profile
= profiles
->profiles
;
3522 profile
++, num_profiles
--)
3523 CFRelease(profile
->profileName
);
3528 CFRelease(printer_name
);
3531 CFRelease(device_name
);
3539 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3544 apple_unregister_profiles(
3545 cupsd_printer_t
*p
) /* I - Printer */
3548 * Make sure ColorSync is available...
3551 if (CMUnregisterColorDevice
!= NULL
)
3552 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3554 #endif /* __APPLE__ */
3557 * 'apply_printer_defaults()' - Apply printer default options to a job.
3561 apply_printer_defaults(
3562 cupsd_printer_t
*printer
, /* I - Printer */
3563 cupsd_job_t
*job
) /* I - Job */
3565 int i
, /* Looping var */
3566 num_options
; /* Number of default options */
3567 cups_option_t
*options
, /* Default options */
3568 *option
; /* Current option */
3572 * Collect all of the default options and add the missing ones to the
3576 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3577 option
= printer
->options
;
3580 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3582 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3587 * Encode these options as attributes in the job object...
3590 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3591 cupsFreeOptions(num_options
, options
);
3596 * 'authenticate_job()' - Set job authentication info.
3600 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3601 ipp_attribute_t
*uri
) /* I - Job URI */
3603 ipp_attribute_t
*attr
, /* job-id attribute */
3604 *auth_info
; /* auth-info attribute */
3605 int jobid
; /* Job ID */
3606 cupsd_job_t
*job
; /* Current job */
3607 char scheme
[HTTP_MAX_URI
],
3608 /* Method portion of URI */
3609 username
[HTTP_MAX_URI
],
3610 /* Username portion of URI */
3612 /* Host portion of URI */
3613 resource
[HTTP_MAX_URI
];
3614 /* Resource portion of URI */
3615 int port
; /* Port portion of URI */
3618 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3619 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3622 * Start with "everything is OK" status...
3625 con
->response
->request
.status
.status_code
= IPP_OK
;
3628 * See if we have a job URI or a printer URI...
3631 if (!strcmp(uri
->name
, "printer-uri"))
3634 * Got a printer URI; see if we also have a job-id attribute...
3637 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3638 IPP_TAG_INTEGER
)) == NULL
)
3640 send_ipp_status(con
, IPP_BAD_REQUEST
,
3641 _("Got a printer-uri attribute but no job-id!"));
3645 jobid
= attr
->values
[0].integer
;
3650 * Got a job URI; parse it to get the job ID...
3653 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3654 sizeof(scheme
), username
, sizeof(username
), host
,
3655 sizeof(host
), &port
, resource
, sizeof(resource
));
3657 if (strncmp(resource
, "/jobs/", 6))
3663 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
3664 uri
->values
[0].string
.text
);
3668 jobid
= atoi(resource
+ 6);
3672 * See if the job exists...
3675 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3678 * Nope - return a "not found" error...
3681 send_ipp_status(con
, IPP_NOT_FOUND
,
3682 _("Job #%d does not exist!"), jobid
);
3687 * See if the job has been completed...
3690 if (job
->state_value
!= IPP_JOB_HELD
)
3693 * Return a "not-possible" error...
3696 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3697 _("Job #%d is not held for authentication!"),
3703 * See if we have already authenticated...
3706 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3708 if (!con
->username
[0] && !auth_info
)
3710 cupsd_printer_t
*printer
; /* Job destination */
3714 * No auth data. If we need to authenticate via Kerberos, send a
3715 * HTTP auth challenge, otherwise just return an IPP error...
3718 printer
= cupsdFindDest(job
->dest
);
3720 if (printer
&& printer
->num_auth_info_required
> 0 &&
3721 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3722 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3724 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3725 _("No authentication information provided!"));
3730 * See if the job is owned by the requesting user...
3733 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3735 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3736 cupsdFindDest(job
->dest
));
3741 * Save the authentication information for this job...
3744 save_auth_info(con
, job
, auth_info
);
3747 * Reset the job-hold-until value to "no-hold"...
3750 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3751 IPP_TAG_KEYWORD
)) == NULL
)
3752 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3756 attr
->value_tag
= IPP_TAG_KEYWORD
;
3757 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3761 * Release the job and return...
3764 cupsdReleaseJob(job
);
3766 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3771 * 'cancel_all_jobs()' - Cancel all print jobs.
3775 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3776 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3778 http_status_t status
; /* Policy status */
3779 cups_ptype_t dtype
; /* Destination type */
3780 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3781 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3782 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3783 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3784 int port
; /* Port portion of URI */
3785 ipp_attribute_t
*attr
; /* Attribute in request */
3786 const char *username
; /* Username */
3787 cupsd_jobaction_t purge
; /* Purge? */
3788 cupsd_printer_t
*printer
; /* Printer */
3791 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3792 con
->http
.fd
, uri
->values
[0].string
.text
);
3795 * See if we have a printer URI...
3798 if (strcmp(uri
->name
, "printer-uri"))
3800 send_ipp_status(con
, IPP_BAD_REQUEST
,
3801 _("The printer-uri attribute is required!"));
3806 * Get the username (if any) for the jobs we want to cancel (only if
3807 * "my-jobs" is specified...
3810 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3811 IPP_TAG_BOOLEAN
)) != NULL
&&
3812 attr
->values
[0].boolean
)
3814 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3815 IPP_TAG_NAME
)) != NULL
)
3816 username
= attr
->values
[0].string
.text
;
3819 send_ipp_status(con
, IPP_BAD_REQUEST
,
3820 _("Missing requesting-user-name attribute!"));
3828 * Look for the "purge-jobs" attribute...
3831 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3832 IPP_TAG_BOOLEAN
)) != NULL
)
3833 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3835 purge
= CUPSD_JOB_PURGE
;
3838 * And if the destination is valid...
3841 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3847 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3848 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3849 hostname
, sizeof(hostname
), &port
,
3850 resource
, sizeof(resource
));
3852 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3853 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3855 send_ipp_status(con
, IPP_NOT_FOUND
,
3856 _("The printer or class was not found."));
3864 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3866 send_http_error(con
, status
, NULL
);
3871 * Cancel all jobs on all printers...
3874 cupsdCancelJobs(NULL
, username
, purge
);
3876 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3877 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3886 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3889 send_http_error(con
, status
, printer
);
3894 * Cancel all of the jobs on the named printer...
3897 cupsdCancelJobs(printer
->name
, username
, purge
);
3899 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3901 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3905 con
->response
->request
.status
.status_code
= IPP_OK
;
3910 * 'cancel_job()' - Cancel a print job.
3914 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3915 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3917 ipp_attribute_t
*attr
; /* Current attribute */
3918 int jobid
; /* Job ID */
3919 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3920 username
[HTTP_MAX_URI
], /* Username portion of URI */
3921 host
[HTTP_MAX_URI
], /* Host portion of URI */
3922 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3923 int port
; /* Port portion of URI */
3924 cupsd_job_t
*job
; /* Job information */
3925 cups_ptype_t dtype
; /* Destination type (printer/class) */
3926 cupsd_printer_t
*printer
; /* Printer data */
3927 cupsd_jobaction_t purge
; /* Purge the job? */
3930 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3931 con
->http
.fd
, uri
->values
[0].string
.text
);
3934 * See if we have a job URI or a printer URI...
3937 if (!strcmp(uri
->name
, "printer-uri"))
3940 * Got a printer URI; see if we also have a job-id attribute...
3943 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3944 IPP_TAG_INTEGER
)) == NULL
)
3946 send_ipp_status(con
, IPP_BAD_REQUEST
,
3947 _("Got a printer-uri attribute but no job-id!"));
3951 if ((jobid
= attr
->values
[0].integer
) == 0)
3954 * Find the current job on the specified printer...
3957 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3963 send_ipp_status(con
, IPP_NOT_FOUND
,
3964 _("The printer or class was not found."));
3969 * See if there are any pending jobs...
3972 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3974 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3975 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3976 !strcasecmp(job
->dest
, printer
->name
))
3984 * No, try stopped jobs...
3987 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3989 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3990 if (job
->state_value
== IPP_JOB_STOPPED
&&
3991 !strcasecmp(job
->dest
, printer
->name
))
3998 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s!"),
4008 * Got a job URI; parse it to get the job ID...
4011 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4012 sizeof(scheme
), username
, sizeof(username
), host
,
4013 sizeof(host
), &port
, resource
, sizeof(resource
));
4015 if (strncmp(resource
, "/jobs/", 6))
4021 send_ipp_status(con
, IPP_BAD_REQUEST
,
4022 _("Bad job-uri attribute \"%s\"!"),
4023 uri
->values
[0].string
.text
);
4027 jobid
= atoi(resource
+ 6);
4031 * Look for the "purge-job" attribute...
4034 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4035 IPP_TAG_BOOLEAN
)) != NULL
)
4036 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4038 purge
= CUPSD_JOB_DEFAULT
;
4041 * See if the job exists...
4044 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4047 * Nope - return a "not found" error...
4050 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
4055 * See if the job is owned by the requesting user...
4058 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4060 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4061 cupsdFindDest(job
->dest
));
4066 * See if the job is already completed, canceled, or aborted; if so,
4067 * we can't cancel...
4070 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4072 switch (job
->state_value
)
4074 case IPP_JOB_CANCELED
:
4075 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4076 _("Job #%d is already canceled - can\'t cancel."),
4080 case IPP_JOB_ABORTED
:
4081 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4082 _("Job #%d is already aborted - can\'t cancel."),
4087 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4088 _("Job #%d is already completed - can\'t cancel."),
4097 * Cancel the job and return...
4100 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4101 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4102 "Job canceled by \"%s\"",
4106 if (purge
== CUPSD_JOB_PURGE
)
4107 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4110 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4113 con
->response
->request
.status
.status_code
= IPP_OK
;
4118 * 'cancel_subscription()' - Cancel a subscription.
4122 cancel_subscription(
4123 cupsd_client_t
*con
, /* I - Client connection */
4124 int sub_id
) /* I - Subscription ID */
4126 http_status_t status
; /* Policy status */
4127 cupsd_subscription_t
*sub
; /* Subscription */
4130 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4131 "cancel_subscription(con=%p[%d], sub_id=%d)",
4132 con
, con
->http
.fd
, sub_id
);
4135 * Is the subscription ID valid?
4138 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4141 * Bad subscription ID...
4144 send_ipp_status(con
, IPP_NOT_FOUND
,
4145 _("notify-subscription-id %d no good!"), sub_id
);
4153 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4155 con
, sub
->owner
)) != HTTP_OK
)
4157 send_http_error(con
, status
, sub
->dest
);
4162 * Cancel the subscription...
4165 cupsdDeleteSubscription(sub
, 1);
4167 con
->response
->request
.status
.status_code
= IPP_OK
;
4172 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4175 static int /* O - 1 if OK, 0 if not */
4176 check_rss_recipient(
4177 const char *recipient
) /* I - Recipient URI */
4179 cupsd_subscription_t
*sub
; /* Current subscription */
4182 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4184 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4188 * Compare the URIs up to the first ?...
4191 const char *r1
, *r2
;
4193 for (r1
= recipient
, r2
= sub
->recipient
;
4194 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4206 * 'check_quotas()' - Check quotas for a printer and user.
4209 static int /* O - 1 if OK, 0 if not */
4210 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4211 cupsd_printer_t
*p
) /* I - Printer or class */
4213 int i
; /* Looping var */
4214 char username
[33]; /* Username */
4215 cupsd_quota_t
*q
; /* Quota data */
4216 #ifdef HAVE_MBR_UID_TO_UUID
4218 * Use Apple membership APIs which require that all names represent
4219 * valid user account or group records accessible by the server.
4222 uuid_t usr_uuid
; /* UUID for job requesting user */
4223 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4224 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4225 int mbr_err
; /* Error from membership function */
4226 int is_member
; /* Is this user a member? */
4229 * Use standard POSIX APIs for checking users and groups...
4232 struct passwd
*pw
; /* User password data */
4233 #endif /* HAVE_MBR_UID_TO_UUID */
4236 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4237 con
, con
->http
.fd
, p
, p
->name
);
4240 * Figure out who is printing...
4243 strlcpy(username
, get_username(con
), sizeof(username
));
4246 * Check global active job limits for printers and users...
4249 if (MaxJobsPerPrinter
)
4252 * Check if there are too many pending jobs on this printer...
4255 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4257 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4266 * Check if there are too many pending jobs for this user...
4269 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4271 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4278 * Check against users...
4281 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4286 #ifdef HAVE_MBR_UID_TO_UUID
4288 * Get UUID for job requesting user...
4291 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4297 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4298 "check_quotas: UUID lookup failed for user \"%s\"",
4300 cupsdLogMessage(CUPSD_LOG_INFO
,
4301 "Denying user \"%s\" access to printer \"%s\" "
4302 "(unknown user)...",
4308 * Get UID and GID of requesting user...
4311 pw
= getpwnam(username
);
4313 #endif /* HAVE_MBR_UID_TO_UUID */
4315 for (i
= 0; i
< p
->num_users
; i
++)
4316 if (p
->users
[i
][0] == '@')
4319 * Check group membership...
4322 #ifdef HAVE_MBR_UID_TO_UUID
4323 if (p
->users
[i
][1] == '#')
4325 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4326 uuid_clear(grp_uuid
);
4328 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4332 * Invalid ACL entries are ignored for matching; just record a
4333 * warning in the log...
4336 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4337 "check_quotas: UUID lookup failed for ACL entry "
4338 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4339 cupsdLogMessage(CUPSD_LOG_WARN
,
4340 "Access control entry \"%s\" not a valid group name; "
4341 "entry ignored", p
->users
[i
]);
4344 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4348 * At this point, there should be no errors, but check anyways...
4351 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4352 "check_quotas: group \"%s\" membership check "
4353 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4358 * Stop if we found a match...
4365 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4367 #endif /* HAVE_MBR_UID_TO_UUID */
4369 #ifdef HAVE_MBR_UID_TO_UUID
4372 if (p
->users
[i
][0] == '#')
4374 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4375 uuid_clear(usr2_uuid
);
4377 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4381 * Invalid ACL entries are ignored for matching; just record a
4382 * warning in the log...
4385 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4386 "check_quotas: UUID lookup failed for ACL entry "
4387 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4388 cupsdLogMessage(CUPSD_LOG_WARN
,
4389 "Access control entry \"%s\" not a valid user name; "
4390 "entry ignored", p
->users
[i
]);
4393 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4397 else if (!strcasecmp(username
, p
->users
[i
]))
4399 #endif /* HAVE_MBR_UID_TO_UUID */
4401 if ((i
< p
->num_users
) == p
->deny_users
)
4403 cupsdLogMessage(CUPSD_LOG_INFO
,
4404 "Denying user \"%s\" access to printer \"%s\"...",
4415 if (AppleQuotas
&& (q
= cupsdFindQuota(p
, username
)) != NULL
)
4418 * TODO: Define these special page count values as constants!
4421 if (q
->page_count
== -4) /* special case: unlimited user */
4423 cupsdLogMessage(CUPSD_LOG_INFO
,
4424 "User \"%s\" request approved for printer %s (%s): "
4426 username
, p
->name
, p
->info
);
4427 q
->page_count
= 0; /* allow user to print */
4430 else if (q
->page_count
== -3) /* quota exceeded */
4432 cupsdLogMessage(CUPSD_LOG_INFO
,
4433 "User \"%s\" request denied for printer %s (%s): "
4434 "quota limit exceeded.",
4435 username
, p
->name
, p
->info
);
4436 q
->page_count
= 2; /* force quota exceeded failure */
4439 else if (q
->page_count
== -2) /* quota disabled for user */
4441 cupsdLogMessage(CUPSD_LOG_INFO
,
4442 "User \"%s\" request denied for printer %s (%s): "
4443 "printing disabled for user.",
4444 username
, p
->name
, p
->info
);
4445 q
->page_count
= 2; /* force quota exceeded failure */
4448 else if (q
->page_count
== -1) /* quota access error */
4450 cupsdLogMessage(CUPSD_LOG_INFO
,
4451 "User \"%s\" request denied for printer %s (%s): "
4452 "unable to determine quota limit.",
4453 username
, p
->name
, p
->info
);
4454 q
->page_count
= 2; /* force quota exceeded failure */
4457 else if (q
->page_count
< 0) /* user not found or other error */
4459 cupsdLogMessage(CUPSD_LOG_INFO
,
4460 "User \"%s\" request denied for printer %s (%s): "
4461 "user disabled / missing quota.",
4462 username
, p
->name
, p
->info
);
4463 q
->page_count
= 2; /* force quota exceeded failure */
4466 else /* page within user limits */
4468 q
->page_count
= 0; /* allow user to print */
4473 #endif /* __APPLE__ */
4474 if (p
->k_limit
|| p
->page_limit
)
4476 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4478 cupsdLogMessage(CUPSD_LOG_ERROR
,
4479 "Unable to allocate quota data for user \"%s\"!",
4484 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4485 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4487 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4494 * If we have gotten this far, we're done!
4502 * 'copy_attribute()' - Copy a single attribute.
4505 static ipp_attribute_t
* /* O - New attribute */
4507 ipp_t
*to
, /* O - Destination request/response */
4508 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4509 int quickcopy
) /* I - Do a quick copy? */
4511 int i
; /* Looping var */
4512 ipp_attribute_t
*toattr
; /* Destination attribute */
4515 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4516 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4517 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4520 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4523 toattr
= ippAddSeparator(to
);
4526 case IPP_TAG_INTEGER
:
4528 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4529 attr
->name
, attr
->num_values
, NULL
);
4531 for (i
= 0; i
< attr
->num_values
; i
++)
4532 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4535 case IPP_TAG_BOOLEAN
:
4536 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4537 attr
->num_values
, NULL
);
4539 for (i
= 0; i
< attr
->num_values
; i
++)
4540 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4543 case IPP_TAG_STRING
:
4546 case IPP_TAG_KEYWORD
:
4548 case IPP_TAG_URISCHEME
:
4549 case IPP_TAG_CHARSET
:
4550 case IPP_TAG_LANGUAGE
:
4551 case IPP_TAG_MIMETYPE
:
4552 toattr
= ippAddStrings(to
, attr
->group_tag
,
4553 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4554 attr
->name
, attr
->num_values
, NULL
, NULL
);
4558 for (i
= 0; i
< attr
->num_values
; i
++)
4559 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4561 else if (attr
->value_tag
& IPP_TAG_COPY
)
4563 for (i
= 0; i
< attr
->num_values
; i
++)
4564 toattr
->values
[i
].string
.text
=
4565 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4569 for (i
= 0; i
< attr
->num_values
; i
++)
4570 toattr
->values
[i
].string
.text
=
4571 _cupsStrRetain(attr
->values
[i
].string
.text
);
4576 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4577 attr
->values
[0].date
);
4580 case IPP_TAG_RESOLUTION
:
4581 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4582 attr
->num_values
, IPP_RES_PER_INCH
,
4585 for (i
= 0; i
< attr
->num_values
; i
++)
4587 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4588 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4589 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4593 case IPP_TAG_RANGE
:
4594 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4595 attr
->num_values
, NULL
, NULL
);
4597 for (i
= 0; i
< attr
->num_values
; i
++)
4599 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4600 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4604 case IPP_TAG_TEXTLANG
:
4605 case IPP_TAG_NAMELANG
:
4606 toattr
= ippAddStrings(to
, attr
->group_tag
,
4607 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4608 attr
->name
, attr
->num_values
, NULL
, NULL
);
4612 for (i
= 0; i
< attr
->num_values
; i
++)
4614 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4615 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4618 else if (attr
->value_tag
& IPP_TAG_COPY
)
4620 for (i
= 0; i
< attr
->num_values
; i
++)
4623 toattr
->values
[i
].string
.charset
=
4624 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4626 toattr
->values
[i
].string
.charset
=
4627 toattr
->values
[0].string
.charset
;
4629 toattr
->values
[i
].string
.text
=
4630 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4635 for (i
= 0; i
< attr
->num_values
; i
++)
4638 toattr
->values
[i
].string
.charset
=
4639 _cupsStrRetain(attr
->values
[i
].string
.charset
);
4641 toattr
->values
[i
].string
.charset
=
4642 toattr
->values
[0].string
.charset
;
4644 toattr
->values
[i
].string
.text
=
4645 _cupsStrRetain(attr
->values
[i
].string
.text
);
4650 case IPP_TAG_BEGIN_COLLECTION
:
4651 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4652 attr
->num_values
, NULL
);
4654 for (i
= 0; i
< attr
->num_values
; i
++)
4656 toattr
->values
[i
].collection
= ippNew();
4657 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
4658 NULL
, IPP_TAG_ZERO
, 0);
4663 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4664 attr
->name
, attr
->num_values
, NULL
);
4666 for (i
= 0; i
< attr
->num_values
; i
++)
4668 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4670 if (toattr
->values
[i
].unknown
.length
> 0)
4672 if ((toattr
->values
[i
].unknown
.data
=
4673 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4674 toattr
->values
[i
].unknown
.length
= 0;
4676 memcpy(toattr
->values
[i
].unknown
.data
,
4677 attr
->values
[i
].unknown
.data
,
4678 toattr
->values
[i
].unknown
.length
);
4681 break; /* anti-compiler-warning-code */
4689 * 'copy_attrs()' - Copy attributes from one request to another.
4693 copy_attrs(ipp_t
*to
, /* I - Destination request */
4694 ipp_t
*from
, /* I - Source request */
4695 cups_array_t
*ra
, /* I - Requested attributes */
4696 ipp_tag_t group
, /* I - Group to copy */
4697 int quickcopy
) /* I - Do a quick copy? */
4699 ipp_attribute_t
*fromattr
; /* Source attribute */
4702 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4703 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4704 to
, from
, ra
, group
, quickcopy
);
4709 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4712 * Filter attributes as needed...
4715 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4716 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4719 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4722 * Don't send collection attributes by default to IPP/1.x clients
4723 * since many do not support collections...
4726 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4727 !ra
&& to
->request
.status
.version
[0] == 1)
4730 copy_attribute(to
, fromattr
, quickcopy
);
4737 * 'copy_banner()' - Copy a banner file to the requests directory for the
4741 static int /* O - Size of banner file in kbytes */
4742 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4743 cupsd_job_t
*job
, /* I - Job information */
4744 const char *name
) /* I - Name of banner */
4746 int i
; /* Looping var */
4747 int kbytes
; /* Size of banner file in kbytes */
4748 char filename
[1024]; /* Job filename */
4749 cupsd_banner_t
*banner
; /* Pointer to banner */
4750 cups_file_t
*in
; /* Input file */
4751 cups_file_t
*out
; /* Output file */
4752 int ch
; /* Character from file */
4753 char attrname
[255], /* Name of attribute */
4754 *s
; /* Pointer into name */
4755 ipp_attribute_t
*attr
; /* Attribute */
4758 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4759 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4760 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4761 name
? name
: "(null)");
4764 * Find the banner; return if not found or "none"...
4767 if (!name
|| !strcmp(name
, "none") ||
4768 (banner
= cupsdFindBanner(name
)) == NULL
)
4772 * Open the banner and job files...
4775 if (add_file(con
, job
, banner
->filetype
, 0))
4778 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4780 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4782 cupsdLogMessage(CUPSD_LOG_ERROR
,
4783 "Unable to create banner job file %s - %s",
4784 filename
, strerror(errno
));
4789 fchmod(cupsFileNumber(out
), 0640);
4790 fchown(cupsFileNumber(out
), RunUser
, Group
);
4793 * Try the localized banner file under the subdirectory...
4796 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4798 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4801 * Convert ll-cc to ll_CC...
4805 attrname
[3] = toupper(attrname
[3] & 255);
4806 attrname
[4] = toupper(attrname
[4] & 255);
4809 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4812 if (access(filename
, 0) && strlen(attrname
) > 2)
4815 * Wasn't able to find "ll_CC" locale file; try the non-national
4816 * localization banner directory.
4821 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4825 if (access(filename
, 0))
4828 * Use the non-localized banner file.
4831 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4834 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4838 cupsdLogMessage(CUPSD_LOG_ERROR
,
4839 "Unable to open banner template file %s - %s",
4840 filename
, strerror(errno
));
4846 * Parse the file to the end...
4849 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4853 * Get an attribute name...
4856 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4857 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4859 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4869 * Ignore { followed by stuff that is not an attribute name...
4872 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4877 * See if it is defined...
4880 if (attrname
[0] == '?')
4885 if (!strcmp(s
, "printer-name"))
4887 cupsFilePuts(out
, job
->dest
);
4890 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4893 * See if we have a leading question mark...
4896 if (attrname
[0] != '?')
4899 * Nope, write to file as-is; probably a PostScript procedure...
4902 cupsFilePrintf(out
, "{%s}", attrname
);
4909 * Output value(s)...
4912 for (i
= 0; i
< attr
->num_values
; i
++)
4915 cupsFilePutChar(out
, ',');
4917 switch (attr
->value_tag
)
4919 case IPP_TAG_INTEGER
:
4921 if (!strncmp(s
, "time-at-", 8))
4923 struct timeval tv
= { attr
->values
[i
].integer
, 0 };
4924 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4927 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4930 case IPP_TAG_BOOLEAN
:
4931 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4934 case IPP_TAG_NOVALUE
:
4935 cupsFilePuts(out
, "novalue");
4938 case IPP_TAG_RANGE
:
4939 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4940 attr
->values
[i
].range
.upper
);
4943 case IPP_TAG_RESOLUTION
:
4944 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4945 attr
->values
[i
].resolution
.yres
,
4946 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4951 case IPP_TAG_STRING
:
4954 case IPP_TAG_KEYWORD
:
4955 case IPP_TAG_CHARSET
:
4956 case IPP_TAG_LANGUAGE
:
4957 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
4960 * Need to quote strings for PS banners...
4965 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4967 if (*p
== '(' || *p
== ')' || *p
== '\\')
4969 cupsFilePutChar(out
, '\\');
4970 cupsFilePutChar(out
, *p
);
4972 else if (*p
< 32 || *p
> 126)
4973 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4975 cupsFilePutChar(out
, *p
);
4979 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4983 break; /* anti-compiler-warning-code */
4987 else if (ch
== '\\') /* Quoted char */
4989 ch
= cupsFileGetChar(in
);
4991 if (ch
!= '{') /* Only do special handling for \{ */
4992 cupsFilePutChar(out
, '\\');
4994 cupsFilePutChar(out
, ch
);
4997 cupsFilePutChar(out
, ch
);
5001 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5003 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5004 IPP_TAG_INTEGER
)) != NULL
)
5005 attr
->values
[0].integer
+= kbytes
;
5014 * 'copy_file()' - Copy a PPD file or interface script...
5017 static int /* O - 0 = success, -1 = error */
5018 copy_file(const char *from
, /* I - Source file */
5019 const char *to
) /* I - Destination file */
5021 cups_file_t
*src
, /* Source file */
5022 *dst
; /* Destination file */
5023 int bytes
; /* Bytes to read/write */
5024 char buffer
[2048]; /* Copy buffer */
5027 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5030 * Open the source and destination file for a copy...
5033 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5036 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5043 * Copy the source file to the destination...
5046 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5047 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5055 * Close both files and return...
5060 return (cupsFileClose(dst
));
5065 * 'copy_model()' - Copy a PPD model file, substituting default values
5069 static int /* O - 0 = success, -1 = error */
5070 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5071 const char *from
, /* I - Source file */
5072 const char *to
) /* I - Destination file */
5074 fd_set input
; /* select() input set */
5075 struct timeval timeout
; /* select() timeout */
5076 int maxfd
; /* Max file descriptor for select() */
5077 char tempfile
[1024]; /* Temporary PPD file */
5078 int tempfd
; /* Temporary PPD file descriptor */
5079 int temppid
; /* Process ID of cups-driverd */
5080 int temppipe
[2]; /* Temporary pipes */
5081 char *argv
[4], /* Command-line arguments */
5082 *envp
[MAX_ENV
]; /* Environment */
5083 cups_file_t
*src
, /* Source file */
5084 *dst
; /* Destination file */
5085 ppd_file_t
*ppd
; /* PPD file */
5086 int bytes
, /* Bytes from pipe */
5087 total
; /* Total bytes from pipe */
5088 char buffer
[2048]; /* Copy buffer */
5089 int i
; /* Looping var */
5090 char option
[PPD_MAX_NAME
], /* Option name */
5091 choice
[PPD_MAX_NAME
]; /* Choice name */
5092 int num_defaults
; /* Number of default options */
5093 cups_option_t
*defaults
; /* Default options */
5094 char cups_protocol
[PPD_MAX_LINE
];
5095 /* cupsProtocol attribute */
5098 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5099 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5103 * Run cups-driverd to get the PPD file...
5106 argv
[0] = "cups-driverd";
5108 argv
[2] = (char *)from
;
5111 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5113 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5114 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5115 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5119 cupsdOpenPipe(temppipe
);
5121 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5122 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5124 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5125 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5136 * Wait up to 30 seconds for the PPD file to be copied...
5141 if (temppipe
[0] > CGIPipes
[0])
5142 maxfd
= temppipe
[0] + 1;
5144 maxfd
= CGIPipes
[0] + 1;
5149 * See if we have data ready...
5153 FD_SET(temppipe
[0], &input
);
5154 FD_SET(CGIPipes
[0], &input
);
5156 timeout
.tv_sec
= 30;
5157 timeout
.tv_usec
= 0;
5159 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5169 * We have timed out...
5175 if (FD_ISSET(temppipe
[0], &input
))
5178 * Read the PPD file from the pipe, and write it to the PPD file.
5181 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5183 if (write(tempfd
, buffer
, bytes
) < bytes
)
5192 if (FD_ISSET(CGIPipes
[0], &input
))
5202 * No data from cups-deviced...
5205 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
5211 * Read the source file and see what page sizes are supported...
5214 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5221 * Open the destination (if possible) and set the default options...
5226 cups_protocol
[0] = '\0';
5228 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5231 * Read all of the default lines from the old PPD...
5234 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5235 if (!strncmp(buffer
, "*Default", 8))
5238 * Add the default option...
5241 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5242 choice
, sizeof(choice
)))
5244 ppd_option_t
*ppdo
; /* PPD option */
5248 * Only add the default if the default hasn't already been
5249 * set and the choice exists in the new PPD...
5252 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5253 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5254 ppdFindChoice(ppdo
, choice
))
5255 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5259 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5260 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5264 else if (ppdPageSize(ppd
, DefaultPaperSize
))
5267 * Add the default media sizes...
5270 num_defaults
= cupsAddOption("PageSize", DefaultPaperSize
,
5271 num_defaults
, &defaults
);
5272 num_defaults
= cupsAddOption("PageRegion", DefaultPaperSize
,
5273 num_defaults
, &defaults
);
5274 num_defaults
= cupsAddOption("PaperDimension", DefaultPaperSize
,
5275 num_defaults
, &defaults
);
5276 num_defaults
= cupsAddOption("ImageableArea", DefaultPaperSize
,
5277 num_defaults
, &defaults
);
5283 * Open the source file for a copy...
5286 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5288 cupsFreeOptions(num_defaults
, defaults
);
5294 * Open the destination file for a copy...
5297 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5299 cupsFreeOptions(num_defaults
, defaults
);
5306 * Copy the source file to the destination...
5309 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5311 if (!strncmp(buffer
, "*Default", 8))
5314 * Check for an previous default option choice...
5317 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5318 choice
, sizeof(choice
)))
5320 const char *val
; /* Default option value */
5323 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5326 * Substitute the previous choice...
5329 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5334 cupsFilePrintf(dst
, "%s\n", buffer
);
5337 if (cups_protocol
[0])
5338 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5340 cupsFreeOptions(num_defaults
, defaults
);
5343 * Close both files and return...
5350 return (cupsFileClose(dst
));
5355 * 'copy_job_attrs()' - Copy job attributes.
5359 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5360 cupsd_job_t
*job
, /* I - Job */
5361 cups_array_t
*ra
) /* I - Requested attributes array */
5363 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5367 * Send the requested attributes for each job...
5370 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5371 con
->servername
, con
->serverport
, "/jobs/%d",
5374 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5375 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5376 "document-count", job
->num_files
);
5378 if (!ra
|| cupsArrayFind(ra
, "job-media-progress"))
5379 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5380 "job-media-progress", job
->progress
);
5382 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5383 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5384 "job-more-info", NULL
, job_uri
);
5386 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5387 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5388 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5389 job
->num_files
> 0);
5391 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5392 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5393 "job-printer-up-time", time(NULL
));
5395 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5396 add_job_state_reasons(con
, job
);
5398 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5399 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5400 "job-uri", NULL
, job_uri
);
5402 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5407 * 'copy_printer_attrs()' - Copy printer attributes.
5412 cupsd_client_t
*con
, /* I - Client connection */
5413 cupsd_printer_t
*printer
, /* I - Printer */
5414 cups_array_t
*ra
) /* I - Requested attributes array */
5416 char printer_uri
[HTTP_MAX_URI
];
5418 time_t curtime
; /* Current time */
5419 int i
; /* Looping var */
5420 ipp_attribute_t
*history
; /* History collection */
5424 * Copy the printer attributes to the response using requested-attributes
5425 * and document-format attributes that may be provided by the client.
5428 curtime
= time(NULL
);
5431 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
5432 printer
->recoverable
)
5433 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5434 "com.apple.print.recoverable-message", NULL
,
5435 printer
->recoverable
);
5436 #endif /* __APPLE__ */
5438 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5439 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5440 "marker-change-time", printer
->marker_time
);
5442 if (printer
->num_printers
> 0 &&
5443 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5445 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5446 cupsd_printer_t
*p2
; /* Printer in class */
5447 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5450 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5451 IPP_TAG_URI
, "member-uris",
5452 printer
->num_printers
, NULL
,
5455 for (i
= 0; i
< printer
->num_printers
; i
++)
5457 p2
= printer
->printers
[i
];
5459 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5460 IPP_TAG_URI
)) != NULL
)
5461 member_uris
->values
[i
].string
.text
=
5462 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5465 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5466 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5468 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5469 "/classes/%s" : "/printers/%s", p2
->name
);
5470 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5476 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5477 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5478 "printer-alert", NULL
, printer
->alert
);
5480 if (printer
->alert_description
&&
5481 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5482 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5483 "printer-alert-description", NULL
,
5484 printer
->alert_description
);
5486 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5487 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5488 ippTimeToDate(curtime
));
5491 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5493 if (printer
->reg_name
)
5494 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5495 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5497 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5498 "printer-dns-sd-name", 0);
5500 #endif /* HAVE_DNSSD */
5502 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5503 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5504 "printer-error-policy", NULL
, printer
->error_policy
);
5506 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
5508 static const char * const errors
[] =/* printer-error-policy-supported values */
5511 "retry-current-job",
5516 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
5517 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5518 "printer-error-policy-supported", NULL
, "retry-current-job");
5520 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5521 "printer-error-policy-supported",
5522 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
5525 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5526 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5527 printer
->accepting
);
5529 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5530 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5533 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5534 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5536 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5537 "http", NULL
, con
->servername
, con
->serverport
,
5538 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5539 "/classes/%s" : "/printers/%s", printer
->name
);
5540 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5541 "printer-more-info", NULL
, printer_uri
);
5544 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5545 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5546 "printer-op-policy", NULL
, printer
->op_policy
);
5548 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5549 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5552 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5553 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5554 "printer-state-change-time", printer
->state_time
);
5556 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5557 cupsArrayFind(ra
, "printer-state-history"))
5560 * Printer history is only sent if specifically requested, so that
5561 * older CUPS/IPP clients won't barf on the collection attributes.
5564 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5565 "printer-state-history",
5566 printer
->num_history
, NULL
);
5568 for (i
= 0; i
< printer
->num_history
; i
++)
5569 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5570 NULL
, IPP_TAG_ZERO
, 0);
5573 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5574 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5575 "printer-state-message", NULL
, printer
->state_message
);
5577 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5578 add_printer_state_reasons(con
, printer
);
5580 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5582 int type
; /* printer-type value */
5586 * Add the CUPS-specific printer-type attribute...
5589 type
= printer
->type
;
5591 if (printer
== DefaultPrinter
)
5592 type
|= CUPS_PRINTER_DEFAULT
;
5594 if (!printer
->accepting
)
5595 type
|= CUPS_PRINTER_REJECTING
;
5597 if (!printer
->shared
)
5598 type
|= CUPS_PRINTER_NOT_SHARED
;
5600 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5604 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5605 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5606 "printer-up-time", curtime
);
5608 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5609 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5611 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5612 "ipp", NULL
, con
->servername
, con
->serverport
,
5613 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5614 "/classes/%s" : "/printers/%s", printer
->name
);
5615 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5616 "printer-uri-supported", NULL
, printer_uri
);
5617 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5621 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5622 add_queued_job_count(con
, printer
);
5624 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5625 if (printer
->ppd_attrs
)
5626 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0);
5627 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5632 * 'copy_subscription_attrs()' - Copy subscription attributes.
5636 copy_subscription_attrs(
5637 cupsd_client_t
*con
, /* I - Client connection */
5638 cupsd_subscription_t
*sub
, /* I - Subscription */
5639 cups_array_t
*ra
) /* I - Requested attributes array */
5641 ipp_attribute_t
*attr
; /* Current attribute */
5642 char printer_uri
[HTTP_MAX_URI
];
5644 int count
; /* Number of events */
5645 unsigned mask
; /* Current event mask */
5646 const char *name
; /* Current event name */
5650 * Copy the subscription attributes to the response using the
5651 * requested-attributes attribute that may be provided by the client.
5654 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5656 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5659 * Simple event list...
5662 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5663 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5664 "notify-events", NULL
, name
);
5669 * Complex event list...
5672 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5673 if (sub
->mask
& mask
)
5676 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5677 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5678 "notify-events", count
, NULL
, NULL
);
5680 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5681 if (sub
->mask
& mask
)
5683 attr
->values
[count
].string
.text
=
5684 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5691 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5692 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5693 "notify-job-id", sub
->job
->id
);
5695 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5696 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5697 "notify-lease-duration", sub
->lease
);
5699 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5701 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5702 "ipp", NULL
, con
->servername
, con
->serverport
,
5703 "/printers/%s", sub
->dest
->name
);
5704 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5705 "notify-printer-uri", NULL
, printer_uri
);
5708 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5709 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5710 "notify-recipient-uri", NULL
, sub
->recipient
);
5711 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5712 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5713 "notify-pull-method", NULL
, "ippget");
5715 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5716 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5717 "notify-subscriber-user-name", NULL
, sub
->owner
);
5719 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5720 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5721 "notify-subscription-id", sub
->id
);
5723 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5724 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5725 "notify-time-interval", sub
->interval
);
5727 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5728 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5729 sub
->user_data
, sub
->user_data_len
);
5734 * 'create_job()' - Print a file to a printer or class.
5738 create_job(cupsd_client_t
*con
, /* I - Client connection */
5739 ipp_attribute_t
*uri
) /* I - Printer URI */
5741 cupsd_printer_t
*printer
; /* Printer */
5742 cupsd_job_t
*job
; /* New job */
5745 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5746 con
->http
.fd
, uri
->values
[0].string
.text
);
5749 * Is the destination valid?
5752 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5758 send_ipp_status(con
, IPP_NOT_FOUND
,
5759 _("The printer or class was not found."));
5764 * Create the job object...
5767 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5770 job
->pending_timeout
= 1;
5773 * Save and log the job...
5776 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5777 job
->dest
, job
->username
);
5782 * 'create_requested_array()' - Create an array for the requested-attributes.
5785 static cups_array_t
* /* O - Array of attributes or NULL */
5786 create_requested_array(ipp_t
*request
) /* I - IPP request */
5788 int i
; /* Looping var */
5789 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5790 cups_array_t
*ra
; /* Requested attributes array */
5791 char *value
; /* Current value */
5795 * Get the requested-attributes attribute, and return NULL if we don't
5799 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5800 IPP_TAG_KEYWORD
)) == NULL
)
5804 * If the attribute contains a single "all" keyword, return NULL...
5807 if (requested
->num_values
== 1 &&
5808 !strcmp(requested
->values
[0].string
.text
, "all"))
5812 * Create an array using "strcmp" as the comparison function...
5815 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5817 for (i
= 0; i
< requested
->num_values
; i
++)
5819 value
= requested
->values
[i
].string
.text
;
5821 if (!strcmp(value
, "job-template"))
5823 cupsArrayAdd(ra
, "copies");
5824 cupsArrayAdd(ra
, "copies-default");
5825 cupsArrayAdd(ra
, "copies-supported");
5826 cupsArrayAdd(ra
, "finishings");
5827 cupsArrayAdd(ra
, "finishings-default");
5828 cupsArrayAdd(ra
, "finishings-supported");
5829 cupsArrayAdd(ra
, "job-hold-until");
5830 cupsArrayAdd(ra
, "job-hold-until-default");
5831 cupsArrayAdd(ra
, "job-hold-until-supported");
5832 cupsArrayAdd(ra
, "job-priority");
5833 cupsArrayAdd(ra
, "job-priority-default");
5834 cupsArrayAdd(ra
, "job-priority-supported");
5835 cupsArrayAdd(ra
, "job-sheets");
5836 cupsArrayAdd(ra
, "job-sheets-default");
5837 cupsArrayAdd(ra
, "job-sheets-supported");
5838 cupsArrayAdd(ra
, "media");
5839 cupsArrayAdd(ra
, "media-default");
5840 cupsArrayAdd(ra
, "media-supported");
5841 cupsArrayAdd(ra
, "multiple-document-handling");
5842 cupsArrayAdd(ra
, "multiple-document-handling-default");
5843 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5844 cupsArrayAdd(ra
, "number-up");
5845 cupsArrayAdd(ra
, "number-up-default");
5846 cupsArrayAdd(ra
, "number-up-supported");
5847 cupsArrayAdd(ra
, "orientation-requested");
5848 cupsArrayAdd(ra
, "orientation-requested-default");
5849 cupsArrayAdd(ra
, "orientation-requested-supported");
5850 cupsArrayAdd(ra
, "page-ranges");
5851 cupsArrayAdd(ra
, "page-ranges-supported");
5852 cupsArrayAdd(ra
, "printer-resolution");
5853 cupsArrayAdd(ra
, "printer-resolution-default");
5854 cupsArrayAdd(ra
, "printer-resolution-supported");
5855 cupsArrayAdd(ra
, "print-quality");
5856 cupsArrayAdd(ra
, "print-quality-default");
5857 cupsArrayAdd(ra
, "print-quality-supported");
5858 cupsArrayAdd(ra
, "sides");
5859 cupsArrayAdd(ra
, "sides-default");
5860 cupsArrayAdd(ra
, "sides-supported");
5862 else if (!strcmp(value
, "job-description"))
5864 cupsArrayAdd(ra
, "date-time-at-completed");
5865 cupsArrayAdd(ra
, "date-time-at-creation");
5866 cupsArrayAdd(ra
, "date-time-at-processing");
5867 cupsArrayAdd(ra
, "job-detailed-status-message");
5868 cupsArrayAdd(ra
, "job-document-access-errors");
5869 cupsArrayAdd(ra
, "job-id");
5870 cupsArrayAdd(ra
, "job-impressions");
5871 cupsArrayAdd(ra
, "job-impressions-completed");
5872 cupsArrayAdd(ra
, "job-k-octets");
5873 cupsArrayAdd(ra
, "job-k-octets-processed");
5874 cupsArrayAdd(ra
, "job-media-progress");
5875 cupsArrayAdd(ra
, "job-media-sheets");
5876 cupsArrayAdd(ra
, "job-media-sheets-completed");
5877 cupsArrayAdd(ra
, "job-message-from-operator");
5878 cupsArrayAdd(ra
, "job-more-info");
5879 cupsArrayAdd(ra
, "job-name");
5880 cupsArrayAdd(ra
, "job-originating-user-name");
5881 cupsArrayAdd(ra
, "job-printer-up-time");
5882 cupsArrayAdd(ra
, "job-printer-uri");
5883 cupsArrayAdd(ra
, "job-state");
5884 cupsArrayAdd(ra
, "job-state-message");
5885 cupsArrayAdd(ra
, "job-state-reasons");
5886 cupsArrayAdd(ra
, "job-uri");
5887 cupsArrayAdd(ra
, "number-of-documents");
5888 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5889 cupsArrayAdd(ra
, "output-device-assigned");
5890 cupsArrayAdd(ra
, "time-at-completed");
5891 cupsArrayAdd(ra
, "time-at-creation");
5892 cupsArrayAdd(ra
, "time-at-processing");
5894 else if (!strcmp(value
, "printer-description"))
5896 cupsArrayAdd(ra
, "charset-configured");
5897 cupsArrayAdd(ra
, "charset-supported");
5898 cupsArrayAdd(ra
, "color-supported");
5899 cupsArrayAdd(ra
, "compression-supported");
5900 cupsArrayAdd(ra
, "document-format-default");
5901 cupsArrayAdd(ra
, "document-format-supported");
5902 cupsArrayAdd(ra
, "generated-natural-language-supported");
5903 cupsArrayAdd(ra
, "ipp-versions-supported");
5904 cupsArrayAdd(ra
, "job-impressions-supported");
5905 cupsArrayAdd(ra
, "job-k-octets-supported");
5906 cupsArrayAdd(ra
, "job-media-sheets-supported");
5907 cupsArrayAdd(ra
, "job-settable-attributes-supported");
5908 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5909 cupsArrayAdd(ra
, "multiple-operation-time-out");
5910 cupsArrayAdd(ra
, "natural-language-configured");
5911 cupsArrayAdd(ra
, "notify-attributes-supported");
5912 cupsArrayAdd(ra
, "notify-lease-duration-default");
5913 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5914 cupsArrayAdd(ra
, "notify-max-events-supported");
5915 cupsArrayAdd(ra
, "notify-events-default");
5916 cupsArrayAdd(ra
, "notify-events-supported");
5917 cupsArrayAdd(ra
, "notify-pull-method-supported");
5918 cupsArrayAdd(ra
, "notify-schemes-supported");
5919 cupsArrayAdd(ra
, "operations-supported");
5920 cupsArrayAdd(ra
, "pages-per-minute");
5921 cupsArrayAdd(ra
, "pages-per-minute-color");
5922 cupsArrayAdd(ra
, "pdl-override-supported");
5923 cupsArrayAdd(ra
, "printer-alert");
5924 cupsArrayAdd(ra
, "printer-alert-description");
5925 cupsArrayAdd(ra
, "printer-commands");
5926 cupsArrayAdd(ra
, "printer-current-time");
5927 cupsArrayAdd(ra
, "printer-driver-installer");
5928 cupsArrayAdd(ra
, "printer-dns-sd-name");
5929 cupsArrayAdd(ra
, "printer-info");
5930 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5931 cupsArrayAdd(ra
, "printer-location");
5932 cupsArrayAdd(ra
, "printer-make-and-model");
5933 cupsArrayAdd(ra
, "printer-message-from-operator");
5934 cupsArrayAdd(ra
, "printer-more-info");
5935 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5936 cupsArrayAdd(ra
, "printer-name");
5937 cupsArrayAdd(ra
, "printer-state");
5938 cupsArrayAdd(ra
, "printer-state-message");
5939 cupsArrayAdd(ra
, "printer-state-reasons");
5940 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
5941 cupsArrayAdd(ra
, "printer-type");
5942 cupsArrayAdd(ra
, "printer-up-time");
5943 cupsArrayAdd(ra
, "printer-uri-supported");
5944 cupsArrayAdd(ra
, "queued-job-count");
5945 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5946 cupsArrayAdd(ra
, "uri-authentication-supported");
5947 cupsArrayAdd(ra
, "uri-security-supported");
5949 else if (!strcmp(value
, "printer-defaults"))
5951 char *name
; /* Option name */
5954 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5956 name
= (char *)cupsArrayNext(CommonDefaults
))
5957 cupsArrayAdd(ra
, name
);
5959 else if (!strcmp(value
, "subscription-template"))
5961 cupsArrayAdd(ra
, "notify-attributes");
5962 cupsArrayAdd(ra
, "notify-charset");
5963 cupsArrayAdd(ra
, "notify-events");
5964 cupsArrayAdd(ra
, "notify-lease-duration");
5965 cupsArrayAdd(ra
, "notify-natural-language");
5966 cupsArrayAdd(ra
, "notify-pull-method");
5967 cupsArrayAdd(ra
, "notify-recipient-uri");
5968 cupsArrayAdd(ra
, "notify-time-interval");
5969 cupsArrayAdd(ra
, "notify-user-data");
5972 cupsArrayAdd(ra
, value
);
5980 * 'create_subscription()' - Create a notification subscription.
5984 create_subscription(
5985 cupsd_client_t
*con
, /* I - Client connection */
5986 ipp_attribute_t
*uri
) /* I - Printer URI */
5988 http_status_t status
; /* Policy status */
5989 int i
; /* Looping var */
5990 ipp_attribute_t
*attr
; /* Current attribute */
5991 cups_ptype_t dtype
; /* Destination type (printer/class) */
5992 char scheme
[HTTP_MAX_URI
],
5993 /* Scheme portion of URI */
5994 userpass
[HTTP_MAX_URI
],
5995 /* Username portion of URI */
5997 /* Host portion of URI */
5998 resource
[HTTP_MAX_URI
];
5999 /* Resource portion of URI */
6000 int port
; /* Port portion of URI */
6001 cupsd_printer_t
*printer
; /* Printer/class */
6002 cupsd_job_t
*job
; /* Job */
6003 int jobid
; /* Job ID */
6004 cupsd_subscription_t
*sub
; /* Subscription object */
6005 const char *username
, /* requesting-user-name or
6006 authenticated username */
6007 *recipient
, /* notify-recipient-uri */
6008 *pullmethod
; /* notify-pull-method */
6009 ipp_attribute_t
*user_data
; /* notify-user-data */
6010 int interval
, /* notify-time-interval */
6011 lease
; /* notify-lease-duration */
6012 unsigned mask
; /* notify-events */
6013 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6014 *notify_lease
; /* notify-lease-duration(-default) */
6018 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6020 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6021 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6022 attr
->value_tag
, attr
->name
);
6024 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6029 * Is the destination valid?
6032 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6033 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6034 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6036 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6037 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6038 sizeof(host
), &port
, resource
, sizeof(resource
));
6040 if (!strcmp(resource
, "/"))
6042 dtype
= (cups_ptype_t
)0;
6045 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6047 dtype
= (cups_ptype_t
)0;
6050 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6052 dtype
= CUPS_PRINTER_CLASS
;
6055 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6061 send_ipp_status(con
, IPP_NOT_FOUND
,
6062 _("The printer or class was not found."));
6072 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6075 send_http_error(con
, status
, printer
);
6079 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6081 send_http_error(con
, status
, NULL
);
6086 * Get the user that is requesting the subscription...
6089 username
= get_username(con
);
6092 * Find the first subscription group attribute; return if we have
6096 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6097 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6102 send_ipp_status(con
, IPP_BAD_REQUEST
,
6103 _("No subscription attributes in request!"));
6108 * Process the subscription attributes in the request...
6111 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6119 lease
= DefaultLeaseDuration
;
6121 mask
= CUPSD_EVENT_NONE
;
6125 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6127 notify_lease
= ippFindAttribute(printer
->attrs
,
6128 "notify-lease-duration-default",
6132 lease
= notify_lease
->values
[0].integer
;
6136 notify_events
= NULL
;
6137 notify_lease
= NULL
;
6140 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6142 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6143 attr
->value_tag
== IPP_TAG_URI
)
6146 * Validate the recipient scheme against the ServerBin/notifier
6150 char notifier
[1024]; /* Notifier filename */
6153 recipient
= attr
->values
[0].string
.text
;
6155 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6156 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6157 host
, sizeof(host
), &port
,
6158 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6160 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6161 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
6162 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6163 "notify-status-code", IPP_URI_SCHEME
);
6167 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6169 if (access(notifier
, X_OK
))
6171 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6172 _("notify-recipient-uri URI \"%s\" uses unknown "
6173 "scheme!"), recipient
);
6174 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6175 "notify-status-code", IPP_URI_SCHEME
);
6179 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6181 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6182 _("notify-recipient-uri URI \"%s\" is already used!"),
6184 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6185 "notify-status-code", IPP_ATTRIBUTES
);
6189 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6190 attr
->value_tag
== IPP_TAG_KEYWORD
)
6192 pullmethod
= attr
->values
[0].string
.text
;
6194 if (strcmp(pullmethod
, "ippget"))
6196 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6197 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
6198 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6199 "notify-status-code", IPP_ATTRIBUTES
);
6203 else if (!strcmp(attr
->name
, "notify-charset") &&
6204 attr
->value_tag
== IPP_TAG_CHARSET
&&
6205 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6206 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6208 send_ipp_status(con
, IPP_CHARSET
,
6209 _("Character set \"%s\" not supported!"),
6210 attr
->values
[0].string
.text
);
6213 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6214 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6215 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6217 send_ipp_status(con
, IPP_CHARSET
,
6218 _("Language \"%s\" not supported!"),
6219 attr
->values
[0].string
.text
);
6222 else if (!strcmp(attr
->name
, "notify-user-data") &&
6223 attr
->value_tag
== IPP_TAG_STRING
)
6225 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6227 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6228 _("The notify-user-data value is too large "
6229 "(%d > 63 octets)!"),
6230 attr
->values
[0].unknown
.length
);
6236 else if (!strcmp(attr
->name
, "notify-events") &&
6237 attr
->value_tag
== IPP_TAG_KEYWORD
)
6238 notify_events
= attr
;
6239 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6240 attr
->value_tag
== IPP_TAG_INTEGER
)
6241 lease
= attr
->values
[0].integer
;
6242 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6243 attr
->value_tag
== IPP_TAG_INTEGER
)
6244 interval
= attr
->values
[0].integer
;
6245 else if (!strcmp(attr
->name
, "notify-job-id") &&
6246 attr
->value_tag
== IPP_TAG_INTEGER
)
6247 jobid
= attr
->values
[0].integer
;
6254 for (i
= 0; i
< notify_events
->num_values
; i
++)
6255 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6259 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6261 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6262 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6263 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6265 if (!recipient
&& !pullmethod
)
6268 if (mask
== CUPSD_EVENT_NONE
)
6271 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6273 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6276 send_ipp_status(con
, IPP_BAD_REQUEST
,
6277 _("notify-events not specified!"));
6282 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6284 cupsdLogMessage(CUPSD_LOG_INFO
,
6285 "create_subscription: Limiting notify-lease-duration to "
6288 lease
= MaxLeaseDuration
;
6293 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6295 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
6302 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6304 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6305 _("There are too many subscriptions."));
6310 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6313 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6314 "Added subscription %d for printer \"%s\"",
6315 sub
->id
, printer
->name
);
6317 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6320 sub
->interval
= interval
;
6322 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6324 cupsdSetString(&sub
->owner
, username
);
6328 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6329 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6330 sub
->user_data_len
);
6333 ippAddSeparator(con
->response
);
6334 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6335 "notify-subscription-id", sub
->id
);
6337 con
->response
->request
.status
.status_code
= IPP_OK
;
6343 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6348 * 'delete_printer()' - Remove a printer or class from the system.
6352 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6353 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6355 http_status_t status
; /* Policy status */
6356 cups_ptype_t dtype
; /* Destination type (printer/class) */
6357 cupsd_printer_t
*printer
; /* Printer/class */
6358 char filename
[1024]; /* Script/PPD filename */
6361 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6362 con
->http
.fd
, uri
->values
[0].string
.text
);
6365 * Do we have a valid URI?
6368 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6374 send_ipp_status(con
, IPP_NOT_FOUND
,
6375 _("The printer or class was not found."));
6383 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6385 send_http_error(con
, status
, NULL
);
6390 * Remove old jobs...
6393 cupsdCancelJobs(printer
->name
, NULL
, 1);
6396 * Remove old subscriptions and send a "deleted printer" event...
6399 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6400 "%s \"%s\" deleted by \"%s\".",
6401 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6402 printer
->name
, get_username(con
));
6404 cupsdExpireSubscriptions(printer
, NULL
);
6407 * Remove any old PPD or script files...
6410 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6414 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6418 snprintf(filename
, sizeof(filename
), "%s/%s.ipp", CacheDir
, printer
->name
);
6423 * Unregister color profiles...
6426 apple_unregister_profiles(printer
);
6427 #endif /* __APPLE__ */
6429 if (dtype
& CUPS_PRINTER_CLASS
)
6431 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6432 printer
->name
, get_username(con
));
6434 cupsdDeletePrinter(printer
, 0);
6435 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6439 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6440 printer
->name
, get_username(con
));
6442 cupsdDeletePrinter(printer
, 0);
6443 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6446 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6449 * Return with no errors...
6452 con
->response
->request
.status
.status_code
= IPP_OK
;
6457 * 'get_default()' - Get the default destination.
6461 get_default(cupsd_client_t
*con
) /* I - Client connection */
6463 http_status_t status
; /* Policy status */
6464 cups_array_t
*ra
; /* Requested attributes array */
6467 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6473 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6475 send_http_error(con
, status
, NULL
);
6481 ra
= create_requested_array(con
->request
);
6483 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6485 cupsArrayDelete(ra
);
6487 con
->response
->request
.status
.status_code
= IPP_OK
;
6490 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6495 * 'get_devices()' - Get the list of available devices on the local system.
6499 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6501 http_status_t status
; /* Policy status */
6502 ipp_attribute_t
*limit
, /* limit attribute */
6503 *timeout
, /* timeout attribute */
6504 *requested
, /* requested-attributes attribute */
6505 *exclude
, /* exclude-schemes attribute */
6506 *include
; /* include-schemes attribute */
6507 char command
[1024], /* cups-deviced command */
6508 options
[2048], /* Options to pass to command */
6510 /* String for requested attributes */
6512 /* String for excluded schemes */
6514 /* String for included schemes */
6517 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6523 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6525 send_http_error(con
, status
, NULL
);
6530 * Run cups-deviced command with the given options...
6533 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6534 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6535 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6537 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6538 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6541 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6543 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6546 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6548 exclude_str
[0] = '\0';
6551 url_encode_attr(include
, include_str
, sizeof(include_str
));
6553 include_str
[0] = '\0';
6555 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6556 snprintf(options
, sizeof(options
),
6557 "%d+%d+%d+%d+%s%s%s%s%s",
6558 con
->request
->request
.op
.request_id
,
6559 limit
? limit
->values
[0].integer
: 0,
6560 timeout
? timeout
->values
[0].integer
: 10,
6563 exclude_str
[0] ? "%20" : "", exclude_str
,
6564 include_str
[0] ? "%20" : "", include_str
);
6566 if (cupsdSendCommand(con
, command
, options
, 1))
6569 * Command started successfully, don't send an IPP response here...
6572 ippDelete(con
->response
);
6573 con
->response
= NULL
;
6578 * Command failed, return "internal error" so the user knows something
6582 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6583 _("cups-deviced failed to execute."));
6589 * 'get_document()' - Get a copy of a job file.
6593 get_document(cupsd_client_t
*con
, /* I - Client connection */
6594 ipp_attribute_t
*uri
) /* I - Job URI */
6596 http_status_t status
; /* Policy status */
6597 ipp_attribute_t
*attr
; /* Current attribute */
6598 int jobid
; /* Job ID */
6599 int docnum
; /* Document number */
6600 cupsd_job_t
*job
; /* Current job */
6601 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6602 username
[HTTP_MAX_URI
], /* Username portion of URI */
6603 host
[HTTP_MAX_URI
], /* Host portion of URI */
6604 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6605 int port
; /* Port portion of URI */
6606 char filename
[1024], /* Filename for document */
6607 format
[1024]; /* Format for document */
6610 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6611 con
->http
.fd
, uri
->values
[0].string
.text
);
6614 * See if we have a job URI or a printer URI...
6617 if (!strcmp(uri
->name
, "printer-uri"))
6620 * Got a printer URI; see if we also have a job-id attribute...
6623 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6624 IPP_TAG_INTEGER
)) == NULL
)
6626 send_ipp_status(con
, IPP_BAD_REQUEST
,
6627 _("Got a printer-uri attribute but no job-id!"));
6631 jobid
= attr
->values
[0].integer
;
6636 * Got a job URI; parse it to get the job ID...
6639 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6640 sizeof(scheme
), username
, sizeof(username
), host
,
6641 sizeof(host
), &port
, resource
, sizeof(resource
));
6643 if (strncmp(resource
, "/jobs/", 6))
6649 send_ipp_status(con
, IPP_BAD_REQUEST
,
6650 _("Bad job-uri attribute \"%s\"!"),
6651 uri
->values
[0].string
.text
);
6655 jobid
= atoi(resource
+ 6);
6659 * See if the job exists...
6662 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6665 * Nope - return a "not found" error...
6668 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6676 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6678 send_http_error(con
, status
, NULL
);
6683 * Get the document number...
6686 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6687 IPP_TAG_INTEGER
)) == NULL
)
6689 send_ipp_status(con
, IPP_BAD_REQUEST
,
6690 _("Missing document-number attribute!"));
6694 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6695 attr
->num_values
> 1)
6697 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6702 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6704 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6706 cupsdLogMessage(CUPSD_LOG_ERROR
,
6707 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6709 send_ipp_status(con
, IPP_NOT_FOUND
,
6710 _("Unable to open document %d in job %d!"), docnum
, jobid
);
6714 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6718 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6719 job
->filetypes
[docnum
- 1]->type
);
6721 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6723 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6725 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6726 IPP_TAG_NAME
)) != NULL
)
6727 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6728 NULL
, attr
->values
[0].string
.text
);
6733 * 'get_job_attrs()' - Get job attributes.
6737 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6738 ipp_attribute_t
*uri
) /* I - Job URI */
6740 http_status_t status
; /* Policy status */
6741 ipp_attribute_t
*attr
; /* Current attribute */
6742 int jobid
; /* Job ID */
6743 cupsd_job_t
*job
; /* Current job */
6744 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6745 username
[HTTP_MAX_URI
], /* Username portion of URI */
6746 host
[HTTP_MAX_URI
], /* Host portion of URI */
6747 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6748 int port
; /* Port portion of URI */
6749 cups_array_t
*ra
; /* Requested attributes array */
6752 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6753 con
->http
.fd
, uri
->values
[0].string
.text
);
6756 * See if we have a job URI or a printer URI...
6759 if (!strcmp(uri
->name
, "printer-uri"))
6762 * Got a printer URI; see if we also have a job-id attribute...
6765 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6766 IPP_TAG_INTEGER
)) == NULL
)
6768 send_ipp_status(con
, IPP_BAD_REQUEST
,
6769 _("Got a printer-uri attribute but no job-id!"));
6773 jobid
= attr
->values
[0].integer
;
6778 * Got a job URI; parse it to get the job ID...
6781 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6782 sizeof(scheme
), username
, sizeof(username
), host
,
6783 sizeof(host
), &port
, resource
, sizeof(resource
));
6785 if (strncmp(resource
, "/jobs/", 6))
6791 send_ipp_status(con
, IPP_BAD_REQUEST
,
6792 _("Bad job-uri attribute \"%s\"!"),
6793 uri
->values
[0].string
.text
);
6797 jobid
= atoi(resource
+ 6);
6801 * See if the job exists...
6804 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6807 * Nope - return a "not found" error...
6810 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6818 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6820 send_http_error(con
, status
, NULL
);
6825 * Copy attributes...
6830 ra
= create_requested_array(con
->request
);
6831 copy_job_attrs(con
, job
, ra
);
6832 cupsArrayDelete(ra
);
6834 con
->response
->request
.status
.status_code
= IPP_OK
;
6839 * 'get_jobs()' - Get a list of jobs for the specified printer.
6843 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6844 ipp_attribute_t
*uri
) /* I - Printer URI */
6846 http_status_t status
; /* Policy status */
6847 ipp_attribute_t
*attr
; /* Current attribute */
6848 const char *dest
; /* Destination */
6849 cups_ptype_t dtype
; /* Destination type (printer/class) */
6850 cups_ptype_t dmask
; /* Destination type mask */
6851 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6852 username
[HTTP_MAX_URI
], /* Username portion of URI */
6853 host
[HTTP_MAX_URI
], /* Host portion of URI */
6854 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6855 int port
; /* Port portion of URI */
6856 int completed
; /* Completed jobs? */
6857 int first_job_id
; /* First job ID */
6858 int limit
; /* Maximum number of jobs to return */
6859 int count
; /* Number of jobs that match */
6860 cupsd_job_t
*job
; /* Current job pointer */
6861 cupsd_printer_t
*printer
; /* Printer */
6862 cups_array_t
*list
; /* Which job list... */
6863 cups_array_t
*ra
; /* Requested attributes array */
6866 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6867 uri
->values
[0].string
.text
);
6870 * Is the destination valid?
6873 if (strcmp(uri
->name
, "printer-uri"))
6875 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request!"));
6879 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6880 sizeof(scheme
), username
, sizeof(username
), host
,
6881 sizeof(host
), &port
, resource
, sizeof(resource
));
6883 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6886 dtype
= (cups_ptype_t
)0;
6887 dmask
= (cups_ptype_t
)0;
6890 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6893 dtype
= (cups_ptype_t
)0;
6894 dmask
= CUPS_PRINTER_CLASS
;
6897 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6900 dtype
= CUPS_PRINTER_CLASS
;
6901 dmask
= CUPS_PRINTER_CLASS
;
6904 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6911 send_ipp_status(con
, IPP_NOT_FOUND
,
6912 _("The printer or class was not found."));
6917 dtype
&= CUPS_PRINTER_CLASS
;
6918 dmask
= CUPS_PRINTER_CLASS
;
6927 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6930 send_http_error(con
, status
, printer
);
6934 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6936 send_http_error(con
, status
, NULL
);
6941 * See if the "which-jobs" attribute have been specified...
6944 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6945 IPP_TAG_KEYWORD
)) != NULL
&&
6946 !strcmp(attr
->values
[0].string
.text
, "completed"))
6951 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
6956 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "processing"))
6959 list
= PrintingJobs
;
6968 * See if they want to limit the number of jobs reported...
6971 if ((attr
= ippFindAttribute(con
->request
, "limit",
6972 IPP_TAG_INTEGER
)) != NULL
)
6973 limit
= attr
->values
[0].integer
;
6977 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6978 IPP_TAG_INTEGER
)) != NULL
)
6979 first_job_id
= attr
->values
[0].integer
;
6984 * See if we only want to see jobs for a specific user...
6987 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6988 IPP_TAG_BOOLEAN
)) != NULL
&&
6989 attr
->values
[0].boolean
)
6990 strlcpy(username
, get_username(con
), sizeof(username
));
6994 ra
= create_requested_array(con
->request
);
6997 * OK, build a list of jobs for this printer...
7000 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7001 (limit
<= 0 || count
< limit
) && job
;
7002 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7005 * Filter out jobs that don't match...
7008 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7009 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7010 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7011 job
->username
, job
->state_value
, job
->attrs
);
7013 if (!job
->dest
|| !job
->username
)
7016 if (!job
->dest
|| !job
->username
)
7019 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7020 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7022 if ((job
->dtype
& dmask
) != dtype
&&
7023 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7025 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
7028 if (job
->id
< first_job_id
)
7035 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d!",
7040 if (username
[0] && strcasecmp(username
, job
->username
))
7044 ippAddSeparator(con
->response
);
7048 copy_job_attrs(con
, job
, ra
);
7051 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7053 cupsArrayDelete(ra
);
7055 con
->response
->request
.status
.status_code
= IPP_OK
;
7060 * 'get_notifications()' - Get events for a subscription.
7064 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7066 int i
, j
; /* Looping vars */
7067 http_status_t status
; /* Policy status */
7068 cupsd_subscription_t
*sub
; /* Subscription */
7069 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7070 *sequences
; /* notify-sequence-numbers */
7071 int min_seq
; /* Minimum sequence number */
7072 int interval
; /* Poll interval */
7075 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7079 * Get subscription attributes...
7082 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7084 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7089 send_ipp_status(con
, IPP_BAD_REQUEST
,
7090 _("Missing notify-subscription-ids attribute!"));
7095 * Are the subscription IDs valid?
7098 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7100 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7103 * Bad subscription ID...
7106 send_ipp_status(con
, IPP_NOT_FOUND
,
7107 _("notify-subscription-id %d no good!"),
7108 ids
->values
[i
].integer
);
7116 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7118 con
, sub
->owner
)) != HTTP_OK
)
7120 send_http_error(con
, status
, sub
->dest
);
7125 * Check the subscription type and update the interval accordingly.
7128 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7131 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7133 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7139 * Tell the client to poll again in N seconds...
7143 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7144 "notify-get-interval", interval
);
7146 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7147 "printer-up-time", time(NULL
));
7150 * Copy the subscription event attributes to the response.
7153 con
->response
->request
.status
.status_code
=
7154 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7156 for (i
= 0; i
< ids
->num_values
; i
++)
7159 * Get the subscription and sequence number...
7162 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7164 if (sequences
&& i
< sequences
->num_values
)
7165 min_seq
= sequences
->values
[i
].integer
;
7170 * If we don't have any new events, nothing to do here...
7173 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7177 * Otherwise copy all of the new events...
7180 if (sub
->first_event_id
> min_seq
)
7183 j
= min_seq
- sub
->first_event_id
;
7185 for (; j
< sub
->num_events
; j
++)
7187 ippAddSeparator(con
->response
);
7189 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7190 IPP_TAG_EVENT_NOTIFICATION
, 0);
7197 * 'get_ppd()' - Get a named PPD from the local system.
7201 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7202 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7204 http_status_t status
; /* Policy status */
7205 cupsd_printer_t
*dest
; /* Destination */
7206 cups_ptype_t dtype
; /* Destination type */
7209 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7210 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7212 if (!strcmp(uri
->name
, "ppd-name"))
7215 * Return a PPD file from cups-driverd...
7218 char command
[1024], /* cups-driverd command */
7219 options
[1024], /* Options to pass to command */
7220 ppd_name
[1024]; /* ppd-name */
7227 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7229 send_http_error(con
, status
, NULL
);
7234 * Run cups-driverd command with the given options...
7237 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7238 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7239 snprintf(options
, sizeof(options
), "get+%d+%s",
7240 con
->request
->request
.op
.request_id
, ppd_name
);
7242 if (cupsdSendCommand(con
, command
, options
, 0))
7245 * Command started successfully, don't send an IPP response here...
7248 ippDelete(con
->response
);
7249 con
->response
= NULL
;
7254 * Command failed, return "internal error" so the user knows something
7258 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7259 _("cups-driverd failed to execute."));
7262 else if (!strcmp(uri
->name
, "printer-uri") &&
7263 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7265 int i
; /* Looping var */
7266 char filename
[1024]; /* PPD filename */
7273 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7275 send_http_error(con
, status
, dest
);
7280 * See if we need the PPD for a class or remote printer...
7283 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7286 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7288 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7289 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7290 "printer-uri", NULL
, dest
->uri
);
7293 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7295 for (i
= 0; i
< dest
->num_printers
; i
++)
7296 if (!(dest
->printers
[i
]->type
&
7297 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7299 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7300 dest
->printers
[i
]->name
);
7302 if (!access(filename
, 0))
7306 if (i
< dest
->num_printers
)
7307 dest
= dest
->printers
[i
];
7310 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7311 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7312 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7318 * Found the printer with the PPD file, now see if there is one...
7321 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7323 send_ipp_status(con
, IPP_NOT_FOUND
,
7324 _("The PPD file \"%s\" could not be opened: %s"),
7325 uri
->values
[0].string
.text
, strerror(errno
));
7329 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7333 con
->response
->request
.status
.status_code
= IPP_OK
;
7336 send_ipp_status(con
, IPP_NOT_FOUND
,
7337 _("The PPD file \"%s\" could not be found."),
7338 uri
->values
[0].string
.text
);
7343 * 'get_ppds()' - Get the list of PPD files on the local system.
7347 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7349 http_status_t status
; /* Policy status */
7350 ipp_attribute_t
*limit
, /* Limit attribute */
7351 *device
, /* ppd-device-id attribute */
7352 *language
, /* ppd-natural-language attribute */
7353 *make
, /* ppd-make attribute */
7354 *model
, /* ppd-make-and-model attribute */
7355 *model_number
, /* ppd-model-number attribute */
7356 *product
, /* ppd-product attribute */
7357 *psversion
, /* ppd-psverion attribute */
7358 *type
, /* ppd-type attribute */
7359 *requested
, /* requested-attributes attribute */
7360 *exclude
, /* exclude-schemes attribute */
7361 *include
; /* include-schemes attribute */
7362 char command
[1024], /* cups-driverd command */
7363 options
[4096], /* Options to pass to command */
7364 device_str
[256],/* Escaped ppd-device-id string */
7366 /* Escaped ppd-natural-language */
7367 make_str
[256], /* Escaped ppd-make string */
7368 model_str
[256], /* Escaped ppd-make-and-model string */
7369 model_number_str
[256],
7370 /* ppd-model-number string */
7372 /* Escaped ppd-product string */
7374 /* Escaped ppd-psversion string */
7375 type_str
[256], /* Escaped ppd-type string */
7377 /* String for requested attributes */
7379 /* String for excluded schemes */
7381 /* String for included schemes */
7384 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7390 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7392 send_http_error(con
, status
, NULL
);
7397 * Run cups-driverd command with the given options...
7400 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7401 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7402 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7404 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7405 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7407 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7409 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7410 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7411 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7412 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7414 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7416 include
= ippFindAttribute(con
->request
, "include-schemes",
7420 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7422 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7425 url_encode_attr(device
, device_str
, sizeof(device_str
));
7427 device_str
[0] = '\0';
7430 url_encode_attr(language
, language_str
, sizeof(language_str
));
7432 language_str
[0] = '\0';
7435 url_encode_attr(make
, make_str
, sizeof(make_str
));
7440 url_encode_attr(model
, model_str
, sizeof(model_str
));
7442 model_str
[0] = '\0';
7445 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7446 model_number
->values
[0].integer
);
7448 model_number_str
[0] = '\0';
7451 url_encode_attr(product
, product_str
, sizeof(product_str
));
7453 product_str
[0] = '\0';
7456 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7458 psversion_str
[0] = '\0';
7461 url_encode_attr(type
, type_str
, sizeof(type_str
));
7466 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7468 exclude_str
[0] = '\0';
7471 url_encode_attr(include
, include_str
, sizeof(include_str
));
7473 include_str
[0] = '\0';
7475 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7476 snprintf(options
, sizeof(options
),
7477 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7478 con
->request
->request
.op
.request_id
,
7479 limit
? limit
->values
[0].integer
: 0,
7481 device
? "%20" : "", device_str
,
7482 language
? "%20" : "", language_str
,
7483 make
? "%20" : "", make_str
,
7484 model
? "%20" : "", model_str
,
7485 model_number
? "%20" : "", model_number_str
,
7486 product
? "%20" : "", product_str
,
7487 psversion
? "%20" : "", psversion_str
,
7488 type
? "%20" : "", type_str
,
7489 exclude_str
[0] ? "%20" : "", exclude_str
,
7490 include_str
[0] ? "%20" : "", include_str
);
7492 if (cupsdSendCommand(con
, command
, options
, 0))
7495 * Command started successfully, don't send an IPP response here...
7498 ippDelete(con
->response
);
7499 con
->response
= NULL
;
7504 * Command failed, return "internal error" so the user knows something
7508 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7509 _("cups-driverd failed to execute."));
7515 * 'get_printer_attrs()' - Get printer attributes.
7519 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7520 ipp_attribute_t
*uri
) /* I - Printer URI */
7522 http_status_t status
; /* Policy status */
7523 cups_ptype_t dtype
; /* Destination type (printer/class) */
7524 cupsd_printer_t
*printer
; /* Printer/class */
7525 cups_array_t
*ra
; /* Requested attributes array */
7528 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7529 con
->http
.fd
, uri
->values
[0].string
.text
);
7532 * Is the destination valid?
7535 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7541 send_ipp_status(con
, IPP_NOT_FOUND
,
7542 _("The printer or class was not found."));
7550 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7552 send_http_error(con
, status
, printer
);
7557 * Send the attributes...
7560 ra
= create_requested_array(con
->request
);
7562 copy_printer_attrs(con
, printer
, ra
);
7564 cupsArrayDelete(ra
);
7566 con
->response
->request
.status
.status_code
= IPP_OK
;
7571 * 'get_printer_supported()' - Get printer supported values.
7575 get_printer_supported(
7576 cupsd_client_t
*con
, /* I - Client connection */
7577 ipp_attribute_t
*uri
) /* I - Printer URI */
7579 http_status_t status
; /* Policy status */
7580 cups_ptype_t dtype
; /* Destination type (printer/class) */
7581 cupsd_printer_t
*printer
; /* Printer/class */
7584 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7585 con
->http
.fd
, uri
->values
[0].string
.text
);
7588 * Is the destination valid?
7591 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7597 send_ipp_status(con
, IPP_NOT_FOUND
,
7598 _("The printer or class was not found."));
7606 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7608 send_http_error(con
, status
, printer
);
7613 * Return a list of attributes that can be set via Set-Printer-Attributes.
7616 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7618 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7619 "printer-location", 0);
7621 con
->response
->request
.status
.status_code
= IPP_OK
;
7626 * 'get_printers()' - Get a list of printers or classes.
7630 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7631 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7633 http_status_t status
; /* Policy status */
7634 ipp_attribute_t
*attr
; /* Current attribute */
7635 int limit
; /* Max number of printers to return */
7636 int count
; /* Number of printers that match */
7637 cupsd_printer_t
*printer
; /* Current printer pointer */
7638 int printer_type
, /* printer-type attribute */
7639 printer_mask
; /* printer-type-mask attribute */
7640 char *location
; /* Location string */
7641 const char *username
; /* Current user */
7642 char *first_printer_name
; /* first-printer-name attribute */
7643 cups_array_t
*ra
; /* Requested attributes array */
7644 int local
; /* Local connection? */
7647 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7648 con
->http
.fd
, type
);
7654 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7656 send_http_error(con
, status
, NULL
);
7661 * Check for printers...
7664 if (!Printers
|| !cupsArrayCount(Printers
))
7666 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7671 * See if they want to limit the number of printers reported...
7674 if ((attr
= ippFindAttribute(con
->request
, "limit",
7675 IPP_TAG_INTEGER
)) != NULL
)
7676 limit
= attr
->values
[0].integer
;
7680 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7681 IPP_TAG_NAME
)) != NULL
)
7682 first_printer_name
= attr
->values
[0].string
.text
;
7684 first_printer_name
= NULL
;
7687 * Support filtering...
7690 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7691 IPP_TAG_ENUM
)) != NULL
)
7692 printer_type
= attr
->values
[0].integer
;
7696 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7697 IPP_TAG_ENUM
)) != NULL
)
7698 printer_mask
= attr
->values
[0].integer
;
7702 local
= httpAddrLocalhost(&(con
->clientaddr
));
7704 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7705 IPP_TAG_TEXT
)) != NULL
)
7706 location
= attr
->values
[0].string
.text
;
7710 if (con
->username
[0])
7711 username
= con
->username
;
7712 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7713 IPP_TAG_NAME
)) != NULL
)
7714 username
= attr
->values
[0].string
.text
;
7718 ra
= create_requested_array(con
->request
);
7721 * OK, build a list of printers for this printer...
7724 if (first_printer_name
)
7726 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7727 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7730 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7733 count
< limit
&& printer
;
7734 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7736 if (!local
&& !printer
->shared
)
7739 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7740 (printer
->type
& printer_mask
) == printer_type
&&
7742 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
7745 * If HideImplicitMembers is enabled, see if this printer or class
7746 * is a member of an implicit class...
7749 if (ImplicitClasses
&& HideImplicitMembers
&&
7750 printer
->in_implicit_class
)
7754 * If a username is specified, see if it is allowed or denied
7758 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
7762 * Add the group separator as needed...
7766 ippAddSeparator(con
->response
);
7771 * Send the attributes...
7774 copy_printer_attrs(con
, printer
, ra
);
7778 cupsArrayDelete(ra
);
7780 con
->response
->request
.status
.status_code
= IPP_OK
;
7785 * 'get_subscription_attrs()' - Get subscription attributes.
7789 get_subscription_attrs(
7790 cupsd_client_t
*con
, /* I - Client connection */
7791 int sub_id
) /* I - Subscription ID */
7793 http_status_t status
; /* Policy status */
7794 cupsd_subscription_t
*sub
; /* Subscription */
7795 cups_array_t
*ra
; /* Requested attributes array */
7798 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7799 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7800 con
, con
->http
.fd
, sub_id
);
7803 * Is the subscription ID valid?
7806 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7809 * Bad subscription ID...
7812 send_ipp_status(con
, IPP_NOT_FOUND
,
7813 _("notify-subscription-id %d no good!"), sub_id
);
7821 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7823 con
, sub
->owner
)) != HTTP_OK
)
7825 send_http_error(con
, status
, sub
->dest
);
7830 * Copy the subscription attributes to the response using the
7831 * requested-attributes attribute that may be provided by the client.
7834 ra
= create_requested_array(con
->request
);
7836 copy_subscription_attrs(con
, sub
, ra
);
7838 cupsArrayDelete(ra
);
7840 con
->response
->request
.status
.status_code
= IPP_OK
;
7845 * 'get_subscriptions()' - Get subscriptions.
7849 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7850 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7852 http_status_t status
; /* Policy status */
7853 int count
; /* Number of subscriptions */
7854 int limit
; /* Limit */
7855 cupsd_subscription_t
*sub
; /* Subscription */
7856 cups_array_t
*ra
; /* Requested attributes array */
7857 ipp_attribute_t
*attr
; /* Attribute */
7858 cups_ptype_t dtype
; /* Destination type (printer/class) */
7859 char scheme
[HTTP_MAX_URI
],
7860 /* Scheme portion of URI */
7861 username
[HTTP_MAX_URI
],
7862 /* Username portion of URI */
7864 /* Host portion of URI */
7865 resource
[HTTP_MAX_URI
];
7866 /* Resource portion of URI */
7867 int port
; /* Port portion of URI */
7868 cupsd_job_t
*job
; /* Job pointer */
7869 cupsd_printer_t
*printer
; /* Printer */
7872 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7873 "get_subscriptions(con=%p[%d], uri=%s)",
7874 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7877 * Is the destination valid?
7880 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7881 sizeof(scheme
), username
, sizeof(username
), host
,
7882 sizeof(host
), &port
, resource
, sizeof(resource
));
7884 if (!strcmp(resource
, "/") ||
7885 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7886 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7887 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7892 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7895 job
= cupsdFindJob(atoi(resource
+ 6));
7899 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
7904 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7910 send_ipp_status(con
, IPP_NOT_FOUND
,
7911 _("The printer or class was not found."));
7914 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7915 IPP_TAG_INTEGER
)) != NULL
)
7917 job
= cupsdFindJob(attr
->values
[0].integer
);
7921 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
7922 attr
->values
[0].integer
);
7933 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
7935 con
, NULL
)) != HTTP_OK
)
7937 send_http_error(con
, status
, printer
);
7942 * Copy the subscription attributes to the response using the
7943 * requested-attributes attribute that may be provided by the client.
7946 ra
= create_requested_array(con
->request
);
7948 if ((attr
= ippFindAttribute(con
->request
, "limit",
7949 IPP_TAG_INTEGER
)) != NULL
)
7950 limit
= attr
->values
[0].integer
;
7955 * See if we only want to see subscriptions for a specific user...
7958 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7959 IPP_TAG_BOOLEAN
)) != NULL
&&
7960 attr
->values
[0].boolean
)
7961 strlcpy(username
, get_username(con
), sizeof(username
));
7965 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7967 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7968 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7969 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
7971 ippAddSeparator(con
->response
);
7972 copy_subscription_attrs(con
, sub
, ra
);
7975 if (limit
&& count
>= limit
)
7979 cupsArrayDelete(ra
);
7982 con
->response
->request
.status
.status_code
= IPP_OK
;
7984 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7989 * 'get_username()' - Get the username associated with a request.
7992 static const char * /* O - Username */
7993 get_username(cupsd_client_t
*con
) /* I - Connection */
7995 ipp_attribute_t
*attr
; /* Attribute */
7998 if (con
->username
[0])
7999 return (con
->username
);
8000 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8001 IPP_TAG_NAME
)) != NULL
)
8002 return (attr
->values
[0].string
.text
);
8004 return ("anonymous");
8009 * 'hold_job()' - Hold a print job.
8013 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8014 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8016 ipp_attribute_t
*attr
; /* Current job-hold-until */
8017 const char *when
; /* New value */
8018 int jobid
; /* Job ID */
8019 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8020 username
[HTTP_MAX_URI
], /* Username portion of URI */
8021 host
[HTTP_MAX_URI
], /* Host portion of URI */
8022 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8023 int port
; /* Port portion of URI */
8024 cupsd_job_t
*job
; /* Job information */
8027 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8028 uri
->values
[0].string
.text
);
8031 * See if we have a job URI or a printer URI...
8034 if (!strcmp(uri
->name
, "printer-uri"))
8037 * Got a printer URI; see if we also have a job-id attribute...
8040 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8041 IPP_TAG_INTEGER
)) == NULL
)
8043 send_ipp_status(con
, IPP_BAD_REQUEST
,
8044 _("Got a printer-uri attribute but no job-id!"));
8048 jobid
= attr
->values
[0].integer
;
8053 * Got a job URI; parse it to get the job ID...
8056 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8057 sizeof(scheme
), username
, sizeof(username
), host
,
8058 sizeof(host
), &port
, resource
, sizeof(resource
));
8060 if (strncmp(resource
, "/jobs/", 6))
8066 send_ipp_status(con
, IPP_BAD_REQUEST
,
8067 _("Bad job-uri attribute \"%s\"!"),
8068 uri
->values
[0].string
.text
);
8072 jobid
= atoi(resource
+ 6);
8076 * See if the job exists...
8079 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8082 * Nope - return a "not found" error...
8085 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8090 * See if the job is owned by the requesting user...
8093 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8095 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8096 cupsdFindDest(job
->dest
));
8101 * Hold the job and return...
8104 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8105 IPP_TAG_KEYWORD
)) == NULL
)
8106 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8110 when
= attr
->values
[0].string
.text
;
8112 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8113 "Job job-hold-until value changed by user.");
8116 when
= "indefinite";
8118 cupsdSetJobHoldUntil(job
, when
, 1);
8119 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8122 con
->response
->request
.status
.status_code
= IPP_OK
;
8127 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8131 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8132 ipp_attribute_t
*uri
) /* I - Printer URI */
8134 http_status_t status
; /* Policy status */
8135 cups_ptype_t dtype
; /* Destination type (printer/class) */
8136 cupsd_printer_t
*printer
; /* Printer data */
8139 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8140 con
->http
.fd
, uri
->values
[0].string
.text
);
8143 * Is the destination valid?
8146 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8152 send_ipp_status(con
, IPP_NOT_FOUND
,
8153 _("The printer or class was not found."));
8161 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8163 send_http_error(con
, status
, printer
);
8168 * Hold pending/new jobs sent to the printer...
8171 printer
->holding_new_jobs
= 1;
8173 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8174 cupsdAddPrinterHistory(printer
);
8176 if (dtype
& CUPS_PRINTER_CLASS
)
8177 cupsdLogMessage(CUPSD_LOG_INFO
,
8178 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8179 printer
->name
, get_username(con
));
8181 cupsdLogMessage(CUPSD_LOG_INFO
,
8182 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8183 printer
->name
, get_username(con
));
8186 * Everything was ok, so return OK status...
8189 con
->response
->request
.status
.status_code
= IPP_OK
;
8194 * 'move_job()' - Move a job to a new destination.
8198 move_job(cupsd_client_t
*con
, /* I - Client connection */
8199 ipp_attribute_t
*uri
) /* I - Job URI */
8201 http_status_t status
; /* Policy status */
8202 ipp_attribute_t
*attr
; /* Current attribute */
8203 int jobid
; /* Job ID */
8204 cupsd_job_t
*job
; /* Current job */
8205 const char *src
; /* Source printer/class */
8206 cups_ptype_t stype
, /* Source type (printer or class) */
8207 dtype
; /* Destination type (printer/class) */
8208 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8209 username
[HTTP_MAX_URI
], /* Username portion of URI */
8210 host
[HTTP_MAX_URI
], /* Host portion of URI */
8211 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8212 int port
; /* Port portion of URI */
8213 cupsd_printer_t
*sprinter
, /* Source printer */
8214 *dprinter
; /* Destination printer */
8217 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8218 uri
->values
[0].string
.text
);
8221 * Get the new printer or class...
8224 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8225 IPP_TAG_URI
)) == NULL
)
8228 * Need job-printer-uri...
8231 send_ipp_status(con
, IPP_BAD_REQUEST
,
8232 _("job-printer-uri attribute missing!"));
8236 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8242 send_ipp_status(con
, IPP_NOT_FOUND
,
8243 _("The printer or class was not found."));
8248 * See if we have a job URI or a printer URI...
8251 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8252 sizeof(scheme
), username
, sizeof(username
), host
,
8253 sizeof(host
), &port
, resource
, sizeof(resource
));
8255 if (!strcmp(uri
->name
, "printer-uri"))
8258 * Got a printer URI; see if we also have a job-id attribute...
8261 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8262 IPP_TAG_INTEGER
)) == NULL
)
8268 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8269 &sprinter
)) == NULL
)
8275 send_ipp_status(con
, IPP_NOT_FOUND
,
8276 _("The printer or class was not found."));
8285 * Otherwise, just move a single job...
8288 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8291 * Nope - return a "not found" error...
8294 send_ipp_status(con
, IPP_NOT_FOUND
,
8295 _("Job #%d does not exist!"), attr
->values
[0].integer
);
8301 * Job found, initialize source pointers...
8312 * Got a job URI; parse it to get the job ID...
8315 if (strncmp(resource
, "/jobs/", 6))
8321 send_ipp_status(con
, IPP_BAD_REQUEST
,
8322 _("Bad job-uri attribute \"%s\"!"),
8323 uri
->values
[0].string
.text
);
8328 * See if the job exists...
8331 jobid
= atoi(resource
+ 6);
8333 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8336 * Nope - return a "not found" error...
8339 send_ipp_status(con
, IPP_NOT_FOUND
,
8340 _("Job #%d does not exist!"), jobid
);
8346 * Job found, initialize source pointers...
8355 * Check the policy of the destination printer...
8358 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8359 job
? job
->username
: NULL
)) != HTTP_OK
)
8361 send_http_error(con
, status
, dprinter
);
8366 * Now move the job or jobs...
8372 * See if the job has been completed...
8375 if (job
->state_value
> IPP_JOB_STOPPED
)
8378 * Return a "not-possible" error...
8381 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8382 _("Job #%d is finished and cannot be altered!"),
8388 * See if the job is owned by the requesting user...
8391 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8393 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8394 cupsdFindDest(job
->dest
));
8399 * Move the job to a different printer or class...
8402 cupsdMoveJob(job
, dprinter
);
8407 * Got the source printer, now look through the jobs...
8410 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8412 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8415 * See if the job is pointing at the source printer or has not been
8419 if (strcasecmp(job
->dest
, src
) ||
8420 job
->state_value
> IPP_JOB_STOPPED
)
8424 * See if the job can be moved by the requesting user...
8427 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8431 * Move the job to a different printer or class...
8434 cupsdMoveJob(job
, dprinter
);
8439 * Start jobs if possible...
8445 * Return with "everything is OK" status...
8448 con
->response
->request
.status
.status_code
= IPP_OK
;
8453 * 'ppd_parse_line()' - Parse a PPD default line.
8456 static int /* O - 0 on success, -1 on failure */
8457 ppd_parse_line(const char *line
, /* I - Line */
8458 char *option
, /* O - Option name */
8459 int olen
, /* I - Size of option name */
8460 char *choice
, /* O - Choice name */
8461 int clen
) /* I - Size of choice name */
8464 * Verify this is a default option line...
8467 if (strncmp(line
, "*Default", 8))
8471 * Read the option name...
8474 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
8484 * Skip everything else up to the colon (:)...
8487 while (*line
&& *line
!= ':')
8496 * Now grab the option choice, skipping leading whitespace...
8499 while (isspace(*line
& 255))
8502 for (clen
--; isalnum(*line
& 255); line
++)
8512 * Return with no errors...
8520 * 'print_job()' - Print a file to a printer or class.
8524 print_job(cupsd_client_t
*con
, /* I - Client connection */
8525 ipp_attribute_t
*uri
) /* I - Printer URI */
8527 ipp_attribute_t
*attr
; /* Current attribute */
8528 ipp_attribute_t
*format
; /* Document-format attribute */
8529 const char *default_format
; /* document-format-default value */
8530 cupsd_job_t
*job
; /* New job */
8531 char filename
[1024]; /* Job filename */
8532 mime_type_t
*filetype
; /* Type of file */
8533 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8534 type
[MIME_MAX_TYPE
], /* Subtype of file */
8535 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8536 /* Textual name of mime type */
8537 cupsd_printer_t
*printer
; /* Printer data */
8538 struct stat fileinfo
; /* File information */
8539 int kbytes
; /* Size of file */
8540 int compression
; /* Document compression */
8543 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8544 uri
->values
[0].string
.text
);
8547 * Validate print file attributes, for now just document-format and
8548 * compression (CUPS only supports "none" and "gzip")...
8551 compression
= CUPS_FILE_NONE
;
8553 if ((attr
= ippFindAttribute(con
->request
, "compression",
8554 IPP_TAG_KEYWORD
)) != NULL
)
8556 if (strcmp(attr
->values
[0].string
.text
, "none")
8558 && strcmp(attr
->values
[0].string
.text
, "gzip")
8559 #endif /* HAVE_LIBZ */
8562 send_ipp_status(con
, IPP_ATTRIBUTES
,
8563 _("Unsupported compression \"%s\"!"),
8564 attr
->values
[0].string
.text
);
8565 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8566 "compression", NULL
, attr
->values
[0].string
.text
);
8571 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8572 compression
= CUPS_FILE_GZIP
;
8573 #endif /* HAVE_LIBZ */
8577 * Do we have a file to print?
8582 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8587 * Is the destination valid?
8590 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8596 send_ipp_status(con
, IPP_NOT_FOUND
,
8597 _("The printer or class was not found."));
8602 * Is it a format we support?
8605 if ((format
= ippFindAttribute(con
->request
, "document-format",
8606 IPP_TAG_MIMETYPE
)) != NULL
)
8609 * Grab format from client...
8612 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8615 send_ipp_status(con
, IPP_BAD_REQUEST
,
8616 _("Could not scan type \"%s\"!"),
8617 format
->values
[0].string
.text
);
8621 else if ((default_format
= cupsGetOption("document-format",
8622 printer
->num_options
,
8623 printer
->options
)) != NULL
)
8626 * Use default document format...
8629 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8631 send_ipp_status(con
, IPP_BAD_REQUEST
,
8632 _("Could not scan type \"%s\"!"),
8643 strcpy(super
, "application");
8644 strcpy(type
, "octet-stream");
8647 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8650 * Auto-type the file...
8653 ipp_attribute_t
*doc_name
; /* document-name attribute */
8656 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8658 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8659 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8660 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8664 filetype
= mimeType(MimeDatabase
, super
, type
);
8666 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8667 filetype
->super
, filetype
->type
);
8670 filetype
= mimeType(MimeDatabase
, super
, type
);
8674 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8677 * Replace the document-format attribute value with the auto-typed or
8681 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8686 _cupsStrFree(format
->values
[0].string
.text
);
8688 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8691 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8692 "document-format", NULL
, mimetype
);
8696 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8697 _("Unsupported format \'%s/%s\'!"), super
, type
);
8698 cupsdLogMessage(CUPSD_LOG_INFO
,
8699 "Hint: Do you have the raw file printing rules enabled?");
8702 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8703 "document-format", NULL
, format
->values
[0].string
.text
);
8709 * Read any embedded job ticket info from PS files...
8712 if (!strcasecmp(filetype
->super
, "application") &&
8713 (!strcasecmp(filetype
->type
, "postscript") ||
8714 !strcasecmp(filetype
->type
, "pdf")))
8715 read_job_ticket(con
);
8718 * Create the job object...
8721 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8725 * Update quota data...
8728 if (stat(con
->filename
, &fileinfo
))
8731 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8733 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8735 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8736 IPP_TAG_INTEGER
)) != NULL
)
8737 attr
->values
[0].integer
+= kbytes
;
8740 * Add the job file...
8743 if (add_file(con
, job
, filetype
, compression
))
8746 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8748 rename(con
->filename
, filename
);
8749 cupsdClearString(&con
->filename
);
8752 * See if we need to add the ending sheet...
8755 if (cupsdTimeoutJob(job
))
8759 * Log and save the job...
8762 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8763 "File of type %s/%s queued by \"%s\".",
8764 filetype
->super
, filetype
->type
, job
->username
);
8765 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8766 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8767 job
->dest
, job
->username
);
8770 * Start the job if possible...
8778 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8780 * This function only gets called when printing a single PDF or PostScript
8781 * file using the Print-Job operation. It doesn't work for Create-Job +
8782 * Send-File, since the job attributes need to be set at job creation
8783 * time for banners to work. The embedded job ticket stuff is here
8784 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8785 * options and IPP attributes which otherwise would be lost.
8787 * The format of a job ticket is simple:
8789 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8791 * %cupsJobTicket: attr1=value1
8792 * %cupsJobTicket: attr2=value2
8794 * %cupsJobTicket: attrN=valueN
8796 * Job ticket lines must appear immediately after the first line that
8797 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8798 * stops looking for job ticket info when it finds a line that does not begin
8799 * with "%cupsJobTicket:".
8801 * The maximum length of a job ticket line, including the prefix, is
8802 * 255 characters to conform with the Adobe DSC.
8804 * Read-only attributes are rejected with a notice to the error log in
8805 * case a malicious user tries anything. Since the job ticket is read
8806 * prior to attribute validation in print_job(), job ticket attributes
8807 * will go through the same validation as IPP attributes...
8811 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8813 cups_file_t
*fp
; /* File to read from */
8814 char line
[256]; /* Line data */
8815 int num_options
; /* Number of options */
8816 cups_option_t
*options
; /* Options */
8817 ipp_t
*ticket
; /* New attributes */
8818 ipp_attribute_t
*attr
, /* Current attribute */
8819 *attr2
, /* Job attribute */
8820 *prev2
; /* Previous job attribute */
8824 * First open the print file...
8827 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8829 cupsdLogMessage(CUPSD_LOG_ERROR
,
8830 "Unable to open print file for job ticket - %s",
8836 * Skip the first line...
8839 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8841 cupsdLogMessage(CUPSD_LOG_ERROR
,
8842 "Unable to read from print file for job ticket - %s",
8848 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8851 * Not a DSC-compliant file, so no job ticket info will be available...
8859 * Read job ticket info from the file...
8865 while (cupsFileGets(fp
, line
, sizeof(line
)))
8868 * Stop at the first non-ticket line...
8871 if (strncmp(line
, "%cupsJobTicket:", 15))
8875 * Add the options to the option array...
8878 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8882 * Done with the file; see if we have any options...
8887 if (num_options
== 0)
8891 * OK, convert the options to an attribute list, and apply them to
8896 cupsEncodeOptions(ticket
, num_options
, options
);
8899 * See what the user wants to change.
8902 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8904 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8907 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8908 !strcmp(attr
->name
, "job-originating-user-name") ||
8909 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8910 !strcmp(attr
->name
, "job-k-octets") ||
8911 !strcmp(attr
->name
, "job-id") ||
8912 !strncmp(attr
->name
, "job-state", 9) ||
8913 !strncmp(attr
->name
, "time-at-", 8))
8914 continue; /* Read-only attrs */
8916 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8917 IPP_TAG_ZERO
)) != NULL
)
8920 * Some other value; first free the old value...
8923 if (con
->request
->attrs
== attr2
)
8925 con
->request
->attrs
= attr2
->next
;
8930 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8931 if (prev2
->next
== attr2
)
8933 prev2
->next
= attr2
->next
;
8938 if (con
->request
->last
== attr2
)
8939 con
->request
->last
= prev2
;
8941 _ippFreeAttr(attr2
);
8945 * Add new option by copying it...
8948 copy_attribute(con
->request
, attr
, 0);
8952 * Then free the attribute list and option array...
8956 cupsFreeOptions(num_options
, options
);
8961 * 'reject_jobs()' - Reject print jobs to a printer.
8965 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8966 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8968 http_status_t status
; /* Policy status */
8969 cups_ptype_t dtype
; /* Destination type (printer/class) */
8970 cupsd_printer_t
*printer
; /* Printer data */
8971 ipp_attribute_t
*attr
; /* printer-state-message text */
8974 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8975 con
->http
.fd
, uri
->values
[0].string
.text
);
8978 * Is the destination valid?
8981 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8987 send_ipp_status(con
, IPP_NOT_FOUND
,
8988 _("The printer or class was not found."));
8996 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8998 send_http_error(con
, status
, printer
);
9003 * Reject jobs sent to the printer...
9006 printer
->accepting
= 0;
9008 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9009 IPP_TAG_TEXT
)) == NULL
)
9010 strcpy(printer
->state_message
, "Rejecting Jobs");
9012 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9013 sizeof(printer
->state_message
));
9015 cupsdAddPrinterHistory(printer
);
9017 if (dtype
& CUPS_PRINTER_CLASS
)
9019 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9021 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9022 printer
->name
, get_username(con
));
9026 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9028 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9029 printer
->name
, get_username(con
));
9033 * Everything was ok, so return OK status...
9036 con
->response
->request
.status
.status_code
= IPP_OK
;
9041 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9045 release_held_new_jobs(
9046 cupsd_client_t
*con
, /* I - Connection */
9047 ipp_attribute_t
*uri
) /* I - Printer URI */
9049 http_status_t status
; /* Policy status */
9050 cups_ptype_t dtype
; /* Destination type (printer/class) */
9051 cupsd_printer_t
*printer
; /* Printer data */
9054 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9055 con
->http
.fd
, uri
->values
[0].string
.text
);
9058 * Is the destination valid?
9061 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9067 send_ipp_status(con
, IPP_NOT_FOUND
,
9068 _("The printer or class was not found."));
9076 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9078 send_http_error(con
, status
, printer
);
9083 * Hold pending/new jobs sent to the printer...
9086 printer
->holding_new_jobs
= 0;
9088 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9089 cupsdAddPrinterHistory(printer
);
9091 if (dtype
& CUPS_PRINTER_CLASS
)
9092 cupsdLogMessage(CUPSD_LOG_INFO
,
9093 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9094 printer
->name
, get_username(con
));
9096 cupsdLogMessage(CUPSD_LOG_INFO
,
9097 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9098 printer
->name
, get_username(con
));
9101 * Everything was ok, so return OK status...
9104 con
->response
->request
.status
.status_code
= IPP_OK
;
9109 * 'release_job()' - Release a held print job.
9113 release_job(cupsd_client_t
*con
, /* I - Client connection */
9114 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9116 ipp_attribute_t
*attr
; /* Current attribute */
9117 int jobid
; /* Job ID */
9118 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9119 username
[HTTP_MAX_URI
], /* Username portion of URI */
9120 host
[HTTP_MAX_URI
], /* Host portion of URI */
9121 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9122 int port
; /* Port portion of URI */
9123 cupsd_job_t
*job
; /* Job information */
9126 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9127 con
->http
.fd
, uri
->values
[0].string
.text
);
9130 * See if we have a job URI or a printer URI...
9133 if (!strcmp(uri
->name
, "printer-uri"))
9136 * Got a printer URI; see if we also have a job-id attribute...
9139 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9140 IPP_TAG_INTEGER
)) == NULL
)
9142 send_ipp_status(con
, IPP_BAD_REQUEST
,
9143 _("Got a printer-uri attribute but no job-id!"));
9147 jobid
= attr
->values
[0].integer
;
9152 * Got a job URI; parse it to get the job ID...
9155 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9156 sizeof(scheme
), username
, sizeof(username
), host
,
9157 sizeof(host
), &port
, resource
, sizeof(resource
));
9159 if (strncmp(resource
, "/jobs/", 6))
9165 send_ipp_status(con
, IPP_BAD_REQUEST
,
9166 _("Bad job-uri attribute \"%s\"!"),
9167 uri
->values
[0].string
.text
);
9171 jobid
= atoi(resource
+ 6);
9175 * See if the job exists...
9178 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9181 * Nope - return a "not found" error...
9184 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9189 * See if job is "held"...
9192 if (job
->state_value
!= IPP_JOB_HELD
)
9195 * Nope - return a "not possible" error...
9198 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
9203 * See if the job is owned by the requesting user...
9206 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9208 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9209 cupsdFindDest(job
->dest
));
9214 * Reset the job-hold-until value to "no-hold"...
9217 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9218 IPP_TAG_KEYWORD
)) == NULL
)
9219 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9223 _cupsStrFree(attr
->values
[0].string
.text
);
9225 attr
->value_tag
= IPP_TAG_KEYWORD
;
9226 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9228 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9229 "Job job-hold-until value changed by user.");
9233 * Release the job and return...
9236 cupsdReleaseJob(job
);
9238 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9239 "Job released by user.");
9241 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9243 con
->response
->request
.status
.status_code
= IPP_OK
;
9250 * 'renew_subscription()' - Renew an existing subscription...
9255 cupsd_client_t
*con
, /* I - Client connection */
9256 int sub_id
) /* I - Subscription ID */
9258 http_status_t status
; /* Policy status */
9259 cupsd_subscription_t
*sub
; /* Subscription */
9260 ipp_attribute_t
*lease
; /* notify-lease-duration */
9263 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9264 "renew_subscription(con=%p[%d], sub_id=%d)",
9265 con
, con
->http
.fd
, sub_id
);
9268 * Is the subscription ID valid?
9271 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9274 * Bad subscription ID...
9277 send_ipp_status(con
, IPP_NOT_FOUND
,
9278 _("notify-subscription-id %d no good!"), sub_id
);
9285 * Job subscriptions cannot be renewed...
9288 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9289 _("Job subscriptions cannot be renewed!"));
9297 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9299 con
, sub
->owner
)) != HTTP_OK
)
9301 send_http_error(con
, status
, sub
->dest
);
9306 * Renew the subscription...
9309 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9312 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9314 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9316 cupsdLogMessage(CUPSD_LOG_INFO
,
9317 "renew_subscription: Limiting notify-lease-duration to "
9320 sub
->lease
= MaxLeaseDuration
;
9323 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9325 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9327 con
->response
->request
.status
.status_code
= IPP_OK
;
9329 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9330 "notify-lease-duration", sub
->lease
);
9335 * 'restart_job()' - Restart an old print job.
9339 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9340 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9342 ipp_attribute_t
*attr
; /* Current attribute */
9343 int jobid
; /* Job ID */
9344 cupsd_job_t
*job
; /* Job information */
9345 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9346 username
[HTTP_MAX_URI
], /* Username portion of URI */
9347 host
[HTTP_MAX_URI
], /* Host portion of URI */
9348 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9349 int port
; /* Port portion of URI */
9352 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9353 con
->http
.fd
, uri
->values
[0].string
.text
);
9356 * See if we have a job URI or a printer URI...
9359 if (!strcmp(uri
->name
, "printer-uri"))
9362 * Got a printer URI; see if we also have a job-id attribute...
9365 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9366 IPP_TAG_INTEGER
)) == NULL
)
9368 send_ipp_status(con
, IPP_BAD_REQUEST
,
9369 _("Got a printer-uri attribute but no job-id!"));
9373 jobid
= attr
->values
[0].integer
;
9378 * Got a job URI; parse it to get the job ID...
9381 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9382 sizeof(scheme
), username
, sizeof(username
), host
,
9383 sizeof(host
), &port
, resource
, sizeof(resource
));
9385 if (strncmp(resource
, "/jobs/", 6))
9391 send_ipp_status(con
, IPP_BAD_REQUEST
,
9392 _("Bad job-uri attribute \"%s\"!"),
9393 uri
->values
[0].string
.text
);
9397 jobid
= atoi(resource
+ 6);
9401 * See if the job exists...
9404 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9407 * Nope - return a "not found" error...
9410 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9415 * See if job is in any of the "completed" states...
9418 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9421 * Nope - return a "not possible" error...
9424 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
9430 * See if we have retained the job files...
9435 if (!job
->attrs
|| job
->num_files
== 0)
9438 * Nope - return a "not possible" error...
9441 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9442 _("Job #%d cannot be restarted - no files!"), jobid
);
9447 * See if the job is owned by the requesting user...
9450 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9452 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9453 cupsdFindDest(job
->dest
));
9458 * See if the job-hold-until attribute is specified...
9461 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9462 IPP_TAG_KEYWORD
)) == NULL
)
9463 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9465 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9468 * Return the job to a held state...
9471 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9472 "Restarted by \"%s\" with job-hold-until=%s.",
9473 username
, attr
->values
[0].string
.text
);
9474 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9476 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9477 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9478 attr
->values
[0].string
.text
);
9483 * Restart the job...
9486 cupsdRestartJob(job
);
9490 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9492 con
->response
->request
.status
.status_code
= IPP_OK
;
9497 * 'save_auth_info()' - Save authentication information for a job.
9502 cupsd_client_t
*con
, /* I - Client connection */
9503 cupsd_job_t
*job
, /* I - Job */
9504 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9506 int i
; /* Looping var */
9507 char filename
[1024]; /* Job authentication filename */
9508 cups_file_t
*fp
; /* Job authentication file */
9509 char line
[2048]; /* Line for file */
9510 cupsd_printer_t
*dest
; /* Destination printer/class */
9514 * This function saves the in-memory authentication information for
9515 * a job so that it can be used to authenticate with a remote host.
9516 * The information is stored in a file that is readable only by the
9517 * root user. The fields are Base-64 encoded, each on a separate line,
9518 * followed by random number (up to 1024) of newlines to limit the
9519 * amount of information that is exposed.
9521 * Because of the potential for exposing of authentication information,
9522 * this functionality is only enabled when running cupsd as root.
9524 * This caching only works for the Basic and BasicDigest authentication
9525 * types. Digest authentication cannot be cached this way, and in
9526 * the future Kerberos authentication may make all of this obsolete.
9528 * Authentication information is saved whenever an authenticated
9529 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9532 * This information is deleted after a job is completed or canceled,
9533 * so reprints may require subsequent re-authentication.
9539 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9543 * Create the authentication file and change permissions...
9546 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9547 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9549 cupsdLogMessage(CUPSD_LOG_ERROR
,
9550 "Unable to save authentication info to \"%s\" - %s",
9551 filename
, strerror(errno
));
9555 fchown(cupsFileNumber(fp
), 0, 0);
9556 fchmod(cupsFileNumber(fp
), 0400);
9558 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9561 * Write 1 to 3 auth values...
9564 cupsdClearString(&job
->auth_username
);
9565 cupsdClearString(&job
->auth_domain
);
9566 cupsdClearString(&job
->auth_password
);
9568 for (i
= 0; i
< auth_info
->num_values
; i
++)
9570 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9571 strlen(auth_info
->values
[i
].string
.text
));
9572 cupsFilePrintf(fp
, "%s\n", line
);
9574 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9575 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9576 auth_info
->values
[i
].string
.text
);
9577 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9578 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9579 auth_info
->values
[i
].string
.text
);
9580 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9581 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9582 auth_info
->values
[i
].string
.text
);
9585 else if (con
->username
[0])
9588 * Write the authenticated username...
9591 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9592 cupsFilePrintf(fp
, "%s\n", line
);
9594 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9595 cupsdClearString(&job
->auth_domain
);
9598 * Write the authenticated password...
9601 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9602 cupsFilePrintf(fp
, "%s\n", line
);
9604 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
9608 * Write a random number of newlines to the end of the file...
9611 for (i
= (rand() % 1024); i
>= 0; i
--)
9612 cupsFilePutChar(fp
, '\n');
9615 * Close the file and return...
9620 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9621 # ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
9622 if (con
->have_gss
&&
9623 (con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
|| con
->gss_creds
))
9625 if (con
->have_gss
&& con
->gss_creds
)
9626 # endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
9627 save_krb5_creds(con
, job
);
9628 else if (job
->ccname
)
9629 cupsdClearString(&(job
->ccname
));
9630 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9634 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9636 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
9640 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
9641 cupsd_job_t
*job
) /* I - Job */
9644 * Get the credentials...
9647 job
->ccache
= cupsdCopyKrb5Creds(con
);
9650 * Add the KRB5CCNAME environment variable to the job so that the
9651 * backend can use the credentials when printing.
9656 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
9657 krb5_cc_get_name(KerberosContext
, job
->ccache
));
9659 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
9662 cupsdClearString(&(job
->ccname
));
9664 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9668 * 'send_document()' - Send a file to a printer or class.
9672 send_document(cupsd_client_t
*con
, /* I - Client connection */
9673 ipp_attribute_t
*uri
) /* I - Printer URI */
9675 ipp_attribute_t
*attr
; /* Current attribute */
9676 ipp_attribute_t
*format
; /* Request's document-format attribute */
9677 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9678 const char *default_format
;/* document-format-default value */
9679 int jobid
; /* Job ID number */
9680 cupsd_job_t
*job
; /* Current job */
9681 char job_uri
[HTTP_MAX_URI
],
9683 scheme
[HTTP_MAX_URI
],
9684 /* Method portion of URI */
9685 username
[HTTP_MAX_URI
],
9686 /* Username portion of URI */
9688 /* Host portion of URI */
9689 resource
[HTTP_MAX_URI
];
9690 /* Resource portion of URI */
9691 int port
; /* Port portion of URI */
9692 mime_type_t
*filetype
; /* Type of file */
9693 char super
[MIME_MAX_SUPER
],
9694 /* Supertype of file */
9695 type
[MIME_MAX_TYPE
],
9696 /* Subtype of file */
9697 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9698 /* Textual name of mime type */
9699 char filename
[1024]; /* Job filename */
9700 cupsd_printer_t
*printer
; /* Current printer */
9701 struct stat fileinfo
; /* File information */
9702 int kbytes
; /* Size of file */
9703 int compression
; /* Type of compression */
9704 int start_job
; /* Start the job? */
9707 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9708 con
->http
.fd
, uri
->values
[0].string
.text
);
9711 * See if we have a job URI or a printer URI...
9714 if (!strcmp(uri
->name
, "printer-uri"))
9717 * Got a printer URI; see if we also have a job-id attribute...
9720 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9721 IPP_TAG_INTEGER
)) == NULL
)
9723 send_ipp_status(con
, IPP_BAD_REQUEST
,
9724 _("Got a printer-uri attribute but no job-id!"));
9728 jobid
= attr
->values
[0].integer
;
9733 * Got a job URI; parse it to get the job ID...
9736 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9737 sizeof(scheme
), username
, sizeof(username
), host
,
9738 sizeof(host
), &port
, resource
, sizeof(resource
));
9740 if (strncmp(resource
, "/jobs/", 6))
9746 send_ipp_status(con
, IPP_BAD_REQUEST
,
9747 _("Bad job-uri attribute \"%s\"!"),
9748 uri
->values
[0].string
.text
);
9752 jobid
= atoi(resource
+ 6);
9756 * See if the job exists...
9759 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9762 * Nope - return a "not found" error...
9765 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9769 printer
= cupsdFindDest(job
->dest
);
9772 * See if the job is owned by the requesting user...
9775 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9777 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9778 cupsdFindDest(job
->dest
));
9783 * OK, see if the client is sending the document compressed - CUPS
9784 * only supports "none" and "gzip".
9787 compression
= CUPS_FILE_NONE
;
9789 if ((attr
= ippFindAttribute(con
->request
, "compression",
9790 IPP_TAG_KEYWORD
)) != NULL
)
9792 if (strcmp(attr
->values
[0].string
.text
, "none")
9794 && strcmp(attr
->values
[0].string
.text
, "gzip")
9795 #endif /* HAVE_LIBZ */
9798 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
9799 attr
->values
[0].string
.text
);
9800 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9801 "compression", NULL
, attr
->values
[0].string
.text
);
9806 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9807 compression
= CUPS_FILE_GZIP
;
9808 #endif /* HAVE_LIBZ */
9812 * Do we have a file to print?
9817 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
9822 * Is it a format we support?
9825 if ((format
= ippFindAttribute(con
->request
, "document-format",
9826 IPP_TAG_MIMETYPE
)) != NULL
)
9829 * Grab format from client...
9832 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9835 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9836 format
->values
[0].string
.text
);
9840 else if ((default_format
= cupsGetOption("document-format",
9841 printer
->num_options
,
9842 printer
->options
)) != NULL
)
9845 * Use default document format...
9848 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9850 send_ipp_status(con
, IPP_BAD_REQUEST
,
9851 _("Could not scan type \"%s\"!"),
9859 * No document format attribute? Auto-type it!
9862 strcpy(super
, "application");
9863 strcpy(type
, "octet-stream");
9866 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9869 * Auto-type the file...
9872 ipp_attribute_t
*doc_name
; /* document-name attribute */
9875 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9877 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9878 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9879 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9883 filetype
= mimeType(MimeDatabase
, super
, type
);
9885 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9886 filetype
->super
, filetype
->type
);
9889 filetype
= mimeType(MimeDatabase
, super
, type
);
9894 * Replace the document-format attribute value with the auto-typed or
9898 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9901 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9902 IPP_TAG_MIMETYPE
)) != NULL
)
9904 _cupsStrFree(jformat
->values
[0].string
.text
);
9906 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9909 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9910 "document-format", NULL
, mimetype
);
9914 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9915 _("Unsupported format \'%s/%s\'!"), super
, type
);
9916 cupsdLogMessage(CUPSD_LOG_INFO
,
9917 "Hint: Do you have the raw file printing rules enabled?");
9920 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9921 "document-format", NULL
, format
->values
[0].string
.text
);
9926 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9928 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9931 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9932 _("Unsupported format \'%s\'!"), mimetype
);
9934 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9935 "document-format", NULL
, mimetype
);
9941 * Add the file to the job...
9946 if (add_file(con
, job
, filetype
, compression
))
9949 if (stat(con
->filename
, &fileinfo
))
9952 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9954 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9956 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9957 IPP_TAG_INTEGER
)) != NULL
)
9958 attr
->values
[0].integer
+= kbytes
;
9960 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9962 rename(con
->filename
, filename
);
9964 cupsdClearString(&con
->filename
);
9966 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9967 filetype
->super
, filetype
->type
, job
->username
);
9970 * Start the job if this is the last document...
9973 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9974 IPP_TAG_BOOLEAN
)) != NULL
&&
9975 attr
->values
[0].boolean
)
9978 * See if we need to add the ending sheet...
9981 if (cupsdTimeoutJob(job
))
9984 if (job
->state_value
== IPP_JOB_STOPPED
)
9986 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9987 job
->state_value
= IPP_JOB_PENDING
;
9989 else if (job
->state_value
== IPP_JOB_HELD
)
9991 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9992 IPP_TAG_KEYWORD
)) == NULL
)
9993 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9995 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9997 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9998 job
->state_value
= IPP_JOB_PENDING
;
10003 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10009 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10010 IPP_TAG_KEYWORD
)) == NULL
)
10011 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10013 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10015 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10016 job
->state_value
= IPP_JOB_HELD
;
10017 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10020 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10027 * Fill in the response info...
10030 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10033 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10036 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10038 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10040 add_job_state_reasons(con
, job
);
10042 con
->response
->request
.status
.status_code
= IPP_OK
;
10045 * Start the job if necessary...
10054 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10059 cupsd_client_t
*con
, /* I - Client connection */
10060 http_status_t status
, /* I - HTTP status code */
10061 cupsd_printer_t
*printer
) /* I - Printer, if any */
10063 ipp_attribute_t
*uri
; /* Request URI, if any */
10066 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10067 IPP_TAG_URI
)) == NULL
)
10068 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10070 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10071 "Returning HTTP %s for %s (%s) from %s",
10072 httpStatus(status
),
10073 ippOpString(con
->request
->request
.op
.operation_id
),
10074 uri
? uri
->values
[0].string
.text
: "no URI",
10075 con
->http
.hostname
);
10079 int auth_type
; /* Type of authentication required */
10082 auth_type
= CUPSD_AUTH_NONE
;
10084 if (status
== HTTP_UNAUTHORIZED
&&
10085 printer
->num_auth_info_required
> 0 &&
10086 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10088 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10089 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10090 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10093 * Creating and authenticating jobs requires Kerberos...
10096 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10101 * Use policy/location-defined authentication requirements...
10104 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10105 cupsd_location_t
*auth
; /* Pointer to authentication element */
10108 if (printer
->type
& CUPS_PRINTER_CLASS
)
10109 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10111 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10113 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10114 auth
->type
== CUPSD_AUTH_NONE
)
10115 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10117 con
->request
->request
.op
.operation_id
:
10122 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10123 auth_type
= DefaultAuthType
;
10125 auth_type
= auth
->type
;
10129 cupsdSendError(con
, status
, auth_type
);
10132 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10134 ippDelete(con
->response
);
10135 con
->response
= NULL
;
10142 * 'send_ipp_status()' - Send a status back to the IPP client.
10146 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10147 ipp_status_t status
, /* I - IPP status code */
10148 const char *message
,/* I - Status message */
10149 ...) /* I - Additional args as needed */
10151 va_list ap
; /* Pointer to additional args */
10152 char formatted
[1024]; /* Formatted errror message */
10155 va_start(ap
, message
);
10156 vsnprintf(formatted
, sizeof(formatted
),
10157 _cupsLangString(con
->language
, message
), ap
);
10160 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10161 ippOpString(con
->request
->request
.op
.operation_id
),
10162 ippErrorString(status
), formatted
);
10164 con
->response
->request
.status
.status_code
= status
;
10166 if (ippFindAttribute(con
->response
, "attributes-charset",
10167 IPP_TAG_ZERO
) == NULL
)
10168 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10169 "attributes-charset", NULL
, DefaultCharset
);
10171 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10172 IPP_TAG_ZERO
) == NULL
)
10173 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10174 "attributes-natural-language", NULL
, DefaultLanguage
);
10176 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10177 "status-message", NULL
, formatted
);
10182 * 'set_default()' - Set the default destination...
10186 set_default(cupsd_client_t
*con
, /* I - Client connection */
10187 ipp_attribute_t
*uri
) /* I - Printer URI */
10189 http_status_t status
; /* Policy status */
10190 cups_ptype_t dtype
; /* Destination type (printer/class) */
10191 cupsd_printer_t
*printer
, /* Printer */
10192 *oldprinter
; /* Old default printer */
10195 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10196 con
->http
.fd
, uri
->values
[0].string
.text
);
10199 * Is the destination valid?
10202 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10208 send_ipp_status(con
, IPP_NOT_FOUND
,
10209 _("The printer or class was not found."));
10217 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10219 send_http_error(con
, status
, NULL
);
10224 * Set it as the default...
10227 oldprinter
= DefaultPrinter
;
10228 DefaultPrinter
= printer
;
10231 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10232 "%s is no longer the default printer.", oldprinter
->name
);
10234 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10235 "%s is now the default printer.", printer
->name
);
10237 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10238 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10240 cupsdLogMessage(CUPSD_LOG_INFO
,
10241 "Default destination set to \"%s\" by \"%s\".",
10242 printer
->name
, get_username(con
));
10245 * Everything was ok, so return OK status...
10248 con
->response
->request
.status
.status_code
= IPP_OK
;
10253 * 'set_job_attrs()' - Set job attributes.
10257 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10258 ipp_attribute_t
*uri
) /* I - Job URI */
10260 ipp_attribute_t
*attr
, /* Current attribute */
10261 *attr2
; /* Job attribute */
10262 int jobid
; /* Job ID */
10263 cupsd_job_t
*job
; /* Current job */
10264 char scheme
[HTTP_MAX_URI
],
10265 /* Method portion of URI */
10266 username
[HTTP_MAX_URI
],
10267 /* Username portion of URI */
10268 host
[HTTP_MAX_URI
],
10269 /* Host portion of URI */
10270 resource
[HTTP_MAX_URI
];
10271 /* Resource portion of URI */
10272 int port
; /* Port portion of URI */
10273 int event
; /* Events? */
10274 int check_jobs
; /* Check jobs? */
10277 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10278 con
->http
.fd
, uri
->values
[0].string
.text
);
10281 * Start with "everything is OK" status...
10284 con
->response
->request
.status
.status_code
= IPP_OK
;
10287 * See if we have a job URI or a printer URI...
10290 if (!strcmp(uri
->name
, "printer-uri"))
10293 * Got a printer URI; see if we also have a job-id attribute...
10296 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10297 IPP_TAG_INTEGER
)) == NULL
)
10299 send_ipp_status(con
, IPP_BAD_REQUEST
,
10300 _("Got a printer-uri attribute but no job-id!"));
10304 jobid
= attr
->values
[0].integer
;
10309 * Got a job URI; parse it to get the job ID...
10312 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10313 sizeof(scheme
), username
, sizeof(username
), host
,
10314 sizeof(host
), &port
, resource
, sizeof(resource
));
10316 if (strncmp(resource
, "/jobs/", 6))
10322 send_ipp_status(con
, IPP_BAD_REQUEST
,
10323 _("Bad job-uri attribute \"%s\"!"),
10324 uri
->values
[0].string
.text
);
10328 jobid
= atoi(resource
+ 6);
10332 * See if the job exists...
10335 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10338 * Nope - return a "not found" error...
10341 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
10346 * See if the job has been completed...
10349 if (job
->state_value
> IPP_JOB_STOPPED
)
10352 * Return a "not-possible" error...
10355 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10356 _("Job #%d is finished and cannot be altered!"), jobid
);
10361 * See if the job is owned by the requesting user...
10364 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10366 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10367 cupsdFindDest(job
->dest
));
10372 * See what the user wants to change.
10380 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10382 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10385 if (!strcmp(attr
->name
, "attributes-charset") ||
10386 !strcmp(attr
->name
, "attributes-natural-language") ||
10387 !strcmp(attr
->name
, "document-compression") ||
10388 !strcmp(attr
->name
, "document-format") ||
10389 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10390 !strcmp(attr
->name
, "job-document-access-errors") ||
10391 !strcmp(attr
->name
, "job-id") ||
10392 !strcmp(attr
->name
, "job-impressions-completed") ||
10393 !strcmp(attr
->name
, "job-k-octets") ||
10394 !strcmp(attr
->name
, "job-originating-host-name") ||
10395 !strcmp(attr
->name
, "job-originating-user-name") ||
10396 !strcmp(attr
->name
, "job-printer-up-time") ||
10397 !strcmp(attr
->name
, "job-printer-uri") ||
10398 !strcmp(attr
->name
, "job-sheets") ||
10399 !strcmp(attr
->name
, "job-state-message") ||
10400 !strcmp(attr
->name
, "job-state-reasons") ||
10401 !strcmp(attr
->name
, "job-uri") ||
10402 !strcmp(attr
->name
, "number-of-documents") ||
10403 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10404 !strcmp(attr
->name
, "output-device-assigned") ||
10405 !strncmp(attr
->name
, "date-time-at-", 13) ||
10406 !strncmp(attr
->name
, "job-k-octets", 12) ||
10407 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10408 !strncmp(attr
->name
, "time-at-", 8))
10414 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10415 _("%s cannot be changed."), attr
->name
);
10417 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10418 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10423 if (!strcmp(attr
->name
, "job-priority"))
10426 * Change the job priority...
10429 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10431 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
10433 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10434 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10436 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10438 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10439 _("Job is completed and cannot be changed."));
10442 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10444 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10445 attr
->values
[0].integer
);
10446 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10449 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10450 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10453 else if (!strcmp(attr
->name
, "job-state"))
10456 * Change the job state...
10459 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10461 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
10463 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10464 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10468 switch (attr
->values
[0].integer
)
10470 case IPP_JOB_PENDING
:
10471 case IPP_JOB_HELD
:
10472 if (job
->state_value
> IPP_JOB_HELD
)
10474 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10475 _("Job state cannot be changed."));
10478 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10480 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10481 attr
->values
[0].integer
);
10482 cupsdSetJobState(job
, attr
->values
[0].integer
,
10484 "Job state changed by \"%s\"", username
);
10489 case IPP_JOB_PROCESSING
:
10490 case IPP_JOB_STOPPED
:
10491 if (job
->state_value
!= attr
->values
[0].integer
)
10493 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10494 _("Job state cannot be changed."));
10499 case IPP_JOB_CANCELED
:
10500 case IPP_JOB_ABORTED
:
10501 case IPP_JOB_COMPLETED
:
10502 if (job
->state_value
> IPP_JOB_PROCESSING
)
10504 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10505 _("Job state cannot be changed."));
10508 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10510 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10511 attr
->values
[0].integer
);
10512 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10514 "Job state changed by \"%s\"", username
);
10521 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10523 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10524 IPP_TAG_ZERO
)) != NULL
)
10527 * Some other value; first free the old value...
10530 if (job
->attrs
->prev
)
10531 job
->attrs
->prev
->next
= attr2
->next
;
10533 job
->attrs
->attrs
= attr2
->next
;
10535 if (job
->attrs
->last
== attr2
)
10536 job
->attrs
->last
= job
->attrs
->prev
;
10538 _ippFreeAttr(attr2
);
10541 * Then copy the attribute...
10544 copy_attribute(job
->attrs
, attr
, 0);
10547 * See if the job-name or job-hold-until is being changed.
10550 if (!strcmp(attr
->name
, "job-hold-until"))
10552 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10553 attr
->values
[0].string
.text
);
10554 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10556 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10558 cupsdReleaseJob(job
);
10562 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10563 "Job held by \"%s\".", username
);
10565 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10568 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10571 * Delete the attribute...
10574 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10575 IPP_TAG_ZERO
)) != NULL
)
10577 if (job
->attrs
->prev
)
10578 job
->attrs
->prev
->next
= attr2
->next
;
10580 job
->attrs
->attrs
= attr2
->next
;
10582 if (attr2
== job
->attrs
->last
)
10583 job
->attrs
->last
= job
->attrs
->prev
;
10585 _ippFreeAttr(attr2
);
10587 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10593 * Add new option by copying it...
10596 copy_attribute(job
->attrs
, attr
, 0);
10598 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10607 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10610 * Send events as needed...
10613 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10614 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10615 cupsdFindDest(job
->dest
), job
,
10616 "Job priority changed by user.");
10618 if (event
& CUPSD_EVENT_JOB_STATE
)
10619 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10620 job
->state_value
== IPP_JOB_HELD
?
10621 "Job held by user." : "Job restarted by user.");
10623 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10624 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10625 "Job options changed by user.");
10628 * Start jobs if possible...
10637 * 'set_printer_attrs()' - Set printer attributes.
10641 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10642 ipp_attribute_t
*uri
) /* I - Printer */
10644 http_status_t status
; /* Policy status */
10645 cups_ptype_t dtype
; /* Destination type (printer/class) */
10646 cupsd_printer_t
*printer
; /* Printer/class */
10647 ipp_attribute_t
*attr
; /* Printer attribute */
10648 int changed
= 0; /* Was anything changed? */
10651 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10652 con
->http
.fd
, uri
->values
[0].string
.text
);
10655 * Is the destination valid?
10658 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10664 send_ipp_status(con
, IPP_NOT_FOUND
,
10665 _("The printer or class was not found."));
10673 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10675 send_http_error(con
, status
, printer
);
10680 * Return a list of attributes that can be set via Set-Printer-Attributes.
10683 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10684 IPP_TAG_TEXT
)) != NULL
)
10686 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10690 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10691 IPP_TAG_TEXT
)) != NULL
)
10693 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10698 * Update the printer attributes and return...
10703 cupsdSetPrinterAttrs(printer
);
10704 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10706 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10707 "Printer \"%s\" description or location changed by \"%s\".",
10708 printer
->name
, get_username(con
));
10710 cupsdLogMessage(CUPSD_LOG_INFO
,
10711 "Printer \"%s\" description or location changed by \"%s\".",
10712 printer
->name
, get_username(con
));
10715 con
->response
->request
.status
.status_code
= IPP_OK
;
10720 * 'set_printer_defaults()' - Set printer default options from a request.
10724 set_printer_defaults(
10725 cupsd_client_t
*con
, /* I - Client connection */
10726 cupsd_printer_t
*printer
) /* I - Printer */
10728 int i
; /* Looping var */
10729 ipp_attribute_t
*attr
; /* Current attribute */
10730 int namelen
; /* Length of attribute name */
10731 char name
[256], /* New attribute name */
10732 value
[256]; /* String version of integer attrs */
10735 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10738 * Skip non-printer attributes...
10741 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10744 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10746 if (!strcmp(attr
->name
, "job-sheets-default"))
10749 * Only allow keywords and names...
10752 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10756 * Only allow job-sheets-default to be set when running without a
10757 * system high classification level...
10760 if (Classification
)
10763 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10765 if (attr
->num_values
> 1)
10766 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10768 cupsdSetString(&printer
->job_sheets
[1], "none");
10770 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10772 cupsdFreePrinterUsers(printer
);
10774 printer
->deny_users
= 0;
10776 if (attr
->value_tag
== IPP_TAG_NAME
&&
10777 (attr
->num_values
> 1 ||
10778 strcmp(attr
->values
[0].string
.text
, "all")))
10780 for (i
= 0; i
< attr
->num_values
; i
++)
10781 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10784 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10786 cupsdFreePrinterUsers(printer
);
10788 printer
->deny_users
= 1;
10790 if (attr
->value_tag
== IPP_TAG_NAME
&&
10791 (attr
->num_values
> 1 ||
10792 strcmp(attr
->values
[0].string
.text
, "none")))
10794 for (i
= 0; i
< attr
->num_values
; i
++)
10795 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10798 else if (!strcmp(attr
->name
, "job-quota-period"))
10800 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10803 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10804 attr
->values
[0].integer
);
10805 cupsdFreeQuotas(printer
);
10807 printer
->quota_period
= attr
->values
[0].integer
;
10809 else if (!strcmp(attr
->name
, "job-k-limit"))
10811 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10814 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10815 attr
->values
[0].integer
);
10816 cupsdFreeQuotas(printer
);
10818 printer
->k_limit
= attr
->values
[0].integer
;
10820 else if (!strcmp(attr
->name
, "job-page-limit"))
10822 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10825 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10826 attr
->values
[0].integer
);
10827 cupsdFreeQuotas(printer
);
10829 printer
->page_limit
= attr
->values
[0].integer
;
10831 else if (!strcmp(attr
->name
, "printer-op-policy"))
10833 cupsd_policy_t
*p
; /* Policy */
10836 if (attr
->value_tag
!= IPP_TAG_NAME
)
10839 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10841 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10842 "Setting printer-op-policy to \"%s\"...",
10843 attr
->values
[0].string
.text
);
10844 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10845 printer
->op_policy_ptr
= p
;
10849 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10850 _("Unknown printer-op-policy \"%s\"."),
10851 attr
->values
[0].string
.text
);
10855 else if (!strcmp(attr
->name
, "printer-error-policy"))
10857 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10860 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10861 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
10862 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10863 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10864 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10866 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10867 _("Unknown printer-error-policy \"%s\"."),
10868 attr
->values
[0].string
.text
);
10872 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10873 "Setting printer-error-policy to \"%s\"...",
10874 attr
->values
[0].string
.text
);
10875 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10879 * Skip any other non-default attributes...
10882 namelen
= strlen(attr
->name
);
10883 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10884 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10888 * OK, anything else must be a user-defined default...
10891 strlcpy(name
, attr
->name
, sizeof(name
));
10892 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10894 switch (attr
->value_tag
)
10896 case IPP_TAG_DELETEATTR
:
10897 printer
->num_options
= cupsRemoveOption(name
,
10898 printer
->num_options
,
10899 &(printer
->options
));
10900 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10901 "Deleting %s", attr
->name
);
10904 case IPP_TAG_NAME
:
10905 case IPP_TAG_KEYWORD
:
10907 printer
->num_options
= cupsAddOption(name
,
10908 attr
->values
[0].string
.text
,
10909 printer
->num_options
,
10910 &(printer
->options
));
10911 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10912 "Setting %s to \"%s\"...", attr
->name
,
10913 attr
->values
[0].string
.text
);
10916 case IPP_TAG_BOOLEAN
:
10917 printer
->num_options
= cupsAddOption(name
,
10918 attr
->values
[0].boolean
?
10920 printer
->num_options
,
10921 &(printer
->options
));
10922 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10923 "Setting %s to %s...", attr
->name
,
10924 attr
->values
[0].boolean
? "true" : "false");
10927 case IPP_TAG_INTEGER
:
10928 case IPP_TAG_ENUM
:
10929 sprintf(value
, "%d", attr
->values
[0].integer
);
10930 printer
->num_options
= cupsAddOption(name
, value
,
10931 printer
->num_options
,
10932 &(printer
->options
));
10933 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10934 "Setting %s to %s...", attr
->name
, value
);
10937 case IPP_TAG_RANGE
:
10938 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10939 attr
->values
[0].range
.upper
);
10940 printer
->num_options
= cupsAddOption(name
, value
,
10941 printer
->num_options
,
10942 &(printer
->options
));
10943 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10944 "Setting %s to %s...", attr
->name
, value
);
10947 case IPP_TAG_RESOLUTION
:
10948 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10949 attr
->values
[0].resolution
.yres
,
10950 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10952 printer
->num_options
= cupsAddOption(name
, value
,
10953 printer
->num_options
,
10954 &(printer
->options
));
10955 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10956 "Setting %s to %s...", attr
->name
, value
);
10960 /* Do nothing for other values */
10968 * 'start_printer()' - Start a printer.
10972 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10973 ipp_attribute_t
*uri
) /* I - Printer URI */
10975 http_status_t status
; /* Policy status */
10976 cups_ptype_t dtype
; /* Destination type (printer/class) */
10977 cupsd_printer_t
*printer
; /* Printer data */
10980 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10981 con
->http
.fd
, uri
->values
[0].string
.text
);
10984 * Is the destination valid?
10987 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10993 send_ipp_status(con
, IPP_NOT_FOUND
,
10994 _("The printer or class was not found."));
11002 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11004 send_http_error(con
, status
, printer
);
11009 * Start the printer...
11012 printer
->state_message
[0] = '\0';
11014 cupsdStartPrinter(printer
, 1);
11016 if (dtype
& CUPS_PRINTER_CLASS
)
11017 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11018 printer
->name
, get_username(con
));
11020 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11021 printer
->name
, get_username(con
));
11026 * Everything was ok, so return OK status...
11029 con
->response
->request
.status
.status_code
= IPP_OK
;
11034 * 'stop_printer()' - Stop a printer.
11038 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11039 ipp_attribute_t
*uri
) /* I - Printer URI */
11041 http_status_t status
; /* Policy status */
11042 cups_ptype_t dtype
; /* Destination type (printer/class) */
11043 cupsd_printer_t
*printer
; /* Printer data */
11044 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11047 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11048 con
->http
.fd
, uri
->values
[0].string
.text
);
11051 * Is the destination valid?
11054 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11060 send_ipp_status(con
, IPP_NOT_FOUND
,
11061 _("The printer or class was not found."));
11069 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11071 send_http_error(con
, status
, printer
);
11076 * Stop the printer...
11079 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11080 IPP_TAG_TEXT
)) == NULL
)
11081 strcpy(printer
->state_message
, "Paused");
11084 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11085 sizeof(printer
->state_message
));
11088 cupsdStopPrinter(printer
, 1);
11090 if (dtype
& CUPS_PRINTER_CLASS
)
11091 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11092 printer
->name
, get_username(con
));
11094 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11095 printer
->name
, get_username(con
));
11098 * Everything was ok, so return OK status...
11101 con
->response
->request
.status
.status_code
= IPP_OK
;
11106 * 'url_encode_attr()' - URL-encode a string attribute.
11110 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11111 char *buffer
,/* I - String buffer */
11112 int bufsize
)/* I - Size of buffer */
11114 int i
; /* Looping var */
11115 char *bufptr
, /* Pointer into buffer */
11116 *bufend
; /* End of buffer */
11119 strlcpy(buffer
, attr
->name
, bufsize
);
11120 bufptr
= buffer
+ strlen(buffer
);
11121 bufend
= buffer
+ bufsize
- 1;
11123 for (i
= 0; i
< attr
->num_values
; i
++)
11125 if (bufptr
>= bufend
)
11133 if (bufptr
>= bufend
)
11138 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11139 bufptr
, bufend
- bufptr
+ 1);
11141 if (bufptr
>= bufend
)
11152 * 'url_encode_string()' - URL-encode a string.
11155 static char * /* O - End of string */
11156 url_encode_string(const char *s
, /* I - String */
11157 char *buffer
, /* I - String buffer */
11158 int bufsize
) /* I - Size of buffer */
11160 char *bufptr
, /* Pointer into buffer */
11161 *bufend
; /* End of buffer */
11162 static const char *hex
= "0123456789ABCDEF";
11167 bufend
= buffer
+ bufsize
- 1;
11169 while (*s
&& bufptr
< bufend
)
11171 if (*s
== ' ' || *s
== '%' || *s
== '+')
11173 if (bufptr
>= (bufend
- 2))
11177 *bufptr
++ = hex
[(*s
>> 4) & 15];
11178 *bufptr
++ = hex
[*s
& 15];
11182 else if (*s
== '\'' || *s
== '\\')
11184 if (bufptr
>= (bufend
- 1))
11201 * 'user_allowed()' - See if a user is allowed to print to a queue.
11204 static int /* O - 0 if not allowed, 1 if allowed */
11205 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11206 const char *username
) /* I - Username */
11208 int i
; /* Looping var */
11209 struct passwd
*pw
; /* User password data */
11210 char baseuser
[256], /* Base username */
11211 *baseptr
; /* Pointer to "@" in base username */
11214 if (p
->num_users
== 0)
11217 if (!strcmp(username
, "root"))
11220 if (strchr(username
, '@'))
11223 * Strip @REALM for username check...
11226 strlcpy(baseuser
, username
, sizeof(baseuser
));
11228 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11231 username
= baseuser
;
11234 pw
= getpwnam(username
);
11237 for (i
= 0; i
< p
->num_users
; i
++)
11239 if (p
->users
[i
][0] == '@')
11242 * Check group membership...
11245 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
11248 else if (p
->users
[i
][0] == '#')
11254 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
11257 else if (!strcasecmp(username
, p
->users
[i
]))
11261 return ((i
< p
->num_users
) != p
->deny_users
);
11266 * 'validate_job()' - Validate printer options and destination.
11270 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11271 ipp_attribute_t
*uri
) /* I - Printer URI */
11273 http_status_t status
; /* Policy status */
11274 ipp_attribute_t
*attr
; /* Current attribute */
11275 ipp_attribute_t
*format
; /* Document-format attribute */
11276 cups_ptype_t dtype
; /* Destination type (printer/class) */
11277 char super
[MIME_MAX_SUPER
],
11278 /* Supertype of file */
11279 type
[MIME_MAX_TYPE
];
11280 /* Subtype of file */
11281 cupsd_printer_t
*printer
; /* Printer */
11284 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11285 con
->http
.fd
, uri
->values
[0].string
.text
);
11288 * OK, see if the client is sending the document compressed - CUPS
11289 * doesn't support compression yet...
11292 if ((attr
= ippFindAttribute(con
->request
, "compression",
11293 IPP_TAG_KEYWORD
)) != NULL
&&
11294 !strcmp(attr
->values
[0].string
.text
, "none"))
11296 send_ipp_status(con
, IPP_ATTRIBUTES
,
11297 _("Unsupported compression attribute %s!"),
11298 attr
->values
[0].string
.text
);
11299 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11300 "compression", NULL
, attr
->values
[0].string
.text
);
11305 * Is it a format we support?
11308 if ((format
= ippFindAttribute(con
->request
, "document-format",
11309 IPP_TAG_MIMETYPE
)) != NULL
)
11311 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11314 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
11315 format
->values
[0].string
.text
);
11319 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11320 !mimeType(MimeDatabase
, super
, type
))
11322 cupsdLogMessage(CUPSD_LOG_INFO
,
11323 "Hint: Do you have the raw file printing rules enabled?");
11324 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11325 _("Unsupported format \"%s\"!"),
11326 format
->values
[0].string
.text
);
11327 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11328 "document-format", NULL
, format
->values
[0].string
.text
);
11334 * Is the destination valid?
11337 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11343 send_ipp_status(con
, IPP_NOT_FOUND
,
11344 _("The printer or class was not found."));
11352 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11354 send_http_error(con
, status
, printer
);
11359 * Everything was ok, so return OK status...
11362 con
->response
->request
.status
.status_code
= IPP_OK
;
11367 * 'validate_name()' - Make sure the printer name only contains valid chars.
11370 static int /* O - 0 if name is no good, 1 if good */
11371 validate_name(const char *name
) /* I - Name to check */
11373 const char *ptr
; /* Pointer into name */
11377 * Scan the whole name...
11380 for (ptr
= name
; *ptr
; ptr
++)
11381 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11385 * All the characters are good; validate the length, too...
11388 return ((ptr
- name
) < 128);
11393 * 'validate_user()' - Validate the user for the request.
11396 static int /* O - 1 if permitted, 0 otherwise */
11397 validate_user(cupsd_job_t
*job
, /* I - Job */
11398 cupsd_client_t
*con
, /* I - Client connection */
11399 const char *owner
, /* I - Owner of job/resource */
11400 char *username
, /* O - Authenticated username */
11401 int userlen
) /* I - Length of username */
11403 cupsd_printer_t
*printer
; /* Printer for job */
11406 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11407 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11409 job
->id
, con
? con
->http
.fd
: 0,
11410 owner
? owner
: "(null)", username
, userlen
);
11413 * Validate input...
11416 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11420 * Get the best authenticated username that is available.
11423 strlcpy(username
, get_username(con
), userlen
);
11426 * Check the username against the owner...
11429 printer
= cupsdFindDest(job
->dest
);
11431 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11432 con
, owner
) == HTTP_OK
);
11437 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".