2 * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2012 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_subscriptions() - Add any subscriptions for a job.
27 * add_job_uuid() - Add job-uuid attribute to a job.
28 * add_printer() - Add a printer to the system.
29 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
30 * based upon the printer state...
31 * add_queued_job_count() - Add the "queued-job-count" attribute for the
32 * specified printer or class.
33 * apply_printer_defaults() - Apply printer default options to a job.
34 * authenticate_job() - Set job authentication info.
35 * cancel_all_jobs() - Cancel all or selected print jobs.
36 * cancel_job() - Cancel a print job.
37 * cancel_subscription() - Cancel a subscription.
38 * check_rss_recipient() - Check that we do not have a duplicate RSS
40 * check_quotas() - Check quotas for a printer and user.
41 * close_job() - Close a multi-file job.
42 * copy_attrs() - Copy attributes from one request to another.
43 * copy_banner() - Copy a banner file to the requests directory
44 * for the specified job.
45 * copy_file() - Copy a PPD file or interface script...
46 * copy_model() - Copy a PPD model file, substituting default
48 * copy_job_attrs() - Copy job attributes.
49 * copy_printer_attrs() - Copy printer attributes.
50 * copy_subscription_attrs() - Copy subscription attributes.
51 * create_job() - Print a file to a printer or class.
52 * create_requested_array() - Create an array for the requested-attributes.
53 * create_subscription() - Create a notification subscription.
54 * delete_printer() - Remove a printer or class from the system.
55 * get_default() - Get the default destination.
56 * get_devices() - Get the list of available devices on the
58 * get_document() - Get a copy of a job file.
59 * get_job_attrs() - Get job attributes.
60 * get_jobs() - Get a list of jobs for the specified printer.
61 * get_notifications() - Get events for a subscription.
62 * get_ppd() - Get a named PPD from the local system.
63 * get_ppds() - Get the list of PPD files on the local
65 * get_printer_attrs() - Get printer attributes.
66 * get_printer_supported() - Get printer supported values.
67 * get_printers() - Get a list of printers or classes.
68 * get_subscription_attrs() - Get subscription attributes.
69 * get_subscriptions() - Get subscriptions.
70 * get_username() - Get the username associated with a request.
71 * hold_job() - Hold a print job.
72 * hold_new_jobs() - Hold pending/new jobs on a printer or class.
73 * move_job() - Move a job to a new destination.
74 * ppd_parse_line() - Parse a PPD default line.
75 * print_job() - Print a file to a printer or class.
76 * read_job_ticket() - Read a job ticket embedded in a print file.
77 * reject_jobs() - Reject print jobs to a printer.
78 * release_held_new_jobs() - Release pending/new jobs on a printer or
80 * release_job() - Release a held print job.
81 * renew_subscription() - Renew an existing subscription...
82 * restart_job() - Restart an old print job.
83 * save_auth_info() - Save authentication information for a job.
84 * send_document() - Send a file to a printer or class.
85 * send_http_error() - Send a HTTP error back to the IPP client.
86 * send_ipp_status() - Send a status back to the IPP client.
87 * set_default() - Set the default destination...
88 * set_job_attrs() - Set job attributes.
89 * set_printer_attrs() - Set printer attributes.
90 * set_printer_defaults() - Set printer default options from a request.
91 * start_printer() - Start a printer.
92 * stop_printer() - Stop a printer.
93 * url_encode_attr() - URL-encode a string attribute.
94 * url_encode_string() - URL-encode a string.
95 * user_allowed() - See if a user is allowed to print to a queue.
96 * validate_job() - Validate printer options and destination.
97 * validate_name() - Make sure the printer name only contains
99 * validate_user() - Validate the user for the request.
103 * Include necessary headers...
107 #include <cups/ppd-private.h>
110 /*# include <ApplicationServices/ApplicationServices.h>
111 extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
112 # include <CoreFoundation/CoreFoundation.h>*/
113 # ifdef HAVE_MEMBERSHIP_H
114 # include <membership.h>
115 # endif /* HAVE_MEMBERSHIP_H */
116 # ifdef HAVE_MEMBERSHIPPRIV_H
117 # include <membershipPriv.h>
119 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
120 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
121 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
122 # endif /* HAVE_MEMBERSHIPPRIV_H */
123 #endif /* __APPLE__ */
130 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
131 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
132 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
133 mime_type_t
*filetype
, int compression
);
134 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
135 mime_type_t
*filetype
);
136 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
137 static void add_job_uuid(cupsd_job_t
*job
);
138 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
139 static void add_printer_state_reasons(cupsd_client_t
*con
,
141 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
142 static void apply_printer_defaults(cupsd_printer_t
*printer
,
144 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
145 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
146 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
147 static void cancel_subscription(cupsd_client_t
*con
, int id
);
148 static int check_rss_recipient(const char *recipient
);
149 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
150 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
151 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
152 ipp_tag_t group
, int quickcopy
,
153 cups_array_t
*exclude
);
154 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
156 static int copy_file(const char *from
, const char *to
);
157 static int copy_model(cupsd_client_t
*con
, const char *from
,
159 static void copy_job_attrs(cupsd_client_t
*con
,
161 cups_array_t
*ra
, cups_array_t
*exclude
);
162 static void copy_printer_attrs(cupsd_client_t
*con
,
163 cupsd_printer_t
*printer
,
165 static void copy_subscription_attrs(cupsd_client_t
*con
,
166 cupsd_subscription_t
*sub
,
168 cups_array_t
*exclude
);
169 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
170 static cups_array_t
*create_requested_array(ipp_t
*request
);
171 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
172 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
173 static void get_default(cupsd_client_t
*con
);
174 static void get_devices(cupsd_client_t
*con
);
175 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
176 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
177 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
178 static void get_notifications(cupsd_client_t
*con
);
179 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
180 static void get_ppds(cupsd_client_t
*con
);
181 static void get_printers(cupsd_client_t
*con
, int type
);
182 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
183 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
184 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
185 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static const char *get_username(cupsd_client_t
*con
);
187 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
188 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
189 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static int ppd_parse_line(const char *line
, char *option
, int olen
,
191 char *choice
, int clen
);
192 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
193 static void read_job_ticket(cupsd_client_t
*con
);
194 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
195 static void release_held_new_jobs(cupsd_client_t
*con
,
196 ipp_attribute_t
*uri
);
197 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
199 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
200 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
201 ipp_attribute_t
*auth_info
);
202 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
203 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
204 cupsd_printer_t
*printer
);
205 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
206 const char *message
, ...)
207 __attribute__((__format__(__printf__
, 3, 4)));
208 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
209 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
210 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
211 static void set_printer_defaults(cupsd_client_t
*con
,
212 cupsd_printer_t
*printer
);
213 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
214 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
215 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
217 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
218 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
219 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
220 static int validate_name(const char *name
);
221 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
222 const char *owner
, char *username
,
227 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
230 int /* O - 1 on success, 0 on failure */
231 cupsdProcessIPPRequest(
232 cupsd_client_t
*con
) /* I - Client connection */
234 ipp_tag_t group
; /* Current group tag */
235 ipp_attribute_t
*attr
; /* Current attribute */
236 ipp_attribute_t
*charset
; /* Character set attribute */
237 ipp_attribute_t
*language
; /* Language attribute */
238 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
239 ipp_attribute_t
*username
; /* requesting-user-name attr */
240 int sub_id
; /* Subscription ID */
243 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
244 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
245 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
248 * First build an empty response message for this request...
251 con
->response
= ippNew();
253 con
->response
->request
.status
.version
[0] =
254 con
->request
->request
.op
.version
[0];
255 con
->response
->request
.status
.version
[1] =
256 con
->request
->request
.op
.version
[1];
257 con
->response
->request
.status
.request_id
=
258 con
->request
->request
.op
.request_id
;
261 * Then validate the request header and required attributes...
264 if (con
->request
->request
.any
.version
[0] != 1 &&
265 con
->request
->request
.any
.version
[0] != 2)
268 * Return an error, since we only support IPP 1.x and 2.x.
271 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
272 "%04X %s Bad request version number %d.%d",
273 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
274 con
->request
->request
.any
.version
[0],
275 con
->request
->request
.any
.version
[1]);
277 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
278 _("Bad request version number %d.%d."),
279 con
->request
->request
.any
.version
[0],
280 con
->request
->request
.any
.version
[1]);
282 else if (con
->request
->request
.any
.request_id
< 1)
285 * Return an error, since request IDs must be between 1 and 2^31-1
288 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
289 "%04X %s Bad request ID %d",
290 IPP_BAD_REQUEST
, con
->http
.hostname
,
291 con
->request
->request
.any
.request_id
);
293 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
294 con
->request
->request
.any
.request_id
);
296 else if (!con
->request
->attrs
)
298 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
299 "%04X %s No attributes in request",
300 IPP_BAD_REQUEST
, con
->http
.hostname
);
302 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
307 * Make sure that the attributes are provided in the correct order and
308 * don't repeat groups...
311 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
314 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
317 * Out of order; return an error...
320 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
321 "%04X %s Attribute groups are out of order",
322 IPP_BAD_REQUEST
, con
->http
.hostname
);
324 send_ipp_status(con
, IPP_BAD_REQUEST
,
325 _("Attribute groups are out of order (%x < %x)."),
326 attr
->group_tag
, group
);
330 group
= attr
->group_tag
;
335 * Then make sure that the first three attributes are:
338 * attributes-natural-language
339 * printer-uri/job-uri
342 attr
= con
->request
->attrs
;
343 if (attr
&& attr
->name
&&
344 !strcmp(attr
->name
, "attributes-charset") &&
345 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
353 if (attr
&& attr
->name
&&
354 !strcmp(attr
->name
, "attributes-natural-language") &&
355 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
360 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
361 IPP_TAG_URI
)) != NULL
)
363 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
364 IPP_TAG_URI
)) != NULL
)
366 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
367 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
372 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
373 "attributes-charset", NULL
,
374 charset
->values
[0].string
.text
);
376 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
377 "attributes-charset", NULL
, "utf-8");
380 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
381 "attributes-natural-language", NULL
,
382 language
->values
[0].string
.text
);
384 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
385 "attributes-natural-language", NULL
, DefaultLanguage
);
388 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
389 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
392 * Bad character set...
395 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
396 charset
->values
[0].string
.text
);
397 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
398 "%04X %s Unsupported attributes-charset value \"%s\"",
399 IPP_CHARSET
, con
->http
.hostname
,
400 charset
->values
[0].string
.text
);
401 send_ipp_status(con
, IPP_BAD_REQUEST
,
402 _("Unsupported character set \"%s\"."),
403 charset
->values
[0].string
.text
);
405 else if (!charset
|| !language
||
407 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
408 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
409 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
410 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
411 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
414 * Return an error, since attributes-charset,
415 * attributes-natural-language, and printer-uri/job-uri are required
416 * for all operations.
421 cupsdLogMessage(CUPSD_LOG_ERROR
,
422 "Missing attributes-charset attribute");
424 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
425 "%04X %s Missing attributes-charset attribute",
426 IPP_BAD_REQUEST
, con
->http
.hostname
);
431 cupsdLogMessage(CUPSD_LOG_ERROR
,
432 "Missing attributes-natural-language attribute");
434 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
435 "%04X %s Missing attributes-natural-language attribute",
436 IPP_BAD_REQUEST
, con
->http
.hostname
);
441 cupsdLogMessage(CUPSD_LOG_ERROR
,
442 "Missing printer-uri, job-uri, or ppd-name "
445 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
446 "%04X %s Missing printer-uri, job-uri, or ppd-name "
447 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
450 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
452 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
453 cupsdLogMessage(CUPSD_LOG_DEBUG
,
454 "attr \"%s\": group_tag = %x, value_tag = %x",
455 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
458 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
460 send_ipp_status(con
, IPP_BAD_REQUEST
,
461 _("Missing required attributes."));
466 * OK, all the checks pass so far; make sure requesting-user-name is
467 * not "root" from a remote host...
470 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
471 IPP_TAG_NAME
)) != NULL
)
474 * Check for root user...
477 if (!strcmp(username
->values
[0].string
.text
, "root") &&
478 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
479 strcmp(con
->username
, "root"))
482 * Remote unauthenticated user masquerading as local root...
485 _cupsStrFree(username
->values
[0].string
.text
);
486 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
490 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
491 IPP_TAG_INTEGER
)) != NULL
)
492 sub_id
= attr
->values
[0].integer
;
497 * Then try processing the operation...
501 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
502 ippOpString(con
->request
->request
.op
.operation_id
),
503 uri
->values
[0].string
.text
);
505 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
506 ippOpString(con
->request
->request
.op
.operation_id
));
508 switch (con
->request
->request
.op
.operation_id
)
514 case IPP_VALIDATE_JOB
:
515 validate_job(con
, uri
);
518 case IPP_CREATE_JOB
:
519 create_job(con
, uri
);
522 case IPP_SEND_DOCUMENT
:
523 send_document(con
, uri
);
526 case IPP_CANCEL_JOB
:
527 cancel_job(con
, uri
);
530 case IPP_GET_JOB_ATTRIBUTES
:
531 get_job_attrs(con
, uri
);
538 case IPP_GET_PRINTER_ATTRIBUTES
:
539 get_printer_attrs(con
, uri
);
542 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
543 get_printer_supported(con
, uri
);
550 case IPP_RELEASE_JOB
:
551 release_job(con
, uri
);
554 case IPP_RESTART_JOB
:
555 restart_job(con
, uri
);
558 case IPP_PAUSE_PRINTER
:
559 stop_printer(con
, uri
);
562 case IPP_RESUME_PRINTER
:
563 start_printer(con
, uri
);
566 case IPP_PURGE_JOBS
:
567 case IPP_CANCEL_JOBS
:
568 case IPP_CANCEL_MY_JOBS
:
569 cancel_all_jobs(con
, uri
);
572 case IPP_SET_JOB_ATTRIBUTES
:
573 set_job_attrs(con
, uri
);
576 case IPP_SET_PRINTER_ATTRIBUTES
:
577 set_printer_attrs(con
, uri
);
580 case IPP_HOLD_NEW_JOBS
:
581 hold_new_jobs(con
, uri
);
584 case IPP_RELEASE_HELD_NEW_JOBS
:
585 release_held_new_jobs(con
, uri
);
592 case CUPS_GET_DEFAULT
:
596 case CUPS_GET_PRINTERS
:
597 get_printers(con
, 0);
600 case CUPS_GET_CLASSES
:
601 get_printers(con
, CUPS_PRINTER_CLASS
);
604 case CUPS_ADD_PRINTER
:
605 add_printer(con
, uri
);
608 case CUPS_DELETE_PRINTER
:
609 delete_printer(con
, uri
);
612 case CUPS_ADD_CLASS
:
616 case CUPS_DELETE_CLASS
:
617 delete_printer(con
, uri
);
620 case CUPS_ACCEPT_JOBS
:
621 case IPP_ENABLE_PRINTER
:
622 accept_jobs(con
, uri
);
625 case CUPS_REJECT_JOBS
:
626 case IPP_DISABLE_PRINTER
:
627 reject_jobs(con
, uri
);
630 case CUPS_SET_DEFAULT
:
631 set_default(con
, uri
);
634 case CUPS_GET_DEVICES
:
638 case CUPS_GET_DOCUMENT
:
639 get_document(con
, uri
);
654 case CUPS_AUTHENTICATE_JOB
:
655 authenticate_job(con
, uri
);
658 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
659 case IPP_CREATE_JOB_SUBSCRIPTION
:
660 create_subscription(con
, uri
);
663 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
664 get_subscription_attrs(con
, sub_id
);
667 case IPP_GET_SUBSCRIPTIONS
:
668 get_subscriptions(con
, uri
);
671 case IPP_RENEW_SUBSCRIPTION
:
672 renew_subscription(con
, sub_id
);
675 case IPP_CANCEL_SUBSCRIPTION
:
676 cancel_subscription(con
, sub_id
);
679 case IPP_GET_NOTIFICATIONS
:
680 get_notifications(con
);
684 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
685 "%04X %s Operation %04X (%s) not supported",
686 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
687 con
->request
->request
.op
.operation_id
,
688 ippOpString(con
->request
->request
.op
.operation_id
));
690 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
691 _("%s not supported."),
693 con
->request
->request
.op
.operation_id
));
703 * Sending data from the scheduler...
706 cupsdLogMessage(con
->response
->request
.status
.status_code
707 >= IPP_BAD_REQUEST
&&
708 con
->response
->request
.status
.status_code
709 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
710 "Returning IPP %s for %s (%s) from %s",
711 ippErrorString(con
->response
->request
.status
.status_code
),
712 ippOpString(con
->request
->request
.op
.operation_id
),
713 uri
? uri
->values
[0].string
.text
: "no URI",
716 if (LogLevel
== CUPSD_LOG_DEBUG2
)
717 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
718 "cupsdProcessIPPRequest: ippLength(response)=%ld",
719 (long)ippLength(con
->response
));
721 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
723 #ifdef CUPSD_USE_CHUNKING
725 * Because older versions of CUPS (1.1.17 and older) and some IPP
726 * clients do not implement chunking properly, we cannot use
727 * chunking by default. This may become the default in future
728 * CUPS releases, or we might add a configuration directive for
732 if (con
->http
.version
== HTTP_1_1
)
734 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
737 if (cupsdFlushHeader(con
) < 0)
740 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
743 #endif /* CUPSD_USE_CHUNKING */
745 size_t length
; /* Length of response */
748 length
= ippLength(con
->response
);
750 if (con
->file
>= 0 && !con
->pipe_pid
)
752 struct stat fileinfo
; /* File information */
754 if (!fstat(con
->file
, &fileinfo
))
755 length
+= fileinfo
.st_size
;
758 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
759 CUPS_LLCAST length
) < 0)
762 if (cupsdFlushHeader(con
) < 0)
765 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
766 con
->http
.data_remaining
= length
;
768 if (con
->http
.data_remaining
<= INT_MAX
)
769 con
->http
._data_remaining
= con
->http
.data_remaining
;
771 con
->http
._data_remaining
= INT_MAX
;
774 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
775 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
778 * Tell the caller the response header was sent successfully...
786 * Tell the caller the response header could not be sent...
795 * Sending data from a subprocess like cups-deviced; tell the caller
796 * everything is A-OK so far...
805 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
808 int /* O - 0 on success, -1 on error */
809 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
811 cupsd_printer_t
*printer
; /* Destination printer or class */
812 ipp_attribute_t
*attr
; /* job-sheets attribute */
813 int kbytes
; /* Kilobytes in banner */
816 job
->pending_timeout
= 0;
819 * See if we need to add the ending sheet...
822 if (!cupsdLoadJob(job
))
825 printer
= cupsdFindDest(job
->dest
);
826 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
828 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
829 attr
&& attr
->num_values
> 1)
835 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
836 attr
->values
[1].string
.text
);
838 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
841 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
849 * 'accept_jobs()' - Accept print jobs to a printer.
853 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
854 ipp_attribute_t
*uri
) /* I - Printer or class URI */
856 http_status_t status
; /* Policy status */
857 cups_ptype_t dtype
; /* Destination type (printer/class) */
858 cupsd_printer_t
*printer
; /* Printer data */
861 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
862 con
->http
.fd
, uri
->values
[0].string
.text
);
865 * Is the destination valid?
868 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
874 send_ipp_status(con
, IPP_NOT_FOUND
,
875 _("The printer or class does not exist."));
883 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
885 send_http_error(con
, status
, printer
);
890 * Accept jobs sent to the printer...
893 printer
->accepting
= 1;
894 printer
->state_message
[0] = '\0';
896 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
897 "Now accepting jobs.");
899 if (dtype
& CUPS_PRINTER_CLASS
)
901 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
903 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
904 printer
->name
, get_username(con
));
908 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
910 cupsdLogMessage(CUPSD_LOG_INFO
,
911 "Printer \"%s\" now accepting jobs (\"%s\").",
912 printer
->name
, get_username(con
));
916 * Everything was ok, so return OK status...
919 con
->response
->request
.status
.status_code
= IPP_OK
;
924 * 'add_class()' - Add a class to the system.
928 add_class(cupsd_client_t
*con
, /* I - Client connection */
929 ipp_attribute_t
*uri
) /* I - URI of class */
931 http_status_t status
; /* Policy status */
932 int i
; /* Looping var */
933 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
934 username
[HTTP_MAX_URI
], /* Username portion of URI */
935 host
[HTTP_MAX_URI
], /* Host portion of URI */
936 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
937 int port
; /* Port portion of URI */
938 cupsd_printer_t
*pclass
, /* Class */
939 *member
; /* Member printer/class */
940 cups_ptype_t dtype
; /* Destination type */
941 ipp_attribute_t
*attr
; /* Printer attribute */
942 int modify
; /* Non-zero if we just modified */
943 int need_restart_job
; /* Need to restart job? */
946 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
947 con
->http
.fd
, uri
->values
[0].string
.text
);
950 * Do we have a valid URI?
953 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
954 sizeof(scheme
), username
, sizeof(username
), host
,
955 sizeof(host
), &port
, resource
, sizeof(resource
));
958 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
961 * No, return an error...
964 send_ipp_status(con
, IPP_BAD_REQUEST
,
965 _("The printer-uri must be of the form "
966 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
971 * Do we have a valid printer name?
974 if (!validate_name(resource
+ 9))
977 * No, return an error...
980 send_ipp_status(con
, IPP_BAD_REQUEST
,
981 _("The printer-uri \"%s\" contains invalid characters."),
982 uri
->values
[0].string
.text
);
987 * See if the class already exists; if not, create a new class...
990 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
993 * Class doesn't exist; see if we have a printer of the same name...
996 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
999 * Yes, return an error...
1002 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1003 _("A printer named \"%s\" already exists."),
1009 * No, check the default policy and then add the class...
1012 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1014 send_http_error(con
, status
, NULL
);
1018 pclass
= cupsdAddClass(resource
+ 9);
1021 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1024 send_http_error(con
, status
, pclass
);
1031 * Look for attributes and copy them over as needed...
1034 need_restart_job
= 0;
1036 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1037 IPP_TAG_TEXT
)) != NULL
)
1038 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1040 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1041 IPP_TAG_TEXT
)) != NULL
)
1042 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1044 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1045 IPP_TAG_BOOLEAN
)) != NULL
&&
1046 attr
->values
[0].boolean
!= pclass
->accepting
)
1048 cupsdLogMessage(CUPSD_LOG_INFO
,
1049 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1050 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1052 pclass
->accepting
= attr
->values
[0].boolean
;
1054 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1055 pclass
->accepting
? "Now" : "No longer");
1058 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1059 IPP_TAG_BOOLEAN
)) != NULL
)
1061 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1062 cupsdDeregisterPrinter(pclass
, 1);
1064 cupsdLogMessage(CUPSD_LOG_INFO
,
1065 "Setting %s printer-is-shared to %d (was %d.)",
1066 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1068 pclass
->shared
= attr
->values
[0].boolean
;
1071 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1072 IPP_TAG_ENUM
)) != NULL
)
1074 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1075 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1077 send_ipp_status(con
, IPP_BAD_REQUEST
,
1078 _("Attempt to set %s printer-state to bad value %d."),
1079 pclass
->name
, attr
->values
[0].integer
);
1083 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1084 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1086 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1087 cupsdStopPrinter(pclass
, 0);
1090 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1091 need_restart_job
= 1;
1094 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1095 IPP_TAG_TEXT
)) != NULL
)
1097 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1098 sizeof(pclass
->state_message
));
1100 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1101 pclass
->state_message
);
1103 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1104 IPP_TAG_URI
)) != NULL
)
1107 * Clear the printer array as needed...
1110 need_restart_job
= 1;
1112 if (pclass
->num_printers
> 0)
1114 free(pclass
->printers
);
1115 pclass
->num_printers
= 0;
1119 * Add each printer or class that is listed...
1122 for (i
= 0; i
< attr
->num_values
; i
++)
1125 * Search for the printer or class URI...
1128 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1134 send_ipp_status(con
, IPP_NOT_FOUND
,
1135 _("The printer or class does not exist."));
1138 else if (dtype
& CUPS_PRINTER_CLASS
)
1140 send_ipp_status(con
, IPP_BAD_REQUEST
,
1141 _("Nested classes are not allowed."));
1146 * Add it to the class...
1149 cupsdAddPrinterToClass(pclass
, member
);
1153 set_printer_defaults(con
, pclass
);
1155 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1156 IPP_TAG_KEYWORD
)) != NULL
)
1157 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1160 * Update the printer class attributes and return...
1163 cupsdSetPrinterAttrs(pclass
);
1164 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1166 if (need_restart_job
&& pclass
->job
)
1169 * Reset the current job to a "pending" status...
1172 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1173 "Job restarted because the class was modified.");
1176 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1180 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1181 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1182 pclass
->name
, get_username(con
));
1184 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1185 pclass
->name
, get_username(con
));
1189 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1190 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1191 pclass
->name
, get_username(con
));
1193 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1194 pclass
->name
, get_username(con
));
1197 con
->response
->request
.status
.status_code
= IPP_OK
;
1202 * 'add_file()' - Add a file to a job.
1205 static int /* O - 0 on success, -1 on error */
1206 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1207 cupsd_job_t
*job
, /* I - Job to add to */
1208 mime_type_t
*filetype
, /* I - Type of file */
1209 int compression
) /* I - Compression */
1211 mime_type_t
**filetypes
; /* New filetypes array... */
1212 int *compressions
; /* New compressions array... */
1215 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1216 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1217 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1218 filetype
->super
, filetype
->type
, compression
);
1221 * Add the file to the job...
1224 if (job
->num_files
== 0)
1226 compressions
= (int *)malloc(sizeof(int));
1227 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1231 compressions
= (int *)realloc(job
->compressions
,
1232 (job
->num_files
+ 1) * sizeof(int));
1233 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1234 (job
->num_files
+ 1) *
1235 sizeof(mime_type_t
*));
1238 if (!compressions
|| !filetypes
)
1240 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1241 "Job aborted because the scheduler ran out of memory.");
1244 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1245 _("Unable to allocate memory for file types."));
1250 job
->compressions
= compressions
;
1251 job
->compressions
[job
->num_files
] = compression
;
1252 job
->filetypes
= filetypes
;
1253 job
->filetypes
[job
->num_files
] = filetype
;
1258 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1265 * 'add_job()' - Add a job to a print queue.
1268 static cupsd_job_t
* /* O - Job object */
1269 add_job(cupsd_client_t
*con
, /* I - Client connection */
1270 cupsd_printer_t
*printer
, /* I - Destination printer */
1271 mime_type_t
*filetype
) /* I - First print file type, if any */
1273 http_status_t status
; /* Policy status */
1274 ipp_attribute_t
*attr
, /* Current attribute */
1275 *auth_info
; /* auth-info attribute */
1276 const char *mandatory
; /* Current mandatory job attribute */
1277 const char *val
; /* Default option value */
1278 int priority
; /* Job priority */
1279 cupsd_job_t
*job
; /* Current job */
1280 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1281 int kbytes
; /* Size of print file */
1282 int i
; /* Looping var */
1283 int lowerpagerange
; /* Page range bound */
1284 int exact
; /* Did we have an exact match? */
1285 ipp_attribute_t
*media_col
, /* media-col attribute */
1286 *media_margin
; /* media-*-margin attribute */
1287 ipp_t
*unsup_col
; /* media-col in unsupported response */
1288 static const char * const readonly
[] =/* List of read-only attributes */
1292 /*"job-impressions",*/ /* For now we allow this since cupsd can't count */
1293 "job-impressions-completed",
1295 "job-media-sheets-completed",
1297 "job-state-message",
1298 "job-state-reasons",
1299 "time-at-completed",
1301 "time-at-processing"
1305 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1306 con
, con
->http
.fd
, printer
, printer
->name
,
1307 filetype
, filetype
? filetype
->super
: "none",
1308 filetype
? filetype
->type
: "none");
1311 * Check remote printing to non-shared printer...
1314 if (!printer
->shared
&&
1315 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
1316 _cups_strcasecmp(con
->http
.hostname
, ServerName
))
1318 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1319 _("The printer or class is not shared."));
1327 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1329 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1331 send_http_error(con
, status
, printer
);
1334 else if (printer
->num_auth_info_required
== 1 &&
1335 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1338 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1342 else if (auth_info
&& !con
->http
.tls
&&
1343 !httpAddrLocalhost(con
->http
.hostaddr
))
1346 * Require encryption of auth-info over non-local connections...
1349 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1352 #endif /* HAVE_SSL */
1355 * See if the printer is accepting jobs...
1358 if (!printer
->accepting
)
1360 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1361 _("Destination \"%s\" is not accepting jobs."),
1367 * Validate job template attributes; for now just document-format,
1368 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1372 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1374 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
],
1375 IPP_TAG_ZERO
)) != NULL
)
1377 ippDeleteAttribute(con
->request
, attr
);
1379 if (StrictConformance
)
1381 send_ipp_status(con
, IPP_BAD_REQUEST
,
1382 _("The '%s' Job Description attribute cannot be "
1383 "supplied in a job creation request."), readonly
[i
]);
1387 cupsdLogMessage(CUPSD_LOG_WARN
,
1388 "Unexpected '%s' Job Description attribute in a job "
1389 "creation request.", readonly
[i
]);
1395 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1397 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1399 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1402 * Missing a required attribute...
1405 send_ipp_status(con
, IPP_CONFLICT
,
1406 _("The \"%s\" attribute is required for print jobs."),
1413 if (filetype
&& printer
->filetypes
&&
1414 !cupsArrayFind(printer
->filetypes
, filetype
))
1416 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1417 /* MIME media type string */
1420 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1423 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1424 _("Unsupported format \"%s\"."), mimetype
);
1426 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1427 "document-format", NULL
, mimetype
);
1432 if ((attr
= ippFindAttribute(con
->request
, "copies",
1433 IPP_TAG_INTEGER
)) != NULL
)
1435 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1437 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1438 attr
->values
[0].integer
);
1439 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1440 "copies", attr
->values
[0].integer
);
1445 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1446 IPP_TAG_ZERO
)) != NULL
)
1448 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1449 attr
->value_tag
!= IPP_TAG_NAME
)
1451 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1455 if (attr
->num_values
> 2)
1457 send_ipp_status(con
, IPP_BAD_REQUEST
,
1458 _("Too many job-sheets values (%d > 2)."),
1463 for (i
= 0; i
< attr
->num_values
; i
++)
1464 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1465 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1467 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1468 attr
->values
[i
].string
.text
);
1473 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1474 IPP_TAG_INTEGER
)) != NULL
)
1476 if (attr
->values
[0].integer
!= 1 &&
1477 attr
->values
[0].integer
!= 2 &&
1478 attr
->values
[0].integer
!= 4 &&
1479 attr
->values
[0].integer
!= 6 &&
1480 attr
->values
[0].integer
!= 9 &&
1481 attr
->values
[0].integer
!= 16)
1483 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1484 attr
->values
[0].integer
);
1485 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1486 "number-up", attr
->values
[0].integer
);
1491 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1492 IPP_TAG_RANGE
)) != NULL
)
1494 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1496 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1497 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1499 send_ipp_status(con
, IPP_BAD_REQUEST
,
1500 _("Bad page-ranges values %d-%d."),
1501 attr
->values
[i
].range
.lower
,
1502 attr
->values
[i
].range
.upper
);
1506 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1511 * Do media selection as needed...
1514 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1515 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1516 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1519 (media_col
= ippFindAttribute(con
->request
, "media-col",
1520 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1522 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1524 unsup_col
= ippNew();
1525 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1526 "media-bottom-margin",
1527 IPP_TAG_INTEGER
)) != NULL
)
1528 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1529 "media-bottom-margin", media_margin
->values
[0].integer
);
1531 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1532 "media-left-margin",
1533 IPP_TAG_INTEGER
)) != NULL
)
1534 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1535 "media-left-margin", media_margin
->values
[0].integer
);
1537 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1538 "media-right-margin",
1539 IPP_TAG_INTEGER
)) != NULL
)
1540 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1541 "media-right-margin", media_margin
->values
[0].integer
);
1543 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1545 IPP_TAG_INTEGER
)) != NULL
)
1546 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1547 "media-top-margin", media_margin
->values
[0].integer
);
1549 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1551 ippDelete(unsup_col
);
1556 * Make sure we aren't over our limit...
1559 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1562 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1564 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1568 if ((i
= check_quotas(con
, printer
)) < 0)
1570 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1575 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1580 * Create the job and set things up...
1583 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1584 IPP_TAG_INTEGER
)) != NULL
)
1585 priority
= attr
->values
[0].integer
;
1588 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1589 printer
->options
)) != NULL
)
1590 priority
= atoi(val
);
1594 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1598 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1599 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1602 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1604 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1605 _("Unable to add job for destination \"%s\"."),
1610 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1611 job
->attrs
= con
->request
;
1613 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1615 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1618 apply_printer_defaults(printer
, job
);
1620 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1622 if (con
->username
[0])
1624 cupsdSetString(&job
->username
, con
->username
);
1627 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1631 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1632 "add_job: requesting-user-name=\"%s\"",
1633 attr
->values
[0].string
.text
);
1635 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1638 cupsdSetString(&job
->username
, "anonymous");
1641 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1642 "job-originating-user-name", NULL
, job
->username
);
1645 attr
->group_tag
= IPP_TAG_JOB
;
1646 _cupsStrFree(attr
->name
);
1647 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1650 if (con
->username
[0] || auth_info
)
1652 save_auth_info(con
, job
, auth_info
);
1655 * Remove the auth-info attribute from the attribute data...
1659 ippDeleteAttribute(job
->attrs
, auth_info
);
1662 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1663 IPP_TAG_ZERO
)) != NULL
)
1666 * Request contains a job-originating-host-name attribute; validate it...
1669 if (attr
->value_tag
!= IPP_TAG_NAME
||
1670 attr
->num_values
!= 1 ||
1671 strcmp(con
->http
.hostname
, "localhost"))
1674 * Can't override the value if we aren't connected via localhost.
1675 * Also, we can only have 1 value and it must be a name value.
1678 switch (attr
->value_tag
)
1680 case IPP_TAG_STRING
:
1681 case IPP_TAG_TEXTLANG
:
1682 case IPP_TAG_NAMELANG
:
1685 case IPP_TAG_KEYWORD
:
1687 case IPP_TAG_URISCHEME
:
1688 case IPP_TAG_CHARSET
:
1689 case IPP_TAG_LANGUAGE
:
1690 case IPP_TAG_MIMETYPE
:
1692 * Free old strings...
1695 for (i
= 0; i
< attr
->num_values
; i
++)
1697 _cupsStrFree(attr
->values
[i
].string
.text
);
1698 attr
->values
[i
].string
.text
= NULL
;
1699 if (attr
->values
[i
].string
.language
)
1701 _cupsStrFree(attr
->values
[i
].string
.language
);
1702 attr
->values
[i
].string
.language
= NULL
;
1711 * Use the default connection hostname instead...
1714 attr
->value_tag
= IPP_TAG_NAME
;
1715 attr
->num_values
= 1;
1716 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1719 attr
->group_tag
= IPP_TAG_JOB
;
1724 * No job-originating-host-name attribute, so use the hostname from
1728 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1729 "job-originating-host-name", NULL
, con
->http
.hostname
);
1732 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1734 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1735 "time-at-processing", 0);
1736 attr
->value_tag
= IPP_TAG_NOVALUE
;
1737 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1738 "time-at-completed", 0);
1739 attr
->value_tag
= IPP_TAG_NOVALUE
;
1742 * Add remaining job attributes...
1745 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1746 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1747 "job-state", IPP_JOB_STOPPED
);
1748 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1749 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1750 "job-state-reasons", NULL
, "job-incoming");
1751 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1752 "job-media-sheets-completed", 0);
1753 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1756 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1757 IPP_TAG_INTEGER
)) != NULL
)
1758 attr
->values
[0].integer
= 0;
1760 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1762 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1763 IPP_TAG_KEYWORD
)) == NULL
)
1764 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1767 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1768 printer
->options
)) == NULL
)
1771 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1772 "job-hold-until", NULL
, val
);
1774 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1777 * Hold job until specified time...
1780 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1782 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1783 job
->state_value
= IPP_JOB_HELD
;
1785 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1787 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1789 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1790 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1791 job
->state_value
= IPP_JOB_HELD
;
1795 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1796 job
->state_value
= IPP_JOB_PENDING
;
1798 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1801 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1804 * Add job sheets options...
1807 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1808 IPP_TAG_ZERO
)) == NULL
)
1810 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1811 "Adding default job-sheets values \"%s,%s\"...",
1812 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1814 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1816 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1817 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1820 job
->job_sheets
= attr
;
1823 * Enforce classification level if set...
1828 cupsdLogMessage(CUPSD_LOG_INFO
,
1829 "Classification=\"%s\", ClassifyOverride=%d",
1830 Classification
? Classification
: "(null)",
1833 if (ClassifyOverride
)
1835 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1836 (attr
->num_values
== 1 ||
1837 !strcmp(attr
->values
[1].string
.text
, "none")))
1840 * Force the leading banner to have the classification on it...
1843 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1845 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1846 "job-sheets=\"%s,none\", "
1847 "job-originating-user-name=\"%s\"",
1848 Classification
, job
->username
);
1850 else if (attr
->num_values
== 2 &&
1851 strcmp(attr
->values
[0].string
.text
,
1852 attr
->values
[1].string
.text
) &&
1853 strcmp(attr
->values
[0].string
.text
, "none") &&
1854 strcmp(attr
->values
[1].string
.text
, "none"))
1857 * Can't put two different security markings on the same document!
1860 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1862 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1863 "job-sheets=\"%s,%s\", "
1864 "job-originating-user-name=\"%s\"",
1865 attr
->values
[0].string
.text
,
1866 attr
->values
[1].string
.text
, job
->username
);
1868 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1869 strcmp(attr
->values
[0].string
.text
, "none") &&
1870 (attr
->num_values
== 1 ||
1871 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1872 strcmp(attr
->values
[1].string
.text
, "none"))))
1874 if (attr
->num_values
== 1)
1875 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1876 "CLASSIFICATION OVERRIDDEN "
1877 "job-sheets=\"%s\", "
1878 "job-originating-user-name=\"%s\"",
1879 attr
->values
[0].string
.text
, job
->username
);
1881 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1882 "CLASSIFICATION OVERRIDDEN "
1883 "job-sheets=\"%s,%s\",fffff "
1884 "job-originating-user-name=\"%s\"",
1885 attr
->values
[0].string
.text
,
1886 attr
->values
[1].string
.text
, job
->username
);
1889 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1890 (attr
->num_values
== 1 ||
1891 strcmp(attr
->values
[1].string
.text
, Classification
)))
1894 * Force the banner to have the classification on it...
1897 if (attr
->num_values
> 1 &&
1898 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1900 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1901 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1905 if (attr
->num_values
== 1 ||
1906 strcmp(attr
->values
[0].string
.text
, "none"))
1907 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1909 if (attr
->num_values
> 1 &&
1910 strcmp(attr
->values
[1].string
.text
, "none"))
1911 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1914 if (attr
->num_values
> 1)
1915 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1916 "CLASSIFICATION FORCED "
1917 "job-sheets=\"%s,%s\", "
1918 "job-originating-user-name=\"%s\"",
1919 attr
->values
[0].string
.text
,
1920 attr
->values
[1].string
.text
, job
->username
);
1922 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1923 "CLASSIFICATION FORCED "
1924 "job-sheets=\"%s\", "
1925 "job-originating-user-name=\"%s\"",
1926 Classification
, job
->username
);
1931 * See if we need to add the starting sheet...
1934 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1936 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1937 attr
->values
[0].string
.text
);
1939 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1941 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1942 "Aborting job because the start banner could not be "
1947 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1950 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1951 IPP_TAG_ZERO
)) != NULL
)
1952 job
->job_sheets
= attr
;
1955 * Fill in the response info...
1958 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1959 con
->servername
, con
->serverport
, "/jobs/%d", job
->id
);
1960 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1963 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1965 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1967 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1968 NULL
, job
->reasons
->values
[0].string
.text
);
1970 con
->response
->request
.status
.status_code
= IPP_OK
;
1973 * Add any job subscriptions...
1976 add_job_subscriptions(con
, job
);
1979 * Set all but the first two attributes to the job attributes group...
1982 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1983 attr
->group_tag
= IPP_TAG_JOB
;
1986 * Fire the "job created" event...
1989 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1992 * Return the new job...
2000 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2004 add_job_subscriptions(
2005 cupsd_client_t
*con
, /* I - Client connection */
2006 cupsd_job_t
*job
) /* I - Newly created job */
2008 int i
; /* Looping var */
2009 ipp_attribute_t
*prev
, /* Previous attribute */
2010 *next
, /* Next attribute */
2011 *attr
; /* Current attribute */
2012 cupsd_subscription_t
*sub
; /* Subscription object */
2013 const char *recipient
, /* notify-recipient-uri */
2014 *pullmethod
; /* notify-pull-method */
2015 ipp_attribute_t
*user_data
; /* notify-user-data */
2016 int interval
; /* notify-time-interval */
2017 unsigned mask
; /* notify-events */
2021 * Find the first subscription group attribute; return if we have
2025 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2026 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2033 * Process the subscription attributes in the request...
2042 mask
= CUPSD_EVENT_NONE
;
2044 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2046 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2047 attr
->value_tag
== IPP_TAG_URI
)
2050 * Validate the recipient scheme against the ServerBin/notifier
2054 char notifier
[1024], /* Notifier filename */
2055 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2056 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2057 host
[HTTP_MAX_URI
], /* Host portion of URI */
2058 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2059 int port
; /* Port portion of URI */
2062 recipient
= attr
->values
[0].string
.text
;
2064 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2065 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2066 host
, sizeof(host
), &port
,
2067 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2069 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2070 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2071 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2072 "notify-status-code", IPP_URI_SCHEME
);
2076 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2078 if (access(notifier
, X_OK
))
2080 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2081 _("notify-recipient-uri URI \"%s\" uses unknown "
2082 "scheme."), recipient
);
2083 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2084 "notify-status-code", IPP_URI_SCHEME
);
2088 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2090 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2091 _("notify-recipient-uri URI \"%s\" is already used."),
2093 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2094 "notify-status-code", IPP_ATTRIBUTES
);
2098 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2099 attr
->value_tag
== IPP_TAG_KEYWORD
)
2101 pullmethod
= attr
->values
[0].string
.text
;
2103 if (strcmp(pullmethod
, "ippget"))
2105 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2106 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2107 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2108 "notify-status-code", IPP_ATTRIBUTES
);
2112 else if (!strcmp(attr
->name
, "notify-charset") &&
2113 attr
->value_tag
== IPP_TAG_CHARSET
&&
2114 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2115 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2117 send_ipp_status(con
, IPP_CHARSET
,
2118 _("Character set \"%s\" not supported."),
2119 attr
->values
[0].string
.text
);
2122 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2123 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2124 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2126 send_ipp_status(con
, IPP_CHARSET
,
2127 _("Language \"%s\" not supported."),
2128 attr
->values
[0].string
.text
);
2131 else if (!strcmp(attr
->name
, "notify-user-data") &&
2132 attr
->value_tag
== IPP_TAG_STRING
)
2134 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2136 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2137 _("The notify-user-data value is too large "
2138 "(%d > 63 octets)."),
2139 attr
->values
[0].unknown
.length
);
2145 else if (!strcmp(attr
->name
, "notify-events") &&
2146 attr
->value_tag
== IPP_TAG_KEYWORD
)
2148 for (i
= 0; i
< attr
->num_values
; i
++)
2149 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2151 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2153 send_ipp_status(con
, IPP_BAD_REQUEST
,
2154 _("The notify-lease-duration attribute cannot be "
2155 "used with job subscriptions."));
2158 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2159 attr
->value_tag
== IPP_TAG_INTEGER
)
2160 interval
= attr
->values
[0].integer
;
2165 if (!recipient
&& !pullmethod
)
2168 if (mask
== CUPSD_EVENT_NONE
)
2169 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2171 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2172 recipient
, 0)) != NULL
)
2174 sub
->interval
= interval
;
2176 cupsdSetString(&sub
->owner
, job
->username
);
2180 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2181 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2182 sub
->user_data_len
);
2185 ippAddSeparator(con
->response
);
2186 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2187 "notify-subscription-id", sub
->id
);
2189 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2197 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2200 * Remove all of the subscription attributes from the job request...
2202 * TODO: Optimize this since subscription groups have to come at the
2203 * end of the request...
2206 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2210 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2211 attr
->group_tag
== IPP_TAG_ZERO
)
2214 * Free and remove this attribute...
2217 ippDeleteAttribute(NULL
, attr
);
2222 job
->attrs
->attrs
= next
;
2228 job
->attrs
->last
= prev
;
2229 job
->attrs
->current
= prev
;
2234 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2236 * See RFC 4122 for the definition of UUIDs and the format.
2240 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2242 char uuid
[64]; /* job-uuid string */
2246 * Add a job-uuid attribute if none exists...
2249 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2250 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2251 _httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2252 uuid
, sizeof(uuid
)));
2257 * 'add_printer()' - Add a printer to the system.
2261 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2262 ipp_attribute_t
*uri
) /* I - URI of printer */
2264 http_status_t status
; /* Policy status */
2265 int i
; /* Looping var */
2266 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2267 username
[HTTP_MAX_URI
], /* Username portion of URI */
2268 host
[HTTP_MAX_URI
], /* Host portion of URI */
2269 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2270 int port
; /* Port portion of URI */
2271 cupsd_printer_t
*printer
; /* Printer/class */
2272 ipp_attribute_t
*attr
; /* Printer attribute */
2273 cups_file_t
*fp
; /* Script/PPD file */
2274 char line
[1024]; /* Line from file... */
2275 char srcfile
[1024], /* Source Script/PPD file */
2276 dstfile
[1024]; /* Destination Script/PPD file */
2277 int modify
; /* Non-zero if we are modifying */
2278 int changed_driver
, /* Changed the PPD/interface script? */
2279 need_restart_job
, /* Need to restart job? */
2280 set_device_uri
, /* Did we set the device URI? */
2281 set_port_monitor
; /* Did we set the port monitor? */
2284 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2285 con
->http
.fd
, uri
->values
[0].string
.text
);
2288 * Do we have a valid URI?
2291 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2292 sizeof(scheme
), username
, sizeof(username
), host
,
2293 sizeof(host
), &port
, resource
, sizeof(resource
));
2295 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2298 * No, return an error...
2301 send_ipp_status(con
, IPP_BAD_REQUEST
,
2302 _("The printer-uri must be of the form "
2303 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2308 * Do we have a valid printer name?
2311 if (!validate_name(resource
+ 10))
2314 * No, return an error...
2317 send_ipp_status(con
, IPP_BAD_REQUEST
,
2318 _("The printer-uri \"%s\" contains invalid characters."),
2319 uri
->values
[0].string
.text
);
2324 * See if the printer already exists; if not, create a new printer...
2327 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2330 * Printer doesn't exist; see if we have a class of the same name...
2333 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2336 * Yes, return an error...
2339 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2340 _("A class named \"%s\" already exists."),
2346 * No, check the default policy then add the printer...
2349 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2351 send_http_error(con
, status
, NULL
);
2355 printer
= cupsdAddPrinter(resource
+ 10);
2358 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2361 send_http_error(con
, status
, printer
);
2368 * Look for attributes and copy them over as needed...
2372 need_restart_job
= 0;
2374 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2375 IPP_TAG_TEXT
)) != NULL
)
2376 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2378 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2379 IPP_TAG_TEXT
)) != NULL
)
2380 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2384 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2385 IPP_TAG_URI
)) != NULL
)
2388 * Do we have a valid device URI?
2391 http_uri_status_t uri_status
; /* URI separation status */
2392 char old_device_uri
[1024];
2393 /* Old device URI */
2396 need_restart_job
= 1;
2398 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2399 attr
->values
[0].string
.text
,
2400 scheme
, sizeof(scheme
),
2401 username
, sizeof(username
),
2402 host
, sizeof(host
), &port
,
2403 resource
, sizeof(resource
));
2405 if (uri_status
< HTTP_URI_OK
)
2407 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2408 attr
->values
[0].string
.text
);
2409 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2410 "add_printer: httpSeparateURI returned %d", uri_status
);
2414 if (!strcmp(scheme
, "file"))
2417 * See if the administrator has enabled file devices...
2420 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2423 * File devices are disabled and the URL is not file:/dev/null...
2426 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2427 _("File device URIs have been disabled. "
2428 "To enable, see the FileDevice directive in "
2429 "\"%s/cupsd.conf\"."),
2437 * See if the backend exists and is executable...
2440 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2441 if (access(srcfile
, X_OK
))
2444 * Could not find device in list!
2447 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2448 _("Bad device-uri scheme \"%s\"."), scheme
);
2453 if (printer
->sanitized_device_uri
)
2454 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2455 sizeof(old_device_uri
));
2457 old_device_uri
[0] = '\0';
2459 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2461 cupsdLogMessage(CUPSD_LOG_INFO
,
2462 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2463 printer
->name
, printer
->sanitized_device_uri
,
2469 set_port_monitor
= 0;
2471 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2472 IPP_TAG_NAME
)) != NULL
)
2474 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2477 need_restart_job
= 1;
2479 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2483 for (i
= 0; i
< supported
->num_values
; i
++)
2484 if (!strcmp(supported
->values
[i
].string
.text
,
2485 attr
->values
[0].string
.text
))
2489 if (!supported
|| i
>= supported
->num_values
)
2491 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2492 attr
->values
[0].string
.text
);
2496 cupsdLogMessage(CUPSD_LOG_INFO
,
2497 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2498 printer
->name
, attr
->values
[0].string
.text
,
2499 printer
->port_monitor
? printer
->port_monitor
: "none");
2501 if (strcmp(attr
->values
[0].string
.text
, "none"))
2502 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2504 cupsdClearString(&printer
->port_monitor
);
2506 set_port_monitor
= 1;
2509 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2510 IPP_TAG_BOOLEAN
)) != NULL
&&
2511 attr
->values
[0].boolean
!= printer
->accepting
)
2513 cupsdLogMessage(CUPSD_LOG_INFO
,
2514 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2515 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2517 printer
->accepting
= attr
->values
[0].boolean
;
2519 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2520 "%s accepting jobs.",
2521 printer
->accepting
? "Now" : "No longer");
2524 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2525 IPP_TAG_BOOLEAN
)) != NULL
)
2527 if (attr
->values
[0].boolean
&&
2528 printer
->num_auth_info_required
== 1 &&
2529 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2531 send_ipp_status(con
, IPP_BAD_REQUEST
,
2532 _("Cannot share a remote Kerberized printer."));
2536 if (printer
->shared
&& !attr
->values
[0].boolean
)
2537 cupsdDeregisterPrinter(printer
, 1);
2539 cupsdLogMessage(CUPSD_LOG_INFO
,
2540 "Setting %s printer-is-shared to %d (was %d.)",
2541 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2543 printer
->shared
= attr
->values
[0].boolean
;
2546 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2547 IPP_TAG_ENUM
)) != NULL
)
2549 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2550 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2552 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2553 attr
->values
[0].integer
);
2557 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2558 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2560 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2561 cupsdStopPrinter(printer
, 0);
2564 need_restart_job
= 1;
2565 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2569 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2570 IPP_TAG_TEXT
)) != NULL
)
2572 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2573 sizeof(printer
->state_message
));
2575 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2576 printer
->state_message
);
2579 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2580 IPP_TAG_KEYWORD
)) != NULL
)
2582 if (attr
->num_values
>
2583 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2585 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2586 _("Too many printer-state-reasons values (%d > %d)."),
2588 (int)(sizeof(printer
->reasons
) /
2589 sizeof(printer
->reasons
[0])));
2593 for (i
= 0; i
< printer
->num_reasons
; i
++)
2594 _cupsStrFree(printer
->reasons
[i
]);
2596 printer
->num_reasons
= 0;
2597 for (i
= 0; i
< attr
->num_values
; i
++)
2599 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2602 printer
->reasons
[printer
->num_reasons
] =
2603 _cupsStrRetain(attr
->values
[i
].string
.text
);
2604 printer
->num_reasons
++;
2606 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2607 printer
->state
!= IPP_PRINTER_STOPPED
)
2609 cupsdLogMessage(CUPSD_LOG_INFO
,
2610 "Setting %s printer-state to %d (was %d.)",
2611 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2612 cupsdStopPrinter(printer
, 0);
2616 if (PrintcapFormat
== PRINTCAP_PLIST
)
2617 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2619 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2620 "Printer \"%s\" state changed.", printer
->name
);
2623 set_printer_defaults(con
, printer
);
2625 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2626 IPP_TAG_KEYWORD
)) != NULL
)
2627 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2630 * See if we have all required attributes...
2633 if (!printer
->device_uri
)
2634 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2637 * See if we have an interface script or PPD file attached to the request...
2642 need_restart_job
= 1;
2645 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2647 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2650 * Yes; get the first line from it...
2654 cupsFileGets(fp
, line
, sizeof(line
));
2658 * Then see what kind of file it is...
2661 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2664 if (!strncmp(line
, "*PPD-Adobe", 10))
2667 * The new file is a PPD file, so remove any old interface script
2668 * that might be lying around...
2676 * This must be an interface script, so move the file over to the
2677 * interfaces directory and make it executable...
2680 if (copy_file(srcfile
, dstfile
))
2682 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2683 _("Unable to copy interface script - %s"),
2688 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2689 "Copied interface script successfully");
2690 chmod(dstfile
, 0755);
2693 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2696 if (!strncmp(line
, "*PPD-Adobe", 10))
2699 * The new file is a PPD file, so move the file over to the
2700 * ppd directory and make it readable by all...
2703 if (copy_file(srcfile
, dstfile
))
2705 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2706 _("Unable to copy PPD file - %s"),
2711 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2712 "Copied PPD file successfully");
2713 chmod(dstfile
, 0644);
2718 * This must be an interface script, so remove any old PPD file that
2719 * may be lying around...
2726 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2727 IPP_TAG_NAME
)) != NULL
)
2729 need_restart_job
= 1;
2732 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2735 * Raw driver, remove any existing PPD or interface script files.
2738 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2742 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2752 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2756 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2759 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2761 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2765 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2766 "Copied PPD file successfully");
2767 chmod(dstfile
, 0644);
2774 * If we changed the PPD/interface script, then remove the printer's cache
2775 * file and clear the printer-state-reasons...
2778 char cache_name
[1024]; /* Cache filename for printer attrs */
2780 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2784 cupsdSetPrinterReasons(printer
, "none");
2787 * (Re)register color profiles...
2790 cupsdRegisterColor(printer
);
2794 * If we set the device URI but not the port monitor, check which port
2795 * monitor to use by default...
2798 if (set_device_uri
&& !set_port_monitor
)
2800 ppd_file_t
*ppd
; /* PPD file */
2801 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2804 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2805 sizeof(scheme
), username
, sizeof(username
), host
,
2806 sizeof(host
), &port
, resource
, sizeof(resource
));
2808 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2810 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2812 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2814 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2815 if (!strcmp(scheme
, ppdattr
->spec
))
2817 cupsdLogMessage(CUPSD_LOG_INFO
,
2818 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2819 printer
->name
, ppdattr
->value
,
2820 printer
->port_monitor
? printer
->port_monitor
2823 if (strcmp(ppdattr
->value
, "none"))
2824 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2826 cupsdClearString(&printer
->port_monitor
);
2836 * Update the printer attributes and return...
2839 cupsdSetPrinterAttrs(printer
);
2840 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2842 if (need_restart_job
&& printer
->job
)
2845 * Restart the current job...
2848 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2849 "Job restarted because the printer was modified.");
2852 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2856 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2857 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2858 printer
->name
, get_username(con
));
2860 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2861 printer
->name
, get_username(con
));
2865 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2866 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2867 printer
->name
, get_username(con
));
2869 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2870 printer
->name
, get_username(con
));
2873 con
->response
->request
.status
.status_code
= IPP_OK
;
2878 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2879 * based upon the printer state...
2883 add_printer_state_reasons(
2884 cupsd_client_t
*con
, /* I - Client connection */
2885 cupsd_printer_t
*p
) /* I - Printer info */
2887 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2888 "add_printer_state_reasons(%p[%d], %p[%s])",
2889 con
, con
->http
.fd
, p
, p
->name
);
2891 if (p
->num_reasons
== 0)
2892 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2893 "printer-state-reasons", NULL
, "none");
2895 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2896 "printer-state-reasons", p
->num_reasons
, NULL
,
2897 (const char * const *)p
->reasons
);
2902 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2903 * the specified printer or class.
2907 add_queued_job_count(
2908 cupsd_client_t
*con
, /* I - Client connection */
2909 cupsd_printer_t
*p
) /* I - Printer or class */
2911 int count
; /* Number of jobs on destination */
2914 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2915 con
, con
->http
.fd
, p
, p
->name
);
2917 count
= cupsdGetPrinterJobCount(p
->name
);
2919 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2920 "queued-job-count", count
);
2925 * 'apply_printer_defaults()' - Apply printer default options to a job.
2929 apply_printer_defaults(
2930 cupsd_printer_t
*printer
, /* I - Printer */
2931 cupsd_job_t
*job
) /* I - Job */
2933 int i
, /* Looping var */
2934 num_options
; /* Number of default options */
2935 cups_option_t
*options
, /* Default options */
2936 *option
; /* Current option */
2940 * Collect all of the default options and add the missing ones to the
2944 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2945 option
= printer
->options
;
2948 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2950 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2955 * Encode these options as attributes in the job object...
2958 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2959 cupsFreeOptions(num_options
, options
);
2964 * 'authenticate_job()' - Set job authentication info.
2968 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2969 ipp_attribute_t
*uri
) /* I - Job URI */
2971 ipp_attribute_t
*attr
, /* job-id attribute */
2972 *auth_info
; /* auth-info attribute */
2973 int jobid
; /* Job ID */
2974 cupsd_job_t
*job
; /* Current job */
2975 char scheme
[HTTP_MAX_URI
],
2976 /* Method portion of URI */
2977 username
[HTTP_MAX_URI
],
2978 /* Username portion of URI */
2980 /* Host portion of URI */
2981 resource
[HTTP_MAX_URI
];
2982 /* Resource portion of URI */
2983 int port
; /* Port portion of URI */
2986 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2987 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
2990 * Start with "everything is OK" status...
2993 con
->response
->request
.status
.status_code
= IPP_OK
;
2996 * See if we have a job URI or a printer URI...
2999 if (!strcmp(uri
->name
, "printer-uri"))
3002 * Got a printer URI; see if we also have a job-id attribute...
3005 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3006 IPP_TAG_INTEGER
)) == NULL
)
3008 send_ipp_status(con
, IPP_BAD_REQUEST
,
3009 _("Got a printer-uri attribute but no job-id."));
3013 jobid
= attr
->values
[0].integer
;
3018 * Got a job URI; parse it to get the job ID...
3021 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3022 sizeof(scheme
), username
, sizeof(username
), host
,
3023 sizeof(host
), &port
, resource
, sizeof(resource
));
3025 if (strncmp(resource
, "/jobs/", 6))
3031 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3032 uri
->values
[0].string
.text
);
3036 jobid
= atoi(resource
+ 6);
3040 * See if the job exists...
3043 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3046 * Nope - return a "not found" error...
3049 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3054 * See if the job has been completed...
3057 if (job
->state_value
!= IPP_JOB_HELD
)
3060 * Return a "not-possible" error...
3063 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3064 _("Job #%d is not held for authentication."),
3070 * See if we have already authenticated...
3073 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3075 if (!con
->username
[0] && !auth_info
)
3077 cupsd_printer_t
*printer
; /* Job destination */
3080 * No auth data. If we need to authenticate via Kerberos, send a
3081 * HTTP auth challenge, otherwise just return an IPP error...
3084 printer
= cupsdFindDest(job
->dest
);
3086 if (printer
&& printer
->num_auth_info_required
> 0 &&
3087 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3088 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3090 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3091 _("No authentication information provided."));
3096 * See if the job is owned by the requesting user...
3099 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3101 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3102 cupsdFindDest(job
->dest
));
3107 * Save the authentication information for this job...
3110 save_auth_info(con
, job
, auth_info
);
3113 * Reset the job-hold-until value to "no-hold"...
3116 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3117 IPP_TAG_KEYWORD
)) == NULL
)
3118 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3122 attr
->value_tag
= IPP_TAG_KEYWORD
;
3123 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3127 * Release the job and return...
3130 cupsdReleaseJob(job
);
3132 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3134 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3141 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3145 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3146 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3148 int i
; /* Looping var */
3149 http_status_t status
; /* Policy status */
3150 cups_ptype_t dtype
; /* Destination type */
3151 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3152 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3153 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3154 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3155 int port
; /* Port portion of URI */
3156 ipp_attribute_t
*attr
; /* Attribute in request */
3157 const char *username
= NULL
; /* Username */
3158 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3160 cupsd_printer_t
*printer
; /* Printer */
3161 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3162 cupsd_job_t
*job
; /* Job */
3165 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3166 con
->http
.fd
, uri
->values
[0].string
.text
);
3169 * Get the jobs to cancel/purge...
3172 switch (con
->request
->request
.op
.operation_id
)
3174 case IPP_PURGE_JOBS
:
3176 * Get the username (if any) for the jobs we want to cancel (only if
3177 * "my-jobs" is specified...
3180 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3181 IPP_TAG_BOOLEAN
)) != NULL
&&
3182 attr
->values
[0].boolean
)
3184 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3185 IPP_TAG_NAME
)) != NULL
)
3186 username
= attr
->values
[0].string
.text
;
3189 send_ipp_status(con
, IPP_BAD_REQUEST
,
3190 _("Missing requesting-user-name attribute."));
3196 * Look for the "purge-jobs" attribute...
3199 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3200 IPP_TAG_BOOLEAN
)) != NULL
)
3201 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3203 purge
= CUPSD_JOB_PURGE
;
3206 case IPP_CANCEL_MY_JOBS
:
3207 if (con
->username
[0])
3208 username
= con
->username
;
3209 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3210 IPP_TAG_NAME
)) != NULL
)
3211 username
= attr
->values
[0].string
.text
;
3214 send_ipp_status(con
, IPP_BAD_REQUEST
,
3215 _("Missing requesting-user-name attribute."));
3223 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3226 * See if we have a printer URI...
3229 if (strcmp(uri
->name
, "printer-uri"))
3231 send_ipp_status(con
, IPP_BAD_REQUEST
,
3232 _("The printer-uri attribute is required."));
3237 * And if the destination is valid...
3240 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3246 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3247 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3248 hostname
, sizeof(hostname
), &port
,
3249 resource
, sizeof(resource
));
3251 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3252 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3254 send_ipp_status(con
, IPP_NOT_FOUND
,
3255 _("The printer or class does not exist."));
3263 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3265 send_http_error(con
, status
, NULL
);
3271 for (i
= 0; i
< job_ids
->num_values
; i
++)
3273 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
3277 if (i
< job_ids
->num_values
)
3279 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3280 job_ids
->values
[i
].integer
);
3284 for (i
= 0; i
< job_ids
->num_values
; i
++)
3286 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3288 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3289 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3290 "Job canceled by user.");
3293 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3294 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3300 * Cancel all jobs on all printers...
3303 cupsdCancelJobs(NULL
, username
, purge
);
3305 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3306 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3316 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3319 send_http_error(con
, status
, printer
);
3325 for (i
= 0; i
< job_ids
->num_values
; i
++)
3327 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3328 _cups_strcasecmp(job
->dest
, printer
->name
))
3332 if (i
< job_ids
->num_values
)
3334 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3335 job_ids
->values
[i
].integer
);
3339 for (i
= 0; i
< job_ids
->num_values
; i
++)
3341 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3343 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3344 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3345 "Job canceled by user.");
3348 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3349 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3355 * Cancel all of the jobs on the named printer...
3358 cupsdCancelJobs(printer
->name
, username
, purge
);
3360 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3362 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3367 con
->response
->request
.status
.status_code
= IPP_OK
;
3372 * 'cancel_job()' - Cancel a print job.
3376 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3377 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3379 ipp_attribute_t
*attr
; /* Current attribute */
3380 int jobid
; /* Job ID */
3381 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3382 username
[HTTP_MAX_URI
], /* Username portion of URI */
3383 host
[HTTP_MAX_URI
], /* Host portion of URI */
3384 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3385 int port
; /* Port portion of URI */
3386 cupsd_job_t
*job
; /* Job information */
3387 cups_ptype_t dtype
; /* Destination type (printer/class) */
3388 cupsd_printer_t
*printer
; /* Printer data */
3389 cupsd_jobaction_t purge
; /* Purge the job? */
3392 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3393 con
->http
.fd
, uri
->values
[0].string
.text
);
3396 * See if we have a job URI or a printer URI...
3399 if (!strcmp(uri
->name
, "printer-uri"))
3402 * Got a printer URI; see if we also have a job-id attribute...
3405 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3406 IPP_TAG_INTEGER
)) == NULL
)
3408 send_ipp_status(con
, IPP_BAD_REQUEST
,
3409 _("Got a printer-uri attribute but no job-id."));
3413 if ((jobid
= attr
->values
[0].integer
) == 0)
3416 * Find the current job on the specified printer...
3419 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3425 send_ipp_status(con
, IPP_NOT_FOUND
,
3426 _("The printer or class does not exist."));
3431 * See if there are any pending jobs...
3434 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3436 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3437 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3438 !_cups_strcasecmp(job
->dest
, printer
->name
))
3446 * No, try stopped jobs...
3449 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3451 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3452 if (job
->state_value
== IPP_JOB_STOPPED
&&
3453 !_cups_strcasecmp(job
->dest
, printer
->name
))
3460 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3470 * Got a job URI; parse it to get the job ID...
3473 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3474 sizeof(scheme
), username
, sizeof(username
), host
,
3475 sizeof(host
), &port
, resource
, sizeof(resource
));
3477 if (strncmp(resource
, "/jobs/", 6))
3483 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3484 uri
->values
[0].string
.text
);
3488 jobid
= atoi(resource
+ 6);
3492 * Look for the "purge-job" attribute...
3495 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3496 IPP_TAG_BOOLEAN
)) != NULL
)
3497 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3499 purge
= CUPSD_JOB_DEFAULT
;
3502 * See if the job exists...
3505 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3508 * Nope - return a "not found" error...
3511 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3516 * See if the job is owned by the requesting user...
3519 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3521 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3522 cupsdFindDest(job
->dest
));
3527 * See if the job is already completed, canceled, or aborted; if so,
3528 * we can't cancel...
3531 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3533 switch (job
->state_value
)
3535 case IPP_JOB_CANCELED
:
3536 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3537 _("Job #%d is already canceled - can\'t cancel."),
3541 case IPP_JOB_ABORTED
:
3542 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3543 _("Job #%d is already aborted - can\'t cancel."),
3548 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3549 _("Job #%d is already completed - can\'t cancel."),
3558 * Cancel the job and return...
3561 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3562 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3563 "Job canceled by \"%s\"",
3567 if (purge
== CUPSD_JOB_PURGE
)
3568 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3571 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3574 con
->response
->request
.status
.status_code
= IPP_OK
;
3579 * 'cancel_subscription()' - Cancel a subscription.
3583 cancel_subscription(
3584 cupsd_client_t
*con
, /* I - Client connection */
3585 int sub_id
) /* I - Subscription ID */
3587 http_status_t status
; /* Policy status */
3588 cupsd_subscription_t
*sub
; /* Subscription */
3591 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3592 "cancel_subscription(con=%p[%d], sub_id=%d)",
3593 con
, con
->http
.fd
, sub_id
);
3596 * Is the subscription ID valid?
3599 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3602 * Bad subscription ID...
3605 send_ipp_status(con
, IPP_NOT_FOUND
,
3606 _("Subscription #%d does not exist."), sub_id
);
3614 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3616 con
, sub
->owner
)) != HTTP_OK
)
3618 send_http_error(con
, status
, sub
->dest
);
3623 * Cancel the subscription...
3626 cupsdDeleteSubscription(sub
, 1);
3628 con
->response
->request
.status
.status_code
= IPP_OK
;
3633 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3636 static int /* O - 1 if OK, 0 if not */
3637 check_rss_recipient(
3638 const char *recipient
) /* I - Recipient URI */
3640 cupsd_subscription_t
*sub
; /* Current subscription */
3643 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3645 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3649 * Compare the URIs up to the first ?...
3652 const char *r1
, *r2
;
3654 for (r1
= recipient
, r2
= sub
->recipient
;
3655 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3667 * 'check_quotas()' - Check quotas for a printer and user.
3670 static int /* O - 1 if OK, 0 if forbidden,
3671 -1 if limit reached */
3672 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3673 cupsd_printer_t
*p
) /* I - Printer or class */
3675 char username
[33], /* Username */
3676 *name
; /* Current user name */
3677 cupsd_quota_t
*q
; /* Quota data */
3678 #ifdef HAVE_MBR_UID_TO_UUID
3680 * Use Apple membership APIs which require that all names represent
3681 * valid user account or group records accessible by the server.
3684 uuid_t usr_uuid
; /* UUID for job requesting user */
3685 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3686 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3687 int mbr_err
; /* Error from membership function */
3688 int is_member
; /* Is this user a member? */
3691 * Use standard POSIX APIs for checking users and groups...
3694 struct passwd
*pw
; /* User password data */
3695 #endif /* HAVE_MBR_UID_TO_UUID */
3698 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3699 con
, con
->http
.fd
, p
, p
->name
);
3702 * Figure out who is printing...
3705 strlcpy(username
, get_username(con
), sizeof(username
));
3707 if ((name
= strchr(username
, '@')) != NULL
)
3708 *name
= '\0'; /* Strip @REALM */
3711 * Check global active job limits for printers and users...
3714 if (MaxJobsPerPrinter
)
3717 * Check if there are too many pending jobs on this printer...
3720 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3722 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3731 * Check if there are too many pending jobs for this user...
3734 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3736 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3743 * Check against users...
3746 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3749 if (cupsArrayCount(p
->users
))
3751 #ifdef HAVE_MBR_UID_TO_UUID
3753 * Get UUID for job requesting user...
3756 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3762 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3763 "check_quotas: UUID lookup failed for user \"%s\"",
3765 cupsdLogMessage(CUPSD_LOG_INFO
,
3766 "Denying user \"%s\" access to printer \"%s\" "
3767 "(unknown user)...",
3773 * Get UID and GID of requesting user...
3776 pw
= getpwnam(username
);
3778 #endif /* HAVE_MBR_UID_TO_UUID */
3780 for (name
= (char *)cupsArrayFirst(p
->users
);
3782 name
= (char *)cupsArrayNext(p
->users
))
3786 * Check group membership...
3789 #ifdef HAVE_MBR_UID_TO_UUID
3792 if (uuid_parse(name
+ 2, grp_uuid
))
3793 uuid_clear(grp_uuid
);
3795 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3798 * Invalid ACL entries are ignored for matching; just record a
3799 * warning in the log...
3802 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3803 "check_quotas: UUID lookup failed for ACL entry "
3804 "\"%s\" (err=%d)", name
, mbr_err
);
3805 cupsdLogMessage(CUPSD_LOG_WARN
,
3806 "Access control entry \"%s\" not a valid group name; "
3807 "entry ignored", name
);
3810 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3814 * At this point, there should be no errors, but check anyways...
3817 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3818 "check_quotas: group \"%s\" membership check "
3819 "failed (err=%d)", name
+ 1, mbr_err
);
3824 * Stop if we found a match...
3831 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3833 #endif /* HAVE_MBR_UID_TO_UUID */
3835 #ifdef HAVE_MBR_UID_TO_UUID
3840 if (uuid_parse(name
+ 1, usr2_uuid
))
3841 uuid_clear(usr2_uuid
);
3843 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3846 * Invalid ACL entries are ignored for matching; just record a
3847 * warning in the log...
3850 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3851 "check_quotas: UUID lookup failed for ACL entry "
3852 "\"%s\" (err=%d)", name
, mbr_err
);
3853 cupsdLogMessage(CUPSD_LOG_WARN
,
3854 "Access control entry \"%s\" not a valid user name; "
3855 "entry ignored", name
);
3858 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3862 else if (!_cups_strcasecmp(username
, name
))
3864 #endif /* HAVE_MBR_UID_TO_UUID */
3866 if ((name
!= NULL
) == p
->deny_users
)
3868 cupsdLogMessage(CUPSD_LOG_INFO
,
3869 "Denying user \"%s\" access to printer \"%s\"...",
3879 if (p
->k_limit
|| p
->page_limit
)
3881 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3883 cupsdLogMessage(CUPSD_LOG_ERROR
,
3884 "Unable to allocate quota data for user \"%s\"",
3889 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3890 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3892 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3899 * If we have gotten this far, we're done!
3907 * 'close_job()' - Close a multi-file job.
3911 close_job(cupsd_client_t
*con
, /* I - Client connection */
3912 ipp_attribute_t
*uri
) /* I - Printer URI */
3914 cupsd_job_t
*job
; /* Job */
3915 ipp_attribute_t
*attr
; /* Attribute */
3916 char job_uri
[HTTP_MAX_URI
],
3918 username
[256]; /* User name */
3921 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3922 con
->http
.fd
, uri
->values
[0].string
.text
);
3925 * See if we have a job URI or a printer URI...
3928 if (strcmp(uri
->name
, "printer-uri"))
3931 * job-uri is not supported by Close-Job!
3934 send_ipp_status(con
, IPP_BAD_REQUEST
,
3935 _("Close-Job doesn't support the job-uri attribute."));
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 ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3954 * Nope - return a "not found" error...
3957 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3958 attr
->values
[0].integer
);
3963 * See if the job is owned by the requesting user...
3966 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3968 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3969 cupsdFindDest(job
->dest
));
3974 * Add any ending sheet...
3977 if (cupsdTimeoutJob(job
))
3980 if (job
->state_value
== IPP_JOB_STOPPED
)
3982 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3983 job
->state_value
= IPP_JOB_PENDING
;
3985 else if (job
->state_value
== IPP_JOB_HELD
)
3987 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3988 IPP_TAG_KEYWORD
)) == NULL
)
3989 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3991 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3993 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3994 job
->state_value
= IPP_JOB_PENDING
;
3999 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
4002 * Fill in the response info...
4005 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4006 con
->servername
, con
->serverport
, "/jobs/%d", job
->id
);
4007 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4010 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4012 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4015 con
->response
->request
.status
.status_code
= IPP_OK
;
4018 * Start the job if necessary...
4026 * 'copy_attrs()' - Copy attributes from one request to another.
4030 copy_attrs(ipp_t
*to
, /* I - Destination request */
4031 ipp_t
*from
, /* I - Source request */
4032 cups_array_t
*ra
, /* I - Requested attributes */
4033 ipp_tag_t group
, /* I - Group to copy */
4034 int quickcopy
, /* I - Do a quick copy? */
4035 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4037 ipp_attribute_t
*fromattr
; /* Source attribute */
4040 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4041 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4042 to
, from
, ra
, group
, quickcopy
);
4047 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4050 * Filter attributes as needed...
4053 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4054 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4057 if (!strcmp(fromattr
->name
, "job-printer-uri"))
4061 (cupsArrayFind(exclude
, fromattr
->name
) ||
4062 cupsArrayFind(exclude
, "all")))
4065 * We need to exclude this attribute for security reasons; we require the
4066 * job-id attribute regardless of the security settings for IPP
4069 * The job-printer-uri attribute is handled by copy_job_attrs().
4071 * Subscription attribute security is handled by copy_subscription_attrs().
4074 if (strcmp(fromattr
->name
, "job-id"))
4078 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4081 * Don't send collection attributes by default to IPP/1.x clients
4082 * since many do not support collections. Also don't send
4083 * media-col-database unless specifically requested by the client.
4086 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4088 (to
->request
.status
.version
[0] == 1 ||
4089 !strcmp(fromattr
->name
, "media-col-database")))
4092 ippCopyAttribute(to
, fromattr
, quickcopy
);
4099 * 'copy_banner()' - Copy a banner file to the requests directory for the
4103 static int /* O - Size of banner file in kbytes */
4104 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4105 cupsd_job_t
*job
, /* I - Job information */
4106 const char *name
) /* I - Name of banner */
4108 int i
; /* Looping var */
4109 int kbytes
; /* Size of banner file in kbytes */
4110 char filename
[1024]; /* Job filename */
4111 cupsd_banner_t
*banner
; /* Pointer to banner */
4112 cups_file_t
*in
; /* Input file */
4113 cups_file_t
*out
; /* Output file */
4114 int ch
; /* Character from file */
4115 char attrname
[255], /* Name of attribute */
4116 *s
; /* Pointer into name */
4117 ipp_attribute_t
*attr
; /* Attribute */
4120 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4121 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4122 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4123 name
? name
: "(null)");
4126 * Find the banner; return if not found or "none"...
4129 if (!name
|| !strcmp(name
, "none") ||
4130 (banner
= cupsdFindBanner(name
)) == NULL
)
4134 * Open the banner and job files...
4137 if (add_file(con
, job
, banner
->filetype
, 0))
4140 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4142 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4144 cupsdLogMessage(CUPSD_LOG_ERROR
,
4145 "Unable to create banner job file %s - %s",
4146 filename
, strerror(errno
));
4151 fchmod(cupsFileNumber(out
), 0640);
4152 fchown(cupsFileNumber(out
), RunUser
, Group
);
4155 * Try the localized banner file under the subdirectory...
4158 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4160 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4163 * Convert ll-cc to ll_CC...
4167 attrname
[3] = toupper(attrname
[3] & 255);
4168 attrname
[4] = toupper(attrname
[4] & 255);
4171 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4174 if (access(filename
, 0) && strlen(attrname
) > 2)
4177 * Wasn't able to find "ll_CC" locale file; try the non-national
4178 * localization banner directory.
4183 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4187 if (access(filename
, 0))
4190 * Use the non-localized banner file.
4193 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4196 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4200 cupsdLogMessage(CUPSD_LOG_ERROR
,
4201 "Unable to open banner template file %s - %s",
4202 filename
, strerror(errno
));
4208 * Parse the file to the end...
4211 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4215 * Get an attribute name...
4218 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4219 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4221 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4231 * Ignore { followed by stuff that is not an attribute name...
4234 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4239 * See if it is defined...
4242 if (attrname
[0] == '?')
4247 if (!strcmp(s
, "printer-name"))
4249 cupsFilePuts(out
, job
->dest
);
4252 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4255 * See if we have a leading question mark...
4258 if (attrname
[0] != '?')
4261 * Nope, write to file as-is; probably a PostScript procedure...
4264 cupsFilePrintf(out
, "{%s}", attrname
);
4271 * Output value(s)...
4274 for (i
= 0; i
< attr
->num_values
; i
++)
4277 cupsFilePutChar(out
, ',');
4279 switch (attr
->value_tag
)
4281 case IPP_TAG_INTEGER
:
4283 if (!strncmp(s
, "time-at-", 8))
4285 struct timeval tv
; /* Time value */
4287 tv
.tv_sec
= attr
->values
[i
].integer
;
4290 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4293 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4296 case IPP_TAG_BOOLEAN
:
4297 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4300 case IPP_TAG_NOVALUE
:
4301 cupsFilePuts(out
, "novalue");
4304 case IPP_TAG_RANGE
:
4305 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4306 attr
->values
[i
].range
.upper
);
4309 case IPP_TAG_RESOLUTION
:
4310 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4311 attr
->values
[i
].resolution
.yres
,
4312 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4317 case IPP_TAG_STRING
:
4320 case IPP_TAG_KEYWORD
:
4321 case IPP_TAG_CHARSET
:
4322 case IPP_TAG_LANGUAGE
:
4323 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4326 * Need to quote strings for PS banners...
4331 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4333 if (*p
== '(' || *p
== ')' || *p
== '\\')
4335 cupsFilePutChar(out
, '\\');
4336 cupsFilePutChar(out
, *p
);
4338 else if (*p
< 32 || *p
> 126)
4339 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4341 cupsFilePutChar(out
, *p
);
4345 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4349 break; /* anti-compiler-warning-code */
4353 else if (ch
== '\\') /* Quoted char */
4355 ch
= cupsFileGetChar(in
);
4357 if (ch
!= '{') /* Only do special handling for \{ */
4358 cupsFilePutChar(out
, '\\');
4360 cupsFilePutChar(out
, ch
);
4363 cupsFilePutChar(out
, ch
);
4367 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4369 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4370 IPP_TAG_INTEGER
)) != NULL
)
4371 attr
->values
[0].integer
+= kbytes
;
4380 * 'copy_file()' - Copy a PPD file or interface script...
4383 static int /* O - 0 = success, -1 = error */
4384 copy_file(const char *from
, /* I - Source file */
4385 const char *to
) /* I - Destination file */
4387 cups_file_t
*src
, /* Source file */
4388 *dst
; /* Destination file */
4389 int bytes
; /* Bytes to read/write */
4390 char buffer
[2048]; /* Copy buffer */
4393 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4396 * Open the source and destination file for a copy...
4399 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4402 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4409 * Copy the source file to the destination...
4412 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4413 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
4421 * Close both files and return...
4426 return (cupsFileClose(dst
));
4431 * 'copy_model()' - Copy a PPD model file, substituting default values
4435 static int /* O - 0 = success, -1 = error */
4436 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4437 const char *from
, /* I - Source file */
4438 const char *to
) /* I - Destination file */
4440 fd_set input
; /* select() input set */
4441 struct timeval timeout
; /* select() timeout */
4442 int maxfd
; /* Max file descriptor for select() */
4443 char tempfile
[1024]; /* Temporary PPD file */
4444 int tempfd
; /* Temporary PPD file descriptor */
4445 int temppid
; /* Process ID of cups-driverd */
4446 int temppipe
[2]; /* Temporary pipes */
4447 char *argv
[4], /* Command-line arguments */
4448 *envp
[MAX_ENV
]; /* Environment */
4449 cups_file_t
*src
, /* Source file */
4450 *dst
; /* Destination file */
4451 ppd_file_t
*ppd
; /* PPD file */
4452 int bytes
, /* Bytes from pipe */
4453 total
; /* Total bytes from pipe */
4454 char buffer
[2048]; /* Copy buffer */
4455 int i
; /* Looping var */
4456 char option
[PPD_MAX_NAME
], /* Option name */
4457 choice
[PPD_MAX_NAME
]; /* Choice name */
4458 ppd_size_t
*size
; /* Default size */
4459 int num_defaults
; /* Number of default options */
4460 cups_option_t
*defaults
; /* Default options */
4461 char cups_protocol
[PPD_MAX_LINE
];
4462 /* cupsProtocol attribute */
4465 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4466 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4470 * Run cups-driverd to get the PPD file...
4473 argv
[0] = "cups-driverd";
4475 argv
[2] = (char *)from
;
4478 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4480 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4481 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
4482 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4483 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4486 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4487 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4489 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4490 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4501 * Wait up to 30 seconds for the PPD file to be copied...
4506 if (temppipe
[0] > CGIPipes
[0])
4507 maxfd
= temppipe
[0] + 1;
4509 maxfd
= CGIPipes
[0] + 1;
4514 * See if we have data ready...
4518 FD_SET(temppipe
[0], &input
);
4519 FD_SET(CGIPipes
[0], &input
);
4521 timeout
.tv_sec
= 30;
4522 timeout
.tv_usec
= 0;
4524 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4534 * We have timed out...
4540 if (FD_ISSET(temppipe
[0], &input
))
4543 * Read the PPD file from the pipe, and write it to the PPD file.
4546 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4548 if (write(tempfd
, buffer
, bytes
) < bytes
)
4557 if (FD_ISSET(CGIPipes
[0], &input
))
4567 * No data from cups-deviced...
4570 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4576 * Open the source file for a copy...
4579 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4586 * Read the source file and see what page sizes are supported...
4589 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4597 * Open the destination (if possible) and set the default options...
4602 cups_protocol
[0] = '\0';
4604 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4607 * Read all of the default lines from the old PPD...
4610 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4611 if (!strncmp(buffer
, "*Default", 8))
4614 * Add the default option...
4617 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4618 choice
, sizeof(choice
)))
4620 ppd_option_t
*ppdo
; /* PPD option */
4624 * Only add the default if the default hasn't already been
4625 * set and the choice exists in the new PPD...
4628 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4629 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4630 ppdFindChoice(ppdo
, choice
))
4631 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4635 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4636 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4640 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4643 * Add the default media sizes...
4646 num_defaults
= cupsAddOption("PageSize", size
->name
,
4647 num_defaults
, &defaults
);
4648 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4649 num_defaults
, &defaults
);
4650 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4651 num_defaults
, &defaults
);
4652 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4653 num_defaults
, &defaults
);
4659 * Open the destination file for a copy...
4662 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4664 cupsFreeOptions(num_defaults
, defaults
);
4671 * Copy the source file to the destination...
4674 cupsFileRewind(src
);
4676 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4678 if (!strncmp(buffer
, "*Default", 8))
4681 * Check for an previous default option choice...
4684 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4685 choice
, sizeof(choice
)))
4687 const char *val
; /* Default option value */
4690 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4693 * Substitute the previous choice...
4696 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4701 cupsFilePrintf(dst
, "%s\n", buffer
);
4704 if (cups_protocol
[0])
4705 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4707 cupsFreeOptions(num_defaults
, defaults
);
4710 * Close both files and return...
4717 return (cupsFileClose(dst
));
4722 * 'copy_job_attrs()' - Copy job attributes.
4726 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4727 cupsd_job_t
*job
, /* I - Job */
4728 cups_array_t
*ra
, /* I - Requested attributes array */
4729 cups_array_t
*exclude
) /* I - Private attributes array */
4731 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4735 * Send the requested attributes for each job...
4738 if (!cupsArrayFind(exclude
, "all"))
4740 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4741 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4742 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4743 "number-of-documents", job
->num_files
);
4745 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4746 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4747 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4748 "job-media-progress", job
->progress
);
4750 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4751 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4753 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4754 NULL
, con
->servername
, con
->serverport
, "/jobs/%d",
4756 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4757 "job-more-info", NULL
, job_uri
);
4760 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4761 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4762 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4763 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4764 job
->num_files
> 0);
4766 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4767 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4768 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4769 "job-printer-up-time", time(NULL
));
4772 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4774 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4775 con
->servername
, con
->serverport
,
4776 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4779 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4780 "job-printer-uri", NULL
, job_uri
);
4783 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4785 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4786 con
->servername
, con
->serverport
, "/jobs/%d",
4788 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4789 "job-uri", NULL
, job_uri
);
4792 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4797 * 'copy_printer_attrs()' - Copy printer attributes.
4802 cupsd_client_t
*con
, /* I - Client connection */
4803 cupsd_printer_t
*printer
, /* I - Printer */
4804 cups_array_t
*ra
) /* I - Requested attributes array */
4806 char printer_uri
[HTTP_MAX_URI
];
4808 char printer_icons
[HTTP_MAX_URI
];
4810 time_t curtime
; /* Current time */
4811 int i
; /* Looping var */
4815 * Copy the printer attributes to the response using requested-attributes
4816 * and document-format attributes that may be provided by the client.
4819 curtime
= time(NULL
);
4821 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4822 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4823 "marker-change-time", printer
->marker_time
);
4825 if (printer
->num_printers
> 0 &&
4826 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4828 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4829 cupsd_printer_t
*p2
; /* Printer in class */
4830 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4833 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4834 IPP_TAG_URI
, "member-uris",
4835 printer
->num_printers
, NULL
,
4838 for (i
= 0; i
< printer
->num_printers
; i
++)
4840 p2
= printer
->printers
[i
];
4842 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4843 IPP_TAG_URI
)) != NULL
)
4844 member_uris
->values
[i
].string
.text
=
4845 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4848 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4849 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
4851 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4852 "/classes/%s" : "/printers/%s", p2
->name
);
4853 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4859 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4860 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4861 "printer-alert", NULL
, printer
->alert
);
4863 if (printer
->alert_description
&&
4864 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4865 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4866 "printer-alert-description", NULL
,
4867 printer
->alert_description
);
4869 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4870 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4871 ippTimeToDate(curtime
));
4873 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4874 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4876 if (printer
->reg_name
)
4877 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4878 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4880 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4881 "printer-dns-sd-name", 0);
4883 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4885 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4886 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4887 "printer-error-policy", NULL
, printer
->error_policy
);
4889 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4891 static const char * const errors
[] =/* printer-error-policy-supported values */
4894 "retry-current-job",
4899 if (printer
->type
& CUPS_PRINTER_CLASS
)
4900 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4901 "printer-error-policy-supported", NULL
, "retry-current-job");
4903 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4904 "printer-error-policy-supported",
4905 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4908 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4910 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4911 "http", NULL
, con
->servername
, con
->serverport
,
4912 "/icons/%s.png", printer
->name
);
4913 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4914 NULL
, printer_icons
);
4915 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4918 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4919 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
4920 printer
->accepting
);
4922 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4923 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
4926 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4928 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4929 "http", NULL
, con
->servername
, con
->serverport
,
4930 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4931 "/classes/%s" : "/printers/%s", printer
->name
);
4932 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4933 "printer-more-info", NULL
, printer_uri
);
4936 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4937 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4938 "printer-op-policy", NULL
, printer
->op_policy
);
4940 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4941 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4944 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4945 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4946 "printer-state-change-time", printer
->state_time
);
4948 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4949 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4950 "printer-state-message", NULL
, printer
->state_message
);
4952 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4953 add_printer_state_reasons(con
, printer
);
4955 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4957 int type
; /* printer-type value */
4960 * Add the CUPS-specific printer-type attribute...
4963 type
= printer
->type
;
4965 if (printer
== DefaultPrinter
)
4966 type
|= CUPS_PRINTER_DEFAULT
;
4968 if (!printer
->accepting
)
4969 type
|= CUPS_PRINTER_REJECTING
;
4971 if (!printer
->shared
)
4972 type
|= CUPS_PRINTER_NOT_SHARED
;
4974 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
4978 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
4979 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4980 "printer-up-time", curtime
);
4982 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
4984 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4985 "ipp", NULL
, con
->servername
, con
->serverport
,
4986 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4987 "/classes/%s" : "/printers/%s", printer
->name
);
4988 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4989 "printer-uri-supported", NULL
, printer_uri
);
4990 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
4994 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
4995 add_queued_job_count(con
, printer
);
4997 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
4998 if (printer
->ppd_attrs
)
4999 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5000 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5005 * 'copy_subscription_attrs()' - Copy subscription attributes.
5009 copy_subscription_attrs(
5010 cupsd_client_t
*con
, /* I - Client connection */
5011 cupsd_subscription_t
*sub
, /* I - Subscription */
5012 cups_array_t
*ra
, /* I - Requested attributes array */
5013 cups_array_t
*exclude
) /* I - Private attributes array */
5015 ipp_attribute_t
*attr
; /* Current attribute */
5016 char printer_uri
[HTTP_MAX_URI
];
5018 int count
; /* Number of events */
5019 unsigned mask
; /* Current event mask */
5020 const char *name
; /* Current event name */
5023 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5024 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5025 con
, sub
, ra
, exclude
);
5028 * Copy the subscription attributes to the response using the
5029 * requested-attributes attribute that may be provided by the client.
5032 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5034 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5035 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5037 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5039 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5042 * Simple event list...
5045 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5046 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5047 "notify-events", NULL
, name
);
5052 * Complex event list...
5055 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5056 if (sub
->mask
& mask
)
5059 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5060 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5061 "notify-events", count
, NULL
, NULL
);
5063 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5064 if (sub
->mask
& mask
)
5066 attr
->values
[count
].string
.text
=
5067 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5074 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5075 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5076 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5077 "notify-lease-duration", sub
->lease
);
5079 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5080 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5081 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5082 "notify-recipient-uri", NULL
, sub
->recipient
);
5083 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5084 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5085 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5086 "notify-pull-method", NULL
, "ippget");
5088 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5089 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5090 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5091 "notify-subscriber-user-name", NULL
, sub
->owner
);
5093 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5094 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5095 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5096 "notify-time-interval", sub
->interval
);
5098 if (sub
->user_data_len
> 0 &&
5099 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5100 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5101 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5102 sub
->user_data
, sub
->user_data_len
);
5105 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5106 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5107 "notify-job-id", sub
->job
->id
);
5109 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5111 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5112 "ipp", NULL
, con
->servername
, con
->serverport
,
5113 "/printers/%s", sub
->dest
->name
);
5114 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5115 "notify-printer-uri", NULL
, printer_uri
);
5118 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5119 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5120 "notify-subscription-id", sub
->id
);
5125 * 'create_job()' - Print a file to a printer or class.
5129 create_job(cupsd_client_t
*con
, /* I - Client connection */
5130 ipp_attribute_t
*uri
) /* I - Printer URI */
5132 int i
; /* Looping var */
5133 cupsd_printer_t
*printer
; /* Printer */
5134 cupsd_job_t
*job
; /* New job */
5135 static const char * const forbidden_attrs
[] =
5136 { /* List of forbidden attributes */
5140 "document-natural-language"
5144 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5145 con
->http
.fd
, uri
->values
[0].string
.text
);
5148 * Is the destination valid?
5151 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5157 send_ipp_status(con
, IPP_NOT_FOUND
,
5158 _("The printer or class does not exist."));
5163 * Check for invalid Create-Job attributes and log a warning or error depending
5164 * on whether cupsd is running in "strict conformance" mode...
5168 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5170 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5172 if (StrictConformance
)
5174 send_ipp_status(con
, IPP_BAD_REQUEST
,
5175 _("The '%s' operation attribute cannot be supplied in a "
5176 "Create-Job request."), forbidden_attrs
[i
]);
5180 cupsdLogMessage(CUPSD_LOG_WARN
,
5181 "Unexpected '%s' operation attribute in a Create-Job "
5182 "request.", forbidden_attrs
[i
]);
5186 * Create the job object...
5189 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5192 job
->pending_timeout
= 1;
5195 * Save and log the job...
5198 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5199 job
->dest
, job
->username
);
5204 * 'create_requested_array()' - Create an array for the requested-attributes.
5207 static cups_array_t
* /* O - Array of attributes or NULL */
5208 create_requested_array(ipp_t
*request
) /* I - IPP request */
5210 int i
; /* Looping var */
5211 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5212 cups_array_t
*ra
; /* Requested attributes array */
5213 char *value
; /* Current value */
5217 * Get the requested-attributes attribute, and return NULL if we don't
5221 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5222 IPP_TAG_KEYWORD
)) == NULL
)
5226 * If the attribute contains a single "all" keyword, return NULL...
5229 if (requested
->num_values
== 1 &&
5230 !strcmp(requested
->values
[0].string
.text
, "all"))
5234 * Create an array using "strcmp" as the comparison function...
5237 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5239 for (i
= 0; i
< requested
->num_values
; i
++)
5241 value
= requested
->values
[i
].string
.text
;
5243 if (!strcmp(value
, "job-template"))
5245 /* Only includes the set of Job Template attributes supported by CUPS */
5246 cupsArrayAdd(ra
, "copies");
5247 cupsArrayAdd(ra
, "copies-default");
5248 cupsArrayAdd(ra
, "copies-supported");
5249 cupsArrayAdd(ra
, "finishings");
5250 cupsArrayAdd(ra
, "finishings-default");
5251 cupsArrayAdd(ra
, "finishings-supported");
5252 cupsArrayAdd(ra
, "job-hold-until");
5253 cupsArrayAdd(ra
, "job-hold-until-default");
5254 cupsArrayAdd(ra
, "job-hold-until-supported");
5255 cupsArrayAdd(ra
, "job-priority");
5256 cupsArrayAdd(ra
, "job-priority-default");
5257 cupsArrayAdd(ra
, "job-priority-supported");
5258 cupsArrayAdd(ra
, "job-sheets");
5259 cupsArrayAdd(ra
, "job-sheets-default");
5260 cupsArrayAdd(ra
, "job-sheets-supported");
5261 cupsArrayAdd(ra
, "media");
5262 cupsArrayAdd(ra
, "media-col");
5263 cupsArrayAdd(ra
, "media-col-default");
5264 cupsArrayAdd(ra
, "media-default");
5265 cupsArrayAdd(ra
, "media-supported");
5266 cupsArrayAdd(ra
, "multiple-document-handling");
5267 cupsArrayAdd(ra
, "multiple-document-handling-default");
5268 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5269 cupsArrayAdd(ra
, "number-up");
5270 cupsArrayAdd(ra
, "number-up-default");
5271 cupsArrayAdd(ra
, "number-up-layout");
5272 cupsArrayAdd(ra
, "number-up-layout-default");
5273 cupsArrayAdd(ra
, "number-up-layout-supported");
5274 cupsArrayAdd(ra
, "number-up-supported");
5275 cupsArrayAdd(ra
, "orientation-requested");
5276 cupsArrayAdd(ra
, "orientation-requested-default");
5277 cupsArrayAdd(ra
, "orientation-requested-supported");
5278 cupsArrayAdd(ra
, "output-bin");
5279 cupsArrayAdd(ra
, "output-bin-default");
5280 cupsArrayAdd(ra
, "output-bin-supported");
5281 cupsArrayAdd(ra
, "page-delivery");
5282 cupsArrayAdd(ra
, "page-delivery-default");
5283 cupsArrayAdd(ra
, "page-delivery-supported");
5284 cupsArrayAdd(ra
, "page-order-received");
5285 cupsArrayAdd(ra
, "page-order-received-default");
5286 cupsArrayAdd(ra
, "page-order-received-supported");
5287 cupsArrayAdd(ra
, "page-ranges");
5288 cupsArrayAdd(ra
, "page-ranges-supported");
5289 cupsArrayAdd(ra
, "presentation-direction-number-up");
5290 cupsArrayAdd(ra
, "presentation-direction-number-up-default");
5291 cupsArrayAdd(ra
, "presentation-direction-number-up-supported");
5292 cupsArrayAdd(ra
, "print-color-mode");
5293 cupsArrayAdd(ra
, "print-color-mode-default");
5294 cupsArrayAdd(ra
, "print-color-mode-supported");
5295 cupsArrayAdd(ra
, "print-content-optimize");
5296 cupsArrayAdd(ra
, "print-content-optimize-default");
5297 cupsArrayAdd(ra
, "print-content-optimize-supported");
5298 cupsArrayAdd(ra
, "print-quality");
5299 cupsArrayAdd(ra
, "print-quality-default");
5300 cupsArrayAdd(ra
, "print-quality-supported");
5301 cupsArrayAdd(ra
, "printer-resolution");
5302 cupsArrayAdd(ra
, "printer-resolution-default");
5303 cupsArrayAdd(ra
, "printer-resolution-supported");
5304 cupsArrayAdd(ra
, "sheet-collate");
5305 cupsArrayAdd(ra
, "sheet-collate-default");
5306 cupsArrayAdd(ra
, "sheet-collate-supported");
5307 cupsArrayAdd(ra
, "sides");
5308 cupsArrayAdd(ra
, "sides-default");
5309 cupsArrayAdd(ra
, "sides-supported");
5311 else if (!strcmp(value
, "job-description"))
5313 /* Only includes the set of Job Description attributes supported by CUPS */
5314 cupsArrayAdd(ra
, "date-time-at-completed");
5315 cupsArrayAdd(ra
, "date-time-at-creation");
5316 cupsArrayAdd(ra
, "date-time-at-processing");
5317 cupsArrayAdd(ra
, "job-charge-info");
5318 cupsArrayAdd(ra
, "job-detailed-status-message");
5319 cupsArrayAdd(ra
, "job-document-access-errors");
5320 cupsArrayAdd(ra
, "job-id");
5321 cupsArrayAdd(ra
, "job-impressions");
5322 cupsArrayAdd(ra
, "job-impressions-completed");
5323 cupsArrayAdd(ra
, "job-k-octets");
5324 cupsArrayAdd(ra
, "job-k-octets-processed");
5325 cupsArrayAdd(ra
, "job-mandatory-attributes");
5326 cupsArrayAdd(ra
, "job-media-progress");
5327 cupsArrayAdd(ra
, "job-media-sheets");
5328 cupsArrayAdd(ra
, "job-media-sheets-completed");
5329 cupsArrayAdd(ra
, "job-message-from-operator");
5330 cupsArrayAdd(ra
, "job-more-info");
5331 cupsArrayAdd(ra
, "job-name");
5332 cupsArrayAdd(ra
, "job-originating-user-name");
5333 cupsArrayAdd(ra
, "job-printer-up-time");
5334 cupsArrayAdd(ra
, "job-printer-uri");
5335 cupsArrayAdd(ra
, "job-state");
5336 cupsArrayAdd(ra
, "job-state-message");
5337 cupsArrayAdd(ra
, "job-state-reasons");
5338 cupsArrayAdd(ra
, "job-uri");
5339 cupsArrayAdd(ra
, "number-of-documents");
5340 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5341 cupsArrayAdd(ra
, "output-device-assigned");
5342 cupsArrayAdd(ra
, "time-at-completed");
5343 cupsArrayAdd(ra
, "time-at-creation");
5344 cupsArrayAdd(ra
, "time-at-processing");
5346 else if (!strcmp(value
, "printer-description"))
5348 /* Only includes the set of Printer Description attributes supported by CUPS */
5349 cupsArrayAdd(ra
, "charset-configured");
5350 cupsArrayAdd(ra
, "charset-supported");
5351 cupsArrayAdd(ra
, "color-supported");
5352 cupsArrayAdd(ra
, "compression-supported");
5353 cupsArrayAdd(ra
, "document-format-default");
5354 cupsArrayAdd(ra
, "document-format-supported");
5355 cupsArrayAdd(ra
, "generated-natural-language-supported");
5356 cupsArrayAdd(ra
, "ipp-versions-supported");
5357 cupsArrayAdd(ra
, "job-creation-attributes-supported");
5358 cupsArrayAdd(ra
, "job-ids-supported");
5359 cupsArrayAdd(ra
, "job-impressions-supported");
5360 cupsArrayAdd(ra
, "job-k-octets-supported");
5361 cupsArrayAdd(ra
, "job-media-sheets-supported");
5362 cupsArrayAdd(ra
, "job-settable-attributes-supported");
5363 cupsArrayAdd(ra
, "jpeg-k-octets-supported");
5364 cupsArrayAdd(ra
, "jpeg-x-dimension-supported");
5365 cupsArrayAdd(ra
, "jpeg-y-dimension-supported");
5366 cupsArrayAdd(ra
, "media-bottom-margin-supported");
5367 cupsArrayAdd(ra
, "media-col-supported");
5368 cupsArrayAdd(ra
, "media-key-supported");
5369 cupsArrayAdd(ra
, "media-left-margin-supported");
5370 cupsArrayAdd(ra
, "media-right-margin-supported");
5371 cupsArrayAdd(ra
, "media-size-supported");
5372 cupsArrayAdd(ra
, "media-source-supported");
5373 cupsArrayAdd(ra
, "media-top-margin-supported");
5374 cupsArrayAdd(ra
, "media-type-supported");
5375 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5376 cupsArrayAdd(ra
, "multiple-operation-time-out");
5377 cupsArrayAdd(ra
, "natural-language-configured");
5378 cupsArrayAdd(ra
, "notify-max-events-supported");
5379 cupsArrayAdd(ra
, "notify-schemes-supported");
5380 cupsArrayAdd(ra
, "operations-supported");
5381 cupsArrayAdd(ra
, "pages-per-minute");
5382 cupsArrayAdd(ra
, "pages-per-minute-color");
5383 cupsArrayAdd(ra
, "pdf-k-octets-supported");
5384 cupsArrayAdd(ra
, "pdl-override-supported");
5385 cupsArrayAdd(ra
, "printer-alert");
5386 cupsArrayAdd(ra
, "printer-alert-description");
5387 cupsArrayAdd(ra
, "printer-charge-info-uri");
5388 cupsArrayAdd(ra
, "printer-commands");
5389 cupsArrayAdd(ra
, "printer-current-time");
5390 cupsArrayAdd(ra
, "printer-dns-sd-name");
5391 cupsArrayAdd(ra
, "printer-info");
5392 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5393 cupsArrayAdd(ra
, "printer-is-shared");
5394 cupsArrayAdd(ra
, "printer-location");
5395 cupsArrayAdd(ra
, "printer-make-and-model");
5396 cupsArrayAdd(ra
, "printer-message-from-operator");
5397 cupsArrayAdd(ra
, "printer-more-info");
5398 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5399 cupsArrayAdd(ra
, "printer-name");
5400 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
5401 cupsArrayAdd(ra
, "printer-state");
5402 cupsArrayAdd(ra
, "printer-state-change-date-time");
5403 cupsArrayAdd(ra
, "printer-state-change-time");
5404 cupsArrayAdd(ra
, "printer-state-message");
5405 cupsArrayAdd(ra
, "printer-state-reasons");
5406 cupsArrayAdd(ra
, "printer-type");
5407 cupsArrayAdd(ra
, "printer-up-time");
5408 cupsArrayAdd(ra
, "printer-uri-supported");
5409 cupsArrayAdd(ra
, "queued-job-count");
5410 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5411 cupsArrayAdd(ra
, "uri-authentication-supported");
5412 cupsArrayAdd(ra
, "uri-security-supported");
5413 cupsArrayAdd(ra
, "which-jobs-supported");
5415 else if (!strcmp(value
, "printer-defaults"))
5417 char *name
; /* Option name */
5420 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5422 name
= (char *)cupsArrayNext(CommonDefaults
))
5423 cupsArrayAdd(ra
, name
);
5425 else if (!strcmp(value
, "subscription-description"))
5427 /* Only includes the set of Subscription Description attributes supported by CUPS */
5428 cupsArrayAdd(ra
, "notify-job-id");
5429 cupsArrayAdd(ra
, "notify-lease-expiration-time");
5430 cupsArrayAdd(ra
, "notify-printer-up-time");
5431 cupsArrayAdd(ra
, "notify-printer-uri");
5432 cupsArrayAdd(ra
, "notify-sequence-number");
5433 cupsArrayAdd(ra
, "notify-subscriber-user-name");
5434 cupsArrayAdd(ra
, "notify-subscription-id");
5436 else if (!strcmp(value
, "subscription-template"))
5438 /* Only includes the set of Subscription Template attributes supported by CUPS */
5439 cupsArrayAdd(ra
, "notify-attributes");
5440 cupsArrayAdd(ra
, "notify-attributes-supported");
5441 cupsArrayAdd(ra
, "notify-charset");
5442 cupsArrayAdd(ra
, "notify-events");
5443 cupsArrayAdd(ra
, "notify-events-default");
5444 cupsArrayAdd(ra
, "notify-events-supported");
5445 cupsArrayAdd(ra
, "notify-lease-duration");
5446 cupsArrayAdd(ra
, "notify-lease-duration-default");
5447 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5448 cupsArrayAdd(ra
, "notify-natural-language");
5449 cupsArrayAdd(ra
, "notify-pull-method");
5450 cupsArrayAdd(ra
, "notify-pull-method-supported");
5451 cupsArrayAdd(ra
, "notify-recipient-uri");
5452 cupsArrayAdd(ra
, "notify-time-interval");
5453 cupsArrayAdd(ra
, "notify-user-data");
5456 cupsArrayAdd(ra
, value
);
5464 * 'create_subscription()' - Create a notification subscription.
5468 create_subscription(
5469 cupsd_client_t
*con
, /* I - Client connection */
5470 ipp_attribute_t
*uri
) /* I - Printer URI */
5472 http_status_t status
; /* Policy status */
5473 int i
; /* Looping var */
5474 ipp_attribute_t
*attr
; /* Current attribute */
5475 cups_ptype_t dtype
; /* Destination type (printer/class) */
5476 char scheme
[HTTP_MAX_URI
],
5477 /* Scheme portion of URI */
5478 userpass
[HTTP_MAX_URI
],
5479 /* Username portion of URI */
5481 /* Host portion of URI */
5482 resource
[HTTP_MAX_URI
];
5483 /* Resource portion of URI */
5484 int port
; /* Port portion of URI */
5485 cupsd_printer_t
*printer
; /* Printer/class */
5486 cupsd_job_t
*job
; /* Job */
5487 int jobid
; /* Job ID */
5488 cupsd_subscription_t
*sub
; /* Subscription object */
5489 const char *username
, /* requesting-user-name or
5490 authenticated username */
5491 *recipient
, /* notify-recipient-uri */
5492 *pullmethod
; /* notify-pull-method */
5493 ipp_attribute_t
*user_data
; /* notify-user-data */
5494 int interval
, /* notify-time-interval */
5495 lease
; /* notify-lease-duration */
5496 unsigned mask
; /* notify-events */
5497 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5498 *notify_lease
; /* notify-lease-duration(-default) */
5502 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5504 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5505 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5506 attr
->value_tag
, attr
->name
);
5508 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5513 * Is the destination valid?
5516 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5517 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
5518 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
5520 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5521 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5522 sizeof(host
), &port
, resource
, sizeof(resource
));
5524 if (!strcmp(resource
, "/"))
5526 dtype
= (cups_ptype_t
)0;
5529 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5531 dtype
= (cups_ptype_t
)0;
5534 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5536 dtype
= CUPS_PRINTER_CLASS
;
5539 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5545 send_ipp_status(con
, IPP_NOT_FOUND
,
5546 _("The printer or class does not exist."));
5556 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5559 send_http_error(con
, status
, printer
);
5563 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5565 send_http_error(con
, status
, NULL
);
5570 * Get the user that is requesting the subscription...
5573 username
= get_username(con
);
5576 * Find the first subscription group attribute; return if we have
5580 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5581 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5586 send_ipp_status(con
, IPP_BAD_REQUEST
,
5587 _("No subscription attributes in request."));
5592 * Process the subscription attributes in the request...
5595 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5603 lease
= DefaultLeaseDuration
;
5605 mask
= CUPSD_EVENT_NONE
;
5609 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5611 notify_lease
= ippFindAttribute(printer
->attrs
,
5612 "notify-lease-duration-default",
5616 lease
= notify_lease
->values
[0].integer
;
5620 notify_events
= NULL
;
5621 notify_lease
= NULL
;
5624 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5626 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5627 attr
->value_tag
== IPP_TAG_URI
)
5630 * Validate the recipient scheme against the ServerBin/notifier
5634 char notifier
[1024]; /* Notifier filename */
5637 recipient
= attr
->values
[0].string
.text
;
5639 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5640 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5641 host
, sizeof(host
), &port
,
5642 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5644 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5645 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5646 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5647 "notify-status-code", IPP_URI_SCHEME
);
5651 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5653 if (access(notifier
, X_OK
))
5655 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5656 _("notify-recipient-uri URI \"%s\" uses unknown "
5657 "scheme."), recipient
);
5658 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5659 "notify-status-code", IPP_URI_SCHEME
);
5663 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5665 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5666 _("notify-recipient-uri URI \"%s\" is already used."),
5668 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5669 "notify-status-code", IPP_ATTRIBUTES
);
5673 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5674 attr
->value_tag
== IPP_TAG_KEYWORD
)
5676 pullmethod
= attr
->values
[0].string
.text
;
5678 if (strcmp(pullmethod
, "ippget"))
5680 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5681 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5682 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5683 "notify-status-code", IPP_ATTRIBUTES
);
5687 else if (!strcmp(attr
->name
, "notify-charset") &&
5688 attr
->value_tag
== IPP_TAG_CHARSET
&&
5689 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5690 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5692 send_ipp_status(con
, IPP_CHARSET
,
5693 _("Character set \"%s\" not supported."),
5694 attr
->values
[0].string
.text
);
5697 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5698 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5699 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5701 send_ipp_status(con
, IPP_CHARSET
,
5702 _("Language \"%s\" not supported."),
5703 attr
->values
[0].string
.text
);
5706 else if (!strcmp(attr
->name
, "notify-user-data") &&
5707 attr
->value_tag
== IPP_TAG_STRING
)
5709 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5711 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5712 _("The notify-user-data value is too large "
5713 "(%d > 63 octets)."),
5714 attr
->values
[0].unknown
.length
);
5720 else if (!strcmp(attr
->name
, "notify-events") &&
5721 attr
->value_tag
== IPP_TAG_KEYWORD
)
5722 notify_events
= attr
;
5723 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5724 attr
->value_tag
== IPP_TAG_INTEGER
)
5725 lease
= attr
->values
[0].integer
;
5726 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5727 attr
->value_tag
== IPP_TAG_INTEGER
)
5728 interval
= attr
->values
[0].integer
;
5729 else if (!strcmp(attr
->name
, "notify-job-id") &&
5730 attr
->value_tag
== IPP_TAG_INTEGER
)
5731 jobid
= attr
->values
[0].integer
;
5738 for (i
= 0; i
< notify_events
->num_values
; i
++)
5739 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5743 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5745 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5746 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5747 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5749 if (!recipient
&& !pullmethod
)
5752 if (mask
== CUPSD_EVENT_NONE
)
5755 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5757 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5760 send_ipp_status(con
, IPP_BAD_REQUEST
,
5761 _("notify-events not specified."));
5766 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5768 cupsdLogMessage(CUPSD_LOG_INFO
,
5769 "create_subscription: Limiting notify-lease-duration to "
5772 lease
= MaxLeaseDuration
;
5777 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5779 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5787 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5789 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5790 _("There are too many subscriptions."));
5795 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5798 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5799 "Added subscription #%d for printer \"%s\".",
5800 sub
->id
, printer
->name
);
5802 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5805 sub
->interval
= interval
;
5807 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5809 cupsdSetString(&sub
->owner
, username
);
5813 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5814 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5815 sub
->user_data_len
);
5818 ippAddSeparator(con
->response
);
5819 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5820 "notify-subscription-id", sub
->id
);
5822 con
->response
->request
.status
.status_code
= IPP_OK
;
5828 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5833 * 'delete_printer()' - Remove a printer or class from the system.
5837 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5838 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5840 http_status_t status
; /* Policy status */
5841 cups_ptype_t dtype
; /* Destination type (printer/class) */
5842 cupsd_printer_t
*printer
; /* Printer/class */
5843 char filename
[1024]; /* Script/PPD filename */
5846 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5847 con
->http
.fd
, uri
->values
[0].string
.text
);
5850 * Do we have a valid URI?
5853 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5859 send_ipp_status(con
, IPP_NOT_FOUND
,
5860 _("The printer or class does not exist."));
5868 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5870 send_http_error(con
, status
, NULL
);
5875 * Remove old jobs...
5878 cupsdCancelJobs(printer
->name
, NULL
, 1);
5881 * Remove old subscriptions and send a "deleted printer" event...
5884 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5885 "%s \"%s\" deleted by \"%s\".",
5886 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5887 printer
->name
, get_username(con
));
5889 cupsdExpireSubscriptions(printer
, NULL
);
5892 * Remove any old PPD or script files...
5895 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
5899 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5903 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
5906 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
5910 * Unregister color profiles...
5913 cupsdUnregisterColor(printer
);
5915 if (dtype
& CUPS_PRINTER_CLASS
)
5917 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5918 printer
->name
, get_username(con
));
5920 cupsdDeletePrinter(printer
, 0);
5921 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5925 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5926 printer
->name
, get_username(con
));
5928 if (cupsdDeletePrinter(printer
, 0))
5929 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5931 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
5934 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
5937 * Return with no errors...
5940 con
->response
->request
.status
.status_code
= IPP_OK
;
5945 * 'get_default()' - Get the default destination.
5949 get_default(cupsd_client_t
*con
) /* I - Client connection */
5951 http_status_t status
; /* Policy status */
5952 cups_array_t
*ra
; /* Requested attributes array */
5955 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
5961 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5963 send_http_error(con
, status
, NULL
);
5969 ra
= create_requested_array(con
->request
);
5971 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5973 cupsArrayDelete(ra
);
5975 con
->response
->request
.status
.status_code
= IPP_OK
;
5978 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
5983 * 'get_devices()' - Get the list of available devices on the local system.
5987 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5989 http_status_t status
; /* Policy status */
5990 ipp_attribute_t
*limit
, /* limit attribute */
5991 *timeout
, /* timeout attribute */
5992 *requested
, /* requested-attributes attribute */
5993 *exclude
, /* exclude-schemes attribute */
5994 *include
; /* include-schemes attribute */
5995 char command
[1024], /* cups-deviced command */
5996 options
[2048], /* Options to pass to command */
5998 /* String for requested attributes */
6000 /* String for excluded schemes */
6002 /* String for included schemes */
6005 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6011 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6013 send_http_error(con
, status
, NULL
);
6018 * Run cups-deviced command with the given options...
6021 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6022 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6023 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6025 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6026 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6029 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6031 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6034 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6036 exclude_str
[0] = '\0';
6039 url_encode_attr(include
, include_str
, sizeof(include_str
));
6041 include_str
[0] = '\0';
6043 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6044 snprintf(options
, sizeof(options
),
6045 "%d+%d+%d+%d+%s%s%s%s%s",
6046 con
->request
->request
.op
.request_id
,
6047 limit
? limit
->values
[0].integer
: 0,
6048 timeout
? timeout
->values
[0].integer
: 15,
6051 exclude_str
[0] ? "%20" : "", exclude_str
,
6052 include_str
[0] ? "%20" : "", include_str
);
6054 if (cupsdSendCommand(con
, command
, options
, 1))
6057 * Command started successfully, don't send an IPP response here...
6060 ippDelete(con
->response
);
6061 con
->response
= NULL
;
6066 * Command failed, return "internal error" so the user knows something
6070 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6071 _("cups-deviced failed to execute."));
6077 * 'get_document()' - Get a copy of a job file.
6081 get_document(cupsd_client_t
*con
, /* I - Client connection */
6082 ipp_attribute_t
*uri
) /* I - Job URI */
6084 http_status_t status
; /* Policy status */
6085 ipp_attribute_t
*attr
; /* Current attribute */
6086 int jobid
; /* Job ID */
6087 int docnum
; /* Document number */
6088 cupsd_job_t
*job
; /* Current job */
6089 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6090 username
[HTTP_MAX_URI
], /* Username portion of URI */
6091 host
[HTTP_MAX_URI
], /* Host portion of URI */
6092 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6093 int port
; /* Port portion of URI */
6094 char filename
[1024], /* Filename for document */
6095 format
[1024]; /* Format for document */
6098 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6099 con
->http
.fd
, uri
->values
[0].string
.text
);
6102 * See if we have a job URI or a printer URI...
6105 if (!strcmp(uri
->name
, "printer-uri"))
6108 * Got a printer URI; see if we also have a job-id attribute...
6111 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6112 IPP_TAG_INTEGER
)) == NULL
)
6114 send_ipp_status(con
, IPP_BAD_REQUEST
,
6115 _("Got a printer-uri attribute but no job-id."));
6119 jobid
= attr
->values
[0].integer
;
6124 * Got a job URI; parse it to get the job ID...
6127 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6128 sizeof(scheme
), username
, sizeof(username
), host
,
6129 sizeof(host
), &port
, resource
, sizeof(resource
));
6131 if (strncmp(resource
, "/jobs/", 6))
6137 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6138 uri
->values
[0].string
.text
);
6142 jobid
= atoi(resource
+ 6);
6146 * See if the job exists...
6149 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6152 * Nope - return a "not found" error...
6155 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6163 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6164 job
->username
)) != HTTP_OK
)
6166 send_http_error(con
, status
, NULL
);
6171 * Get the document number...
6174 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6175 IPP_TAG_INTEGER
)) == NULL
)
6177 send_ipp_status(con
, IPP_BAD_REQUEST
,
6178 _("Missing document-number attribute."));
6182 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6183 attr
->num_values
> 1)
6185 send_ipp_status(con
, IPP_NOT_FOUND
,
6186 _("Document #%d does not exist in job #%d."), docnum
,
6191 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6193 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6195 cupsdLogMessage(CUPSD_LOG_ERROR
,
6196 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6198 send_ipp_status(con
, IPP_NOT_FOUND
,
6199 _("Unable to open document #%d in job #%d."), docnum
,
6204 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6208 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6209 job
->filetypes
[docnum
- 1]->type
);
6211 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6213 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6215 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6216 IPP_TAG_NAME
)) != NULL
)
6217 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6218 NULL
, attr
->values
[0].string
.text
);
6223 * 'get_job_attrs()' - Get job attributes.
6227 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6228 ipp_attribute_t
*uri
) /* I - Job URI */
6230 http_status_t status
; /* Policy status */
6231 ipp_attribute_t
*attr
; /* Current attribute */
6232 int jobid
; /* Job ID */
6233 cupsd_job_t
*job
; /* Current job */
6234 cupsd_printer_t
*printer
; /* Current printer */
6235 cupsd_policy_t
*policy
; /* Current security policy */
6236 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6237 username
[HTTP_MAX_URI
], /* Username portion of URI */
6238 host
[HTTP_MAX_URI
], /* Host portion of URI */
6239 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6240 int port
; /* Port portion of URI */
6241 cups_array_t
*ra
, /* Requested attributes array */
6242 *exclude
; /* Private attributes array */
6245 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6246 con
->http
.fd
, uri
->values
[0].string
.text
);
6249 * See if we have a job URI or a printer URI...
6252 if (!strcmp(uri
->name
, "printer-uri"))
6255 * Got a printer URI; see if we also have a job-id attribute...
6258 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6259 IPP_TAG_INTEGER
)) == NULL
)
6261 send_ipp_status(con
, IPP_BAD_REQUEST
,
6262 _("Got a printer-uri attribute but no job-id."));
6266 jobid
= attr
->values
[0].integer
;
6271 * Got a job URI; parse it to get the job ID...
6274 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6275 sizeof(scheme
), username
, sizeof(username
), host
,
6276 sizeof(host
), &port
, resource
, sizeof(resource
));
6278 if (strncmp(resource
, "/jobs/", 6))
6284 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6285 uri
->values
[0].string
.text
);
6289 jobid
= atoi(resource
+ 6);
6293 * See if the job exists...
6296 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6299 * Nope - return a "not found" error...
6302 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6310 if ((printer
= job
->printer
) == NULL
)
6311 printer
= cupsdFindDest(job
->dest
);
6314 policy
= printer
->op_policy_ptr
;
6316 policy
= DefaultPolicyPtr
;
6318 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6320 send_http_error(con
, status
, NULL
);
6324 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6327 * Copy attributes...
6332 ra
= create_requested_array(con
->request
);
6333 copy_job_attrs(con
, job
, ra
, exclude
);
6334 cupsArrayDelete(ra
);
6336 con
->response
->request
.status
.status_code
= IPP_OK
;
6341 * 'get_jobs()' - Get a list of jobs for the specified printer.
6345 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6346 ipp_attribute_t
*uri
) /* I - Printer URI */
6348 http_status_t status
; /* Policy status */
6349 ipp_attribute_t
*attr
; /* Current attribute */
6350 const char *dest
; /* Destination */
6351 cups_ptype_t dtype
; /* Destination type (printer/class) */
6352 cups_ptype_t dmask
; /* Destination type mask */
6353 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6354 username
[HTTP_MAX_URI
], /* Username portion of URI */
6355 host
[HTTP_MAX_URI
], /* Host portion of URI */
6356 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6357 int port
; /* Port portion of URI */
6358 int job_comparison
; /* Job comparison */
6359 ipp_jstate_t job_state
; /* job-state value */
6360 int first_job_id
; /* First job ID */
6361 int limit
; /* Maximum number of jobs to return */
6362 int count
; /* Number of jobs that match */
6363 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6364 cupsd_job_t
*job
; /* Current job pointer */
6365 cupsd_printer_t
*printer
; /* Printer */
6366 cups_array_t
*list
; /* Which job list... */
6367 cups_array_t
*ra
, /* Requested attributes array */
6368 *exclude
; /* Private attributes array */
6369 cupsd_policy_t
*policy
; /* Current policy */
6372 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6373 uri
->values
[0].string
.text
);
6376 * Is the destination valid?
6379 if (strcmp(uri
->name
, "printer-uri"))
6381 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6385 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6386 sizeof(scheme
), username
, sizeof(username
), host
,
6387 sizeof(host
), &port
, resource
, sizeof(resource
));
6389 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6392 dtype
= (cups_ptype_t
)0;
6393 dmask
= (cups_ptype_t
)0;
6396 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6399 dtype
= (cups_ptype_t
)0;
6400 dmask
= CUPS_PRINTER_CLASS
;
6403 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6406 dtype
= CUPS_PRINTER_CLASS
;
6407 dmask
= CUPS_PRINTER_CLASS
;
6410 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6417 send_ipp_status(con
, IPP_NOT_FOUND
,
6418 _("The printer or class does not exist."));
6423 dtype
&= CUPS_PRINTER_CLASS
;
6424 dmask
= CUPS_PRINTER_CLASS
;
6432 policy
= printer
->op_policy_ptr
;
6434 policy
= DefaultPolicyPtr
;
6436 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6438 send_http_error(con
, status
, NULL
);
6442 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6445 * See if the "which-jobs" attribute have been specified...
6448 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6449 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6451 send_ipp_status(con
, IPP_CONFLICT
,
6452 _("The %s attribute cannot be provided with job-ids."),
6456 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6458 job_comparison
= -1;
6459 job_state
= IPP_JOB_STOPPED
;
6462 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6465 job_state
= IPP_JOB_CANCELED
;
6468 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6471 job_state
= IPP_JOB_ABORTED
;
6474 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6477 job_state
= IPP_JOB_PENDING
;
6480 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6483 job_state
= IPP_JOB_CANCELED
;
6486 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6489 job_state
= IPP_JOB_PENDING
;
6492 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6495 job_state
= IPP_JOB_HELD
;
6498 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6501 job_state
= IPP_JOB_PROCESSING
;
6502 list
= PrintingJobs
;
6504 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6507 job_state
= IPP_JOB_STOPPED
;
6512 send_ipp_status(con
, IPP_ATTRIBUTES
,
6513 _("The which-jobs value \"%s\" is not supported."),
6514 attr
->values
[0].string
.text
);
6515 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6516 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6521 * See if they want to limit the number of jobs reported...
6524 if ((attr
= ippFindAttribute(con
->request
, "limit",
6525 IPP_TAG_INTEGER
)) != NULL
)
6529 send_ipp_status(con
, IPP_CONFLICT
,
6530 _("The %s attribute cannot be provided with job-ids."),
6535 limit
= attr
->values
[0].integer
;
6540 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6541 IPP_TAG_INTEGER
)) != NULL
)
6545 send_ipp_status(con
, IPP_CONFLICT
,
6546 _("The %s attribute cannot be provided with job-ids."),
6551 first_job_id
= attr
->values
[0].integer
;
6557 * See if we only want to see jobs for a specific user...
6560 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6561 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6563 send_ipp_status(con
, IPP_CONFLICT
,
6564 _("The %s attribute cannot be provided with job-ids."),
6568 else if (attr
&& attr
->values
[0].boolean
)
6569 strlcpy(username
, get_username(con
), sizeof(username
));
6573 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
6574 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
6577 * IPP conformance - Get-Jobs has a default requested-attributes value of
6578 * "job-id" and "job-uri".
6581 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6582 cupsArrayAdd(ra
, "job-id");
6583 cupsArrayAdd(ra
, "job-uri");
6587 * OK, build a list of jobs for this printer...
6592 int i
; /* Looping var */
6594 for (i
= 0; i
< job_ids
->num_values
; i
++)
6596 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6600 if (i
< job_ids
->num_values
)
6602 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6603 job_ids
->values
[i
].integer
);
6607 for (i
= 0; i
< job_ids
->num_values
; i
++)
6609 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6615 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6621 ippAddSeparator(con
->response
);
6623 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6624 job
->printer
->op_policy_ptr
:
6625 policy
, con
, job
->printer
,
6628 copy_job_attrs(con
, job
, ra
, exclude
);
6633 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6634 (limit
<= 0 || count
< limit
) && job
;
6635 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6638 * Filter out jobs that don't match...
6641 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6642 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6643 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6644 job
->username
, job
->state_value
, job
->attrs
);
6646 if (!job
->dest
|| !job
->username
)
6649 if (!job
->dest
|| !job
->username
)
6652 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6653 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6655 if ((job
->dtype
& dmask
) != dtype
&&
6656 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6659 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6660 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6661 (job_comparison
> 0 && job
->state_value
< job_state
))
6664 if (job
->id
< first_job_id
)
6671 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6676 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6680 ippAddSeparator(con
->response
);
6684 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6685 job
->printer
->op_policy_ptr
:
6686 policy
, con
, job
->printer
,
6689 copy_job_attrs(con
, job
, ra
, exclude
);
6692 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6695 cupsArrayDelete(ra
);
6697 con
->response
->request
.status
.status_code
= IPP_OK
;
6702 * 'get_notifications()' - Get events for a subscription.
6706 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6708 int i
, j
; /* Looping vars */
6709 http_status_t status
; /* Policy status */
6710 cupsd_subscription_t
*sub
; /* Subscription */
6711 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6712 *sequences
; /* notify-sequence-numbers */
6713 int min_seq
; /* Minimum sequence number */
6714 int interval
; /* Poll interval */
6717 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6721 * Get subscription attributes...
6724 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6726 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6731 send_ipp_status(con
, IPP_BAD_REQUEST
,
6732 _("Missing notify-subscription-ids attribute."));
6737 * Are the subscription IDs valid?
6740 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6742 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6745 * Bad subscription ID...
6748 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6749 ids
->values
[i
].integer
);
6757 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6759 con
, sub
->owner
)) != HTTP_OK
)
6761 send_http_error(con
, status
, sub
->dest
);
6766 * Check the subscription type and update the interval accordingly.
6769 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6772 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6774 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6780 * Tell the client to poll again in N seconds...
6784 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6785 "notify-get-interval", interval
);
6787 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6788 "printer-up-time", time(NULL
));
6791 * Copy the subscription event attributes to the response.
6794 con
->response
->request
.status
.status_code
=
6795 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6797 for (i
= 0; i
< ids
->num_values
; i
++)
6800 * Get the subscription and sequence number...
6803 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6805 if (sequences
&& i
< sequences
->num_values
)
6806 min_seq
= sequences
->values
[i
].integer
;
6811 * If we don't have any new events, nothing to do here...
6814 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6818 * Otherwise copy all of the new events...
6821 if (sub
->first_event_id
> min_seq
)
6824 j
= min_seq
- sub
->first_event_id
;
6826 for (; j
< cupsArrayCount(sub
->events
); j
++)
6828 ippAddSeparator(con
->response
);
6830 copy_attrs(con
->response
,
6831 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
6832 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
6839 * 'get_ppd()' - Get a named PPD from the local system.
6843 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6844 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6846 http_status_t status
; /* Policy status */
6847 cupsd_printer_t
*dest
; /* Destination */
6848 cups_ptype_t dtype
; /* Destination type */
6851 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6852 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6854 if (!strcmp(uri
->name
, "ppd-name"))
6857 * Return a PPD file from cups-driverd...
6860 char command
[1024], /* cups-driverd command */
6861 options
[1024], /* Options to pass to command */
6862 ppd_name
[1024]; /* ppd-name */
6869 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6871 send_http_error(con
, status
, NULL
);
6876 * Run cups-driverd command with the given options...
6879 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6880 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
6881 snprintf(options
, sizeof(options
), "get+%d+%s",
6882 con
->request
->request
.op
.request_id
, ppd_name
);
6884 if (cupsdSendCommand(con
, command
, options
, 0))
6887 * Command started successfully, don't send an IPP response here...
6890 ippDelete(con
->response
);
6891 con
->response
= NULL
;
6896 * Command failed, return "internal error" so the user knows something
6900 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6901 _("cups-driverd failed to execute."));
6904 else if (!strcmp(uri
->name
, "printer-uri") &&
6905 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
6907 int i
; /* Looping var */
6908 char filename
[1024]; /* PPD filename */
6915 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6917 send_http_error(con
, status
, dest
);
6922 * See if we need the PPD for a class or remote printer...
6925 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6928 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
6930 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6931 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6932 "printer-uri", NULL
, dest
->uri
);
6935 else if (dtype
& CUPS_PRINTER_CLASS
)
6937 for (i
= 0; i
< dest
->num_printers
; i
++)
6938 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
6940 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6941 dest
->printers
[i
]->name
);
6943 if (!access(filename
, 0))
6947 if (i
< dest
->num_printers
)
6948 dest
= dest
->printers
[i
];
6951 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6952 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6953 "printer-uri", NULL
, dest
->printers
[0]->uri
);
6959 * Found the printer with the PPD file, now see if there is one...
6962 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
6964 send_ipp_status(con
, IPP_NOT_FOUND
,
6965 _("The PPD file \"%s\" could not be opened: %s"),
6966 uri
->values
[0].string
.text
, strerror(errno
));
6970 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6974 con
->response
->request
.status
.status_code
= IPP_OK
;
6977 send_ipp_status(con
, IPP_NOT_FOUND
,
6978 _("The PPD file \"%s\" could not be found."),
6979 uri
->values
[0].string
.text
);
6984 * 'get_ppds()' - Get the list of PPD files on the local system.
6988 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
6990 http_status_t status
; /* Policy status */
6991 ipp_attribute_t
*limit
, /* Limit attribute */
6992 *device
, /* ppd-device-id attribute */
6993 *language
, /* ppd-natural-language attribute */
6994 *make
, /* ppd-make attribute */
6995 *model
, /* ppd-make-and-model attribute */
6996 *model_number
, /* ppd-model-number attribute */
6997 *product
, /* ppd-product attribute */
6998 *psversion
, /* ppd-psverion attribute */
6999 *type
, /* ppd-type attribute */
7000 *requested
, /* requested-attributes attribute */
7001 *exclude
, /* exclude-schemes attribute */
7002 *include
; /* include-schemes attribute */
7003 char command
[1024], /* cups-driverd command */
7004 options
[4096], /* Options to pass to command */
7005 device_str
[256],/* Escaped ppd-device-id string */
7007 /* Escaped ppd-natural-language */
7008 make_str
[256], /* Escaped ppd-make string */
7009 model_str
[256], /* Escaped ppd-make-and-model string */
7010 model_number_str
[256],
7011 /* ppd-model-number string */
7013 /* Escaped ppd-product string */
7015 /* Escaped ppd-psversion string */
7016 type_str
[256], /* Escaped ppd-type string */
7018 /* String for requested attributes */
7020 /* String for excluded schemes */
7022 /* String for included schemes */
7025 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7031 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7033 send_http_error(con
, status
, NULL
);
7038 * Run cups-driverd command with the given options...
7041 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7042 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7043 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7045 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7046 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7048 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7050 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7051 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7052 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7053 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7055 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7057 include
= ippFindAttribute(con
->request
, "include-schemes",
7061 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7063 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7066 url_encode_attr(device
, device_str
, sizeof(device_str
));
7068 device_str
[0] = '\0';
7071 url_encode_attr(language
, language_str
, sizeof(language_str
));
7073 language_str
[0] = '\0';
7076 url_encode_attr(make
, make_str
, sizeof(make_str
));
7081 url_encode_attr(model
, model_str
, sizeof(model_str
));
7083 model_str
[0] = '\0';
7086 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7087 model_number
->values
[0].integer
);
7089 model_number_str
[0] = '\0';
7092 url_encode_attr(product
, product_str
, sizeof(product_str
));
7094 product_str
[0] = '\0';
7097 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7099 psversion_str
[0] = '\0';
7102 url_encode_attr(type
, type_str
, sizeof(type_str
));
7107 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7109 exclude_str
[0] = '\0';
7112 url_encode_attr(include
, include_str
, sizeof(include_str
));
7114 include_str
[0] = '\0';
7116 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7117 snprintf(options
, sizeof(options
),
7118 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7119 con
->request
->request
.op
.request_id
,
7120 limit
? limit
->values
[0].integer
: 0,
7122 device
? "%20" : "", device_str
,
7123 language
? "%20" : "", language_str
,
7124 make
? "%20" : "", make_str
,
7125 model
? "%20" : "", model_str
,
7126 model_number
? "%20" : "", model_number_str
,
7127 product
? "%20" : "", product_str
,
7128 psversion
? "%20" : "", psversion_str
,
7129 type
? "%20" : "", type_str
,
7130 exclude_str
[0] ? "%20" : "", exclude_str
,
7131 include_str
[0] ? "%20" : "", include_str
);
7133 if (cupsdSendCommand(con
, command
, options
, 0))
7136 * Command started successfully, don't send an IPP response here...
7139 ippDelete(con
->response
);
7140 con
->response
= NULL
;
7145 * Command failed, return "internal error" so the user knows something
7149 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7150 _("cups-driverd failed to execute."));
7156 * 'get_printer_attrs()' - Get printer attributes.
7160 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7161 ipp_attribute_t
*uri
) /* I - Printer URI */
7163 http_status_t status
; /* Policy status */
7164 cups_ptype_t dtype
; /* Destination type (printer/class) */
7165 cupsd_printer_t
*printer
; /* Printer/class */
7166 cups_array_t
*ra
; /* Requested attributes array */
7169 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7170 con
->http
.fd
, uri
->values
[0].string
.text
);
7173 * Is the destination valid?
7176 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7182 send_ipp_status(con
, IPP_NOT_FOUND
,
7183 _("The printer or class does not exist."));
7191 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7193 send_http_error(con
, status
, printer
);
7198 * Send the attributes...
7201 ra
= create_requested_array(con
->request
);
7203 copy_printer_attrs(con
, printer
, ra
);
7205 cupsArrayDelete(ra
);
7207 con
->response
->request
.status
.status_code
= IPP_OK
;
7212 * 'get_printer_supported()' - Get printer supported values.
7216 get_printer_supported(
7217 cupsd_client_t
*con
, /* I - Client connection */
7218 ipp_attribute_t
*uri
) /* I - Printer URI */
7220 http_status_t status
; /* Policy status */
7221 cups_ptype_t dtype
; /* Destination type (printer/class) */
7222 cupsd_printer_t
*printer
; /* Printer/class */
7225 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7226 con
->http
.fd
, uri
->values
[0].string
.text
);
7229 * Is the destination valid?
7232 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7238 send_ipp_status(con
, IPP_NOT_FOUND
,
7239 _("The printer or class does not exist."));
7247 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7249 send_http_error(con
, status
, printer
);
7254 * Return a list of attributes that can be set via Set-Printer-Attributes.
7257 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7259 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7260 "printer-location", 0);
7262 con
->response
->request
.status
.status_code
= IPP_OK
;
7267 * 'get_printers()' - Get a list of printers or classes.
7271 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7272 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7274 http_status_t status
; /* Policy status */
7275 ipp_attribute_t
*attr
; /* Current attribute */
7276 int limit
; /* Max number of printers to return */
7277 int count
; /* Number of printers that match */
7278 cupsd_printer_t
*printer
; /* Current printer pointer */
7279 int printer_type
, /* printer-type attribute */
7280 printer_mask
; /* printer-type-mask attribute */
7281 char *location
; /* Location string */
7282 const char *username
; /* Current user */
7283 char *first_printer_name
; /* first-printer-name attribute */
7284 cups_array_t
*ra
; /* Requested attributes array */
7285 int local
; /* Local connection? */
7288 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7289 con
->http
.fd
, type
);
7295 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7297 send_http_error(con
, status
, NULL
);
7302 * Check for printers...
7305 if (!Printers
|| !cupsArrayCount(Printers
))
7307 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7312 * See if they want to limit the number of printers reported...
7315 if ((attr
= ippFindAttribute(con
->request
, "limit",
7316 IPP_TAG_INTEGER
)) != NULL
)
7317 limit
= attr
->values
[0].integer
;
7321 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7322 IPP_TAG_NAME
)) != NULL
)
7323 first_printer_name
= attr
->values
[0].string
.text
;
7325 first_printer_name
= NULL
;
7328 * Support filtering...
7331 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7332 IPP_TAG_ENUM
)) != NULL
)
7333 printer_type
= attr
->values
[0].integer
;
7337 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7338 IPP_TAG_ENUM
)) != NULL
)
7339 printer_mask
= attr
->values
[0].integer
;
7343 local
= httpAddrLocalhost(&(con
->clientaddr
));
7345 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7346 IPP_TAG_TEXT
)) != NULL
)
7347 location
= attr
->values
[0].string
.text
;
7351 if (con
->username
[0])
7352 username
= con
->username
;
7353 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7354 IPP_TAG_NAME
)) != NULL
)
7355 username
= attr
->values
[0].string
.text
;
7359 ra
= create_requested_array(con
->request
);
7362 * OK, build a list of printers for this printer...
7365 if (first_printer_name
)
7367 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7368 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7371 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7374 count
< limit
&& printer
;
7375 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7377 if (!local
&& !printer
->shared
)
7380 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7381 (printer
->type
& printer_mask
) == printer_type
&&
7383 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7386 * If a username is specified, see if it is allowed or denied
7390 if (cupsArrayCount(printer
->users
) && username
&&
7391 !user_allowed(printer
, username
))
7395 * Add the group separator as needed...
7399 ippAddSeparator(con
->response
);
7404 * Send the attributes...
7407 copy_printer_attrs(con
, printer
, ra
);
7411 cupsArrayDelete(ra
);
7413 con
->response
->request
.status
.status_code
= IPP_OK
;
7418 * 'get_subscription_attrs()' - Get subscription attributes.
7422 get_subscription_attrs(
7423 cupsd_client_t
*con
, /* I - Client connection */
7424 int sub_id
) /* I - Subscription ID */
7426 http_status_t status
; /* Policy status */
7427 cupsd_subscription_t
*sub
; /* Subscription */
7428 cupsd_policy_t
*policy
; /* Current security policy */
7429 cups_array_t
*ra
, /* Requested attributes array */
7430 *exclude
; /* Private attributes array */
7433 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7434 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7435 con
, con
->http
.fd
, sub_id
);
7438 * Is the subscription ID valid?
7441 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7444 * Bad subscription ID...
7447 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7457 policy
= sub
->dest
->op_policy_ptr
;
7459 policy
= DefaultPolicyPtr
;
7461 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7463 send_http_error(con
, status
, sub
->dest
);
7467 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7470 * Copy the subscription attributes to the response using the
7471 * requested-attributes attribute that may be provided by the client.
7474 ra
= create_requested_array(con
->request
);
7476 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7478 cupsArrayDelete(ra
);
7480 con
->response
->request
.status
.status_code
= IPP_OK
;
7485 * 'get_subscriptions()' - Get subscriptions.
7489 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7490 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7492 http_status_t status
; /* Policy status */
7493 int count
; /* Number of subscriptions */
7494 int limit
; /* Limit */
7495 cupsd_subscription_t
*sub
; /* Subscription */
7496 cups_array_t
*ra
; /* Requested attributes array */
7497 ipp_attribute_t
*attr
; /* Attribute */
7498 cups_ptype_t dtype
; /* Destination type (printer/class) */
7499 char scheme
[HTTP_MAX_URI
],
7500 /* Scheme portion of URI */
7501 username
[HTTP_MAX_URI
],
7502 /* Username portion of URI */
7504 /* Host portion of URI */
7505 resource
[HTTP_MAX_URI
];
7506 /* Resource portion of URI */
7507 int port
; /* Port portion of URI */
7508 cupsd_job_t
*job
; /* Job pointer */
7509 cupsd_printer_t
*printer
; /* Printer */
7510 cupsd_policy_t
*policy
; /* Policy */
7511 cups_array_t
*exclude
; /* Private attributes array */
7514 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7515 "get_subscriptions(con=%p[%d], uri=%s)",
7516 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7519 * Is the destination valid?
7522 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7523 sizeof(scheme
), username
, sizeof(username
), host
,
7524 sizeof(host
), &port
, resource
, sizeof(resource
));
7526 if (!strcmp(resource
, "/") ||
7527 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7528 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7529 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7534 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7537 job
= cupsdFindJob(atoi(resource
+ 6));
7541 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7542 atoi(resource
+ 6));
7546 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7552 send_ipp_status(con
, IPP_NOT_FOUND
,
7553 _("The printer or class does not exist."));
7556 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7557 IPP_TAG_INTEGER
)) != NULL
)
7559 job
= cupsdFindJob(attr
->values
[0].integer
);
7563 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7564 attr
->values
[0].integer
);
7576 policy
= printer
->op_policy_ptr
;
7578 policy
= DefaultPolicyPtr
;
7580 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7582 send_http_error(con
, status
, printer
);
7587 * Copy the subscription attributes to the response using the
7588 * requested-attributes attribute that may be provided by the client.
7591 ra
= create_requested_array(con
->request
);
7593 if ((attr
= ippFindAttribute(con
->request
, "limit",
7594 IPP_TAG_INTEGER
)) != NULL
)
7595 limit
= attr
->values
[0].integer
;
7600 * See if we only want to see subscriptions for a specific user...
7603 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7604 IPP_TAG_BOOLEAN
)) != NULL
&&
7605 attr
->values
[0].boolean
)
7606 strlcpy(username
, get_username(con
), sizeof(username
));
7610 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7612 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7613 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7614 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7616 ippAddSeparator(con
->response
);
7618 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7619 policy
, con
, sub
->dest
,
7622 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7625 if (limit
&& count
>= limit
)
7629 cupsArrayDelete(ra
);
7632 con
->response
->request
.status
.status_code
= IPP_OK
;
7634 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7639 * 'get_username()' - Get the username associated with a request.
7642 static const char * /* O - Username */
7643 get_username(cupsd_client_t
*con
) /* I - Connection */
7645 ipp_attribute_t
*attr
; /* Attribute */
7648 if (con
->username
[0])
7649 return (con
->username
);
7650 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7651 IPP_TAG_NAME
)) != NULL
)
7652 return (attr
->values
[0].string
.text
);
7654 return ("anonymous");
7659 * 'hold_job()' - Hold a print job.
7663 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7664 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7666 ipp_attribute_t
*attr
; /* Current job-hold-until */
7667 const char *when
; /* New value */
7668 int jobid
; /* Job ID */
7669 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7670 username
[HTTP_MAX_URI
], /* Username portion of URI */
7671 host
[HTTP_MAX_URI
], /* Host portion of URI */
7672 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7673 int port
; /* Port portion of URI */
7674 cupsd_job_t
*job
; /* Job information */
7677 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
7678 uri
->values
[0].string
.text
);
7681 * See if we have a job URI or a printer URI...
7684 if (!strcmp(uri
->name
, "printer-uri"))
7687 * Got a printer URI; see if we also have a job-id attribute...
7690 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7691 IPP_TAG_INTEGER
)) == NULL
)
7693 send_ipp_status(con
, IPP_BAD_REQUEST
,
7694 _("Got a printer-uri attribute but no job-id."));
7698 jobid
= attr
->values
[0].integer
;
7703 * Got a job URI; parse it to get the job ID...
7706 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7707 sizeof(scheme
), username
, sizeof(username
), host
,
7708 sizeof(host
), &port
, resource
, sizeof(resource
));
7710 if (strncmp(resource
, "/jobs/", 6))
7716 send_ipp_status(con
, IPP_BAD_REQUEST
,
7717 _("Bad job-uri \"%s\"."),
7718 uri
->values
[0].string
.text
);
7722 jobid
= atoi(resource
+ 6);
7726 * See if the job exists...
7729 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7732 * Nope - return a "not found" error...
7735 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7740 * See if the job is owned by the requesting user...
7743 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7745 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7746 cupsdFindDest(job
->dest
));
7751 * See if the job is in a state that allows holding...
7754 if (job
->state_value
> IPP_JOB_STOPPED
)
7757 * Return a "not-possible" error...
7760 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7761 _("Job #%d is finished and cannot be altered."),
7767 * Hold the job and return...
7770 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7771 IPP_TAG_KEYWORD
)) == NULL
)
7772 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7776 when
= attr
->values
[0].string
.text
;
7778 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7779 "Job job-hold-until value changed by user.");
7782 when
= "indefinite";
7784 cupsdSetJobHoldUntil(job
, when
, 1);
7785 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7788 con
->response
->request
.status
.status_code
= IPP_OK
;
7793 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7797 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7798 ipp_attribute_t
*uri
) /* I - Printer URI */
7800 http_status_t status
; /* Policy status */
7801 cups_ptype_t dtype
; /* Destination type (printer/class) */
7802 cupsd_printer_t
*printer
; /* Printer data */
7805 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7806 con
->http
.fd
, uri
->values
[0].string
.text
);
7809 * Is the destination valid?
7812 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7818 send_ipp_status(con
, IPP_NOT_FOUND
,
7819 _("The printer or class does not exist."));
7827 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7829 send_http_error(con
, status
, printer
);
7834 * Hold pending/new jobs sent to the printer...
7837 printer
->holding_new_jobs
= 1;
7839 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
7841 if (dtype
& CUPS_PRINTER_CLASS
)
7842 cupsdLogMessage(CUPSD_LOG_INFO
,
7843 "Class \"%s\" now holding pending/new jobs (\"%s\").",
7844 printer
->name
, get_username(con
));
7846 cupsdLogMessage(CUPSD_LOG_INFO
,
7847 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
7848 printer
->name
, get_username(con
));
7851 * Everything was ok, so return OK status...
7854 con
->response
->request
.status
.status_code
= IPP_OK
;
7859 * 'move_job()' - Move a job to a new destination.
7863 move_job(cupsd_client_t
*con
, /* I - Client connection */
7864 ipp_attribute_t
*uri
) /* I - Job URI */
7866 http_status_t status
; /* Policy status */
7867 ipp_attribute_t
*attr
; /* Current attribute */
7868 int jobid
; /* Job ID */
7869 cupsd_job_t
*job
; /* Current job */
7870 const char *src
; /* Source printer/class */
7871 cups_ptype_t stype
, /* Source type (printer or class) */
7872 dtype
; /* Destination type (printer/class) */
7873 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7874 username
[HTTP_MAX_URI
], /* Username portion of URI */
7875 host
[HTTP_MAX_URI
], /* Host portion of URI */
7876 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7877 int port
; /* Port portion of URI */
7878 cupsd_printer_t
*sprinter
, /* Source printer */
7879 *dprinter
; /* Destination printer */
7882 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
7883 uri
->values
[0].string
.text
);
7886 * Get the new printer or class...
7889 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7890 IPP_TAG_URI
)) == NULL
)
7893 * Need job-printer-uri...
7896 send_ipp_status(con
, IPP_BAD_REQUEST
,
7897 _("job-printer-uri attribute missing."));
7901 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
7907 send_ipp_status(con
, IPP_NOT_FOUND
,
7908 _("The printer or class does not exist."));
7913 * See if we have a job URI or a printer URI...
7916 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7917 sizeof(scheme
), username
, sizeof(username
), host
,
7918 sizeof(host
), &port
, resource
, sizeof(resource
));
7920 if (!strcmp(uri
->name
, "printer-uri"))
7923 * Got a printer URI; see if we also have a job-id attribute...
7926 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7927 IPP_TAG_INTEGER
)) == NULL
)
7933 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
7934 &sprinter
)) == NULL
)
7940 send_ipp_status(con
, IPP_NOT_FOUND
,
7941 _("The printer or class does not exist."));
7950 * Otherwise, just move a single job...
7953 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
7956 * Nope - return a "not found" error...
7959 send_ipp_status(con
, IPP_NOT_FOUND
,
7960 _("Job #%d does not exist."), attr
->values
[0].integer
);
7966 * Job found, initialize source pointers...
7977 * Got a job URI; parse it to get the job ID...
7980 if (strncmp(resource
, "/jobs/", 6))
7986 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7987 uri
->values
[0].string
.text
);
7992 * See if the job exists...
7995 jobid
= atoi(resource
+ 6);
7997 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8000 * Nope - return a "not found" error...
8003 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8009 * Job found, initialize source pointers...
8018 * Check the policy of the destination printer...
8021 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8022 job
? job
->username
: NULL
)) != HTTP_OK
)
8024 send_http_error(con
, status
, dprinter
);
8029 * Now move the job or jobs...
8035 * See if the job has been completed...
8038 if (job
->state_value
> IPP_JOB_STOPPED
)
8041 * Return a "not-possible" error...
8044 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8045 _("Job #%d is finished and cannot be altered."),
8051 * See if the job is owned by the requesting user...
8054 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8056 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8057 cupsdFindDest(job
->dest
));
8062 * Move the job to a different printer or class...
8065 cupsdMoveJob(job
, dprinter
);
8070 * Got the source printer, now look through the jobs...
8073 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8075 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8078 * See if the job is pointing at the source printer or has not been
8082 if (_cups_strcasecmp(job
->dest
, src
) ||
8083 job
->state_value
> IPP_JOB_STOPPED
)
8087 * See if the job can be moved by the requesting user...
8090 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8094 * Move the job to a different printer or class...
8097 cupsdMoveJob(job
, dprinter
);
8102 * Start jobs if possible...
8108 * Return with "everything is OK" status...
8111 con
->response
->request
.status
.status_code
= IPP_OK
;
8116 * 'ppd_parse_line()' - Parse a PPD default line.
8119 static int /* O - 0 on success, -1 on failure */
8120 ppd_parse_line(const char *line
, /* I - Line */
8121 char *option
, /* O - Option name */
8122 int olen
, /* I - Size of option name */
8123 char *choice
, /* O - Choice name */
8124 int clen
) /* I - Size of choice name */
8127 * Verify this is a default option line...
8130 if (strncmp(line
, "*Default", 8))
8134 * Read the option name...
8137 for (line
+= 8, olen
--;
8138 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8149 * Skip everything else up to the colon (:)...
8152 while (*line
&& *line
!= ':')
8161 * Now grab the option choice, skipping leading whitespace...
8164 while (isspace(*line
& 255))
8168 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8179 * Return with no errors...
8187 * 'print_job()' - Print a file to a printer or class.
8191 print_job(cupsd_client_t
*con
, /* I - Client connection */
8192 ipp_attribute_t
*uri
) /* I - Printer URI */
8194 ipp_attribute_t
*attr
; /* Current attribute */
8195 ipp_attribute_t
*format
; /* Document-format attribute */
8196 const char *default_format
; /* document-format-default value */
8197 cupsd_job_t
*job
; /* New job */
8198 char filename
[1024]; /* Job filename */
8199 mime_type_t
*filetype
; /* Type of file */
8200 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8201 type
[MIME_MAX_TYPE
], /* Subtype of file */
8202 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8203 /* Textual name of mime type */
8204 cupsd_printer_t
*printer
; /* Printer data */
8205 struct stat fileinfo
; /* File information */
8206 int kbytes
; /* Size of file */
8207 int compression
; /* Document compression */
8210 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8211 uri
->values
[0].string
.text
);
8214 * Validate print file attributes, for now just document-format and
8215 * compression (CUPS only supports "none" and "gzip")...
8218 compression
= CUPS_FILE_NONE
;
8220 if ((attr
= ippFindAttribute(con
->request
, "compression",
8221 IPP_TAG_KEYWORD
)) != NULL
)
8223 if (strcmp(attr
->values
[0].string
.text
, "none")
8225 && strcmp(attr
->values
[0].string
.text
, "gzip")
8226 #endif /* HAVE_LIBZ */
8229 send_ipp_status(con
, IPP_ATTRIBUTES
,
8230 _("Unsupported compression \"%s\"."),
8231 attr
->values
[0].string
.text
);
8232 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8233 "compression", NULL
, attr
->values
[0].string
.text
);
8238 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8239 compression
= CUPS_FILE_GZIP
;
8240 #endif /* HAVE_LIBZ */
8244 * Do we have a file to print?
8249 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8254 * Is the destination valid?
8257 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8263 send_ipp_status(con
, IPP_NOT_FOUND
,
8264 _("The printer or class does not exist."));
8269 * Is it a format we support?
8272 if ((format
= ippFindAttribute(con
->request
, "document-format",
8273 IPP_TAG_MIMETYPE
)) != NULL
)
8276 * Grab format from client...
8279 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8282 send_ipp_status(con
, IPP_BAD_REQUEST
,
8283 _("Bad document-format \"%s\"."),
8284 format
->values
[0].string
.text
);
8288 else if ((default_format
= cupsGetOption("document-format",
8289 printer
->num_options
,
8290 printer
->options
)) != NULL
)
8293 * Use default document format...
8296 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8298 send_ipp_status(con
, IPP_BAD_REQUEST
,
8299 _("Bad document-format \"%s\"."),
8310 strlcpy(super
, "application", sizeof(super
));
8311 strlcpy(type
, "octet-stream", sizeof(type
));
8314 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8317 * Auto-type the file...
8320 ipp_attribute_t
*doc_name
; /* document-name attribute */
8323 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8325 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8326 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8327 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8331 filetype
= mimeType(MimeDatabase
, super
, type
);
8333 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8334 filetype
->super
, filetype
->type
);
8337 filetype
= mimeType(MimeDatabase
, super
, type
);
8341 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8344 * Replace the document-format attribute value with the auto-typed or
8348 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8353 _cupsStrFree(format
->values
[0].string
.text
);
8355 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8358 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8359 "document-format", NULL
, mimetype
);
8363 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8364 _("Unsupported document-format \"%s\"."),
8365 format
? format
->values
[0].string
.text
:
8366 "application/octet-stream");
8367 cupsdLogMessage(CUPSD_LOG_INFO
,
8368 "Hint: Do you have the raw file printing rules enabled?");
8371 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8372 "document-format", NULL
, format
->values
[0].string
.text
);
8378 * Read any embedded job ticket info from PS files...
8381 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8382 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8383 !_cups_strcasecmp(filetype
->type
, "pdf")))
8384 read_job_ticket(con
);
8387 * Create the job object...
8390 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8394 * Update quota data...
8397 if (stat(con
->filename
, &fileinfo
))
8400 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8402 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8404 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8405 IPP_TAG_INTEGER
)) != NULL
)
8406 attr
->values
[0].integer
+= kbytes
;
8409 * Add the job file...
8412 if (add_file(con
, job
, filetype
, compression
))
8415 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8417 rename(con
->filename
, filename
);
8418 cupsdClearString(&con
->filename
);
8421 * See if we need to add the ending sheet...
8424 if (cupsdTimeoutJob(job
))
8428 * Log and save the job...
8431 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8432 "File of type %s/%s queued by \"%s\".",
8433 filetype
->super
, filetype
->type
, job
->username
);
8434 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8435 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8436 job
->dest
, job
->username
);
8439 * Start the job if possible...
8447 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8449 * This function only gets called when printing a single PDF or PostScript
8450 * file using the Print-Job operation. It doesn't work for Create-Job +
8451 * Send-File, since the job attributes need to be set at job creation
8452 * time for banners to work. The embedded job ticket stuff is here
8453 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8454 * options and IPP attributes which otherwise would be lost.
8456 * The format of a job ticket is simple:
8458 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8460 * %cupsJobTicket: attr1=value1
8461 * %cupsJobTicket: attr2=value2
8463 * %cupsJobTicket: attrN=valueN
8465 * Job ticket lines must appear immediately after the first line that
8466 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8467 * stops looking for job ticket info when it finds a line that does not begin
8468 * with "%cupsJobTicket:".
8470 * The maximum length of a job ticket line, including the prefix, is
8471 * 255 characters to conform with the Adobe DSC.
8473 * Read-only attributes are rejected with a notice to the error log in
8474 * case a malicious user tries anything. Since the job ticket is read
8475 * prior to attribute validation in print_job(), job ticket attributes
8476 * will go through the same validation as IPP attributes...
8480 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8482 cups_file_t
*fp
; /* File to read from */
8483 char line
[256]; /* Line data */
8484 int num_options
; /* Number of options */
8485 cups_option_t
*options
; /* Options */
8486 ipp_t
*ticket
; /* New attributes */
8487 ipp_attribute_t
*attr
, /* Current attribute */
8488 *attr2
, /* Job attribute */
8489 *prev2
; /* Previous job attribute */
8493 * First open the print file...
8496 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8498 cupsdLogMessage(CUPSD_LOG_ERROR
,
8499 "Unable to open print file for job ticket - %s",
8505 * Skip the first line...
8508 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8510 cupsdLogMessage(CUPSD_LOG_ERROR
,
8511 "Unable to read from print file for job ticket - %s",
8517 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8520 * Not a DSC-compliant file, so no job ticket info will be available...
8528 * Read job ticket info from the file...
8534 while (cupsFileGets(fp
, line
, sizeof(line
)))
8537 * Stop at the first non-ticket line...
8540 if (strncmp(line
, "%cupsJobTicket:", 15))
8544 * Add the options to the option array...
8547 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8551 * Done with the file; see if we have any options...
8556 if (num_options
== 0)
8560 * OK, convert the options to an attribute list, and apply them to
8565 cupsEncodeOptions(ticket
, num_options
, options
);
8568 * See what the user wants to change.
8571 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8573 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8576 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8577 !strcmp(attr
->name
, "job-originating-user-name") ||
8578 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8579 !strcmp(attr
->name
, "job-k-octets") ||
8580 !strcmp(attr
->name
, "job-id") ||
8581 !strncmp(attr
->name
, "job-state", 9) ||
8582 !strncmp(attr
->name
, "time-at-", 8))
8583 continue; /* Read-only attrs */
8585 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8586 IPP_TAG_ZERO
)) != NULL
)
8589 * Some other value; first free the old value...
8592 if (con
->request
->attrs
== attr2
)
8594 con
->request
->attrs
= attr2
->next
;
8599 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8600 if (prev2
->next
== attr2
)
8602 prev2
->next
= attr2
->next
;
8607 if (con
->request
->last
== attr2
)
8608 con
->request
->last
= prev2
;
8610 ippDeleteAttribute(NULL
, attr2
);
8614 * Add new option by copying it...
8617 ippCopyAttribute(con
->request
, attr
, 0);
8621 * Then free the attribute list and option array...
8625 cupsFreeOptions(num_options
, options
);
8630 * 'reject_jobs()' - Reject print jobs to a printer.
8634 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8635 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8637 http_status_t status
; /* Policy status */
8638 cups_ptype_t dtype
; /* Destination type (printer/class) */
8639 cupsd_printer_t
*printer
; /* Printer data */
8640 ipp_attribute_t
*attr
; /* printer-state-message text */
8643 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8644 con
->http
.fd
, uri
->values
[0].string
.text
);
8647 * Is the destination valid?
8650 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8656 send_ipp_status(con
, IPP_NOT_FOUND
,
8657 _("The printer or class does not exist."));
8665 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8667 send_http_error(con
, status
, printer
);
8672 * Reject jobs sent to the printer...
8675 printer
->accepting
= 0;
8677 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8678 IPP_TAG_TEXT
)) == NULL
)
8679 strlcpy(printer
->state_message
, "Rejecting Jobs",
8680 sizeof(printer
->state_message
));
8682 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8683 sizeof(printer
->state_message
));
8685 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8686 "No longer accepting jobs.");
8688 if (dtype
& CUPS_PRINTER_CLASS
)
8690 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8692 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8693 printer
->name
, get_username(con
));
8697 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8699 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8700 printer
->name
, get_username(con
));
8704 * Everything was ok, so return OK status...
8707 con
->response
->request
.status
.status_code
= IPP_OK
;
8712 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8716 release_held_new_jobs(
8717 cupsd_client_t
*con
, /* I - Connection */
8718 ipp_attribute_t
*uri
) /* I - Printer URI */
8720 http_status_t status
; /* Policy status */
8721 cups_ptype_t dtype
; /* Destination type (printer/class) */
8722 cupsd_printer_t
*printer
; /* Printer data */
8725 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8726 con
->http
.fd
, uri
->values
[0].string
.text
);
8729 * Is the destination valid?
8732 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8738 send_ipp_status(con
, IPP_NOT_FOUND
,
8739 _("The printer or class does not exist."));
8747 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8749 send_http_error(con
, status
, printer
);
8754 * Hold pending/new jobs sent to the printer...
8757 printer
->holding_new_jobs
= 0;
8759 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8761 if (dtype
& CUPS_PRINTER_CLASS
)
8762 cupsdLogMessage(CUPSD_LOG_INFO
,
8763 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8764 printer
->name
, get_username(con
));
8766 cupsdLogMessage(CUPSD_LOG_INFO
,
8767 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8768 printer
->name
, get_username(con
));
8771 * Everything was ok, so return OK status...
8774 con
->response
->request
.status
.status_code
= IPP_OK
;
8779 * 'release_job()' - Release a held print job.
8783 release_job(cupsd_client_t
*con
, /* I - Client connection */
8784 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8786 ipp_attribute_t
*attr
; /* Current attribute */
8787 int jobid
; /* Job ID */
8788 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8789 username
[HTTP_MAX_URI
], /* Username portion of URI */
8790 host
[HTTP_MAX_URI
], /* Host portion of URI */
8791 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8792 int port
; /* Port portion of URI */
8793 cupsd_job_t
*job
; /* Job information */
8796 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8797 con
->http
.fd
, uri
->values
[0].string
.text
);
8800 * See if we have a job URI or a printer URI...
8803 if (!strcmp(uri
->name
, "printer-uri"))
8806 * Got a printer URI; see if we also have a job-id attribute...
8809 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8810 IPP_TAG_INTEGER
)) == NULL
)
8812 send_ipp_status(con
, IPP_BAD_REQUEST
,
8813 _("Got a printer-uri attribute but no job-id."));
8817 jobid
= attr
->values
[0].integer
;
8822 * Got a job URI; parse it to get the job ID...
8825 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8826 sizeof(scheme
), username
, sizeof(username
), host
,
8827 sizeof(host
), &port
, resource
, sizeof(resource
));
8829 if (strncmp(resource
, "/jobs/", 6))
8835 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8836 uri
->values
[0].string
.text
);
8840 jobid
= atoi(resource
+ 6);
8844 * See if the job exists...
8847 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8850 * Nope - return a "not found" error...
8853 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8858 * See if job is "held"...
8861 if (job
->state_value
!= IPP_JOB_HELD
)
8864 * Nope - return a "not possible" error...
8867 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
8872 * See if the job is owned by the requesting user...
8875 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8877 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8878 cupsdFindDest(job
->dest
));
8883 * Reset the job-hold-until value to "no-hold"...
8886 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8887 IPP_TAG_KEYWORD
)) == NULL
)
8888 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8892 _cupsStrFree(attr
->values
[0].string
.text
);
8894 attr
->value_tag
= IPP_TAG_KEYWORD
;
8895 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8897 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8898 "Job job-hold-until value changed by user.");
8899 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
8903 * Release the job and return...
8906 cupsdReleaseJob(job
);
8908 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8909 "Job released by user.");
8911 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
8913 con
->response
->request
.status
.status_code
= IPP_OK
;
8920 * 'renew_subscription()' - Renew an existing subscription...
8925 cupsd_client_t
*con
, /* I - Client connection */
8926 int sub_id
) /* I - Subscription ID */
8928 http_status_t status
; /* Policy status */
8929 cupsd_subscription_t
*sub
; /* Subscription */
8930 ipp_attribute_t
*lease
; /* notify-lease-duration */
8933 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8934 "renew_subscription(con=%p[%d], sub_id=%d)",
8935 con
, con
->http
.fd
, sub_id
);
8938 * Is the subscription ID valid?
8941 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8944 * Bad subscription ID...
8947 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8955 * Job subscriptions cannot be renewed...
8958 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8959 _("Job subscriptions cannot be renewed."));
8967 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8969 con
, sub
->owner
)) != HTTP_OK
)
8971 send_http_error(con
, status
, sub
->dest
);
8976 * Renew the subscription...
8979 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8982 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
8984 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
8986 cupsdLogMessage(CUPSD_LOG_INFO
,
8987 "renew_subscription: Limiting notify-lease-duration to "
8990 sub
->lease
= MaxLeaseDuration
;
8993 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
8995 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
8997 con
->response
->request
.status
.status_code
= IPP_OK
;
8999 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9000 "notify-lease-duration", sub
->lease
);
9005 * 'restart_job()' - Restart an old print job.
9009 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9010 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9012 ipp_attribute_t
*attr
; /* Current attribute */
9013 int jobid
; /* Job ID */
9014 cupsd_job_t
*job
; /* Job information */
9015 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9016 username
[HTTP_MAX_URI
], /* Username portion of URI */
9017 host
[HTTP_MAX_URI
], /* Host portion of URI */
9018 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9019 int port
; /* Port portion of URI */
9022 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9023 con
->http
.fd
, uri
->values
[0].string
.text
);
9026 * See if we have a job URI or a printer URI...
9029 if (!strcmp(uri
->name
, "printer-uri"))
9032 * Got a printer URI; see if we also have a job-id attribute...
9035 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9036 IPP_TAG_INTEGER
)) == NULL
)
9038 send_ipp_status(con
, IPP_BAD_REQUEST
,
9039 _("Got a printer-uri attribute but no job-id."));
9043 jobid
= attr
->values
[0].integer
;
9048 * Got a job URI; parse it to get the job ID...
9051 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9052 sizeof(scheme
), username
, sizeof(username
), host
,
9053 sizeof(host
), &port
, resource
, sizeof(resource
));
9055 if (strncmp(resource
, "/jobs/", 6))
9061 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9062 uri
->values
[0].string
.text
);
9066 jobid
= atoi(resource
+ 6);
9070 * See if the job exists...
9073 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9076 * Nope - return a "not found" error...
9079 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9084 * See if job is in any of the "completed" states...
9087 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9090 * Nope - return a "not possible" error...
9093 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9099 * See if we have retained the job files...
9104 if (!job
->attrs
|| job
->num_files
== 0)
9107 * Nope - return a "not possible" error...
9110 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9111 _("Job #%d cannot be restarted - no files."), jobid
);
9116 * See if the job is owned by the requesting user...
9119 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9121 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9122 cupsdFindDest(job
->dest
));
9127 * See if the job-hold-until attribute is specified...
9130 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9131 IPP_TAG_KEYWORD
)) == NULL
)
9132 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9134 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9137 * Return the job to a held state...
9140 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9141 "Restarted by \"%s\" with job-hold-until=%s.",
9142 username
, attr
->values
[0].string
.text
);
9143 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9145 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9146 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9147 attr
->values
[0].string
.text
);
9152 * Restart the job...
9155 cupsdRestartJob(job
);
9159 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9161 con
->response
->request
.status
.status_code
= IPP_OK
;
9166 * 'save_auth_info()' - Save authentication information for a job.
9171 cupsd_client_t
*con
, /* I - Client connection */
9172 cupsd_job_t
*job
, /* I - Job */
9173 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9175 int i
; /* Looping var */
9176 char filename
[1024]; /* Job authentication filename */
9177 cups_file_t
*fp
; /* Job authentication file */
9178 char line
[65536]; /* Line for file */
9179 cupsd_printer_t
*dest
; /* Destination printer/class */
9183 * This function saves the in-memory authentication information for
9184 * a job so that it can be used to authenticate with a remote host.
9185 * The information is stored in a file that is readable only by the
9186 * root user. The fields are Base-64 encoded, each on a separate line,
9187 * followed by random number (up to 1024) of newlines to limit the
9188 * amount of information that is exposed.
9190 * Because of the potential for exposing of authentication information,
9191 * this functionality is only enabled when running cupsd as root.
9193 * This caching only works for the Basic and BasicDigest authentication
9194 * types. Digest authentication cannot be cached this way, and in
9195 * the future Kerberos authentication may make all of this obsolete.
9197 * Authentication information is saved whenever an authenticated
9198 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9201 * This information is deleted after a job is completed or canceled,
9202 * so reprints may require subsequent re-authentication.
9208 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9212 * Create the authentication file and change permissions...
9215 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9216 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9218 cupsdLogMessage(CUPSD_LOG_ERROR
,
9219 "Unable to save authentication info to \"%s\" - %s",
9220 filename
, strerror(errno
));
9224 fchown(cupsFileNumber(fp
), 0, 0);
9225 fchmod(cupsFileNumber(fp
), 0400);
9227 cupsFilePuts(fp
, "CUPSD-AUTH-V2\n");
9230 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9232 cupsdClearString(job
->auth_env
+ i
);
9234 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9237 * Write 1 to 3 auth values...
9241 i
< auth_info
->num_values
&&
9242 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9245 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9246 strlen(auth_info
->values
[i
].string
.text
));
9247 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9249 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9250 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9251 auth_info
->values
[i
].string
.text
);
9252 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9253 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9254 auth_info
->values
[i
].string
.text
);
9255 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9256 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9257 auth_info
->values
[i
].string
.text
);
9258 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9259 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9260 auth_info
->values
[i
].string
.text
);
9265 else if (auth_info
&& auth_info
->num_values
== 2 &&
9266 dest
->num_auth_info_required
== 1 &&
9267 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9270 * Allow fallback to username+password for Kerberized queues...
9273 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
,
9274 strlen(auth_info
->values
[0].string
.text
));
9275 cupsFilePutConf(fp
, "username", line
);
9277 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9278 auth_info
->values
[0].string
.text
);
9280 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
,
9281 strlen(auth_info
->values
[1].string
.text
));
9282 cupsFilePutConf(fp
, "password", line
);
9284 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9285 auth_info
->values
[1].string
.text
);
9287 else if (con
->username
[0])
9290 * Write the authenticated username...
9293 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9294 cupsFilePutConf(fp
, "username", line
);
9296 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9299 * Write the authenticated password...
9302 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9303 cupsFilePutConf(fp
, "password", line
);
9305 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9309 if (con
->gss_uid
> 0)
9311 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9312 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9314 #endif /* HAVE_GSSAPI */
9317 * Write a random number of newlines to the end of the file...
9320 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9321 cupsFilePutChar(fp
, '\n');
9324 * Close the file and return...
9332 * 'send_document()' - Send a file to a printer or class.
9336 send_document(cupsd_client_t
*con
, /* I - Client connection */
9337 ipp_attribute_t
*uri
) /* I - Printer URI */
9339 ipp_attribute_t
*attr
; /* Current attribute */
9340 ipp_attribute_t
*format
; /* Request's document-format attribute */
9341 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9342 const char *default_format
;/* document-format-default value */
9343 int jobid
; /* Job ID number */
9344 cupsd_job_t
*job
; /* Current job */
9345 char job_uri
[HTTP_MAX_URI
],
9347 scheme
[HTTP_MAX_URI
],
9348 /* Method portion of URI */
9349 username
[HTTP_MAX_URI
],
9350 /* Username portion of URI */
9352 /* Host portion of URI */
9353 resource
[HTTP_MAX_URI
];
9354 /* Resource portion of URI */
9355 int port
; /* Port portion of URI */
9356 mime_type_t
*filetype
; /* Type of file */
9357 char super
[MIME_MAX_SUPER
],
9358 /* Supertype of file */
9359 type
[MIME_MAX_TYPE
],
9360 /* Subtype of file */
9361 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9362 /* Textual name of mime type */
9363 char filename
[1024]; /* Job filename */
9364 cupsd_printer_t
*printer
; /* Current printer */
9365 struct stat fileinfo
; /* File information */
9366 int kbytes
; /* Size of file */
9367 int compression
; /* Type of compression */
9368 int start_job
; /* Start the job? */
9371 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9372 con
->http
.fd
, uri
->values
[0].string
.text
);
9375 * See if we have a job URI or a printer URI...
9378 if (!strcmp(uri
->name
, "printer-uri"))
9381 * Got a printer URI; see if we also have a job-id attribute...
9384 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9385 IPP_TAG_INTEGER
)) == NULL
)
9387 send_ipp_status(con
, IPP_BAD_REQUEST
,
9388 _("Got a printer-uri attribute but no job-id."));
9392 jobid
= attr
->values
[0].integer
;
9397 * Got a job URI; parse it to get the job ID...
9400 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9401 sizeof(scheme
), username
, sizeof(username
), host
,
9402 sizeof(host
), &port
, resource
, sizeof(resource
));
9404 if (strncmp(resource
, "/jobs/", 6))
9410 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9411 uri
->values
[0].string
.text
);
9415 jobid
= atoi(resource
+ 6);
9419 * See if the job exists...
9422 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9425 * Nope - return a "not found" error...
9428 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9432 printer
= cupsdFindDest(job
->dest
);
9435 * See if the job is owned by the requesting user...
9438 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9440 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9441 cupsdFindDest(job
->dest
));
9446 * OK, see if the client is sending the document compressed - CUPS
9447 * only supports "none" and "gzip".
9450 compression
= CUPS_FILE_NONE
;
9452 if ((attr
= ippFindAttribute(con
->request
, "compression",
9453 IPP_TAG_KEYWORD
)) != NULL
)
9455 if (strcmp(attr
->values
[0].string
.text
, "none")
9457 && strcmp(attr
->values
[0].string
.text
, "gzip")
9458 #endif /* HAVE_LIBZ */
9461 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9462 attr
->values
[0].string
.text
);
9463 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9464 "compression", NULL
, attr
->values
[0].string
.text
);
9469 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9470 compression
= CUPS_FILE_GZIP
;
9471 #endif /* HAVE_LIBZ */
9475 * Do we have a file to print?
9478 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9479 IPP_TAG_BOOLEAN
)) == NULL
)
9481 send_ipp_status(con
, IPP_BAD_REQUEST
,
9482 _("Missing last-document attribute in request."));
9489 * Check for an empty request with "last-document" set to true, which is
9490 * used to close an "open" job by RFC 2911, section 3.3.2.
9493 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9496 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9501 * Is it a format we support?
9504 if ((format
= ippFindAttribute(con
->request
, "document-format",
9505 IPP_TAG_MIMETYPE
)) != NULL
)
9508 * Grab format from client...
9511 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9514 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9515 format
->values
[0].string
.text
);
9519 else if ((default_format
= cupsGetOption("document-format",
9520 printer
->num_options
,
9521 printer
->options
)) != NULL
)
9524 * Use default document format...
9527 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9529 send_ipp_status(con
, IPP_BAD_REQUEST
,
9530 _("Bad document-format-default \"%s\"."), default_format
);
9537 * No document format attribute? Auto-type it!
9540 strlcpy(super
, "application", sizeof(super
));
9541 strlcpy(type
, "octet-stream", sizeof(type
));
9544 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9547 * Auto-type the file...
9550 ipp_attribute_t
*doc_name
; /* document-name attribute */
9553 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9555 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9556 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9557 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9561 filetype
= mimeType(MimeDatabase
, super
, type
);
9564 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9565 filetype
->super
, filetype
->type
);
9568 filetype
= mimeType(MimeDatabase
, super
, type
);
9573 * Replace the document-format attribute value with the auto-typed or
9577 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9580 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9581 IPP_TAG_MIMETYPE
)) != NULL
)
9583 _cupsStrFree(jformat
->values
[0].string
.text
);
9585 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9588 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9589 "document-format", NULL
, mimetype
);
9593 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9594 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9595 cupsdLogMessage(CUPSD_LOG_INFO
,
9596 "Hint: Do you have the raw file printing rules enabled?");
9599 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9600 "document-format", NULL
, format
->values
[0].string
.text
);
9605 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9607 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9610 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9611 _("Unsupported document-format \"%s\"."), mimetype
);
9613 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9614 "document-format", NULL
, mimetype
);
9620 * Add the file to the job...
9625 if (add_file(con
, job
, filetype
, compression
))
9628 if (stat(con
->filename
, &fileinfo
))
9631 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9633 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9635 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9636 IPP_TAG_INTEGER
)) != NULL
)
9637 attr
->values
[0].integer
+= kbytes
;
9639 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9641 rename(con
->filename
, filename
);
9643 cupsdClearString(&con
->filename
);
9645 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9646 filetype
->super
, filetype
->type
, job
->username
);
9649 * Start the job if this is the last document...
9654 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9655 IPP_TAG_BOOLEAN
)) != NULL
&&
9656 attr
->values
[0].boolean
)
9659 * See if we need to add the ending sheet...
9662 if (cupsdTimeoutJob(job
))
9665 if (job
->state_value
== IPP_JOB_STOPPED
)
9667 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9668 job
->state_value
= IPP_JOB_PENDING
;
9670 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9672 else if (job
->state_value
== IPP_JOB_HELD
)
9674 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9675 IPP_TAG_KEYWORD
)) == NULL
)
9676 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9678 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9680 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9681 job
->state_value
= IPP_JOB_PENDING
;
9683 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9686 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9690 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9696 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9697 IPP_TAG_KEYWORD
)) == NULL
)
9698 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9700 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9702 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9703 job
->state_value
= IPP_JOB_HELD
;
9704 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9706 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9709 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9716 * Fill in the response info...
9719 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9720 con
->servername
, con
->serverport
, "/jobs/%d", jobid
);
9721 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9724 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9726 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9728 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9729 NULL
, job
->reasons
->values
[0].string
.text
);
9731 con
->response
->request
.status
.status_code
= IPP_OK
;
9734 * Start the job if necessary...
9743 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9748 cupsd_client_t
*con
, /* I - Client connection */
9749 http_status_t status
, /* I - HTTP status code */
9750 cupsd_printer_t
*printer
) /* I - Printer, if any */
9752 ipp_attribute_t
*uri
; /* Request URI, if any */
9755 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9756 IPP_TAG_URI
)) == NULL
)
9757 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9759 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9760 "Returning HTTP %s for %s (%s) from %s",
9763 ippOpString(con
->request
->request
.op
.operation_id
) :
9765 uri
? uri
->values
[0].string
.text
: "no URI",
9766 con
->http
.hostname
);
9770 int auth_type
; /* Type of authentication required */
9773 auth_type
= CUPSD_AUTH_NONE
;
9775 if (status
== HTTP_UNAUTHORIZED
&&
9776 printer
->num_auth_info_required
> 0 &&
9777 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9779 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9780 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9781 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9784 * Creating and authenticating jobs requires Kerberos...
9787 auth_type
= CUPSD_AUTH_NEGOTIATE
;
9792 * Use policy/location-defined authentication requirements...
9795 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9796 cupsd_location_t
*auth
; /* Pointer to authentication element */
9799 if (printer
->type
& CUPS_PRINTER_CLASS
)
9800 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9802 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9804 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9805 auth
->type
== CUPSD_AUTH_NONE
)
9806 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9808 con
->request
->request
.op
.operation_id
:
9813 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9814 auth_type
= cupsdDefaultAuthType();
9816 auth_type
= auth
->type
;
9820 cupsdSendError(con
, status
, auth_type
);
9823 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9825 ippDelete(con
->response
);
9826 con
->response
= NULL
;
9833 * 'send_ipp_status()' - Send a status back to the IPP client.
9837 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9838 ipp_status_t status
, /* I - IPP status code */
9839 const char *message
,/* I - Status message */
9840 ...) /* I - Additional args as needed */
9842 va_list ap
; /* Pointer to additional args */
9843 char formatted
[1024]; /* Formatted errror message */
9846 va_start(ap
, message
);
9847 vsnprintf(formatted
, sizeof(formatted
),
9848 _cupsLangString(con
->language
, message
), ap
);
9851 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9852 ippOpString(con
->request
->request
.op
.operation_id
),
9853 ippErrorString(status
), formatted
);
9855 con
->response
->request
.status
.status_code
= status
;
9857 if (ippFindAttribute(con
->response
, "attributes-charset",
9858 IPP_TAG_ZERO
) == NULL
)
9859 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9860 "attributes-charset", NULL
, "utf-8");
9862 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9863 IPP_TAG_ZERO
) == NULL
)
9864 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9865 "attributes-natural-language", NULL
, DefaultLanguage
);
9867 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9868 "status-message", NULL
, formatted
);
9873 * 'set_default()' - Set the default destination...
9877 set_default(cupsd_client_t
*con
, /* I - Client connection */
9878 ipp_attribute_t
*uri
) /* I - Printer URI */
9880 http_status_t status
; /* Policy status */
9881 cups_ptype_t dtype
; /* Destination type (printer/class) */
9882 cupsd_printer_t
*printer
, /* Printer */
9883 *oldprinter
; /* Old default printer */
9886 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9887 con
->http
.fd
, uri
->values
[0].string
.text
);
9890 * Is the destination valid?
9893 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9899 send_ipp_status(con
, IPP_NOT_FOUND
,
9900 _("The printer or class does not exist."));
9908 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9910 send_http_error(con
, status
, NULL
);
9915 * Set it as the default...
9918 oldprinter
= DefaultPrinter
;
9919 DefaultPrinter
= printer
;
9922 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
9923 "%s is no longer the default printer.", oldprinter
->name
);
9925 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9926 "%s is now the default printer.", printer
->name
);
9928 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
9929 CUPSD_DIRTY_PRINTCAP
);
9931 cupsdLogMessage(CUPSD_LOG_INFO
,
9932 "Default destination set to \"%s\" by \"%s\".",
9933 printer
->name
, get_username(con
));
9936 * Everything was ok, so return OK status...
9939 con
->response
->request
.status
.status_code
= IPP_OK
;
9944 * 'set_job_attrs()' - Set job attributes.
9948 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9949 ipp_attribute_t
*uri
) /* I - Job URI */
9951 ipp_attribute_t
*attr
, /* Current attribute */
9952 *attr2
; /* Job attribute */
9953 int jobid
; /* Job ID */
9954 cupsd_job_t
*job
; /* Current job */
9955 char scheme
[HTTP_MAX_URI
],
9956 /* Method portion of URI */
9957 username
[HTTP_MAX_URI
],
9958 /* Username portion of URI */
9960 /* Host portion of URI */
9961 resource
[HTTP_MAX_URI
];
9962 /* Resource portion of URI */
9963 int port
; /* Port portion of URI */
9964 int event
; /* Events? */
9965 int check_jobs
; /* Check jobs? */
9968 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9969 con
->http
.fd
, uri
->values
[0].string
.text
);
9972 * Start with "everything is OK" status...
9975 con
->response
->request
.status
.status_code
= IPP_OK
;
9978 * See if we have a job URI or a printer URI...
9981 if (!strcmp(uri
->name
, "printer-uri"))
9984 * Got a printer URI; see if we also have a job-id attribute...
9987 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9988 IPP_TAG_INTEGER
)) == NULL
)
9990 send_ipp_status(con
, IPP_BAD_REQUEST
,
9991 _("Got a printer-uri attribute but no job-id."));
9995 jobid
= attr
->values
[0].integer
;
10000 * Got a job URI; parse it to get the job ID...
10003 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10004 sizeof(scheme
), username
, sizeof(username
), host
,
10005 sizeof(host
), &port
, resource
, sizeof(resource
));
10007 if (strncmp(resource
, "/jobs/", 6))
10013 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10014 uri
->values
[0].string
.text
);
10018 jobid
= atoi(resource
+ 6);
10022 * See if the job exists...
10025 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10028 * Nope - return a "not found" error...
10031 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10036 * See if the job has been completed...
10039 if (job
->state_value
> IPP_JOB_STOPPED
)
10042 * Return a "not-possible" error...
10045 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10046 _("Job #%d is finished and cannot be altered."), jobid
);
10051 * See if the job is owned by the requesting user...
10054 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10056 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10057 cupsdFindDest(job
->dest
));
10062 * See what the user wants to change.
10070 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10072 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10075 if (!strcmp(attr
->name
, "attributes-charset") ||
10076 !strcmp(attr
->name
, "attributes-natural-language") ||
10077 !strcmp(attr
->name
, "document-compression") ||
10078 !strcmp(attr
->name
, "document-format") ||
10079 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10080 !strcmp(attr
->name
, "job-document-access-errors") ||
10081 !strcmp(attr
->name
, "job-id") ||
10082 !strcmp(attr
->name
, "job-impressions-completed") ||
10083 !strcmp(attr
->name
, "job-k-octets") ||
10084 !strcmp(attr
->name
, "job-originating-host-name") ||
10085 !strcmp(attr
->name
, "job-originating-user-name") ||
10086 !strcmp(attr
->name
, "job-printer-up-time") ||
10087 !strcmp(attr
->name
, "job-printer-uri") ||
10088 !strcmp(attr
->name
, "job-sheets") ||
10089 !strcmp(attr
->name
, "job-state-message") ||
10090 !strcmp(attr
->name
, "job-state-reasons") ||
10091 !strcmp(attr
->name
, "job-uri") ||
10092 !strcmp(attr
->name
, "number-of-documents") ||
10093 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10094 !strcmp(attr
->name
, "output-device-assigned") ||
10095 !strncmp(attr
->name
, "date-time-at-", 13) ||
10096 !strncmp(attr
->name
, "job-k-octets", 12) ||
10097 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10098 !strncmp(attr
->name
, "time-at-", 8))
10104 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10105 _("%s cannot be changed."), attr
->name
);
10107 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10108 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10112 if (!strcmp(attr
->name
, "job-priority"))
10115 * Change the job priority...
10118 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10120 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10122 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10123 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10125 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10127 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10128 _("Job is completed and cannot be changed."));
10131 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10133 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10134 attr
->values
[0].integer
);
10135 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10138 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10139 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10142 else if (!strcmp(attr
->name
, "job-state"))
10145 * Change the job state...
10148 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10150 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10152 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10153 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10157 switch (attr
->values
[0].integer
)
10159 case IPP_JOB_PENDING
:
10160 case IPP_JOB_HELD
:
10161 if (job
->state_value
> IPP_JOB_HELD
)
10163 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10164 _("Job state cannot be changed."));
10167 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10169 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10170 attr
->values
[0].integer
);
10171 cupsdSetJobState(job
, attr
->values
[0].integer
,
10173 "Job state changed by \"%s\"", username
);
10178 case IPP_JOB_PROCESSING
:
10179 case IPP_JOB_STOPPED
:
10180 if (job
->state_value
!= attr
->values
[0].integer
)
10182 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10183 _("Job state cannot be changed."));
10188 case IPP_JOB_CANCELED
:
10189 case IPP_JOB_ABORTED
:
10190 case IPP_JOB_COMPLETED
:
10191 if (job
->state_value
> IPP_JOB_PROCESSING
)
10193 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10194 _("Job state cannot be changed."));
10197 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10199 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10200 attr
->values
[0].integer
);
10201 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10203 "Job state changed by \"%s\"", username
);
10210 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10212 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10213 IPP_TAG_ZERO
)) != NULL
)
10216 * Some other value; first free the old value...
10219 if (job
->attrs
->prev
)
10220 job
->attrs
->prev
->next
= attr2
->next
;
10222 job
->attrs
->attrs
= attr2
->next
;
10224 if (job
->attrs
->last
== attr2
)
10225 job
->attrs
->last
= job
->attrs
->prev
;
10227 ippDeleteAttribute(NULL
, attr2
);
10230 * Then copy the attribute...
10233 ippCopyAttribute(job
->attrs
, attr
, 0);
10236 * See if the job-name or job-hold-until is being changed.
10239 if (!strcmp(attr
->name
, "job-hold-until"))
10241 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10242 attr
->values
[0].string
.text
);
10243 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10245 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10247 cupsdReleaseJob(job
);
10251 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10252 "Job held by \"%s\".", username
);
10254 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10257 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10260 * Delete the attribute...
10263 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10264 IPP_TAG_ZERO
)) != NULL
)
10266 if (job
->attrs
->prev
)
10267 job
->attrs
->prev
->next
= attr2
->next
;
10269 job
->attrs
->attrs
= attr2
->next
;
10271 if (attr2
== job
->attrs
->last
)
10272 job
->attrs
->last
= job
->attrs
->prev
;
10274 ippDeleteAttribute(NULL
, attr2
);
10276 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10282 * Add new option by copying it...
10285 ippCopyAttribute(job
->attrs
, attr
, 0);
10287 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10296 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10299 * Send events as needed...
10302 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10303 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10304 cupsdFindDest(job
->dest
), job
,
10305 "Job priority changed by user.");
10307 if (event
& CUPSD_EVENT_JOB_STATE
)
10308 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10309 job
->state_value
== IPP_JOB_HELD
?
10310 "Job held by user." : "Job restarted by user.");
10312 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10313 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10314 "Job options changed by user.");
10317 * Start jobs if possible...
10326 * 'set_printer_attrs()' - Set printer attributes.
10330 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10331 ipp_attribute_t
*uri
) /* I - Printer */
10333 http_status_t status
; /* Policy status */
10334 cups_ptype_t dtype
; /* Destination type (printer/class) */
10335 cupsd_printer_t
*printer
; /* Printer/class */
10336 ipp_attribute_t
*attr
; /* Printer attribute */
10337 int changed
= 0; /* Was anything changed? */
10340 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10341 con
->http
.fd
, uri
->values
[0].string
.text
);
10344 * Is the destination valid?
10347 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10353 send_ipp_status(con
, IPP_NOT_FOUND
,
10354 _("The printer or class does not exist."));
10362 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10364 send_http_error(con
, status
, printer
);
10369 * Return a list of attributes that can be set via Set-Printer-Attributes.
10372 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10373 IPP_TAG_TEXT
)) != NULL
)
10375 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10379 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10380 IPP_TAG_TEXT
)) != NULL
)
10382 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10387 * Update the printer attributes and return...
10392 cupsdSetPrinterAttrs(printer
);
10393 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10395 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10396 "Printer \"%s\" description or location changed by \"%s\".",
10397 printer
->name
, get_username(con
));
10399 cupsdLogMessage(CUPSD_LOG_INFO
,
10400 "Printer \"%s\" description or location changed by \"%s\".",
10401 printer
->name
, get_username(con
));
10404 con
->response
->request
.status
.status_code
= IPP_OK
;
10409 * 'set_printer_defaults()' - Set printer default options from a request.
10413 set_printer_defaults(
10414 cupsd_client_t
*con
, /* I - Client connection */
10415 cupsd_printer_t
*printer
) /* I - Printer */
10417 int i
; /* Looping var */
10418 ipp_attribute_t
*attr
; /* Current attribute */
10419 int namelen
; /* Length of attribute name */
10420 char name
[256], /* New attribute name */
10421 value
[256]; /* String version of integer attrs */
10424 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10427 * Skip non-printer attributes...
10430 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10433 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10435 if (!strcmp(attr
->name
, "job-sheets-default"))
10438 * Only allow keywords and names...
10441 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10445 * Only allow job-sheets-default to be set when running without a
10446 * system high classification level...
10449 if (Classification
)
10452 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10454 if (attr
->num_values
> 1)
10455 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10457 cupsdSetString(&printer
->job_sheets
[1], "none");
10459 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10461 cupsdFreeStrings(&(printer
->users
));
10463 printer
->deny_users
= 0;
10465 if (attr
->value_tag
== IPP_TAG_NAME
&&
10466 (attr
->num_values
> 1 ||
10467 strcmp(attr
->values
[0].string
.text
, "all")))
10469 for (i
= 0; i
< attr
->num_values
; i
++)
10470 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10473 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10475 cupsdFreeStrings(&(printer
->users
));
10477 printer
->deny_users
= 1;
10479 if (attr
->value_tag
== IPP_TAG_NAME
&&
10480 (attr
->num_values
> 1 ||
10481 strcmp(attr
->values
[0].string
.text
, "none")))
10483 for (i
= 0; i
< attr
->num_values
; i
++)
10484 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10487 else if (!strcmp(attr
->name
, "job-quota-period"))
10489 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10492 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10493 attr
->values
[0].integer
);
10494 cupsdFreeQuotas(printer
);
10496 printer
->quota_period
= attr
->values
[0].integer
;
10498 else if (!strcmp(attr
->name
, "job-k-limit"))
10500 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10503 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10504 attr
->values
[0].integer
);
10505 cupsdFreeQuotas(printer
);
10507 printer
->k_limit
= attr
->values
[0].integer
;
10509 else if (!strcmp(attr
->name
, "job-page-limit"))
10511 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10514 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10515 attr
->values
[0].integer
);
10516 cupsdFreeQuotas(printer
);
10518 printer
->page_limit
= attr
->values
[0].integer
;
10520 else if (!strcmp(attr
->name
, "printer-op-policy"))
10522 cupsd_policy_t
*p
; /* Policy */
10525 if (attr
->value_tag
!= IPP_TAG_NAME
)
10528 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10530 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10531 "Setting printer-op-policy to \"%s\"...",
10532 attr
->values
[0].string
.text
);
10533 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10534 printer
->op_policy_ptr
= p
;
10538 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10539 _("Unknown printer-op-policy \"%s\"."),
10540 attr
->values
[0].string
.text
);
10544 else if (!strcmp(attr
->name
, "printer-error-policy"))
10546 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10549 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10550 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10551 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10552 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10553 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10555 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10556 _("Unknown printer-error-policy \"%s\"."),
10557 attr
->values
[0].string
.text
);
10561 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10562 "Setting printer-error-policy to \"%s\"...",
10563 attr
->values
[0].string
.text
);
10564 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10568 * Skip any other non-default attributes...
10571 namelen
= strlen(attr
->name
);
10572 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10573 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10577 * OK, anything else must be a user-defined default...
10580 strlcpy(name
, attr
->name
, sizeof(name
));
10581 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10583 switch (attr
->value_tag
)
10585 case IPP_TAG_DELETEATTR
:
10586 printer
->num_options
= cupsRemoveOption(name
,
10587 printer
->num_options
,
10588 &(printer
->options
));
10589 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10590 "Deleting %s", attr
->name
);
10593 case IPP_TAG_NAME
:
10594 case IPP_TAG_TEXT
:
10595 case IPP_TAG_KEYWORD
:
10597 printer
->num_options
= cupsAddOption(name
,
10598 attr
->values
[0].string
.text
,
10599 printer
->num_options
,
10600 &(printer
->options
));
10601 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10602 "Setting %s to \"%s\"...", attr
->name
,
10603 attr
->values
[0].string
.text
);
10606 case IPP_TAG_BOOLEAN
:
10607 printer
->num_options
= cupsAddOption(name
,
10608 attr
->values
[0].boolean
?
10610 printer
->num_options
,
10611 &(printer
->options
));
10612 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10613 "Setting %s to %s...", attr
->name
,
10614 attr
->values
[0].boolean
? "true" : "false");
10617 case IPP_TAG_INTEGER
:
10618 case IPP_TAG_ENUM
:
10619 sprintf(value
, "%d", attr
->values
[0].integer
);
10620 printer
->num_options
= cupsAddOption(name
, value
,
10621 printer
->num_options
,
10622 &(printer
->options
));
10623 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10624 "Setting %s to %s...", attr
->name
, value
);
10627 case IPP_TAG_RANGE
:
10628 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10629 attr
->values
[0].range
.upper
);
10630 printer
->num_options
= cupsAddOption(name
, value
,
10631 printer
->num_options
,
10632 &(printer
->options
));
10633 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10634 "Setting %s to %s...", attr
->name
, value
);
10637 case IPP_TAG_RESOLUTION
:
10638 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10639 attr
->values
[0].resolution
.yres
,
10640 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10642 printer
->num_options
= cupsAddOption(name
, value
,
10643 printer
->num_options
,
10644 &(printer
->options
));
10645 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10646 "Setting %s to %s...", attr
->name
, value
);
10650 /* Do nothing for other values */
10658 * 'start_printer()' - Start a printer.
10662 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10663 ipp_attribute_t
*uri
) /* I - Printer URI */
10665 int i
; /* Temporary variable */
10666 http_status_t status
; /* Policy status */
10667 cups_ptype_t dtype
; /* Destination type (printer/class) */
10668 cupsd_printer_t
*printer
; /* Printer data */
10671 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10672 con
->http
.fd
, uri
->values
[0].string
.text
);
10675 * Is the destination valid?
10678 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10684 send_ipp_status(con
, IPP_NOT_FOUND
,
10685 _("The printer or class does not exist."));
10693 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10695 send_http_error(con
, status
, printer
);
10700 * Start the printer...
10703 printer
->state_message
[0] = '\0';
10705 cupsdStartPrinter(printer
, 1);
10707 if (dtype
& CUPS_PRINTER_CLASS
)
10708 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10709 printer
->name
, get_username(con
));
10711 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10712 printer
->name
, get_username(con
));
10720 if ((i
= check_quotas(con
, printer
)) < 0)
10722 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10727 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10732 * Everything was ok, so return OK status...
10735 con
->response
->request
.status
.status_code
= IPP_OK
;
10740 * 'stop_printer()' - Stop a printer.
10744 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10745 ipp_attribute_t
*uri
) /* I - Printer URI */
10747 http_status_t status
; /* Policy status */
10748 cups_ptype_t dtype
; /* Destination type (printer/class) */
10749 cupsd_printer_t
*printer
; /* Printer data */
10750 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10753 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10754 con
->http
.fd
, uri
->values
[0].string
.text
);
10757 * Is the destination valid?
10760 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10766 send_ipp_status(con
, IPP_NOT_FOUND
,
10767 _("The printer or class does not exist."));
10775 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10777 send_http_error(con
, status
, printer
);
10782 * Stop the printer...
10785 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10786 IPP_TAG_TEXT
)) == NULL
)
10787 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
10790 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10791 sizeof(printer
->state_message
));
10794 cupsdStopPrinter(printer
, 1);
10796 if (dtype
& CUPS_PRINTER_CLASS
)
10797 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10798 printer
->name
, get_username(con
));
10800 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10801 printer
->name
, get_username(con
));
10804 * Everything was ok, so return OK status...
10807 con
->response
->request
.status
.status_code
= IPP_OK
;
10812 * 'url_encode_attr()' - URL-encode a string attribute.
10816 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10817 char *buffer
,/* I - String buffer */
10818 int bufsize
)/* I - Size of buffer */
10820 int i
; /* Looping var */
10821 char *bufptr
, /* Pointer into buffer */
10822 *bufend
; /* End of buffer */
10825 strlcpy(buffer
, attr
->name
, bufsize
);
10826 bufptr
= buffer
+ strlen(buffer
);
10827 bufend
= buffer
+ bufsize
- 1;
10829 for (i
= 0; i
< attr
->num_values
; i
++)
10831 if (bufptr
>= bufend
)
10839 if (bufptr
>= bufend
)
10844 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
10845 bufptr
, bufend
- bufptr
+ 1);
10847 if (bufptr
>= bufend
)
10858 * 'url_encode_string()' - URL-encode a string.
10861 static char * /* O - End of string */
10862 url_encode_string(const char *s
, /* I - String */
10863 char *buffer
, /* I - String buffer */
10864 int bufsize
) /* I - Size of buffer */
10866 char *bufptr
, /* Pointer into buffer */
10867 *bufend
; /* End of buffer */
10868 static const char *hex
= "0123456789ABCDEF";
10873 bufend
= buffer
+ bufsize
- 1;
10875 while (*s
&& bufptr
< bufend
)
10877 if (*s
== ' ' || *s
== '%' || *s
== '+')
10879 if (bufptr
>= (bufend
- 2))
10883 *bufptr
++ = hex
[(*s
>> 4) & 15];
10884 *bufptr
++ = hex
[*s
& 15];
10888 else if (*s
== '\'' || *s
== '\\')
10890 if (bufptr
>= (bufend
- 1))
10907 * 'user_allowed()' - See if a user is allowed to print to a queue.
10910 static int /* O - 0 if not allowed, 1 if allowed */
10911 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10912 const char *username
) /* I - Username */
10914 struct passwd
*pw
; /* User password data */
10915 char baseuser
[256], /* Base username */
10916 *baseptr
, /* Pointer to "@" in base username */
10917 *name
; /* Current user name */
10920 if (cupsArrayCount(p
->users
) == 0)
10923 if (!strcmp(username
, "root"))
10926 if (strchr(username
, '@'))
10929 * Strip @REALM for username check...
10932 strlcpy(baseuser
, username
, sizeof(baseuser
));
10934 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10937 username
= baseuser
;
10940 pw
= getpwnam(username
);
10943 for (name
= (char *)cupsArrayFirst(p
->users
);
10945 name
= (char *)cupsArrayNext(p
->users
))
10947 if (name
[0] == '@')
10950 * Check group membership...
10953 if (cupsdCheckGroup(username
, pw
, name
+ 1))
10956 else if (name
[0] == '#')
10962 if (cupsdCheckGroup(username
, pw
, name
))
10965 else if (!_cups_strcasecmp(username
, name
))
10969 return ((name
!= NULL
) != p
->deny_users
);
10974 * 'validate_job()' - Validate printer options and destination.
10978 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10979 ipp_attribute_t
*uri
) /* I - Printer URI */
10981 http_status_t status
; /* Policy status */
10982 ipp_attribute_t
*attr
, /* Current attribute */
10983 *auth_info
; /* auth-info attribute */
10984 ipp_attribute_t
*format
, /* Document-format attribute */
10985 *name
; /* Job-name attribute */
10986 cups_ptype_t dtype
; /* Destination type (printer/class) */
10987 char super
[MIME_MAX_SUPER
],
10988 /* Supertype of file */
10989 type
[MIME_MAX_TYPE
];
10990 /* Subtype of file */
10991 cupsd_printer_t
*printer
; /* Printer */
10994 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10995 con
->http
.fd
, uri
->values
[0].string
.text
);
10998 * OK, see if the client is sending the document compressed - CUPS
10999 * doesn't support compression yet...
11002 if ((attr
= ippFindAttribute(con
->request
, "compression",
11003 IPP_TAG_KEYWORD
)) != NULL
)
11005 if (strcmp(attr
->values
[0].string
.text
, "none")
11007 && strcmp(attr
->values
[0].string
.text
, "gzip")
11008 #endif /* HAVE_LIBZ */
11011 send_ipp_status(con
, IPP_ATTRIBUTES
,
11012 _("Unsupported 'compression' value \"%s\"."),
11013 attr
->values
[0].string
.text
);
11014 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11015 "compression", NULL
, attr
->values
[0].string
.text
);
11021 * Is it a format we support?
11024 if ((format
= ippFindAttribute(con
->request
, "document-format",
11025 IPP_TAG_MIMETYPE
)) != NULL
)
11027 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11030 send_ipp_status(con
, IPP_BAD_REQUEST
,
11031 _("Bad 'document-format' value \"%s\"."),
11032 format
->values
[0].string
.text
);
11036 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11037 !mimeType(MimeDatabase
, super
, type
))
11039 cupsdLogMessage(CUPSD_LOG_INFO
,
11040 "Hint: Do you have the raw file printing rules enabled?");
11041 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11042 _("Unsupported 'document-format' value \"%s\"."),
11043 format
->values
[0].string
.text
);
11044 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11045 "document-format", NULL
, format
->values
[0].string
.text
);
11051 * Is the job-name valid?
11054 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
11056 int bad_name
= 0; /* Is the job-name value bad? */
11058 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
11059 name
->num_values
!= 1)
11066 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
11067 * IPP Everywhere requirements for "name" values...
11070 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
11072 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
11076 if (*nameptr
< ' ' && *nameptr
!= '\t')
11078 else if (*nameptr
== 0x7f)
11080 else if ((*nameptr
& 0xe0) == 0xc0)
11082 if ((nameptr
[1] & 0xc0) != 0x80)
11087 else if ((*nameptr
& 0xf0) == 0xe0)
11089 if ((nameptr
[1] & 0xc0) != 0x80 ||
11090 (nameptr
[2] & 0xc0) != 0x80)
11095 else if ((*nameptr
& 0xf8) == 0xf0)
11097 if ((nameptr
[1] & 0xc0) != 0x80 ||
11098 (nameptr
[2] & 0xc0) != 0x80 ||
11099 (nameptr
[3] & 0xc0) != 0x80)
11104 else if (*nameptr
& 0x80)
11114 if (StrictConformance
)
11116 send_ipp_status(con
, IPP_ATTRIBUTES
,
11117 _("Unsupported 'job-name' value."));
11118 ippCopyAttribute(con
->response
, name
, 0);
11123 cupsdLogMessage(CUPSD_LOG_WARN
,
11124 "Unsupported 'job-name' value, deleting from request.");
11125 ippDeleteAttribute(con
->request
, name
);
11131 * Is the destination valid?
11134 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11140 send_ipp_status(con
, IPP_NOT_FOUND
,
11141 _("The printer or class does not exist."));
11149 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11151 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11153 send_http_error(con
, status
, printer
);
11156 else if (printer
->num_auth_info_required
== 1 &&
11157 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11160 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11164 else if (auth_info
&& !con
->http
.tls
&&
11165 !httpAddrLocalhost(con
->http
.hostaddr
))
11168 * Require encryption of auth-info over non-local connections...
11171 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11174 #endif /* HAVE_SSL */
11177 * Everything was ok, so return OK status...
11180 con
->response
->request
.status
.status_code
= IPP_OK
;
11185 * 'validate_name()' - Make sure the printer name only contains valid chars.
11188 static int /* O - 0 if name is no good, 1 if good */
11189 validate_name(const char *name
) /* I - Name to check */
11191 const char *ptr
; /* Pointer into name */
11195 * Scan the whole name...
11198 for (ptr
= name
; *ptr
; ptr
++)
11199 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11203 * All the characters are good; validate the length, too...
11206 return ((ptr
- name
) < 128);
11211 * 'validate_user()' - Validate the user for the request.
11214 static int /* O - 1 if permitted, 0 otherwise */
11215 validate_user(cupsd_job_t
*job
, /* I - Job */
11216 cupsd_client_t
*con
, /* I - Client connection */
11217 const char *owner
, /* I - Owner of job/resource */
11218 char *username
, /* O - Authenticated username */
11219 int userlen
) /* I - Length of username */
11221 cupsd_printer_t
*printer
; /* Printer for job */
11224 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11225 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11227 job
->id
, con
? con
->http
.fd
: 0,
11228 owner
? owner
: "(null)", username
, userlen
);
11231 * Validate input...
11234 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11238 * Get the best authenticated username that is available.
11241 strlcpy(username
, get_username(con
), userlen
);
11244 * Check the username against the owner...
11247 printer
= cupsdFindDest(job
->dest
);
11249 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11250 con
, owner
) == HTTP_OK
);
11255 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".