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 */
755 if (!fstat(con
->file
, &fileinfo
))
756 length
+= fileinfo
.st_size
;
759 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
760 CUPS_LLCAST length
) < 0)
763 if (cupsdFlushHeader(con
) < 0)
766 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
767 con
->http
.data_remaining
= length
;
769 if (con
->http
.data_remaining
<= INT_MAX
)
770 con
->http
._data_remaining
= con
->http
.data_remaining
;
772 con
->http
._data_remaining
= INT_MAX
;
775 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
776 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
779 * Tell the caller the response header was sent successfully...
787 * Tell the caller the response header could not be sent...
796 * Sending data from a subprocess like cups-deviced; tell the caller
797 * everything is A-OK so far...
806 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
809 int /* O - 0 on success, -1 on error */
810 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
812 cupsd_printer_t
*printer
; /* Destination printer or class */
813 ipp_attribute_t
*attr
; /* job-sheets attribute */
814 int kbytes
; /* Kilobytes in banner */
817 job
->pending_timeout
= 0;
820 * See if we need to add the ending sheet...
823 if (!cupsdLoadJob(job
))
826 printer
= cupsdFindDest(job
->dest
);
827 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
829 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
830 attr
&& attr
->num_values
> 1)
836 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
837 attr
->values
[1].string
.text
);
839 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
842 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
850 * 'accept_jobs()' - Accept print jobs to a printer.
854 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
855 ipp_attribute_t
*uri
) /* I - Printer or class URI */
857 http_status_t status
; /* Policy status */
858 cups_ptype_t dtype
; /* Destination type (printer/class) */
859 cupsd_printer_t
*printer
; /* Printer data */
862 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
863 con
->http
.fd
, uri
->values
[0].string
.text
);
866 * Is the destination valid?
869 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
875 send_ipp_status(con
, IPP_NOT_FOUND
,
876 _("The printer or class does not exist."));
884 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
886 send_http_error(con
, status
, printer
);
891 * Accept jobs sent to the printer...
894 printer
->accepting
= 1;
895 printer
->state_message
[0] = '\0';
897 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
898 "Now accepting jobs.");
900 if (dtype
& CUPS_PRINTER_CLASS
)
902 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
904 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
905 printer
->name
, get_username(con
));
909 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
911 cupsdLogMessage(CUPSD_LOG_INFO
,
912 "Printer \"%s\" now accepting jobs (\"%s\").",
913 printer
->name
, get_username(con
));
917 * Everything was ok, so return OK status...
920 con
->response
->request
.status
.status_code
= IPP_OK
;
925 * 'add_class()' - Add a class to the system.
929 add_class(cupsd_client_t
*con
, /* I - Client connection */
930 ipp_attribute_t
*uri
) /* I - URI of class */
932 http_status_t status
; /* Policy status */
933 int i
; /* Looping var */
934 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
935 username
[HTTP_MAX_URI
], /* Username portion of URI */
936 host
[HTTP_MAX_URI
], /* Host portion of URI */
937 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
938 int port
; /* Port portion of URI */
939 cupsd_printer_t
*pclass
, /* Class */
940 *member
; /* Member printer/class */
941 cups_ptype_t dtype
; /* Destination type */
942 ipp_attribute_t
*attr
; /* Printer attribute */
943 int modify
; /* Non-zero if we just modified */
944 int need_restart_job
; /* Need to restart job? */
947 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
948 con
->http
.fd
, uri
->values
[0].string
.text
);
951 * Do we have a valid URI?
954 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
955 sizeof(scheme
), username
, sizeof(username
), host
,
956 sizeof(host
), &port
, resource
, sizeof(resource
));
959 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
962 * No, return an error...
965 send_ipp_status(con
, IPP_BAD_REQUEST
,
966 _("The printer-uri must be of the form "
967 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
972 * Do we have a valid printer name?
975 if (!validate_name(resource
+ 9))
978 * No, return an error...
981 send_ipp_status(con
, IPP_BAD_REQUEST
,
982 _("The printer-uri \"%s\" contains invalid characters."),
983 uri
->values
[0].string
.text
);
988 * See if the class already exists; if not, create a new class...
991 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
994 * Class doesn't exist; see if we have a printer of the same name...
997 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
1000 * Yes, return an error...
1003 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1004 _("A printer named \"%s\" already exists."),
1010 * No, check the default policy and then add the class...
1013 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1015 send_http_error(con
, status
, NULL
);
1019 pclass
= cupsdAddClass(resource
+ 9);
1022 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1025 send_http_error(con
, status
, pclass
);
1032 * Look for attributes and copy them over as needed...
1035 need_restart_job
= 0;
1037 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1038 IPP_TAG_TEXT
)) != NULL
)
1039 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1041 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1042 IPP_TAG_TEXT
)) != NULL
)
1043 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1045 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1046 IPP_TAG_BOOLEAN
)) != NULL
&&
1047 attr
->values
[0].boolean
!= pclass
->accepting
)
1049 cupsdLogMessage(CUPSD_LOG_INFO
,
1050 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1051 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1053 pclass
->accepting
= attr
->values
[0].boolean
;
1055 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1056 pclass
->accepting
? "Now" : "No longer");
1059 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1060 IPP_TAG_BOOLEAN
)) != NULL
)
1062 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1063 cupsdDeregisterPrinter(pclass
, 1);
1065 cupsdLogMessage(CUPSD_LOG_INFO
,
1066 "Setting %s printer-is-shared to %d (was %d.)",
1067 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1069 pclass
->shared
= attr
->values
[0].boolean
;
1072 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1073 IPP_TAG_ENUM
)) != NULL
)
1075 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1076 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1078 send_ipp_status(con
, IPP_BAD_REQUEST
,
1079 _("Attempt to set %s printer-state to bad value %d."),
1080 pclass
->name
, attr
->values
[0].integer
);
1084 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1085 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1087 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1088 cupsdStopPrinter(pclass
, 0);
1091 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1092 need_restart_job
= 1;
1095 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1096 IPP_TAG_TEXT
)) != NULL
)
1098 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1099 sizeof(pclass
->state_message
));
1101 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1102 pclass
->state_message
);
1104 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1105 IPP_TAG_URI
)) != NULL
)
1108 * Clear the printer array as needed...
1111 need_restart_job
= 1;
1113 if (pclass
->num_printers
> 0)
1115 free(pclass
->printers
);
1116 pclass
->num_printers
= 0;
1120 * Add each printer or class that is listed...
1123 for (i
= 0; i
< attr
->num_values
; i
++)
1126 * Search for the printer or class URI...
1129 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1135 send_ipp_status(con
, IPP_NOT_FOUND
,
1136 _("The printer or class does not exist."));
1139 else if (dtype
& CUPS_PRINTER_CLASS
)
1141 send_ipp_status(con
, IPP_BAD_REQUEST
,
1142 _("Nested classes are not allowed."));
1147 * Add it to the class...
1150 cupsdAddPrinterToClass(pclass
, member
);
1154 set_printer_defaults(con
, pclass
);
1156 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1157 IPP_TAG_KEYWORD
)) != NULL
)
1158 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1161 * Update the printer class attributes and return...
1164 cupsdSetPrinterAttrs(pclass
);
1165 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1167 if (need_restart_job
&& pclass
->job
)
1170 * Reset the current job to a "pending" status...
1173 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1174 "Job restarted because the class was modified.");
1177 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1181 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1182 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1183 pclass
->name
, get_username(con
));
1185 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1186 pclass
->name
, get_username(con
));
1190 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1191 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1192 pclass
->name
, get_username(con
));
1194 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1195 pclass
->name
, get_username(con
));
1198 con
->response
->request
.status
.status_code
= IPP_OK
;
1203 * 'add_file()' - Add a file to a job.
1206 static int /* O - 0 on success, -1 on error */
1207 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1208 cupsd_job_t
*job
, /* I - Job to add to */
1209 mime_type_t
*filetype
, /* I - Type of file */
1210 int compression
) /* I - Compression */
1212 mime_type_t
**filetypes
; /* New filetypes array... */
1213 int *compressions
; /* New compressions array... */
1216 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1217 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1218 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1219 filetype
->super
, filetype
->type
, compression
);
1222 * Add the file to the job...
1225 if (job
->num_files
== 0)
1227 compressions
= (int *)malloc(sizeof(int));
1228 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1232 compressions
= (int *)realloc(job
->compressions
,
1233 (job
->num_files
+ 1) * sizeof(int));
1234 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1235 (job
->num_files
+ 1) *
1236 sizeof(mime_type_t
*));
1239 if (!compressions
|| !filetypes
)
1241 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1242 "Job aborted because the scheduler ran out of memory.");
1245 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1246 _("Unable to allocate memory for file types."));
1251 job
->compressions
= compressions
;
1252 job
->compressions
[job
->num_files
] = compression
;
1253 job
->filetypes
= filetypes
;
1254 job
->filetypes
[job
->num_files
] = filetype
;
1259 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1266 * 'add_job()' - Add a job to a print queue.
1269 static cupsd_job_t
* /* O - Job object */
1270 add_job(cupsd_client_t
*con
, /* I - Client connection */
1271 cupsd_printer_t
*printer
, /* I - Destination printer */
1272 mime_type_t
*filetype
) /* I - First print file type, if any */
1274 http_status_t status
; /* Policy status */
1275 ipp_attribute_t
*attr
, /* Current attribute */
1276 *auth_info
; /* auth-info 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 */
1290 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1291 con
, con
->http
.fd
, printer
, printer
->name
,
1292 filetype
, filetype
? filetype
->super
: "none",
1293 filetype
? filetype
->type
: "none");
1296 * Check remote printing to non-shared printer...
1299 if (!printer
->shared
&&
1300 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
1301 _cups_strcasecmp(con
->http
.hostname
, ServerName
))
1303 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1304 _("The printer or class is not shared."));
1312 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1314 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1316 send_http_error(con
, status
, printer
);
1319 else if (printer
->num_auth_info_required
== 1 &&
1320 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1323 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1327 else if (auth_info
&& !con
->http
.tls
&&
1328 !httpAddrLocalhost(con
->http
.hostaddr
))
1331 * Require encryption of auth-info over non-local connections...
1334 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1337 #endif /* HAVE_SSL */
1340 * See if the printer is accepting jobs...
1343 if (!printer
->accepting
)
1345 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1346 _("Destination \"%s\" is not accepting jobs."),
1352 * Validate job template attributes; for now just document-format,
1353 * copies, number-up, and page-ranges...
1356 if (filetype
&& printer
->filetypes
&&
1357 !cupsArrayFind(printer
->filetypes
, filetype
))
1359 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1360 /* MIME media type string */
1363 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1366 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1367 _("Unsupported format \"%s\"."), mimetype
);
1369 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1370 "document-format", NULL
, mimetype
);
1375 if ((attr
= ippFindAttribute(con
->request
, "copies",
1376 IPP_TAG_INTEGER
)) != NULL
)
1378 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1380 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1381 attr
->values
[0].integer
);
1382 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1383 "copies", attr
->values
[0].integer
);
1388 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1389 IPP_TAG_ZERO
)) != NULL
)
1391 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1392 attr
->value_tag
!= IPP_TAG_NAME
)
1394 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1398 if (attr
->num_values
> 2)
1400 send_ipp_status(con
, IPP_BAD_REQUEST
,
1401 _("Too many job-sheets values (%d > 2)."),
1406 for (i
= 0; i
< attr
->num_values
; i
++)
1407 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1408 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1410 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1411 attr
->values
[i
].string
.text
);
1416 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1417 IPP_TAG_INTEGER
)) != NULL
)
1419 if (attr
->values
[0].integer
!= 1 &&
1420 attr
->values
[0].integer
!= 2 &&
1421 attr
->values
[0].integer
!= 4 &&
1422 attr
->values
[0].integer
!= 6 &&
1423 attr
->values
[0].integer
!= 9 &&
1424 attr
->values
[0].integer
!= 16)
1426 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1427 attr
->values
[0].integer
);
1428 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1429 "number-up", attr
->values
[0].integer
);
1434 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1435 IPP_TAG_RANGE
)) != NULL
)
1437 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1439 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1440 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1442 send_ipp_status(con
, IPP_BAD_REQUEST
,
1443 _("Bad page-ranges values %d-%d."),
1444 attr
->values
[i
].range
.lower
,
1445 attr
->values
[i
].range
.upper
);
1449 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1454 * Do media selection as needed...
1457 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1458 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1459 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1462 (media_col
= ippFindAttribute(con
->request
, "media-col",
1463 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1465 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1467 unsup_col
= ippNew();
1468 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1469 "media-bottom-margin",
1470 IPP_TAG_INTEGER
)) != NULL
)
1471 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1472 "media-bottom-margin", media_margin
->values
[0].integer
);
1474 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1475 "media-left-margin",
1476 IPP_TAG_INTEGER
)) != NULL
)
1477 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1478 "media-left-margin", media_margin
->values
[0].integer
);
1480 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1481 "media-right-margin",
1482 IPP_TAG_INTEGER
)) != NULL
)
1483 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1484 "media-right-margin", media_margin
->values
[0].integer
);
1486 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1488 IPP_TAG_INTEGER
)) != NULL
)
1489 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1490 "media-top-margin", media_margin
->values
[0].integer
);
1492 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1494 ippDelete(unsup_col
);
1499 * Make sure we aren't over our limit...
1502 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1505 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1507 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1511 if ((i
= check_quotas(con
, printer
)) < 0)
1513 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1518 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1523 * Create the job and set things up...
1526 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1527 IPP_TAG_INTEGER
)) != NULL
)
1528 priority
= attr
->values
[0].integer
;
1531 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1532 printer
->options
)) != NULL
)
1533 priority
= atoi(val
);
1537 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1541 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1542 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1545 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1547 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1548 _("Unable to add job for destination \"%s\"."),
1553 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1554 job
->attrs
= con
->request
;
1556 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1558 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1561 apply_printer_defaults(printer
, job
);
1563 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1565 if (con
->username
[0])
1567 cupsdSetString(&job
->username
, con
->username
);
1570 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1574 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1575 "add_job: requesting-user-name=\"%s\"",
1576 attr
->values
[0].string
.text
);
1578 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1581 cupsdSetString(&job
->username
, "anonymous");
1584 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1585 "job-originating-user-name", NULL
, job
->username
);
1588 attr
->group_tag
= IPP_TAG_JOB
;
1589 _cupsStrFree(attr
->name
);
1590 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1593 if (con
->username
[0] || auth_info
)
1595 save_auth_info(con
, job
, auth_info
);
1598 * Remove the auth-info attribute from the attribute data...
1602 ippDeleteAttribute(job
->attrs
, auth_info
);
1605 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1606 IPP_TAG_ZERO
)) != NULL
)
1609 * Request contains a job-originating-host-name attribute; validate it...
1612 if (attr
->value_tag
!= IPP_TAG_NAME
||
1613 attr
->num_values
!= 1 ||
1614 strcmp(con
->http
.hostname
, "localhost"))
1617 * Can't override the value if we aren't connected via localhost.
1618 * Also, we can only have 1 value and it must be a name value.
1621 switch (attr
->value_tag
)
1623 case IPP_TAG_STRING
:
1624 case IPP_TAG_TEXTLANG
:
1625 case IPP_TAG_NAMELANG
:
1628 case IPP_TAG_KEYWORD
:
1630 case IPP_TAG_URISCHEME
:
1631 case IPP_TAG_CHARSET
:
1632 case IPP_TAG_LANGUAGE
:
1633 case IPP_TAG_MIMETYPE
:
1635 * Free old strings...
1638 for (i
= 0; i
< attr
->num_values
; i
++)
1640 _cupsStrFree(attr
->values
[i
].string
.text
);
1641 attr
->values
[i
].string
.text
= NULL
;
1642 if (attr
->values
[i
].string
.language
)
1644 _cupsStrFree(attr
->values
[i
].string
.language
);
1645 attr
->values
[i
].string
.language
= NULL
;
1654 * Use the default connection hostname instead...
1657 attr
->value_tag
= IPP_TAG_NAME
;
1658 attr
->num_values
= 1;
1659 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1662 attr
->group_tag
= IPP_TAG_JOB
;
1667 * No job-originating-host-name attribute, so use the hostname from
1671 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1672 "job-originating-host-name", NULL
, con
->http
.hostname
);
1675 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1677 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1678 "time-at-processing", 0);
1679 attr
->value_tag
= IPP_TAG_NOVALUE
;
1680 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1681 "time-at-completed", 0);
1682 attr
->value_tag
= IPP_TAG_NOVALUE
;
1685 * Add remaining job attributes...
1688 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1689 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1690 "job-state", IPP_JOB_STOPPED
);
1691 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1692 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1693 "job-state-reasons", NULL
, "job-incoming");
1694 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1695 "job-media-sheets-completed", 0);
1696 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1699 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1700 IPP_TAG_INTEGER
)) != NULL
)
1701 attr
->values
[0].integer
= 0;
1703 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1705 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1706 IPP_TAG_KEYWORD
)) == NULL
)
1707 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1710 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1711 printer
->options
)) == NULL
)
1714 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1715 "job-hold-until", NULL
, val
);
1717 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1720 * Hold job until specified time...
1723 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1725 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1726 job
->state_value
= IPP_JOB_HELD
;
1728 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1730 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1732 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1733 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1734 job
->state_value
= IPP_JOB_HELD
;
1738 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1739 job
->state_value
= IPP_JOB_PENDING
;
1741 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1744 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1747 * Add job sheets options...
1750 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1751 IPP_TAG_ZERO
)) == NULL
)
1753 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1754 "Adding default job-sheets values \"%s,%s\"...",
1755 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1757 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1759 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1760 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1763 job
->job_sheets
= attr
;
1766 * Enforce classification level if set...
1771 cupsdLogMessage(CUPSD_LOG_INFO
,
1772 "Classification=\"%s\", ClassifyOverride=%d",
1773 Classification
? Classification
: "(null)",
1776 if (ClassifyOverride
)
1778 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1779 (attr
->num_values
== 1 ||
1780 !strcmp(attr
->values
[1].string
.text
, "none")))
1783 * Force the leading banner to have the classification on it...
1786 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1788 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1789 "job-sheets=\"%s,none\", "
1790 "job-originating-user-name=\"%s\"",
1791 Classification
, job
->username
);
1793 else if (attr
->num_values
== 2 &&
1794 strcmp(attr
->values
[0].string
.text
,
1795 attr
->values
[1].string
.text
) &&
1796 strcmp(attr
->values
[0].string
.text
, "none") &&
1797 strcmp(attr
->values
[1].string
.text
, "none"))
1800 * Can't put two different security markings on the same document!
1803 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1805 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1806 "job-sheets=\"%s,%s\", "
1807 "job-originating-user-name=\"%s\"",
1808 attr
->values
[0].string
.text
,
1809 attr
->values
[1].string
.text
, job
->username
);
1811 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1812 strcmp(attr
->values
[0].string
.text
, "none") &&
1813 (attr
->num_values
== 1 ||
1814 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1815 strcmp(attr
->values
[1].string
.text
, "none"))))
1817 if (attr
->num_values
== 1)
1818 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1819 "CLASSIFICATION OVERRIDDEN "
1820 "job-sheets=\"%s\", "
1821 "job-originating-user-name=\"%s\"",
1822 attr
->values
[0].string
.text
, job
->username
);
1824 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1825 "CLASSIFICATION OVERRIDDEN "
1826 "job-sheets=\"%s,%s\",fffff "
1827 "job-originating-user-name=\"%s\"",
1828 attr
->values
[0].string
.text
,
1829 attr
->values
[1].string
.text
, job
->username
);
1832 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1833 (attr
->num_values
== 1 ||
1834 strcmp(attr
->values
[1].string
.text
, Classification
)))
1837 * Force the banner to have the classification on it...
1840 if (attr
->num_values
> 1 &&
1841 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1843 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1844 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1848 if (attr
->num_values
== 1 ||
1849 strcmp(attr
->values
[0].string
.text
, "none"))
1850 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1852 if (attr
->num_values
> 1 &&
1853 strcmp(attr
->values
[1].string
.text
, "none"))
1854 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1857 if (attr
->num_values
> 1)
1858 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1859 "CLASSIFICATION FORCED "
1860 "job-sheets=\"%s,%s\", "
1861 "job-originating-user-name=\"%s\"",
1862 attr
->values
[0].string
.text
,
1863 attr
->values
[1].string
.text
, job
->username
);
1865 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1866 "CLASSIFICATION FORCED "
1867 "job-sheets=\"%s\", "
1868 "job-originating-user-name=\"%s\"",
1869 Classification
, job
->username
);
1874 * See if we need to add the starting sheet...
1877 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1879 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1880 attr
->values
[0].string
.text
);
1882 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1884 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1885 "Aborting job because the start banner could not be "
1890 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1893 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1894 IPP_TAG_ZERO
)) != NULL
)
1895 job
->job_sheets
= attr
;
1898 * Fill in the response info...
1901 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1902 con
->servername
, con
->serverport
, "/jobs/%d", job
->id
);
1903 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1906 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1908 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1910 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1911 NULL
, job
->reasons
->values
[0].string
.text
);
1913 con
->response
->request
.status
.status_code
= IPP_OK
;
1916 * Add any job subscriptions...
1919 add_job_subscriptions(con
, job
);
1922 * Set all but the first two attributes to the job attributes group...
1925 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1926 attr
->group_tag
= IPP_TAG_JOB
;
1929 * Fire the "job created" event...
1932 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1935 * Return the new job...
1943 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1947 add_job_subscriptions(
1948 cupsd_client_t
*con
, /* I - Client connection */
1949 cupsd_job_t
*job
) /* I - Newly created job */
1951 int i
; /* Looping var */
1952 ipp_attribute_t
*prev
, /* Previous attribute */
1953 *next
, /* Next attribute */
1954 *attr
; /* Current attribute */
1955 cupsd_subscription_t
*sub
; /* Subscription object */
1956 const char *recipient
, /* notify-recipient-uri */
1957 *pullmethod
; /* notify-pull-method */
1958 ipp_attribute_t
*user_data
; /* notify-user-data */
1959 int interval
; /* notify-time-interval */
1960 unsigned mask
; /* notify-events */
1964 * Find the first subscription group attribute; return if we have
1968 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1969 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1976 * Process the subscription attributes in the request...
1985 mask
= CUPSD_EVENT_NONE
;
1987 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1989 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
1990 attr
->value_tag
== IPP_TAG_URI
)
1993 * Validate the recipient scheme against the ServerBin/notifier
1997 char notifier
[1024], /* Notifier filename */
1998 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
1999 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2000 host
[HTTP_MAX_URI
], /* Host portion of URI */
2001 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2002 int port
; /* Port portion of URI */
2005 recipient
= attr
->values
[0].string
.text
;
2007 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2008 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2009 host
, sizeof(host
), &port
,
2010 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2012 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2013 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2014 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2015 "notify-status-code", IPP_URI_SCHEME
);
2019 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2021 if (access(notifier
, X_OK
))
2023 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2024 _("notify-recipient-uri URI \"%s\" uses unknown "
2025 "scheme."), recipient
);
2026 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2027 "notify-status-code", IPP_URI_SCHEME
);
2031 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2033 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2034 _("notify-recipient-uri URI \"%s\" is already used."),
2036 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2037 "notify-status-code", IPP_ATTRIBUTES
);
2041 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2042 attr
->value_tag
== IPP_TAG_KEYWORD
)
2044 pullmethod
= attr
->values
[0].string
.text
;
2046 if (strcmp(pullmethod
, "ippget"))
2048 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2049 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2050 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2051 "notify-status-code", IPP_ATTRIBUTES
);
2055 else if (!strcmp(attr
->name
, "notify-charset") &&
2056 attr
->value_tag
== IPP_TAG_CHARSET
&&
2057 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2058 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2060 send_ipp_status(con
, IPP_CHARSET
,
2061 _("Character set \"%s\" not supported."),
2062 attr
->values
[0].string
.text
);
2065 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2066 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2067 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2069 send_ipp_status(con
, IPP_CHARSET
,
2070 _("Language \"%s\" not supported."),
2071 attr
->values
[0].string
.text
);
2074 else if (!strcmp(attr
->name
, "notify-user-data") &&
2075 attr
->value_tag
== IPP_TAG_STRING
)
2077 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2079 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2080 _("The notify-user-data value is too large "
2081 "(%d > 63 octets)."),
2082 attr
->values
[0].unknown
.length
);
2088 else if (!strcmp(attr
->name
, "notify-events") &&
2089 attr
->value_tag
== IPP_TAG_KEYWORD
)
2091 for (i
= 0; i
< attr
->num_values
; i
++)
2092 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2094 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2096 send_ipp_status(con
, IPP_BAD_REQUEST
,
2097 _("The notify-lease-duration attribute cannot be "
2098 "used with job subscriptions."));
2101 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2102 attr
->value_tag
== IPP_TAG_INTEGER
)
2103 interval
= attr
->values
[0].integer
;
2108 if (!recipient
&& !pullmethod
)
2111 if (mask
== CUPSD_EVENT_NONE
)
2112 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2114 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2115 recipient
, 0)) != NULL
)
2117 sub
->interval
= interval
;
2119 cupsdSetString(&sub
->owner
, job
->username
);
2123 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2124 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2125 sub
->user_data_len
);
2128 ippAddSeparator(con
->response
);
2129 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2130 "notify-subscription-id", sub
->id
);
2132 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2140 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2143 * Remove all of the subscription attributes from the job request...
2145 * TODO: Optimize this since subscription groups have to come at the
2146 * end of the request...
2149 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2153 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2154 attr
->group_tag
== IPP_TAG_ZERO
)
2157 * Free and remove this attribute...
2160 ippDeleteAttribute(NULL
, attr
);
2165 job
->attrs
->attrs
= next
;
2171 job
->attrs
->last
= prev
;
2172 job
->attrs
->current
= prev
;
2177 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2179 * See RFC 4122 for the definition of UUIDs and the format.
2183 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2185 char uuid
[64]; /* job-uuid string */
2189 * Add a job-uuid attribute if none exists...
2192 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2193 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2194 _httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2195 uuid
, sizeof(uuid
)));
2200 * 'add_printer()' - Add a printer to the system.
2204 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2205 ipp_attribute_t
*uri
) /* I - URI of printer */
2207 http_status_t status
; /* Policy status */
2208 int i
; /* Looping var */
2209 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2210 username
[HTTP_MAX_URI
], /* Username portion of URI */
2211 host
[HTTP_MAX_URI
], /* Host portion of URI */
2212 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2213 int port
; /* Port portion of URI */
2214 cupsd_printer_t
*printer
; /* Printer/class */
2215 ipp_attribute_t
*attr
; /* Printer attribute */
2216 cups_file_t
*fp
; /* Script/PPD file */
2217 char line
[1024]; /* Line from file... */
2218 char srcfile
[1024], /* Source Script/PPD file */
2219 dstfile
[1024]; /* Destination Script/PPD file */
2220 int modify
; /* Non-zero if we are modifying */
2221 int changed_driver
, /* Changed the PPD/interface script? */
2222 need_restart_job
, /* Need to restart job? */
2223 set_device_uri
, /* Did we set the device URI? */
2224 set_port_monitor
; /* Did we set the port monitor? */
2227 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2228 con
->http
.fd
, uri
->values
[0].string
.text
);
2231 * Do we have a valid URI?
2234 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2235 sizeof(scheme
), username
, sizeof(username
), host
,
2236 sizeof(host
), &port
, resource
, sizeof(resource
));
2238 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2241 * No, return an error...
2244 send_ipp_status(con
, IPP_BAD_REQUEST
,
2245 _("The printer-uri must be of the form "
2246 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2251 * Do we have a valid printer name?
2254 if (!validate_name(resource
+ 10))
2257 * No, return an error...
2260 send_ipp_status(con
, IPP_BAD_REQUEST
,
2261 _("The printer-uri \"%s\" contains invalid characters."),
2262 uri
->values
[0].string
.text
);
2267 * See if the printer already exists; if not, create a new printer...
2270 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2273 * Printer doesn't exist; see if we have a class of the same name...
2276 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2279 * Yes, return an error...
2282 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2283 _("A class named \"%s\" already exists."),
2289 * No, check the default policy then add the printer...
2292 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2294 send_http_error(con
, status
, NULL
);
2298 printer
= cupsdAddPrinter(resource
+ 10);
2301 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2304 send_http_error(con
, status
, printer
);
2311 * Look for attributes and copy them over as needed...
2315 need_restart_job
= 0;
2317 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2318 IPP_TAG_TEXT
)) != NULL
)
2319 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2321 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2322 IPP_TAG_TEXT
)) != NULL
)
2323 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2327 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2328 IPP_TAG_URI
)) != NULL
)
2331 * Do we have a valid device URI?
2334 http_uri_status_t uri_status
; /* URI separation status */
2335 char old_device_uri
[1024];
2336 /* Old device URI */
2339 need_restart_job
= 1;
2341 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2342 attr
->values
[0].string
.text
,
2343 scheme
, sizeof(scheme
),
2344 username
, sizeof(username
),
2345 host
, sizeof(host
), &port
,
2346 resource
, sizeof(resource
));
2348 if (uri_status
< HTTP_URI_OK
)
2350 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2351 attr
->values
[0].string
.text
);
2352 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2353 "add_printer: httpSeparateURI returned %d", uri_status
);
2357 if (!strcmp(scheme
, "file"))
2360 * See if the administrator has enabled file devices...
2363 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2366 * File devices are disabled and the URL is not file:/dev/null...
2369 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2370 _("File device URIs have been disabled. "
2371 "To enable, see the FileDevice directive in "
2372 "\"%s/cupsd.conf\"."),
2380 * See if the backend exists and is executable...
2383 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2384 if (access(srcfile
, X_OK
))
2387 * Could not find device in list!
2390 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2391 _("Bad device-uri scheme \"%s\"."), scheme
);
2396 if (printer
->sanitized_device_uri
)
2397 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2398 sizeof(old_device_uri
));
2400 old_device_uri
[0] = '\0';
2402 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2404 cupsdLogMessage(CUPSD_LOG_INFO
,
2405 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2406 printer
->name
, printer
->sanitized_device_uri
,
2412 set_port_monitor
= 0;
2414 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2415 IPP_TAG_NAME
)) != NULL
)
2417 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2420 need_restart_job
= 1;
2422 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2426 for (i
= 0; i
< supported
->num_values
; i
++)
2427 if (!strcmp(supported
->values
[i
].string
.text
,
2428 attr
->values
[0].string
.text
))
2432 if (!supported
|| i
>= supported
->num_values
)
2434 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2435 attr
->values
[0].string
.text
);
2439 cupsdLogMessage(CUPSD_LOG_INFO
,
2440 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2441 printer
->name
, attr
->values
[0].string
.text
,
2442 printer
->port_monitor
? printer
->port_monitor
: "none");
2444 if (strcmp(attr
->values
[0].string
.text
, "none"))
2445 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2447 cupsdClearString(&printer
->port_monitor
);
2449 set_port_monitor
= 1;
2452 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2453 IPP_TAG_BOOLEAN
)) != NULL
&&
2454 attr
->values
[0].boolean
!= printer
->accepting
)
2456 cupsdLogMessage(CUPSD_LOG_INFO
,
2457 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2458 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2460 printer
->accepting
= attr
->values
[0].boolean
;
2462 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2463 "%s accepting jobs.",
2464 printer
->accepting
? "Now" : "No longer");
2467 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2468 IPP_TAG_BOOLEAN
)) != NULL
)
2470 if (attr
->values
[0].boolean
&&
2471 printer
->num_auth_info_required
== 1 &&
2472 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2474 send_ipp_status(con
, IPP_BAD_REQUEST
,
2475 _("Cannot share a remote Kerberized printer."));
2479 if (printer
->shared
&& !attr
->values
[0].boolean
)
2480 cupsdDeregisterPrinter(printer
, 1);
2482 cupsdLogMessage(CUPSD_LOG_INFO
,
2483 "Setting %s printer-is-shared to %d (was %d.)",
2484 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2486 printer
->shared
= attr
->values
[0].boolean
;
2489 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2490 IPP_TAG_ENUM
)) != NULL
)
2492 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2493 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2495 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2496 attr
->values
[0].integer
);
2500 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2501 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2503 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2504 cupsdStopPrinter(printer
, 0);
2507 need_restart_job
= 1;
2508 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2512 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2513 IPP_TAG_TEXT
)) != NULL
)
2515 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2516 sizeof(printer
->state_message
));
2518 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2519 printer
->state_message
);
2522 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2523 IPP_TAG_KEYWORD
)) != NULL
)
2525 if (attr
->num_values
>
2526 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2528 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2529 _("Too many printer-state-reasons values (%d > %d)."),
2531 (int)(sizeof(printer
->reasons
) /
2532 sizeof(printer
->reasons
[0])));
2536 for (i
= 0; i
< printer
->num_reasons
; i
++)
2537 _cupsStrFree(printer
->reasons
[i
]);
2539 printer
->num_reasons
= 0;
2540 for (i
= 0; i
< attr
->num_values
; i
++)
2542 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2545 printer
->reasons
[printer
->num_reasons
] =
2546 _cupsStrRetain(attr
->values
[i
].string
.text
);
2547 printer
->num_reasons
++;
2549 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2550 printer
->state
!= IPP_PRINTER_STOPPED
)
2552 cupsdLogMessage(CUPSD_LOG_INFO
,
2553 "Setting %s printer-state to %d (was %d.)",
2554 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2555 cupsdStopPrinter(printer
, 0);
2559 if (PrintcapFormat
== PRINTCAP_PLIST
)
2560 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2562 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2563 "Printer \"%s\" state changed.", printer
->name
);
2566 set_printer_defaults(con
, printer
);
2568 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2569 IPP_TAG_KEYWORD
)) != NULL
)
2570 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2573 * See if we have all required attributes...
2576 if (!printer
->device_uri
)
2577 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2580 * See if we have an interface script or PPD file attached to the request...
2585 need_restart_job
= 1;
2588 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2590 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2593 * Yes; get the first line from it...
2597 cupsFileGets(fp
, line
, sizeof(line
));
2601 * Then see what kind of file it is...
2604 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2607 if (!strncmp(line
, "*PPD-Adobe", 10))
2610 * The new file is a PPD file, so remove any old interface script
2611 * that might be lying around...
2619 * This must be an interface script, so move the file over to the
2620 * interfaces directory and make it executable...
2623 if (copy_file(srcfile
, dstfile
))
2625 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2626 _("Unable to copy interface script - %s"),
2631 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2632 "Copied interface script successfully");
2633 chmod(dstfile
, 0755);
2636 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2639 if (!strncmp(line
, "*PPD-Adobe", 10))
2642 * The new file is a PPD file, so move the file over to the
2643 * ppd directory and make it readable by all...
2646 if (copy_file(srcfile
, dstfile
))
2648 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2649 _("Unable to copy PPD file - %s"),
2654 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2655 "Copied PPD file successfully");
2656 chmod(dstfile
, 0644);
2661 * This must be an interface script, so remove any old PPD file that
2662 * may be lying around...
2669 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2670 IPP_TAG_NAME
)) != NULL
)
2672 need_restart_job
= 1;
2675 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2678 * Raw driver, remove any existing PPD or interface script files.
2681 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2685 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2695 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2699 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2702 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2704 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2708 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2709 "Copied PPD file successfully");
2710 chmod(dstfile
, 0644);
2717 * If we changed the PPD/interface script, then remove the printer's cache
2718 * file and clear the printer-state-reasons...
2721 char cache_name
[1024]; /* Cache filename for printer attrs */
2723 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2727 cupsdSetPrinterReasons(printer
, "none");
2730 * (Re)register color profiles...
2733 cupsdRegisterColor(printer
);
2737 * If we set the device URI but not the port monitor, check which port
2738 * monitor to use by default...
2741 if (set_device_uri
&& !set_port_monitor
)
2743 ppd_file_t
*ppd
; /* PPD file */
2744 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2747 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2748 sizeof(scheme
), username
, sizeof(username
), host
,
2749 sizeof(host
), &port
, resource
, sizeof(resource
));
2751 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2753 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2755 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2757 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2758 if (!strcmp(scheme
, ppdattr
->spec
))
2760 cupsdLogMessage(CUPSD_LOG_INFO
,
2761 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2762 printer
->name
, ppdattr
->value
,
2763 printer
->port_monitor
? printer
->port_monitor
2766 if (strcmp(ppdattr
->value
, "none"))
2767 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2769 cupsdClearString(&printer
->port_monitor
);
2779 * Update the printer attributes and return...
2782 cupsdSetPrinterAttrs(printer
);
2783 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2785 if (need_restart_job
&& printer
->job
)
2788 * Restart the current job...
2791 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2792 "Job restarted because the printer was modified.");
2795 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2799 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2800 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2801 printer
->name
, get_username(con
));
2803 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2804 printer
->name
, get_username(con
));
2808 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2809 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2810 printer
->name
, get_username(con
));
2812 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2813 printer
->name
, get_username(con
));
2816 con
->response
->request
.status
.status_code
= IPP_OK
;
2821 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2822 * based upon the printer state...
2826 add_printer_state_reasons(
2827 cupsd_client_t
*con
, /* I - Client connection */
2828 cupsd_printer_t
*p
) /* I - Printer info */
2830 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2831 "add_printer_state_reasons(%p[%d], %p[%s])",
2832 con
, con
->http
.fd
, p
, p
->name
);
2834 if (p
->num_reasons
== 0)
2835 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2836 "printer-state-reasons", NULL
, "none");
2838 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2839 "printer-state-reasons", p
->num_reasons
, NULL
,
2840 (const char * const *)p
->reasons
);
2845 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2846 * the specified printer or class.
2850 add_queued_job_count(
2851 cupsd_client_t
*con
, /* I - Client connection */
2852 cupsd_printer_t
*p
) /* I - Printer or class */
2854 int count
; /* Number of jobs on destination */
2857 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2858 con
, con
->http
.fd
, p
, p
->name
);
2860 count
= cupsdGetPrinterJobCount(p
->name
);
2862 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2863 "queued-job-count", count
);
2868 * 'apply_printer_defaults()' - Apply printer default options to a job.
2872 apply_printer_defaults(
2873 cupsd_printer_t
*printer
, /* I - Printer */
2874 cupsd_job_t
*job
) /* I - Job */
2876 int i
, /* Looping var */
2877 num_options
; /* Number of default options */
2878 cups_option_t
*options
, /* Default options */
2879 *option
; /* Current option */
2883 * Collect all of the default options and add the missing ones to the
2887 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2888 option
= printer
->options
;
2891 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2893 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2898 * Encode these options as attributes in the job object...
2901 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2902 cupsFreeOptions(num_options
, options
);
2907 * 'authenticate_job()' - Set job authentication info.
2911 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2912 ipp_attribute_t
*uri
) /* I - Job URI */
2914 ipp_attribute_t
*attr
, /* job-id attribute */
2915 *auth_info
; /* auth-info attribute */
2916 int jobid
; /* Job ID */
2917 cupsd_job_t
*job
; /* Current job */
2918 char scheme
[HTTP_MAX_URI
],
2919 /* Method portion of URI */
2920 username
[HTTP_MAX_URI
],
2921 /* Username portion of URI */
2923 /* Host portion of URI */
2924 resource
[HTTP_MAX_URI
];
2925 /* Resource portion of URI */
2926 int port
; /* Port portion of URI */
2929 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2930 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
2933 * Start with "everything is OK" status...
2936 con
->response
->request
.status
.status_code
= IPP_OK
;
2939 * See if we have a job URI or a printer URI...
2942 if (!strcmp(uri
->name
, "printer-uri"))
2945 * Got a printer URI; see if we also have a job-id attribute...
2948 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2949 IPP_TAG_INTEGER
)) == NULL
)
2951 send_ipp_status(con
, IPP_BAD_REQUEST
,
2952 _("Got a printer-uri attribute but no job-id."));
2956 jobid
= attr
->values
[0].integer
;
2961 * Got a job URI; parse it to get the job ID...
2964 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2965 sizeof(scheme
), username
, sizeof(username
), host
,
2966 sizeof(host
), &port
, resource
, sizeof(resource
));
2968 if (strncmp(resource
, "/jobs/", 6))
2974 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
2975 uri
->values
[0].string
.text
);
2979 jobid
= atoi(resource
+ 6);
2983 * See if the job exists...
2986 if ((job
= cupsdFindJob(jobid
)) == NULL
)
2989 * Nope - return a "not found" error...
2992 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
2997 * See if the job has been completed...
3000 if (job
->state_value
!= IPP_JOB_HELD
)
3003 * Return a "not-possible" error...
3006 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3007 _("Job #%d is not held for authentication."),
3013 * See if we have already authenticated...
3016 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3018 if (!con
->username
[0] && !auth_info
)
3020 cupsd_printer_t
*printer
; /* Job destination */
3023 * No auth data. If we need to authenticate via Kerberos, send a
3024 * HTTP auth challenge, otherwise just return an IPP error...
3027 printer
= cupsdFindDest(job
->dest
);
3029 if (printer
&& printer
->num_auth_info_required
> 0 &&
3030 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3031 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3033 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3034 _("No authentication information provided."));
3039 * See if the job is owned by the requesting user...
3042 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3044 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3045 cupsdFindDest(job
->dest
));
3050 * Save the authentication information for this job...
3053 save_auth_info(con
, job
, auth_info
);
3056 * Reset the job-hold-until value to "no-hold"...
3059 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3060 IPP_TAG_KEYWORD
)) == NULL
)
3061 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3065 attr
->value_tag
= IPP_TAG_KEYWORD
;
3066 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3070 * Release the job and return...
3073 cupsdReleaseJob(job
);
3075 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3077 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3084 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3088 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3089 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3091 int i
; /* Looping var */
3092 http_status_t status
; /* Policy status */
3093 cups_ptype_t dtype
; /* Destination type */
3094 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3095 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3096 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3097 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3098 int port
; /* Port portion of URI */
3099 ipp_attribute_t
*attr
; /* Attribute in request */
3100 const char *username
= NULL
; /* Username */
3101 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3103 cupsd_printer_t
*printer
; /* Printer */
3104 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3105 cupsd_job_t
*job
; /* Job */
3108 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3109 con
->http
.fd
, uri
->values
[0].string
.text
);
3112 * Get the jobs to cancel/purge...
3115 switch (con
->request
->request
.op
.operation_id
)
3117 case IPP_PURGE_JOBS
:
3119 * Get the username (if any) for the jobs we want to cancel (only if
3120 * "my-jobs" is specified...
3123 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3124 IPP_TAG_BOOLEAN
)) != NULL
&&
3125 attr
->values
[0].boolean
)
3127 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3128 IPP_TAG_NAME
)) != NULL
)
3129 username
= attr
->values
[0].string
.text
;
3132 send_ipp_status(con
, IPP_BAD_REQUEST
,
3133 _("Missing requesting-user-name attribute."));
3139 * Look for the "purge-jobs" attribute...
3142 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3143 IPP_TAG_BOOLEAN
)) != NULL
)
3144 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3146 purge
= CUPSD_JOB_PURGE
;
3149 case IPP_CANCEL_MY_JOBS
:
3150 if (con
->username
[0])
3151 username
= con
->username
;
3152 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3153 IPP_TAG_NAME
)) != NULL
)
3154 username
= attr
->values
[0].string
.text
;
3157 send_ipp_status(con
, IPP_BAD_REQUEST
,
3158 _("Missing requesting-user-name attribute."));
3166 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3169 * See if we have a printer URI...
3172 if (strcmp(uri
->name
, "printer-uri"))
3174 send_ipp_status(con
, IPP_BAD_REQUEST
,
3175 _("The printer-uri attribute is required."));
3180 * And if the destination is valid...
3183 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3189 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3190 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3191 hostname
, sizeof(hostname
), &port
,
3192 resource
, sizeof(resource
));
3194 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3195 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3197 send_ipp_status(con
, IPP_NOT_FOUND
,
3198 _("The printer or class does not exist."));
3206 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3208 send_http_error(con
, status
, NULL
);
3214 for (i
= 0; i
< job_ids
->num_values
; i
++)
3216 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
3220 if (i
< job_ids
->num_values
)
3222 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3223 job_ids
->values
[i
].integer
);
3227 for (i
= 0; i
< job_ids
->num_values
; i
++)
3229 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3231 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3232 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3233 "Job canceled by user.");
3236 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3237 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3243 * Cancel all jobs on all printers...
3246 cupsdCancelJobs(NULL
, username
, purge
);
3248 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3249 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3259 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3262 send_http_error(con
, status
, printer
);
3268 for (i
= 0; i
< job_ids
->num_values
; i
++)
3270 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3271 _cups_strcasecmp(job
->dest
, printer
->name
))
3275 if (i
< job_ids
->num_values
)
3277 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3278 job_ids
->values
[i
].integer
);
3282 for (i
= 0; i
< job_ids
->num_values
; i
++)
3284 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3286 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3287 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3288 "Job canceled by user.");
3291 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3292 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3298 * Cancel all of the jobs on the named printer...
3301 cupsdCancelJobs(printer
->name
, username
, purge
);
3303 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3305 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3310 con
->response
->request
.status
.status_code
= IPP_OK
;
3315 * 'cancel_job()' - Cancel a print job.
3319 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3320 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3322 ipp_attribute_t
*attr
; /* Current attribute */
3323 int jobid
; /* Job ID */
3324 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3325 username
[HTTP_MAX_URI
], /* Username portion of URI */
3326 host
[HTTP_MAX_URI
], /* Host portion of URI */
3327 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3328 int port
; /* Port portion of URI */
3329 cupsd_job_t
*job
; /* Job information */
3330 cups_ptype_t dtype
; /* Destination type (printer/class) */
3331 cupsd_printer_t
*printer
; /* Printer data */
3332 cupsd_jobaction_t purge
; /* Purge the job? */
3335 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3336 con
->http
.fd
, uri
->values
[0].string
.text
);
3339 * See if we have a job URI or a printer URI...
3342 if (!strcmp(uri
->name
, "printer-uri"))
3345 * Got a printer URI; see if we also have a job-id attribute...
3348 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3349 IPP_TAG_INTEGER
)) == NULL
)
3351 send_ipp_status(con
, IPP_BAD_REQUEST
,
3352 _("Got a printer-uri attribute but no job-id."));
3356 if ((jobid
= attr
->values
[0].integer
) == 0)
3359 * Find the current job on the specified printer...
3362 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3368 send_ipp_status(con
, IPP_NOT_FOUND
,
3369 _("The printer or class does not exist."));
3374 * See if there are any pending jobs...
3377 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3379 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3380 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3381 !_cups_strcasecmp(job
->dest
, printer
->name
))
3389 * No, try stopped jobs...
3392 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3394 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3395 if (job
->state_value
== IPP_JOB_STOPPED
&&
3396 !_cups_strcasecmp(job
->dest
, printer
->name
))
3403 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3413 * Got a job URI; parse it to get the job ID...
3416 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3417 sizeof(scheme
), username
, sizeof(username
), host
,
3418 sizeof(host
), &port
, resource
, sizeof(resource
));
3420 if (strncmp(resource
, "/jobs/", 6))
3426 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3427 uri
->values
[0].string
.text
);
3431 jobid
= atoi(resource
+ 6);
3435 * Look for the "purge-job" attribute...
3438 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3439 IPP_TAG_BOOLEAN
)) != NULL
)
3440 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3442 purge
= CUPSD_JOB_DEFAULT
;
3445 * See if the job exists...
3448 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3451 * Nope - return a "not found" error...
3454 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3459 * See if the job is owned by the requesting user...
3462 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3464 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3465 cupsdFindDest(job
->dest
));
3470 * See if the job is already completed, canceled, or aborted; if so,
3471 * we can't cancel...
3474 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3476 switch (job
->state_value
)
3478 case IPP_JOB_CANCELED
:
3479 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3480 _("Job #%d is already canceled - can\'t cancel."),
3484 case IPP_JOB_ABORTED
:
3485 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3486 _("Job #%d is already aborted - can\'t cancel."),
3491 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3492 _("Job #%d is already completed - can\'t cancel."),
3501 * Cancel the job and return...
3504 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3505 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3506 "Job canceled by \"%s\"",
3510 if (purge
== CUPSD_JOB_PURGE
)
3511 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3514 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3517 con
->response
->request
.status
.status_code
= IPP_OK
;
3522 * 'cancel_subscription()' - Cancel a subscription.
3526 cancel_subscription(
3527 cupsd_client_t
*con
, /* I - Client connection */
3528 int sub_id
) /* I - Subscription ID */
3530 http_status_t status
; /* Policy status */
3531 cupsd_subscription_t
*sub
; /* Subscription */
3534 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3535 "cancel_subscription(con=%p[%d], sub_id=%d)",
3536 con
, con
->http
.fd
, sub_id
);
3539 * Is the subscription ID valid?
3542 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3545 * Bad subscription ID...
3548 send_ipp_status(con
, IPP_NOT_FOUND
,
3549 _("Subscription #%d does not exist."), sub_id
);
3557 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3559 con
, sub
->owner
)) != HTTP_OK
)
3561 send_http_error(con
, status
, sub
->dest
);
3566 * Cancel the subscription...
3569 cupsdDeleteSubscription(sub
, 1);
3571 con
->response
->request
.status
.status_code
= IPP_OK
;
3576 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3579 static int /* O - 1 if OK, 0 if not */
3580 check_rss_recipient(
3581 const char *recipient
) /* I - Recipient URI */
3583 cupsd_subscription_t
*sub
; /* Current subscription */
3586 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3588 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3592 * Compare the URIs up to the first ?...
3595 const char *r1
, *r2
;
3597 for (r1
= recipient
, r2
= sub
->recipient
;
3598 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3610 * 'check_quotas()' - Check quotas for a printer and user.
3613 static int /* O - 1 if OK, 0 if forbidden,
3614 -1 if limit reached */
3615 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3616 cupsd_printer_t
*p
) /* I - Printer or class */
3618 char username
[33], /* Username */
3619 *name
; /* Current user name */
3620 cupsd_quota_t
*q
; /* Quota data */
3621 #ifdef HAVE_MBR_UID_TO_UUID
3623 * Use Apple membership APIs which require that all names represent
3624 * valid user account or group records accessible by the server.
3627 uuid_t usr_uuid
; /* UUID for job requesting user */
3628 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3629 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3630 int mbr_err
; /* Error from membership function */
3631 int is_member
; /* Is this user a member? */
3634 * Use standard POSIX APIs for checking users and groups...
3637 struct passwd
*pw
; /* User password data */
3638 #endif /* HAVE_MBR_UID_TO_UUID */
3641 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3642 con
, con
->http
.fd
, p
, p
->name
);
3645 * Figure out who is printing...
3648 strlcpy(username
, get_username(con
), sizeof(username
));
3650 if ((name
= strchr(username
, '@')) != NULL
)
3651 *name
= '\0'; /* Strip @REALM */
3654 * Check global active job limits for printers and users...
3657 if (MaxJobsPerPrinter
)
3660 * Check if there are too many pending jobs on this printer...
3663 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3665 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3674 * Check if there are too many pending jobs for this user...
3677 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3679 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3686 * Check against users...
3689 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3692 if (cupsArrayCount(p
->users
))
3694 #ifdef HAVE_MBR_UID_TO_UUID
3696 * Get UUID for job requesting user...
3699 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3705 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3706 "check_quotas: UUID lookup failed for user \"%s\"",
3708 cupsdLogMessage(CUPSD_LOG_INFO
,
3709 "Denying user \"%s\" access to printer \"%s\" "
3710 "(unknown user)...",
3716 * Get UID and GID of requesting user...
3719 pw
= getpwnam(username
);
3721 #endif /* HAVE_MBR_UID_TO_UUID */
3723 for (name
= (char *)cupsArrayFirst(p
->users
);
3725 name
= (char *)cupsArrayNext(p
->users
))
3729 * Check group membership...
3732 #ifdef HAVE_MBR_UID_TO_UUID
3735 if (uuid_parse(name
+ 2, grp_uuid
))
3736 uuid_clear(grp_uuid
);
3738 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3741 * Invalid ACL entries are ignored for matching; just record a
3742 * warning in the log...
3745 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3746 "check_quotas: UUID lookup failed for ACL entry "
3747 "\"%s\" (err=%d)", name
, mbr_err
);
3748 cupsdLogMessage(CUPSD_LOG_WARN
,
3749 "Access control entry \"%s\" not a valid group name; "
3750 "entry ignored", name
);
3753 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3757 * At this point, there should be no errors, but check anyways...
3760 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3761 "check_quotas: group \"%s\" membership check "
3762 "failed (err=%d)", name
+ 1, mbr_err
);
3767 * Stop if we found a match...
3774 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3776 #endif /* HAVE_MBR_UID_TO_UUID */
3778 #ifdef HAVE_MBR_UID_TO_UUID
3783 if (uuid_parse(name
+ 1, usr2_uuid
))
3784 uuid_clear(usr2_uuid
);
3786 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3789 * Invalid ACL entries are ignored for matching; just record a
3790 * warning in the log...
3793 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3794 "check_quotas: UUID lookup failed for ACL entry "
3795 "\"%s\" (err=%d)", name
, mbr_err
);
3796 cupsdLogMessage(CUPSD_LOG_WARN
,
3797 "Access control entry \"%s\" not a valid user name; "
3798 "entry ignored", name
);
3801 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3805 else if (!_cups_strcasecmp(username
, name
))
3807 #endif /* HAVE_MBR_UID_TO_UUID */
3809 if ((name
!= NULL
) == p
->deny_users
)
3811 cupsdLogMessage(CUPSD_LOG_INFO
,
3812 "Denying user \"%s\" access to printer \"%s\"...",
3822 if (p
->k_limit
|| p
->page_limit
)
3824 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3826 cupsdLogMessage(CUPSD_LOG_ERROR
,
3827 "Unable to allocate quota data for user \"%s\"",
3832 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3833 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3835 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3842 * If we have gotten this far, we're done!
3850 * 'close_job()' - Close a multi-file job.
3854 close_job(cupsd_client_t
*con
, /* I - Client connection */
3855 ipp_attribute_t
*uri
) /* I - Printer URI */
3857 cupsd_job_t
*job
; /* Job */
3858 ipp_attribute_t
*attr
; /* Attribute */
3859 char job_uri
[HTTP_MAX_URI
],
3861 username
[256]; /* User name */
3864 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3865 con
->http
.fd
, uri
->values
[0].string
.text
);
3868 * See if we have a job URI or a printer URI...
3871 if (strcmp(uri
->name
, "printer-uri"))
3874 * job-uri is not supported by Close-Job!
3877 send_ipp_status(con
, IPP_BAD_REQUEST
,
3878 _("Close-Job doesn't support the job-uri attribute."));
3883 * Got a printer URI; see if we also have a job-id attribute...
3886 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3887 IPP_TAG_INTEGER
)) == NULL
)
3889 send_ipp_status(con
, IPP_BAD_REQUEST
,
3890 _("Got a printer-uri attribute but no job-id."));
3894 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3897 * Nope - return a "not found" error...
3900 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3901 attr
->values
[0].integer
);
3906 * See if the job is owned by the requesting user...
3909 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3911 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3912 cupsdFindDest(job
->dest
));
3917 * Add any ending sheet...
3920 if (cupsdTimeoutJob(job
))
3923 if (job
->state_value
== IPP_JOB_STOPPED
)
3925 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3926 job
->state_value
= IPP_JOB_PENDING
;
3928 else if (job
->state_value
== IPP_JOB_HELD
)
3930 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3931 IPP_TAG_KEYWORD
)) == NULL
)
3932 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3934 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3936 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3937 job
->state_value
= IPP_JOB_PENDING
;
3942 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3945 * Fill in the response info...
3948 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
3949 con
->servername
, con
->serverport
, "/jobs/%d", job
->id
);
3950 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
3953 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
3955 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
3958 con
->response
->request
.status
.status_code
= IPP_OK
;
3961 * Start the job if necessary...
3969 * 'copy_attrs()' - Copy attributes from one request to another.
3973 copy_attrs(ipp_t
*to
, /* I - Destination request */
3974 ipp_t
*from
, /* I - Source request */
3975 cups_array_t
*ra
, /* I - Requested attributes */
3976 ipp_tag_t group
, /* I - Group to copy */
3977 int quickcopy
, /* I - Do a quick copy? */
3978 cups_array_t
*exclude
) /* I - Attributes to exclude? */
3980 ipp_attribute_t
*fromattr
; /* Source attribute */
3983 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3984 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
3985 to
, from
, ra
, group
, quickcopy
);
3990 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
3993 * Filter attributes as needed...
3996 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
3997 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4000 if (!strcmp(fromattr
->name
, "job-printer-uri"))
4004 (cupsArrayFind(exclude
, fromattr
->name
) ||
4005 cupsArrayFind(exclude
, "all")))
4008 * We need to exclude this attribute for security reasons; we require the
4009 * job-id attribute regardless of the security settings for IPP
4012 * The job-printer-uri attribute is handled by copy_job_attrs().
4014 * Subscription attribute security is handled by copy_subscription_attrs().
4017 if (strcmp(fromattr
->name
, "job-id"))
4021 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4024 * Don't send collection attributes by default to IPP/1.x clients
4025 * since many do not support collections. Also don't send
4026 * media-col-database unless specifically requested by the client.
4029 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4031 (to
->request
.status
.version
[0] == 1 ||
4032 !strcmp(fromattr
->name
, "media-col-database")))
4035 ippCopyAttribute(to
, fromattr
, quickcopy
);
4042 * 'copy_banner()' - Copy a banner file to the requests directory for the
4046 static int /* O - Size of banner file in kbytes */
4047 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4048 cupsd_job_t
*job
, /* I - Job information */
4049 const char *name
) /* I - Name of banner */
4051 int i
; /* Looping var */
4052 int kbytes
; /* Size of banner file in kbytes */
4053 char filename
[1024]; /* Job filename */
4054 cupsd_banner_t
*banner
; /* Pointer to banner */
4055 cups_file_t
*in
; /* Input file */
4056 cups_file_t
*out
; /* Output file */
4057 int ch
; /* Character from file */
4058 char attrname
[255], /* Name of attribute */
4059 *s
; /* Pointer into name */
4060 ipp_attribute_t
*attr
; /* Attribute */
4063 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4064 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4065 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4066 name
? name
: "(null)");
4069 * Find the banner; return if not found or "none"...
4072 if (!name
|| !strcmp(name
, "none") ||
4073 (banner
= cupsdFindBanner(name
)) == NULL
)
4077 * Open the banner and job files...
4080 if (add_file(con
, job
, banner
->filetype
, 0))
4083 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4085 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4087 cupsdLogMessage(CUPSD_LOG_ERROR
,
4088 "Unable to create banner job file %s - %s",
4089 filename
, strerror(errno
));
4094 fchmod(cupsFileNumber(out
), 0640);
4095 fchown(cupsFileNumber(out
), RunUser
, Group
);
4098 * Try the localized banner file under the subdirectory...
4101 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4103 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4106 * Convert ll-cc to ll_CC...
4110 attrname
[3] = toupper(attrname
[3] & 255);
4111 attrname
[4] = toupper(attrname
[4] & 255);
4114 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4117 if (access(filename
, 0) && strlen(attrname
) > 2)
4120 * Wasn't able to find "ll_CC" locale file; try the non-national
4121 * localization banner directory.
4126 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4130 if (access(filename
, 0))
4133 * Use the non-localized banner file.
4136 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4139 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4143 cupsdLogMessage(CUPSD_LOG_ERROR
,
4144 "Unable to open banner template file %s - %s",
4145 filename
, strerror(errno
));
4151 * Parse the file to the end...
4154 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4158 * Get an attribute name...
4161 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4162 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4164 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4174 * Ignore { followed by stuff that is not an attribute name...
4177 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4182 * See if it is defined...
4185 if (attrname
[0] == '?')
4190 if (!strcmp(s
, "printer-name"))
4192 cupsFilePuts(out
, job
->dest
);
4195 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4198 * See if we have a leading question mark...
4201 if (attrname
[0] != '?')
4204 * Nope, write to file as-is; probably a PostScript procedure...
4207 cupsFilePrintf(out
, "{%s}", attrname
);
4214 * Output value(s)...
4217 for (i
= 0; i
< attr
->num_values
; i
++)
4220 cupsFilePutChar(out
, ',');
4222 switch (attr
->value_tag
)
4224 case IPP_TAG_INTEGER
:
4226 if (!strncmp(s
, "time-at-", 8))
4228 struct timeval tv
; /* Time value */
4230 tv
.tv_sec
= attr
->values
[i
].integer
;
4233 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4236 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4239 case IPP_TAG_BOOLEAN
:
4240 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4243 case IPP_TAG_NOVALUE
:
4244 cupsFilePuts(out
, "novalue");
4247 case IPP_TAG_RANGE
:
4248 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4249 attr
->values
[i
].range
.upper
);
4252 case IPP_TAG_RESOLUTION
:
4253 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4254 attr
->values
[i
].resolution
.yres
,
4255 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4260 case IPP_TAG_STRING
:
4263 case IPP_TAG_KEYWORD
:
4264 case IPP_TAG_CHARSET
:
4265 case IPP_TAG_LANGUAGE
:
4266 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4269 * Need to quote strings for PS banners...
4274 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4276 if (*p
== '(' || *p
== ')' || *p
== '\\')
4278 cupsFilePutChar(out
, '\\');
4279 cupsFilePutChar(out
, *p
);
4281 else if (*p
< 32 || *p
> 126)
4282 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4284 cupsFilePutChar(out
, *p
);
4288 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4292 break; /* anti-compiler-warning-code */
4296 else if (ch
== '\\') /* Quoted char */
4298 ch
= cupsFileGetChar(in
);
4300 if (ch
!= '{') /* Only do special handling for \{ */
4301 cupsFilePutChar(out
, '\\');
4303 cupsFilePutChar(out
, ch
);
4306 cupsFilePutChar(out
, ch
);
4310 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4312 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4313 IPP_TAG_INTEGER
)) != NULL
)
4314 attr
->values
[0].integer
+= kbytes
;
4323 * 'copy_file()' - Copy a PPD file or interface script...
4326 static int /* O - 0 = success, -1 = error */
4327 copy_file(const char *from
, /* I - Source file */
4328 const char *to
) /* I - Destination file */
4330 cups_file_t
*src
, /* Source file */
4331 *dst
; /* Destination file */
4332 int bytes
; /* Bytes to read/write */
4333 char buffer
[2048]; /* Copy buffer */
4336 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4339 * Open the source and destination file for a copy...
4342 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4345 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4352 * Copy the source file to the destination...
4355 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4356 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
4364 * Close both files and return...
4369 return (cupsFileClose(dst
));
4374 * 'copy_model()' - Copy a PPD model file, substituting default values
4378 static int /* O - 0 = success, -1 = error */
4379 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4380 const char *from
, /* I - Source file */
4381 const char *to
) /* I - Destination file */
4383 fd_set input
; /* select() input set */
4384 struct timeval timeout
; /* select() timeout */
4385 int maxfd
; /* Max file descriptor for select() */
4386 char tempfile
[1024]; /* Temporary PPD file */
4387 int tempfd
; /* Temporary PPD file descriptor */
4388 int temppid
; /* Process ID of cups-driverd */
4389 int temppipe
[2]; /* Temporary pipes */
4390 char *argv
[4], /* Command-line arguments */
4391 *envp
[MAX_ENV
]; /* Environment */
4392 cups_file_t
*src
, /* Source file */
4393 *dst
; /* Destination file */
4394 ppd_file_t
*ppd
; /* PPD file */
4395 int bytes
, /* Bytes from pipe */
4396 total
; /* Total bytes from pipe */
4397 char buffer
[2048]; /* Copy buffer */
4398 int i
; /* Looping var */
4399 char option
[PPD_MAX_NAME
], /* Option name */
4400 choice
[PPD_MAX_NAME
]; /* Choice name */
4401 ppd_size_t
*size
; /* Default size */
4402 int num_defaults
; /* Number of default options */
4403 cups_option_t
*defaults
; /* Default options */
4404 char cups_protocol
[PPD_MAX_LINE
];
4405 /* cupsProtocol attribute */
4408 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4409 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4413 * Run cups-driverd to get the PPD file...
4416 argv
[0] = "cups-driverd";
4418 argv
[2] = (char *)from
;
4421 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4423 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4424 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
4425 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4426 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4429 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4430 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4432 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4433 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4444 * Wait up to 30 seconds for the PPD file to be copied...
4449 if (temppipe
[0] > CGIPipes
[0])
4450 maxfd
= temppipe
[0] + 1;
4452 maxfd
= CGIPipes
[0] + 1;
4457 * See if we have data ready...
4461 FD_SET(temppipe
[0], &input
);
4462 FD_SET(CGIPipes
[0], &input
);
4464 timeout
.tv_sec
= 30;
4465 timeout
.tv_usec
= 0;
4467 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4477 * We have timed out...
4483 if (FD_ISSET(temppipe
[0], &input
))
4486 * Read the PPD file from the pipe, and write it to the PPD file.
4489 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4491 if (write(tempfd
, buffer
, bytes
) < bytes
)
4500 if (FD_ISSET(CGIPipes
[0], &input
))
4510 * No data from cups-deviced...
4513 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4519 * Open the source file for a copy...
4522 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4529 * Read the source file and see what page sizes are supported...
4532 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4540 * Open the destination (if possible) and set the default options...
4545 cups_protocol
[0] = '\0';
4547 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4550 * Read all of the default lines from the old PPD...
4553 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4554 if (!strncmp(buffer
, "*Default", 8))
4557 * Add the default option...
4560 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4561 choice
, sizeof(choice
)))
4563 ppd_option_t
*ppdo
; /* PPD option */
4567 * Only add the default if the default hasn't already been
4568 * set and the choice exists in the new PPD...
4571 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4572 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4573 ppdFindChoice(ppdo
, choice
))
4574 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4578 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4579 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4583 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4586 * Add the default media sizes...
4589 num_defaults
= cupsAddOption("PageSize", size
->name
,
4590 num_defaults
, &defaults
);
4591 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4592 num_defaults
, &defaults
);
4593 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4594 num_defaults
, &defaults
);
4595 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4596 num_defaults
, &defaults
);
4602 * Open the destination file for a copy...
4605 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4607 cupsFreeOptions(num_defaults
, defaults
);
4614 * Copy the source file to the destination...
4617 cupsFileRewind(src
);
4619 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4621 if (!strncmp(buffer
, "*Default", 8))
4624 * Check for an previous default option choice...
4627 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4628 choice
, sizeof(choice
)))
4630 const char *val
; /* Default option value */
4633 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4636 * Substitute the previous choice...
4639 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4644 cupsFilePrintf(dst
, "%s\n", buffer
);
4647 if (cups_protocol
[0])
4648 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4650 cupsFreeOptions(num_defaults
, defaults
);
4653 * Close both files and return...
4660 return (cupsFileClose(dst
));
4665 * 'copy_job_attrs()' - Copy job attributes.
4669 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4670 cupsd_job_t
*job
, /* I - Job */
4671 cups_array_t
*ra
, /* I - Requested attributes array */
4672 cups_array_t
*exclude
) /* I - Private attributes array */
4674 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4678 * Send the requested attributes for each job...
4681 if (!cupsArrayFind(exclude
, "all"))
4683 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4684 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4685 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4686 "number-of-documents", job
->num_files
);
4688 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4689 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4690 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4691 "job-media-progress", job
->progress
);
4693 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4694 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4696 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4697 NULL
, con
->servername
, con
->serverport
, "/jobs/%d",
4699 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4700 "job-more-info", NULL
, job_uri
);
4703 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4704 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4705 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4706 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4707 job
->num_files
> 0);
4709 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4710 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4711 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4712 "job-printer-up-time", time(NULL
));
4715 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4717 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4718 con
->servername
, con
->serverport
,
4719 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4722 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4723 "job-printer-uri", NULL
, job_uri
);
4726 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4728 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4729 con
->servername
, con
->serverport
, "/jobs/%d",
4731 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4732 "job-uri", NULL
, job_uri
);
4735 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4740 * 'copy_printer_attrs()' - Copy printer attributes.
4745 cupsd_client_t
*con
, /* I - Client connection */
4746 cupsd_printer_t
*printer
, /* I - Printer */
4747 cups_array_t
*ra
) /* I - Requested attributes array */
4749 char printer_uri
[HTTP_MAX_URI
];
4751 char printer_icons
[HTTP_MAX_URI
];
4753 time_t curtime
; /* Current time */
4754 int i
; /* Looping var */
4758 * Copy the printer attributes to the response using requested-attributes
4759 * and document-format attributes that may be provided by the client.
4762 curtime
= time(NULL
);
4764 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4765 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4766 "marker-change-time", printer
->marker_time
);
4768 if (printer
->num_printers
> 0 &&
4769 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4771 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4772 cupsd_printer_t
*p2
; /* Printer in class */
4773 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4776 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4777 IPP_TAG_URI
, "member-uris",
4778 printer
->num_printers
, NULL
,
4781 for (i
= 0; i
< printer
->num_printers
; i
++)
4783 p2
= printer
->printers
[i
];
4785 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4786 IPP_TAG_URI
)) != NULL
)
4787 member_uris
->values
[i
].string
.text
=
4788 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4791 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4792 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
4794 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4795 "/classes/%s" : "/printers/%s", p2
->name
);
4796 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4802 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4803 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4804 "printer-alert", NULL
, printer
->alert
);
4806 if (printer
->alert_description
&&
4807 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4808 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4809 "printer-alert-description", NULL
,
4810 printer
->alert_description
);
4812 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4813 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4814 ippTimeToDate(curtime
));
4817 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4819 if (printer
->reg_name
)
4820 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4821 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4823 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4824 "printer-dns-sd-name", 0);
4826 #endif /* HAVE_DNSSD */
4828 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4829 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4830 "printer-error-policy", NULL
, printer
->error_policy
);
4832 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4834 static const char * const errors
[] =/* printer-error-policy-supported values */
4837 "retry-current-job",
4842 if (printer
->type
& CUPS_PRINTER_CLASS
)
4843 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4844 "printer-error-policy-supported", NULL
, "retry-current-job");
4846 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4847 "printer-error-policy-supported",
4848 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4851 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4853 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4854 "http", NULL
, con
->servername
, con
->serverport
,
4855 "/icons/%s.png", printer
->name
);
4856 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4857 NULL
, printer_icons
);
4858 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4861 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4862 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
4863 printer
->accepting
);
4865 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4866 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
4869 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4871 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4872 "http", NULL
, con
->servername
, con
->serverport
,
4873 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4874 "/classes/%s" : "/printers/%s", printer
->name
);
4875 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4876 "printer-more-info", NULL
, printer_uri
);
4879 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4880 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4881 "printer-op-policy", NULL
, printer
->op_policy
);
4883 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4884 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4887 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4888 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4889 "printer-state-change-time", printer
->state_time
);
4891 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4892 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4893 "printer-state-message", NULL
, printer
->state_message
);
4895 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4896 add_printer_state_reasons(con
, printer
);
4898 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4900 int type
; /* printer-type value */
4903 * Add the CUPS-specific printer-type attribute...
4906 type
= printer
->type
;
4908 if (printer
== DefaultPrinter
)
4909 type
|= CUPS_PRINTER_DEFAULT
;
4911 if (!printer
->accepting
)
4912 type
|= CUPS_PRINTER_REJECTING
;
4914 if (!printer
->shared
)
4915 type
|= CUPS_PRINTER_NOT_SHARED
;
4917 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
4921 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
4922 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4923 "printer-up-time", curtime
);
4925 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
4927 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4928 "ipp", NULL
, con
->servername
, con
->serverport
,
4929 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4930 "/classes/%s" : "/printers/%s", printer
->name
);
4931 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4932 "printer-uri-supported", NULL
, printer_uri
);
4933 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
4937 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
4938 add_queued_job_count(con
, printer
);
4940 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
4941 if (printer
->ppd_attrs
)
4942 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
4943 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
4948 * 'copy_subscription_attrs()' - Copy subscription attributes.
4952 copy_subscription_attrs(
4953 cupsd_client_t
*con
, /* I - Client connection */
4954 cupsd_subscription_t
*sub
, /* I - Subscription */
4955 cups_array_t
*ra
, /* I - Requested attributes array */
4956 cups_array_t
*exclude
) /* I - Private attributes array */
4958 ipp_attribute_t
*attr
; /* Current attribute */
4959 char printer_uri
[HTTP_MAX_URI
];
4961 int count
; /* Number of events */
4962 unsigned mask
; /* Current event mask */
4963 const char *name
; /* Current event name */
4966 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4967 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
4968 con
, sub
, ra
, exclude
);
4971 * Copy the subscription attributes to the response using the
4972 * requested-attributes attribute that may be provided by the client.
4975 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
4977 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
4978 (!ra
|| cupsArrayFind(ra
, "notify-events")))
4980 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
4982 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
4985 * Simple event list...
4988 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
4989 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
4990 "notify-events", NULL
, name
);
4995 * Complex event list...
4998 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
4999 if (sub
->mask
& mask
)
5002 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5003 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5004 "notify-events", count
, NULL
, NULL
);
5006 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5007 if (sub
->mask
& mask
)
5009 attr
->values
[count
].string
.text
=
5010 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5017 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5018 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5019 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5020 "notify-lease-duration", sub
->lease
);
5022 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5023 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5024 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5025 "notify-recipient-uri", NULL
, sub
->recipient
);
5026 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5027 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5028 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5029 "notify-pull-method", NULL
, "ippget");
5031 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5032 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5033 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5034 "notify-subscriber-user-name", NULL
, sub
->owner
);
5036 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5037 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5038 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5039 "notify-time-interval", sub
->interval
);
5041 if (sub
->user_data_len
> 0 &&
5042 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5043 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5044 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5045 sub
->user_data
, sub
->user_data_len
);
5048 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5049 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5050 "notify-job-id", sub
->job
->id
);
5052 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5054 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5055 "ipp", NULL
, con
->servername
, con
->serverport
,
5056 "/printers/%s", sub
->dest
->name
);
5057 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5058 "notify-printer-uri", NULL
, printer_uri
);
5061 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5062 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5063 "notify-subscription-id", sub
->id
);
5068 * 'create_job()' - Print a file to a printer or class.
5072 create_job(cupsd_client_t
*con
, /* I - Client connection */
5073 ipp_attribute_t
*uri
) /* I - Printer URI */
5075 int i
; /* Looping var */
5076 cupsd_printer_t
*printer
; /* Printer */
5077 cupsd_job_t
*job
; /* New job */
5078 static const char * const forbidden_attrs
[] =
5079 { /* List of forbidden attributes */
5083 "document-natural-language"
5087 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5088 con
->http
.fd
, uri
->values
[0].string
.text
);
5091 * Is the destination valid?
5094 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5100 send_ipp_status(con
, IPP_NOT_FOUND
,
5101 _("The printer or class does not exist."));
5106 * Check for invalid Create-Job attributes and log a warning or error depending
5107 * on whether cupsd is running in "strict conformance" mode...
5111 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5113 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5115 if (StrictConformance
)
5117 send_ipp_status(con
, IPP_BAD_REQUEST
,
5118 _("The '%s' operation attribute cannot be supplied in a "
5119 "Create-Job request."), forbidden_attrs
[i
]);
5123 cupsdLogMessage(CUPSD_LOG_WARN
,
5124 "Unexpected '%s' operation attribute in a Create-Job "
5125 "request.", forbidden_attrs
[i
]);
5129 * Create the job object...
5132 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5135 job
->pending_timeout
= 1;
5138 * Save and log the job...
5141 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5142 job
->dest
, job
->username
);
5147 * 'create_requested_array()' - Create an array for the requested-attributes.
5150 static cups_array_t
* /* O - Array of attributes or NULL */
5151 create_requested_array(ipp_t
*request
) /* I - IPP request */
5153 int i
; /* Looping var */
5154 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5155 cups_array_t
*ra
; /* Requested attributes array */
5156 char *value
; /* Current value */
5160 * Get the requested-attributes attribute, and return NULL if we don't
5164 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5165 IPP_TAG_KEYWORD
)) == NULL
)
5169 * If the attribute contains a single "all" keyword, return NULL...
5172 if (requested
->num_values
== 1 &&
5173 !strcmp(requested
->values
[0].string
.text
, "all"))
5177 * Create an array using "strcmp" as the comparison function...
5180 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5182 for (i
= 0; i
< requested
->num_values
; i
++)
5184 value
= requested
->values
[i
].string
.text
;
5186 if (!strcmp(value
, "job-template"))
5188 /* Only includes the set of Job Template attributes supported by CUPS */
5189 cupsArrayAdd(ra
, "copies");
5190 cupsArrayAdd(ra
, "copies-default");
5191 cupsArrayAdd(ra
, "copies-supported");
5192 cupsArrayAdd(ra
, "finishings");
5193 cupsArrayAdd(ra
, "finishings-default");
5194 cupsArrayAdd(ra
, "finishings-supported");
5195 cupsArrayAdd(ra
, "job-hold-until");
5196 cupsArrayAdd(ra
, "job-hold-until-default");
5197 cupsArrayAdd(ra
, "job-hold-until-supported");
5198 cupsArrayAdd(ra
, "job-priority");
5199 cupsArrayAdd(ra
, "job-priority-default");
5200 cupsArrayAdd(ra
, "job-priority-supported");
5201 cupsArrayAdd(ra
, "job-sheets");
5202 cupsArrayAdd(ra
, "job-sheets-default");
5203 cupsArrayAdd(ra
, "job-sheets-supported");
5204 cupsArrayAdd(ra
, "media");
5205 cupsArrayAdd(ra
, "media-col");
5206 cupsArrayAdd(ra
, "media-col-default");
5207 cupsArrayAdd(ra
, "media-default");
5208 cupsArrayAdd(ra
, "media-supported");
5209 cupsArrayAdd(ra
, "multiple-document-handling");
5210 cupsArrayAdd(ra
, "multiple-document-handling-default");
5211 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5212 cupsArrayAdd(ra
, "number-up");
5213 cupsArrayAdd(ra
, "number-up-default");
5214 cupsArrayAdd(ra
, "number-up-layout");
5215 cupsArrayAdd(ra
, "number-up-layout-default");
5216 cupsArrayAdd(ra
, "number-up-layout-supported");
5217 cupsArrayAdd(ra
, "number-up-supported");
5218 cupsArrayAdd(ra
, "orientation-requested");
5219 cupsArrayAdd(ra
, "orientation-requested-default");
5220 cupsArrayAdd(ra
, "orientation-requested-supported");
5221 cupsArrayAdd(ra
, "output-bin");
5222 cupsArrayAdd(ra
, "output-bin-default");
5223 cupsArrayAdd(ra
, "output-bin-supported");
5224 cupsArrayAdd(ra
, "page-delivery");
5225 cupsArrayAdd(ra
, "page-delivery-default");
5226 cupsArrayAdd(ra
, "page-delivery-supported");
5227 cupsArrayAdd(ra
, "page-order-received");
5228 cupsArrayAdd(ra
, "page-order-received-default");
5229 cupsArrayAdd(ra
, "page-order-received-supported");
5230 cupsArrayAdd(ra
, "page-ranges");
5231 cupsArrayAdd(ra
, "page-ranges-supported");
5232 cupsArrayAdd(ra
, "presentation-direction-number-up");
5233 cupsArrayAdd(ra
, "presentation-direction-number-up-default");
5234 cupsArrayAdd(ra
, "presentation-direction-number-up-supported");
5235 cupsArrayAdd(ra
, "print-color-mode");
5236 cupsArrayAdd(ra
, "print-color-mode-default");
5237 cupsArrayAdd(ra
, "print-color-mode-supported");
5238 cupsArrayAdd(ra
, "print-content-optimize");
5239 cupsArrayAdd(ra
, "print-content-optimize-default");
5240 cupsArrayAdd(ra
, "print-content-optimize-supported");
5241 cupsArrayAdd(ra
, "print-quality");
5242 cupsArrayAdd(ra
, "print-quality-default");
5243 cupsArrayAdd(ra
, "print-quality-supported");
5244 cupsArrayAdd(ra
, "printer-resolution");
5245 cupsArrayAdd(ra
, "printer-resolution-default");
5246 cupsArrayAdd(ra
, "printer-resolution-supported");
5247 cupsArrayAdd(ra
, "sheet-collate");
5248 cupsArrayAdd(ra
, "sheet-collate-default");
5249 cupsArrayAdd(ra
, "sheet-collate-supported");
5250 cupsArrayAdd(ra
, "sides");
5251 cupsArrayAdd(ra
, "sides-default");
5252 cupsArrayAdd(ra
, "sides-supported");
5254 else if (!strcmp(value
, "job-description"))
5256 /* Only includes the set of Job Description attributes supported by CUPS */
5257 cupsArrayAdd(ra
, "date-time-at-completed");
5258 cupsArrayAdd(ra
, "date-time-at-creation");
5259 cupsArrayAdd(ra
, "date-time-at-processing");
5260 cupsArrayAdd(ra
, "job-detailed-status-message");
5261 cupsArrayAdd(ra
, "job-document-access-errors");
5262 cupsArrayAdd(ra
, "job-id");
5263 cupsArrayAdd(ra
, "job-impressions");
5264 cupsArrayAdd(ra
, "job-impressions-completed");
5265 cupsArrayAdd(ra
, "job-k-octets");
5266 cupsArrayAdd(ra
, "job-k-octets-processed");
5267 cupsArrayAdd(ra
, "job-mandatory-attributes");
5268 cupsArrayAdd(ra
, "job-media-progress");
5269 cupsArrayAdd(ra
, "job-media-sheets");
5270 cupsArrayAdd(ra
, "job-media-sheets-completed");
5271 cupsArrayAdd(ra
, "job-message-from-operator");
5272 cupsArrayAdd(ra
, "job-more-info");
5273 cupsArrayAdd(ra
, "job-name");
5274 cupsArrayAdd(ra
, "job-originating-user-name");
5275 cupsArrayAdd(ra
, "job-printer-up-time");
5276 cupsArrayAdd(ra
, "job-printer-uri");
5277 cupsArrayAdd(ra
, "job-state");
5278 cupsArrayAdd(ra
, "job-state-message");
5279 cupsArrayAdd(ra
, "job-state-reasons");
5280 cupsArrayAdd(ra
, "job-uri");
5281 cupsArrayAdd(ra
, "number-of-documents");
5282 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5283 cupsArrayAdd(ra
, "output-device-assigned");
5284 cupsArrayAdd(ra
, "time-at-completed");
5285 cupsArrayAdd(ra
, "time-at-creation");
5286 cupsArrayAdd(ra
, "time-at-processing");
5288 else if (!strcmp(value
, "printer-description"))
5290 /* Only includes the set of Printer Description attributes supported by CUPS */
5291 cupsArrayAdd(ra
, "charset-configured");
5292 cupsArrayAdd(ra
, "charset-supported");
5293 cupsArrayAdd(ra
, "color-supported");
5294 cupsArrayAdd(ra
, "compression-supported");
5295 cupsArrayAdd(ra
, "document-format-default");
5296 cupsArrayAdd(ra
, "document-format-supported");
5297 cupsArrayAdd(ra
, "generated-natural-language-supported");
5298 cupsArrayAdd(ra
, "ipp-versions-supported");
5299 cupsArrayAdd(ra
, "job-creation-attributes-supported");
5300 cupsArrayAdd(ra
, "job-ids-supported");
5301 cupsArrayAdd(ra
, "job-impressions-supported");
5302 cupsArrayAdd(ra
, "job-k-octets-supported");
5303 cupsArrayAdd(ra
, "job-media-sheets-supported");
5304 cupsArrayAdd(ra
, "job-settable-attributes-supported");
5305 cupsArrayAdd(ra
, "jpeg-k-octets-supported");
5306 cupsArrayAdd(ra
, "jpeg-x-dimension-supported");
5307 cupsArrayAdd(ra
, "jpeg-y-dimension-supported");
5308 cupsArrayAdd(ra
, "media-bottom-margin-supported");
5309 cupsArrayAdd(ra
, "media-col-supported");
5310 cupsArrayAdd(ra
, "media-key-supported");
5311 cupsArrayAdd(ra
, "media-left-margin-supported");
5312 cupsArrayAdd(ra
, "media-right-margin-supported");
5313 cupsArrayAdd(ra
, "media-size-supported");
5314 cupsArrayAdd(ra
, "media-source-supported");
5315 cupsArrayAdd(ra
, "media-top-margin-supported");
5316 cupsArrayAdd(ra
, "media-type-supported");
5317 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5318 cupsArrayAdd(ra
, "multiple-operation-time-out");
5319 cupsArrayAdd(ra
, "natural-language-configured");
5320 cupsArrayAdd(ra
, "notify-max-events-supported");
5321 cupsArrayAdd(ra
, "notify-schemes-supported");
5322 cupsArrayAdd(ra
, "operations-supported");
5323 cupsArrayAdd(ra
, "pages-per-minute");
5324 cupsArrayAdd(ra
, "pages-per-minute-color");
5325 cupsArrayAdd(ra
, "pdf-k-octets-supported");
5326 cupsArrayAdd(ra
, "pdl-override-supported");
5327 cupsArrayAdd(ra
, "printer-alert");
5328 cupsArrayAdd(ra
, "printer-alert-description");
5329 cupsArrayAdd(ra
, "printer-commands");
5330 cupsArrayAdd(ra
, "printer-current-time");
5331 cupsArrayAdd(ra
, "printer-dns-sd-name");
5332 cupsArrayAdd(ra
, "printer-info");
5333 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5334 cupsArrayAdd(ra
, "printer-is-shared");
5335 cupsArrayAdd(ra
, "printer-location");
5336 cupsArrayAdd(ra
, "printer-make-and-model");
5337 cupsArrayAdd(ra
, "printer-message-from-operator");
5338 cupsArrayAdd(ra
, "printer-more-info");
5339 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5340 cupsArrayAdd(ra
, "printer-name");
5341 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
5342 cupsArrayAdd(ra
, "printer-state");
5343 cupsArrayAdd(ra
, "printer-state-change-date-time");
5344 cupsArrayAdd(ra
, "printer-state-change-time");
5345 cupsArrayAdd(ra
, "printer-state-message");
5346 cupsArrayAdd(ra
, "printer-state-reasons");
5347 cupsArrayAdd(ra
, "printer-type");
5348 cupsArrayAdd(ra
, "printer-up-time");
5349 cupsArrayAdd(ra
, "printer-uri-supported");
5350 cupsArrayAdd(ra
, "queued-job-count");
5351 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5352 cupsArrayAdd(ra
, "uri-authentication-supported");
5353 cupsArrayAdd(ra
, "uri-security-supported");
5354 cupsArrayAdd(ra
, "which-jobs-supported");
5356 else if (!strcmp(value
, "printer-defaults"))
5358 char *name
; /* Option name */
5361 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5363 name
= (char *)cupsArrayNext(CommonDefaults
))
5364 cupsArrayAdd(ra
, name
);
5366 else if (!strcmp(value
, "subscription-description"))
5368 /* Only includes the set of Subscription Description attributes supported by CUPS */
5369 cupsArrayAdd(ra
, "notify-job-id");
5370 cupsArrayAdd(ra
, "notify-lease-expiration-time");
5371 cupsArrayAdd(ra
, "notify-printer-up-time");
5372 cupsArrayAdd(ra
, "notify-printer-uri");
5373 cupsArrayAdd(ra
, "notify-sequence-number");
5374 cupsArrayAdd(ra
, "notify-subscriber-user-name");
5375 cupsArrayAdd(ra
, "notify-subscription-id");
5377 else if (!strcmp(value
, "subscription-template"))
5379 /* Only includes the set of Subscription Template attributes supported by CUPS */
5380 cupsArrayAdd(ra
, "notify-attributes");
5381 cupsArrayAdd(ra
, "notify-attributes-supported");
5382 cupsArrayAdd(ra
, "notify-charset");
5383 cupsArrayAdd(ra
, "notify-events");
5384 cupsArrayAdd(ra
, "notify-events-default");
5385 cupsArrayAdd(ra
, "notify-events-supported");
5386 cupsArrayAdd(ra
, "notify-lease-duration");
5387 cupsArrayAdd(ra
, "notify-lease-duration-default");
5388 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5389 cupsArrayAdd(ra
, "notify-natural-language");
5390 cupsArrayAdd(ra
, "notify-pull-method");
5391 cupsArrayAdd(ra
, "notify-pull-method-supported");
5392 cupsArrayAdd(ra
, "notify-recipient-uri");
5393 cupsArrayAdd(ra
, "notify-time-interval");
5394 cupsArrayAdd(ra
, "notify-user-data");
5397 cupsArrayAdd(ra
, value
);
5405 * 'create_subscription()' - Create a notification subscription.
5409 create_subscription(
5410 cupsd_client_t
*con
, /* I - Client connection */
5411 ipp_attribute_t
*uri
) /* I - Printer URI */
5413 http_status_t status
; /* Policy status */
5414 int i
; /* Looping var */
5415 ipp_attribute_t
*attr
; /* Current attribute */
5416 cups_ptype_t dtype
; /* Destination type (printer/class) */
5417 char scheme
[HTTP_MAX_URI
],
5418 /* Scheme portion of URI */
5419 userpass
[HTTP_MAX_URI
],
5420 /* Username portion of URI */
5422 /* Host portion of URI */
5423 resource
[HTTP_MAX_URI
];
5424 /* Resource portion of URI */
5425 int port
; /* Port portion of URI */
5426 cupsd_printer_t
*printer
; /* Printer/class */
5427 cupsd_job_t
*job
; /* Job */
5428 int jobid
; /* Job ID */
5429 cupsd_subscription_t
*sub
; /* Subscription object */
5430 const char *username
, /* requesting-user-name or
5431 authenticated username */
5432 *recipient
, /* notify-recipient-uri */
5433 *pullmethod
; /* notify-pull-method */
5434 ipp_attribute_t
*user_data
; /* notify-user-data */
5435 int interval
, /* notify-time-interval */
5436 lease
; /* notify-lease-duration */
5437 unsigned mask
; /* notify-events */
5438 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5439 *notify_lease
; /* notify-lease-duration(-default) */
5443 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5445 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5446 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5447 attr
->value_tag
, attr
->name
);
5449 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5454 * Is the destination valid?
5457 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5458 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
5459 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
5461 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5462 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5463 sizeof(host
), &port
, resource
, sizeof(resource
));
5465 if (!strcmp(resource
, "/"))
5467 dtype
= (cups_ptype_t
)0;
5470 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5472 dtype
= (cups_ptype_t
)0;
5475 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5477 dtype
= CUPS_PRINTER_CLASS
;
5480 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5486 send_ipp_status(con
, IPP_NOT_FOUND
,
5487 _("The printer or class does not exist."));
5497 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5500 send_http_error(con
, status
, printer
);
5504 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5506 send_http_error(con
, status
, NULL
);
5511 * Get the user that is requesting the subscription...
5514 username
= get_username(con
);
5517 * Find the first subscription group attribute; return if we have
5521 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5522 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5527 send_ipp_status(con
, IPP_BAD_REQUEST
,
5528 _("No subscription attributes in request."));
5533 * Process the subscription attributes in the request...
5536 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5544 lease
= DefaultLeaseDuration
;
5546 mask
= CUPSD_EVENT_NONE
;
5550 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5552 notify_lease
= ippFindAttribute(printer
->attrs
,
5553 "notify-lease-duration-default",
5557 lease
= notify_lease
->values
[0].integer
;
5561 notify_events
= NULL
;
5562 notify_lease
= NULL
;
5565 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5567 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5568 attr
->value_tag
== IPP_TAG_URI
)
5571 * Validate the recipient scheme against the ServerBin/notifier
5575 char notifier
[1024]; /* Notifier filename */
5578 recipient
= attr
->values
[0].string
.text
;
5580 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5581 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5582 host
, sizeof(host
), &port
,
5583 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5585 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5586 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5587 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5588 "notify-status-code", IPP_URI_SCHEME
);
5592 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5594 if (access(notifier
, X_OK
))
5596 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5597 _("notify-recipient-uri URI \"%s\" uses unknown "
5598 "scheme."), recipient
);
5599 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5600 "notify-status-code", IPP_URI_SCHEME
);
5604 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5606 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5607 _("notify-recipient-uri URI \"%s\" is already used."),
5609 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5610 "notify-status-code", IPP_ATTRIBUTES
);
5614 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5615 attr
->value_tag
== IPP_TAG_KEYWORD
)
5617 pullmethod
= attr
->values
[0].string
.text
;
5619 if (strcmp(pullmethod
, "ippget"))
5621 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5622 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5623 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5624 "notify-status-code", IPP_ATTRIBUTES
);
5628 else if (!strcmp(attr
->name
, "notify-charset") &&
5629 attr
->value_tag
== IPP_TAG_CHARSET
&&
5630 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5631 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5633 send_ipp_status(con
, IPP_CHARSET
,
5634 _("Character set \"%s\" not supported."),
5635 attr
->values
[0].string
.text
);
5638 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5639 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5640 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5642 send_ipp_status(con
, IPP_CHARSET
,
5643 _("Language \"%s\" not supported."),
5644 attr
->values
[0].string
.text
);
5647 else if (!strcmp(attr
->name
, "notify-user-data") &&
5648 attr
->value_tag
== IPP_TAG_STRING
)
5650 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5652 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5653 _("The notify-user-data value is too large "
5654 "(%d > 63 octets)."),
5655 attr
->values
[0].unknown
.length
);
5661 else if (!strcmp(attr
->name
, "notify-events") &&
5662 attr
->value_tag
== IPP_TAG_KEYWORD
)
5663 notify_events
= attr
;
5664 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5665 attr
->value_tag
== IPP_TAG_INTEGER
)
5666 lease
= attr
->values
[0].integer
;
5667 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5668 attr
->value_tag
== IPP_TAG_INTEGER
)
5669 interval
= attr
->values
[0].integer
;
5670 else if (!strcmp(attr
->name
, "notify-job-id") &&
5671 attr
->value_tag
== IPP_TAG_INTEGER
)
5672 jobid
= attr
->values
[0].integer
;
5679 for (i
= 0; i
< notify_events
->num_values
; i
++)
5680 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5684 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5686 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5687 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5688 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5690 if (!recipient
&& !pullmethod
)
5693 if (mask
== CUPSD_EVENT_NONE
)
5696 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5698 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5701 send_ipp_status(con
, IPP_BAD_REQUEST
,
5702 _("notify-events not specified."));
5707 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5709 cupsdLogMessage(CUPSD_LOG_INFO
,
5710 "create_subscription: Limiting notify-lease-duration to "
5713 lease
= MaxLeaseDuration
;
5718 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5720 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5728 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5730 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5731 _("There are too many subscriptions."));
5736 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5739 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5740 "Added subscription #%d for printer \"%s\".",
5741 sub
->id
, printer
->name
);
5743 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5746 sub
->interval
= interval
;
5748 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5750 cupsdSetString(&sub
->owner
, username
);
5754 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5755 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5756 sub
->user_data_len
);
5759 ippAddSeparator(con
->response
);
5760 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5761 "notify-subscription-id", sub
->id
);
5763 con
->response
->request
.status
.status_code
= IPP_OK
;
5769 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5774 * 'delete_printer()' - Remove a printer or class from the system.
5778 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5779 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5781 http_status_t status
; /* Policy status */
5782 cups_ptype_t dtype
; /* Destination type (printer/class) */
5783 cupsd_printer_t
*printer
; /* Printer/class */
5784 char filename
[1024]; /* Script/PPD filename */
5787 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5788 con
->http
.fd
, uri
->values
[0].string
.text
);
5791 * Do we have a valid URI?
5794 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5800 send_ipp_status(con
, IPP_NOT_FOUND
,
5801 _("The printer or class does not exist."));
5809 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5811 send_http_error(con
, status
, NULL
);
5816 * Remove old jobs...
5819 cupsdCancelJobs(printer
->name
, NULL
, 1);
5822 * Remove old subscriptions and send a "deleted printer" event...
5825 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5826 "%s \"%s\" deleted by \"%s\".",
5827 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5828 printer
->name
, get_username(con
));
5830 cupsdExpireSubscriptions(printer
, NULL
);
5833 * Remove any old PPD or script files...
5836 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
5840 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5844 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
5847 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
5851 * Unregister color profiles...
5854 cupsdUnregisterColor(printer
);
5856 if (dtype
& CUPS_PRINTER_CLASS
)
5858 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5859 printer
->name
, get_username(con
));
5861 cupsdDeletePrinter(printer
, 0);
5862 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5866 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5867 printer
->name
, get_username(con
));
5869 if (cupsdDeletePrinter(printer
, 0))
5870 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5872 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
5875 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
5878 * Return with no errors...
5881 con
->response
->request
.status
.status_code
= IPP_OK
;
5886 * 'get_default()' - Get the default destination.
5890 get_default(cupsd_client_t
*con
) /* I - Client connection */
5892 http_status_t status
; /* Policy status */
5893 cups_array_t
*ra
; /* Requested attributes array */
5896 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
5902 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5904 send_http_error(con
, status
, NULL
);
5910 ra
= create_requested_array(con
->request
);
5912 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5914 cupsArrayDelete(ra
);
5916 con
->response
->request
.status
.status_code
= IPP_OK
;
5919 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
5924 * 'get_devices()' - Get the list of available devices on the local system.
5928 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5930 http_status_t status
; /* Policy status */
5931 ipp_attribute_t
*limit
, /* limit attribute */
5932 *timeout
, /* timeout attribute */
5933 *requested
, /* requested-attributes attribute */
5934 *exclude
, /* exclude-schemes attribute */
5935 *include
; /* include-schemes attribute */
5936 char command
[1024], /* cups-deviced command */
5937 options
[2048], /* Options to pass to command */
5939 /* String for requested attributes */
5941 /* String for excluded schemes */
5943 /* String for included schemes */
5946 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
5952 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5954 send_http_error(con
, status
, NULL
);
5959 * Run cups-deviced command with the given options...
5962 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5963 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
5964 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5966 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
5967 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
5970 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5972 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5975 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
5977 exclude_str
[0] = '\0';
5980 url_encode_attr(include
, include_str
, sizeof(include_str
));
5982 include_str
[0] = '\0';
5984 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
5985 snprintf(options
, sizeof(options
),
5986 "%d+%d+%d+%d+%s%s%s%s%s",
5987 con
->request
->request
.op
.request_id
,
5988 limit
? limit
->values
[0].integer
: 0,
5989 timeout
? timeout
->values
[0].integer
: 15,
5992 exclude_str
[0] ? "%20" : "", exclude_str
,
5993 include_str
[0] ? "%20" : "", include_str
);
5995 if (cupsdSendCommand(con
, command
, options
, 1))
5998 * Command started successfully, don't send an IPP response here...
6001 ippDelete(con
->response
);
6002 con
->response
= NULL
;
6007 * Command failed, return "internal error" so the user knows something
6011 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6012 _("cups-deviced failed to execute."));
6018 * 'get_document()' - Get a copy of a job file.
6022 get_document(cupsd_client_t
*con
, /* I - Client connection */
6023 ipp_attribute_t
*uri
) /* I - Job URI */
6025 http_status_t status
; /* Policy status */
6026 ipp_attribute_t
*attr
; /* Current attribute */
6027 int jobid
; /* Job ID */
6028 int docnum
; /* Document number */
6029 cupsd_job_t
*job
; /* Current job */
6030 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6031 username
[HTTP_MAX_URI
], /* Username portion of URI */
6032 host
[HTTP_MAX_URI
], /* Host portion of URI */
6033 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6034 int port
; /* Port portion of URI */
6035 char filename
[1024], /* Filename for document */
6036 format
[1024]; /* Format for document */
6039 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6040 con
->http
.fd
, uri
->values
[0].string
.text
);
6043 * See if we have a job URI or a printer URI...
6046 if (!strcmp(uri
->name
, "printer-uri"))
6049 * Got a printer URI; see if we also have a job-id attribute...
6052 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6053 IPP_TAG_INTEGER
)) == NULL
)
6055 send_ipp_status(con
, IPP_BAD_REQUEST
,
6056 _("Got a printer-uri attribute but no job-id."));
6060 jobid
= attr
->values
[0].integer
;
6065 * Got a job URI; parse it to get the job ID...
6068 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6069 sizeof(scheme
), username
, sizeof(username
), host
,
6070 sizeof(host
), &port
, resource
, sizeof(resource
));
6072 if (strncmp(resource
, "/jobs/", 6))
6078 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6079 uri
->values
[0].string
.text
);
6083 jobid
= atoi(resource
+ 6);
6087 * See if the job exists...
6090 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6093 * Nope - return a "not found" error...
6096 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6104 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6105 job
->username
)) != HTTP_OK
)
6107 send_http_error(con
, status
, NULL
);
6112 * Get the document number...
6115 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6116 IPP_TAG_INTEGER
)) == NULL
)
6118 send_ipp_status(con
, IPP_BAD_REQUEST
,
6119 _("Missing document-number attribute."));
6123 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6124 attr
->num_values
> 1)
6126 send_ipp_status(con
, IPP_NOT_FOUND
,
6127 _("Document #%d does not exist in job #%d."), docnum
,
6132 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6134 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6136 cupsdLogMessage(CUPSD_LOG_ERROR
,
6137 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6139 send_ipp_status(con
, IPP_NOT_FOUND
,
6140 _("Unable to open document #%d in job #%d."), docnum
,
6145 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6149 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6150 job
->filetypes
[docnum
- 1]->type
);
6152 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6154 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6156 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6157 IPP_TAG_NAME
)) != NULL
)
6158 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6159 NULL
, attr
->values
[0].string
.text
);
6164 * 'get_job_attrs()' - Get job attributes.
6168 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6169 ipp_attribute_t
*uri
) /* I - Job URI */
6171 http_status_t status
; /* Policy status */
6172 ipp_attribute_t
*attr
; /* Current attribute */
6173 int jobid
; /* Job ID */
6174 cupsd_job_t
*job
; /* Current job */
6175 cupsd_printer_t
*printer
; /* Current printer */
6176 cupsd_policy_t
*policy
; /* Current security policy */
6177 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6178 username
[HTTP_MAX_URI
], /* Username portion of URI */
6179 host
[HTTP_MAX_URI
], /* Host portion of URI */
6180 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6181 int port
; /* Port portion of URI */
6182 cups_array_t
*ra
, /* Requested attributes array */
6183 *exclude
; /* Private attributes array */
6186 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6187 con
->http
.fd
, uri
->values
[0].string
.text
);
6190 * See if we have a job URI or a printer URI...
6193 if (!strcmp(uri
->name
, "printer-uri"))
6196 * Got a printer URI; see if we also have a job-id attribute...
6199 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6200 IPP_TAG_INTEGER
)) == NULL
)
6202 send_ipp_status(con
, IPP_BAD_REQUEST
,
6203 _("Got a printer-uri attribute but no job-id."));
6207 jobid
= attr
->values
[0].integer
;
6212 * Got a job URI; parse it to get the job ID...
6215 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6216 sizeof(scheme
), username
, sizeof(username
), host
,
6217 sizeof(host
), &port
, resource
, sizeof(resource
));
6219 if (strncmp(resource
, "/jobs/", 6))
6225 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6226 uri
->values
[0].string
.text
);
6230 jobid
= atoi(resource
+ 6);
6234 * See if the job exists...
6237 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6240 * Nope - return a "not found" error...
6243 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6251 if ((printer
= job
->printer
) == NULL
)
6252 printer
= cupsdFindDest(job
->dest
);
6255 policy
= printer
->op_policy_ptr
;
6257 policy
= DefaultPolicyPtr
;
6259 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6261 send_http_error(con
, status
, NULL
);
6265 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6268 * Copy attributes...
6273 ra
= create_requested_array(con
->request
);
6274 copy_job_attrs(con
, job
, ra
, exclude
);
6275 cupsArrayDelete(ra
);
6277 con
->response
->request
.status
.status_code
= IPP_OK
;
6282 * 'get_jobs()' - Get a list of jobs for the specified printer.
6286 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6287 ipp_attribute_t
*uri
) /* I - Printer URI */
6289 http_status_t status
; /* Policy status */
6290 ipp_attribute_t
*attr
; /* Current attribute */
6291 const char *dest
; /* Destination */
6292 cups_ptype_t dtype
; /* Destination type (printer/class) */
6293 cups_ptype_t dmask
; /* Destination type mask */
6294 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6295 username
[HTTP_MAX_URI
], /* Username portion of URI */
6296 host
[HTTP_MAX_URI
], /* Host portion of URI */
6297 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6298 int port
; /* Port portion of URI */
6299 int job_comparison
; /* Job comparison */
6300 ipp_jstate_t job_state
; /* job-state value */
6301 int first_job_id
; /* First job ID */
6302 int limit
; /* Maximum number of jobs to return */
6303 int count
; /* Number of jobs that match */
6304 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6305 cupsd_job_t
*job
; /* Current job pointer */
6306 cupsd_printer_t
*printer
; /* Printer */
6307 cups_array_t
*list
; /* Which job list... */
6308 cups_array_t
*ra
, /* Requested attributes array */
6309 *exclude
; /* Private attributes array */
6310 cupsd_policy_t
*policy
; /* Current policy */
6313 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6314 uri
->values
[0].string
.text
);
6317 * Is the destination valid?
6320 if (strcmp(uri
->name
, "printer-uri"))
6322 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6326 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6327 sizeof(scheme
), username
, sizeof(username
), host
,
6328 sizeof(host
), &port
, resource
, sizeof(resource
));
6330 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6333 dtype
= (cups_ptype_t
)0;
6334 dmask
= (cups_ptype_t
)0;
6337 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6340 dtype
= (cups_ptype_t
)0;
6341 dmask
= CUPS_PRINTER_CLASS
;
6344 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6347 dtype
= CUPS_PRINTER_CLASS
;
6348 dmask
= CUPS_PRINTER_CLASS
;
6351 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6358 send_ipp_status(con
, IPP_NOT_FOUND
,
6359 _("The printer or class does not exist."));
6364 dtype
&= CUPS_PRINTER_CLASS
;
6365 dmask
= CUPS_PRINTER_CLASS
;
6373 policy
= printer
->op_policy_ptr
;
6375 policy
= DefaultPolicyPtr
;
6377 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6379 send_http_error(con
, status
, NULL
);
6383 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6386 * See if the "which-jobs" attribute have been specified...
6389 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6390 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6392 send_ipp_status(con
, IPP_CONFLICT
,
6393 _("The %s attribute cannot be provided with job-ids."),
6397 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6399 job_comparison
= -1;
6400 job_state
= IPP_JOB_STOPPED
;
6403 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6406 job_state
= IPP_JOB_CANCELED
;
6409 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6412 job_state
= IPP_JOB_ABORTED
;
6415 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6418 job_state
= IPP_JOB_PENDING
;
6421 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6424 job_state
= IPP_JOB_CANCELED
;
6427 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6430 job_state
= IPP_JOB_PENDING
;
6433 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6436 job_state
= IPP_JOB_HELD
;
6439 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6442 job_state
= IPP_JOB_PROCESSING
;
6443 list
= PrintingJobs
;
6445 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6448 job_state
= IPP_JOB_STOPPED
;
6453 send_ipp_status(con
, IPP_ATTRIBUTES
,
6454 _("The which-jobs value \"%s\" is not supported."),
6455 attr
->values
[0].string
.text
);
6456 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6457 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6462 * See if they want to limit the number of jobs reported...
6465 if ((attr
= ippFindAttribute(con
->request
, "limit",
6466 IPP_TAG_INTEGER
)) != NULL
)
6470 send_ipp_status(con
, IPP_CONFLICT
,
6471 _("The %s attribute cannot be provided with job-ids."),
6476 limit
= attr
->values
[0].integer
;
6481 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6482 IPP_TAG_INTEGER
)) != NULL
)
6486 send_ipp_status(con
, IPP_CONFLICT
,
6487 _("The %s attribute cannot be provided with job-ids."),
6492 first_job_id
= attr
->values
[0].integer
;
6498 * See if we only want to see jobs for a specific user...
6501 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6502 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6504 send_ipp_status(con
, IPP_CONFLICT
,
6505 _("The %s attribute cannot be provided with job-ids."),
6509 else if (attr
&& attr
->values
[0].boolean
)
6510 strlcpy(username
, get_username(con
), sizeof(username
));
6514 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
6515 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
6518 * IPP conformance - Get-Jobs has a default requested-attributes value of
6519 * "job-id" and "job-uri".
6522 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6523 cupsArrayAdd(ra
, "job-id");
6524 cupsArrayAdd(ra
, "job-uri");
6528 * OK, build a list of jobs for this printer...
6533 int i
; /* Looping var */
6535 for (i
= 0; i
< job_ids
->num_values
; i
++)
6537 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6541 if (i
< job_ids
->num_values
)
6543 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6544 job_ids
->values
[i
].integer
);
6548 for (i
= 0; i
< job_ids
->num_values
; i
++)
6550 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6556 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6562 ippAddSeparator(con
->response
);
6564 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6565 job
->printer
->op_policy_ptr
:
6566 policy
, con
, job
->printer
,
6569 copy_job_attrs(con
, job
, ra
, exclude
);
6574 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6575 (limit
<= 0 || count
< limit
) && job
;
6576 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6579 * Filter out jobs that don't match...
6582 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6583 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6584 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6585 job
->username
, job
->state_value
, job
->attrs
);
6587 if (!job
->dest
|| !job
->username
)
6590 if (!job
->dest
|| !job
->username
)
6593 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6594 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6596 if ((job
->dtype
& dmask
) != dtype
&&
6597 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6600 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6601 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6602 (job_comparison
> 0 && job
->state_value
< job_state
))
6605 if (job
->id
< first_job_id
)
6612 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6617 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6621 ippAddSeparator(con
->response
);
6625 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6626 job
->printer
->op_policy_ptr
:
6627 policy
, con
, job
->printer
,
6630 copy_job_attrs(con
, job
, ra
, exclude
);
6633 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6636 cupsArrayDelete(ra
);
6638 con
->response
->request
.status
.status_code
= IPP_OK
;
6643 * 'get_notifications()' - Get events for a subscription.
6647 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6649 int i
, j
; /* Looping vars */
6650 http_status_t status
; /* Policy status */
6651 cupsd_subscription_t
*sub
; /* Subscription */
6652 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6653 *sequences
; /* notify-sequence-numbers */
6654 int min_seq
; /* Minimum sequence number */
6655 int interval
; /* Poll interval */
6658 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6662 * Get subscription attributes...
6665 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6667 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6672 send_ipp_status(con
, IPP_BAD_REQUEST
,
6673 _("Missing notify-subscription-ids attribute."));
6678 * Are the subscription IDs valid?
6681 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6683 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6686 * Bad subscription ID...
6689 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6690 ids
->values
[i
].integer
);
6698 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6700 con
, sub
->owner
)) != HTTP_OK
)
6702 send_http_error(con
, status
, sub
->dest
);
6707 * Check the subscription type and update the interval accordingly.
6710 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6713 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6715 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6721 * Tell the client to poll again in N seconds...
6725 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6726 "notify-get-interval", interval
);
6728 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6729 "printer-up-time", time(NULL
));
6732 * Copy the subscription event attributes to the response.
6735 con
->response
->request
.status
.status_code
=
6736 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6738 for (i
= 0; i
< ids
->num_values
; i
++)
6741 * Get the subscription and sequence number...
6744 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6746 if (sequences
&& i
< sequences
->num_values
)
6747 min_seq
= sequences
->values
[i
].integer
;
6752 * If we don't have any new events, nothing to do here...
6755 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6759 * Otherwise copy all of the new events...
6762 if (sub
->first_event_id
> min_seq
)
6765 j
= min_seq
- sub
->first_event_id
;
6767 for (; j
< cupsArrayCount(sub
->events
); j
++)
6769 ippAddSeparator(con
->response
);
6771 copy_attrs(con
->response
,
6772 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
6773 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
6780 * 'get_ppd()' - Get a named PPD from the local system.
6784 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6785 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6787 http_status_t status
; /* Policy status */
6788 cupsd_printer_t
*dest
; /* Destination */
6789 cups_ptype_t dtype
; /* Destination type */
6792 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6793 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6795 if (!strcmp(uri
->name
, "ppd-name"))
6798 * Return a PPD file from cups-driverd...
6801 char command
[1024], /* cups-driverd command */
6802 options
[1024], /* Options to pass to command */
6803 ppd_name
[1024]; /* ppd-name */
6810 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6812 send_http_error(con
, status
, NULL
);
6817 * Run cups-driverd command with the given options...
6820 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6821 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
6822 snprintf(options
, sizeof(options
), "get+%d+%s",
6823 con
->request
->request
.op
.request_id
, ppd_name
);
6825 if (cupsdSendCommand(con
, command
, options
, 0))
6828 * Command started successfully, don't send an IPP response here...
6831 ippDelete(con
->response
);
6832 con
->response
= NULL
;
6837 * Command failed, return "internal error" so the user knows something
6841 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6842 _("cups-driverd failed to execute."));
6845 else if (!strcmp(uri
->name
, "printer-uri") &&
6846 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
6848 int i
; /* Looping var */
6849 char filename
[1024]; /* PPD filename */
6856 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6858 send_http_error(con
, status
, dest
);
6863 * See if we need the PPD for a class or remote printer...
6866 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6869 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
6871 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6872 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6873 "printer-uri", NULL
, dest
->uri
);
6876 else if (dtype
& CUPS_PRINTER_CLASS
)
6878 for (i
= 0; i
< dest
->num_printers
; i
++)
6879 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
6881 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6882 dest
->printers
[i
]->name
);
6884 if (!access(filename
, 0))
6888 if (i
< dest
->num_printers
)
6889 dest
= dest
->printers
[i
];
6892 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6893 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6894 "printer-uri", NULL
, dest
->printers
[0]->uri
);
6900 * Found the printer with the PPD file, now see if there is one...
6903 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
6905 send_ipp_status(con
, IPP_NOT_FOUND
,
6906 _("The PPD file \"%s\" could not be opened: %s"),
6907 uri
->values
[0].string
.text
, strerror(errno
));
6911 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6915 con
->response
->request
.status
.status_code
= IPP_OK
;
6918 send_ipp_status(con
, IPP_NOT_FOUND
,
6919 _("The PPD file \"%s\" could not be found."),
6920 uri
->values
[0].string
.text
);
6925 * 'get_ppds()' - Get the list of PPD files on the local system.
6929 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
6931 http_status_t status
; /* Policy status */
6932 ipp_attribute_t
*limit
, /* Limit attribute */
6933 *device
, /* ppd-device-id attribute */
6934 *language
, /* ppd-natural-language attribute */
6935 *make
, /* ppd-make attribute */
6936 *model
, /* ppd-make-and-model attribute */
6937 *model_number
, /* ppd-model-number attribute */
6938 *product
, /* ppd-product attribute */
6939 *psversion
, /* ppd-psverion attribute */
6940 *type
, /* ppd-type attribute */
6941 *requested
, /* requested-attributes attribute */
6942 *exclude
, /* exclude-schemes attribute */
6943 *include
; /* include-schemes attribute */
6944 char command
[1024], /* cups-driverd command */
6945 options
[4096], /* Options to pass to command */
6946 device_str
[256],/* Escaped ppd-device-id string */
6948 /* Escaped ppd-natural-language */
6949 make_str
[256], /* Escaped ppd-make string */
6950 model_str
[256], /* Escaped ppd-make-and-model string */
6951 model_number_str
[256],
6952 /* ppd-model-number string */
6954 /* Escaped ppd-product string */
6956 /* Escaped ppd-psversion string */
6957 type_str
[256], /* Escaped ppd-type string */
6959 /* String for requested attributes */
6961 /* String for excluded schemes */
6963 /* String for included schemes */
6966 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
6972 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6974 send_http_error(con
, status
, NULL
);
6979 * Run cups-driverd command with the given options...
6982 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6983 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
6984 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
6986 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
6987 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
6989 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
6991 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
6992 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
6993 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
6994 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6996 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
6998 include
= ippFindAttribute(con
->request
, "include-schemes",
7002 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7004 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7007 url_encode_attr(device
, device_str
, sizeof(device_str
));
7009 device_str
[0] = '\0';
7012 url_encode_attr(language
, language_str
, sizeof(language_str
));
7014 language_str
[0] = '\0';
7017 url_encode_attr(make
, make_str
, sizeof(make_str
));
7022 url_encode_attr(model
, model_str
, sizeof(model_str
));
7024 model_str
[0] = '\0';
7027 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7028 model_number
->values
[0].integer
);
7030 model_number_str
[0] = '\0';
7033 url_encode_attr(product
, product_str
, sizeof(product_str
));
7035 product_str
[0] = '\0';
7038 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7040 psversion_str
[0] = '\0';
7043 url_encode_attr(type
, type_str
, sizeof(type_str
));
7048 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7050 exclude_str
[0] = '\0';
7053 url_encode_attr(include
, include_str
, sizeof(include_str
));
7055 include_str
[0] = '\0';
7057 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7058 snprintf(options
, sizeof(options
),
7059 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7060 con
->request
->request
.op
.request_id
,
7061 limit
? limit
->values
[0].integer
: 0,
7063 device
? "%20" : "", device_str
,
7064 language
? "%20" : "", language_str
,
7065 make
? "%20" : "", make_str
,
7066 model
? "%20" : "", model_str
,
7067 model_number
? "%20" : "", model_number_str
,
7068 product
? "%20" : "", product_str
,
7069 psversion
? "%20" : "", psversion_str
,
7070 type
? "%20" : "", type_str
,
7071 exclude_str
[0] ? "%20" : "", exclude_str
,
7072 include_str
[0] ? "%20" : "", include_str
);
7074 if (cupsdSendCommand(con
, command
, options
, 0))
7077 * Command started successfully, don't send an IPP response here...
7080 ippDelete(con
->response
);
7081 con
->response
= NULL
;
7086 * Command failed, return "internal error" so the user knows something
7090 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7091 _("cups-driverd failed to execute."));
7097 * 'get_printer_attrs()' - Get printer attributes.
7101 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7102 ipp_attribute_t
*uri
) /* I - Printer URI */
7104 http_status_t status
; /* Policy status */
7105 cups_ptype_t dtype
; /* Destination type (printer/class) */
7106 cupsd_printer_t
*printer
; /* Printer/class */
7107 cups_array_t
*ra
; /* Requested attributes array */
7110 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7111 con
->http
.fd
, uri
->values
[0].string
.text
);
7114 * Is the destination valid?
7117 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7123 send_ipp_status(con
, IPP_NOT_FOUND
,
7124 _("The printer or class does not exist."));
7132 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7134 send_http_error(con
, status
, printer
);
7139 * Send the attributes...
7142 ra
= create_requested_array(con
->request
);
7144 copy_printer_attrs(con
, printer
, ra
);
7146 cupsArrayDelete(ra
);
7148 con
->response
->request
.status
.status_code
= IPP_OK
;
7153 * 'get_printer_supported()' - Get printer supported values.
7157 get_printer_supported(
7158 cupsd_client_t
*con
, /* I - Client connection */
7159 ipp_attribute_t
*uri
) /* I - Printer URI */
7161 http_status_t status
; /* Policy status */
7162 cups_ptype_t dtype
; /* Destination type (printer/class) */
7163 cupsd_printer_t
*printer
; /* Printer/class */
7166 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7167 con
->http
.fd
, uri
->values
[0].string
.text
);
7170 * Is the destination valid?
7173 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7179 send_ipp_status(con
, IPP_NOT_FOUND
,
7180 _("The printer or class does not exist."));
7188 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7190 send_http_error(con
, status
, printer
);
7195 * Return a list of attributes that can be set via Set-Printer-Attributes.
7198 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7200 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7201 "printer-location", 0);
7203 con
->response
->request
.status
.status_code
= IPP_OK
;
7208 * 'get_printers()' - Get a list of printers or classes.
7212 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7213 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7215 http_status_t status
; /* Policy status */
7216 ipp_attribute_t
*attr
; /* Current attribute */
7217 int limit
; /* Max number of printers to return */
7218 int count
; /* Number of printers that match */
7219 cupsd_printer_t
*printer
; /* Current printer pointer */
7220 int printer_type
, /* printer-type attribute */
7221 printer_mask
; /* printer-type-mask attribute */
7222 char *location
; /* Location string */
7223 const char *username
; /* Current user */
7224 char *first_printer_name
; /* first-printer-name attribute */
7225 cups_array_t
*ra
; /* Requested attributes array */
7226 int local
; /* Local connection? */
7229 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7230 con
->http
.fd
, type
);
7236 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7238 send_http_error(con
, status
, NULL
);
7243 * Check for printers...
7246 if (!Printers
|| !cupsArrayCount(Printers
))
7248 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7253 * See if they want to limit the number of printers reported...
7256 if ((attr
= ippFindAttribute(con
->request
, "limit",
7257 IPP_TAG_INTEGER
)) != NULL
)
7258 limit
= attr
->values
[0].integer
;
7262 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7263 IPP_TAG_NAME
)) != NULL
)
7264 first_printer_name
= attr
->values
[0].string
.text
;
7266 first_printer_name
= NULL
;
7269 * Support filtering...
7272 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7273 IPP_TAG_ENUM
)) != NULL
)
7274 printer_type
= attr
->values
[0].integer
;
7278 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7279 IPP_TAG_ENUM
)) != NULL
)
7280 printer_mask
= attr
->values
[0].integer
;
7284 local
= httpAddrLocalhost(&(con
->clientaddr
));
7286 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7287 IPP_TAG_TEXT
)) != NULL
)
7288 location
= attr
->values
[0].string
.text
;
7292 if (con
->username
[0])
7293 username
= con
->username
;
7294 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7295 IPP_TAG_NAME
)) != NULL
)
7296 username
= attr
->values
[0].string
.text
;
7300 ra
= create_requested_array(con
->request
);
7303 * OK, build a list of printers for this printer...
7306 if (first_printer_name
)
7308 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7309 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7312 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7315 count
< limit
&& printer
;
7316 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7318 if (!local
&& !printer
->shared
)
7321 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7322 (printer
->type
& printer_mask
) == printer_type
&&
7324 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7327 * If a username is specified, see if it is allowed or denied
7331 if (cupsArrayCount(printer
->users
) && username
&&
7332 !user_allowed(printer
, username
))
7336 * Add the group separator as needed...
7340 ippAddSeparator(con
->response
);
7345 * Send the attributes...
7348 copy_printer_attrs(con
, printer
, ra
);
7352 cupsArrayDelete(ra
);
7354 con
->response
->request
.status
.status_code
= IPP_OK
;
7359 * 'get_subscription_attrs()' - Get subscription attributes.
7363 get_subscription_attrs(
7364 cupsd_client_t
*con
, /* I - Client connection */
7365 int sub_id
) /* I - Subscription ID */
7367 http_status_t status
; /* Policy status */
7368 cupsd_subscription_t
*sub
; /* Subscription */
7369 cupsd_policy_t
*policy
; /* Current security policy */
7370 cups_array_t
*ra
, /* Requested attributes array */
7371 *exclude
; /* Private attributes array */
7374 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7375 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7376 con
, con
->http
.fd
, sub_id
);
7379 * Is the subscription ID valid?
7382 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7385 * Bad subscription ID...
7388 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7398 policy
= sub
->dest
->op_policy_ptr
;
7400 policy
= DefaultPolicyPtr
;
7402 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7404 send_http_error(con
, status
, sub
->dest
);
7408 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7411 * Copy the subscription attributes to the response using the
7412 * requested-attributes attribute that may be provided by the client.
7415 ra
= create_requested_array(con
->request
);
7417 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7419 cupsArrayDelete(ra
);
7421 con
->response
->request
.status
.status_code
= IPP_OK
;
7426 * 'get_subscriptions()' - Get subscriptions.
7430 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7431 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7433 http_status_t status
; /* Policy status */
7434 int count
; /* Number of subscriptions */
7435 int limit
; /* Limit */
7436 cupsd_subscription_t
*sub
; /* Subscription */
7437 cups_array_t
*ra
; /* Requested attributes array */
7438 ipp_attribute_t
*attr
; /* Attribute */
7439 cups_ptype_t dtype
; /* Destination type (printer/class) */
7440 char scheme
[HTTP_MAX_URI
],
7441 /* Scheme portion of URI */
7442 username
[HTTP_MAX_URI
],
7443 /* Username portion of URI */
7445 /* Host portion of URI */
7446 resource
[HTTP_MAX_URI
];
7447 /* Resource portion of URI */
7448 int port
; /* Port portion of URI */
7449 cupsd_job_t
*job
; /* Job pointer */
7450 cupsd_printer_t
*printer
; /* Printer */
7451 cupsd_policy_t
*policy
; /* Policy */
7452 cups_array_t
*exclude
; /* Private attributes array */
7455 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7456 "get_subscriptions(con=%p[%d], uri=%s)",
7457 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7460 * Is the destination valid?
7463 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7464 sizeof(scheme
), username
, sizeof(username
), host
,
7465 sizeof(host
), &port
, resource
, sizeof(resource
));
7467 if (!strcmp(resource
, "/") ||
7468 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7469 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7470 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7475 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7478 job
= cupsdFindJob(atoi(resource
+ 6));
7482 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7483 atoi(resource
+ 6));
7487 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7493 send_ipp_status(con
, IPP_NOT_FOUND
,
7494 _("The printer or class does not exist."));
7497 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7498 IPP_TAG_INTEGER
)) != NULL
)
7500 job
= cupsdFindJob(attr
->values
[0].integer
);
7504 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7505 attr
->values
[0].integer
);
7517 policy
= printer
->op_policy_ptr
;
7519 policy
= DefaultPolicyPtr
;
7521 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7523 send_http_error(con
, status
, printer
);
7528 * Copy the subscription attributes to the response using the
7529 * requested-attributes attribute that may be provided by the client.
7532 ra
= create_requested_array(con
->request
);
7534 if ((attr
= ippFindAttribute(con
->request
, "limit",
7535 IPP_TAG_INTEGER
)) != NULL
)
7536 limit
= attr
->values
[0].integer
;
7541 * See if we only want to see subscriptions for a specific user...
7544 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7545 IPP_TAG_BOOLEAN
)) != NULL
&&
7546 attr
->values
[0].boolean
)
7547 strlcpy(username
, get_username(con
), sizeof(username
));
7551 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7553 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7554 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7555 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7557 ippAddSeparator(con
->response
);
7559 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7560 policy
, con
, sub
->dest
,
7563 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7566 if (limit
&& count
>= limit
)
7570 cupsArrayDelete(ra
);
7573 con
->response
->request
.status
.status_code
= IPP_OK
;
7575 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7580 * 'get_username()' - Get the username associated with a request.
7583 static const char * /* O - Username */
7584 get_username(cupsd_client_t
*con
) /* I - Connection */
7586 ipp_attribute_t
*attr
; /* Attribute */
7589 if (con
->username
[0])
7590 return (con
->username
);
7591 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7592 IPP_TAG_NAME
)) != NULL
)
7593 return (attr
->values
[0].string
.text
);
7595 return ("anonymous");
7600 * 'hold_job()' - Hold a print job.
7604 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7605 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7607 ipp_attribute_t
*attr
; /* Current job-hold-until */
7608 const char *when
; /* New value */
7609 int jobid
; /* Job ID */
7610 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7611 username
[HTTP_MAX_URI
], /* Username portion of URI */
7612 host
[HTTP_MAX_URI
], /* Host portion of URI */
7613 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7614 int port
; /* Port portion of URI */
7615 cupsd_job_t
*job
; /* Job information */
7618 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
7619 uri
->values
[0].string
.text
);
7622 * See if we have a job URI or a printer URI...
7625 if (!strcmp(uri
->name
, "printer-uri"))
7628 * Got a printer URI; see if we also have a job-id attribute...
7631 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7632 IPP_TAG_INTEGER
)) == NULL
)
7634 send_ipp_status(con
, IPP_BAD_REQUEST
,
7635 _("Got a printer-uri attribute but no job-id."));
7639 jobid
= attr
->values
[0].integer
;
7644 * Got a job URI; parse it to get the job ID...
7647 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7648 sizeof(scheme
), username
, sizeof(username
), host
,
7649 sizeof(host
), &port
, resource
, sizeof(resource
));
7651 if (strncmp(resource
, "/jobs/", 6))
7657 send_ipp_status(con
, IPP_BAD_REQUEST
,
7658 _("Bad job-uri \"%s\"."),
7659 uri
->values
[0].string
.text
);
7663 jobid
= atoi(resource
+ 6);
7667 * See if the job exists...
7670 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7673 * Nope - return a "not found" error...
7676 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7681 * See if the job is owned by the requesting user...
7684 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7686 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7687 cupsdFindDest(job
->dest
));
7692 * See if the job is in a state that allows holding...
7695 if (job
->state_value
> IPP_JOB_STOPPED
)
7698 * Return a "not-possible" error...
7701 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7702 _("Job #%d is finished and cannot be altered."),
7708 * Hold the job and return...
7711 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7712 IPP_TAG_KEYWORD
)) == NULL
)
7713 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7717 when
= attr
->values
[0].string
.text
;
7719 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7720 "Job job-hold-until value changed by user.");
7723 when
= "indefinite";
7725 cupsdSetJobHoldUntil(job
, when
, 1);
7726 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7729 con
->response
->request
.status
.status_code
= IPP_OK
;
7734 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7738 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7739 ipp_attribute_t
*uri
) /* I - Printer URI */
7741 http_status_t status
; /* Policy status */
7742 cups_ptype_t dtype
; /* Destination type (printer/class) */
7743 cupsd_printer_t
*printer
; /* Printer data */
7746 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7747 con
->http
.fd
, uri
->values
[0].string
.text
);
7750 * Is the destination valid?
7753 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7759 send_ipp_status(con
, IPP_NOT_FOUND
,
7760 _("The printer or class does not exist."));
7768 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7770 send_http_error(con
, status
, printer
);
7775 * Hold pending/new jobs sent to the printer...
7778 printer
->holding_new_jobs
= 1;
7780 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
7782 if (dtype
& CUPS_PRINTER_CLASS
)
7783 cupsdLogMessage(CUPSD_LOG_INFO
,
7784 "Class \"%s\" now holding pending/new jobs (\"%s\").",
7785 printer
->name
, get_username(con
));
7787 cupsdLogMessage(CUPSD_LOG_INFO
,
7788 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
7789 printer
->name
, get_username(con
));
7792 * Everything was ok, so return OK status...
7795 con
->response
->request
.status
.status_code
= IPP_OK
;
7800 * 'move_job()' - Move a job to a new destination.
7804 move_job(cupsd_client_t
*con
, /* I - Client connection */
7805 ipp_attribute_t
*uri
) /* I - Job URI */
7807 http_status_t status
; /* Policy status */
7808 ipp_attribute_t
*attr
; /* Current attribute */
7809 int jobid
; /* Job ID */
7810 cupsd_job_t
*job
; /* Current job */
7811 const char *src
; /* Source printer/class */
7812 cups_ptype_t stype
, /* Source type (printer or class) */
7813 dtype
; /* Destination type (printer/class) */
7814 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7815 username
[HTTP_MAX_URI
], /* Username portion of URI */
7816 host
[HTTP_MAX_URI
], /* Host portion of URI */
7817 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7818 int port
; /* Port portion of URI */
7819 cupsd_printer_t
*sprinter
, /* Source printer */
7820 *dprinter
; /* Destination printer */
7823 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
7824 uri
->values
[0].string
.text
);
7827 * Get the new printer or class...
7830 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7831 IPP_TAG_URI
)) == NULL
)
7834 * Need job-printer-uri...
7837 send_ipp_status(con
, IPP_BAD_REQUEST
,
7838 _("job-printer-uri attribute missing."));
7842 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
7848 send_ipp_status(con
, IPP_NOT_FOUND
,
7849 _("The printer or class does not exist."));
7854 * See if we have a job URI or a printer URI...
7857 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7858 sizeof(scheme
), username
, sizeof(username
), host
,
7859 sizeof(host
), &port
, resource
, sizeof(resource
));
7861 if (!strcmp(uri
->name
, "printer-uri"))
7864 * Got a printer URI; see if we also have a job-id attribute...
7867 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7868 IPP_TAG_INTEGER
)) == NULL
)
7874 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
7875 &sprinter
)) == NULL
)
7881 send_ipp_status(con
, IPP_NOT_FOUND
,
7882 _("The printer or class does not exist."));
7891 * Otherwise, just move a single job...
7894 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
7897 * Nope - return a "not found" error...
7900 send_ipp_status(con
, IPP_NOT_FOUND
,
7901 _("Job #%d does not exist."), attr
->values
[0].integer
);
7907 * Job found, initialize source pointers...
7918 * Got a job URI; parse it to get the job ID...
7921 if (strncmp(resource
, "/jobs/", 6))
7927 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7928 uri
->values
[0].string
.text
);
7933 * See if the job exists...
7936 jobid
= atoi(resource
+ 6);
7938 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7941 * Nope - return a "not found" error...
7944 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7950 * Job found, initialize source pointers...
7959 * Check the policy of the destination printer...
7962 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
7963 job
? job
->username
: NULL
)) != HTTP_OK
)
7965 send_http_error(con
, status
, dprinter
);
7970 * Now move the job or jobs...
7976 * See if the job has been completed...
7979 if (job
->state_value
> IPP_JOB_STOPPED
)
7982 * Return a "not-possible" error...
7985 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7986 _("Job #%d is finished and cannot be altered."),
7992 * See if the job is owned by the requesting user...
7995 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7997 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7998 cupsdFindDest(job
->dest
));
8003 * Move the job to a different printer or class...
8006 cupsdMoveJob(job
, dprinter
);
8011 * Got the source printer, now look through the jobs...
8014 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8016 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8019 * See if the job is pointing at the source printer or has not been
8023 if (_cups_strcasecmp(job
->dest
, src
) ||
8024 job
->state_value
> IPP_JOB_STOPPED
)
8028 * See if the job can be moved by the requesting user...
8031 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8035 * Move the job to a different printer or class...
8038 cupsdMoveJob(job
, dprinter
);
8043 * Start jobs if possible...
8049 * Return with "everything is OK" status...
8052 con
->response
->request
.status
.status_code
= IPP_OK
;
8057 * 'ppd_parse_line()' - Parse a PPD default line.
8060 static int /* O - 0 on success, -1 on failure */
8061 ppd_parse_line(const char *line
, /* I - Line */
8062 char *option
, /* O - Option name */
8063 int olen
, /* I - Size of option name */
8064 char *choice
, /* O - Choice name */
8065 int clen
) /* I - Size of choice name */
8068 * Verify this is a default option line...
8071 if (strncmp(line
, "*Default", 8))
8075 * Read the option name...
8078 for (line
+= 8, olen
--;
8079 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8090 * Skip everything else up to the colon (:)...
8093 while (*line
&& *line
!= ':')
8102 * Now grab the option choice, skipping leading whitespace...
8105 while (isspace(*line
& 255))
8109 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8120 * Return with no errors...
8128 * 'print_job()' - Print a file to a printer or class.
8132 print_job(cupsd_client_t
*con
, /* I - Client connection */
8133 ipp_attribute_t
*uri
) /* I - Printer URI */
8135 ipp_attribute_t
*attr
; /* Current attribute */
8136 ipp_attribute_t
*format
; /* Document-format attribute */
8137 const char *default_format
; /* document-format-default value */
8138 cupsd_job_t
*job
; /* New job */
8139 char filename
[1024]; /* Job filename */
8140 mime_type_t
*filetype
; /* Type of file */
8141 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8142 type
[MIME_MAX_TYPE
], /* Subtype of file */
8143 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8144 /* Textual name of mime type */
8145 cupsd_printer_t
*printer
; /* Printer data */
8146 struct stat fileinfo
; /* File information */
8147 int kbytes
; /* Size of file */
8148 int compression
; /* Document compression */
8151 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8152 uri
->values
[0].string
.text
);
8155 * Validate print file attributes, for now just document-format and
8156 * compression (CUPS only supports "none" and "gzip")...
8159 compression
= CUPS_FILE_NONE
;
8161 if ((attr
= ippFindAttribute(con
->request
, "compression",
8162 IPP_TAG_KEYWORD
)) != NULL
)
8164 if (strcmp(attr
->values
[0].string
.text
, "none")
8166 && strcmp(attr
->values
[0].string
.text
, "gzip")
8167 #endif /* HAVE_LIBZ */
8170 send_ipp_status(con
, IPP_ATTRIBUTES
,
8171 _("Unsupported compression \"%s\"."),
8172 attr
->values
[0].string
.text
);
8173 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8174 "compression", NULL
, attr
->values
[0].string
.text
);
8179 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8180 compression
= CUPS_FILE_GZIP
;
8181 #endif /* HAVE_LIBZ */
8185 * Do we have a file to print?
8190 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8195 * Is the destination valid?
8198 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8204 send_ipp_status(con
, IPP_NOT_FOUND
,
8205 _("The printer or class does not exist."));
8210 * Is it a format we support?
8213 if ((format
= ippFindAttribute(con
->request
, "document-format",
8214 IPP_TAG_MIMETYPE
)) != NULL
)
8217 * Grab format from client...
8220 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8223 send_ipp_status(con
, IPP_BAD_REQUEST
,
8224 _("Bad document-format \"%s\"."),
8225 format
->values
[0].string
.text
);
8229 else if ((default_format
= cupsGetOption("document-format",
8230 printer
->num_options
,
8231 printer
->options
)) != NULL
)
8234 * Use default document format...
8237 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8239 send_ipp_status(con
, IPP_BAD_REQUEST
,
8240 _("Bad document-format \"%s\"."),
8251 strcpy(super
, "application");
8252 strcpy(type
, "octet-stream");
8255 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8258 * Auto-type the file...
8261 ipp_attribute_t
*doc_name
; /* document-name attribute */
8264 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8266 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8267 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8268 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8272 filetype
= mimeType(MimeDatabase
, super
, type
);
8274 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8275 filetype
->super
, filetype
->type
);
8278 filetype
= mimeType(MimeDatabase
, super
, type
);
8282 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8285 * Replace the document-format attribute value with the auto-typed or
8289 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8294 _cupsStrFree(format
->values
[0].string
.text
);
8296 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8299 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8300 "document-format", NULL
, mimetype
);
8304 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8305 _("Unsupported document-format \"%s\"."),
8306 format
? format
->values
[0].string
.text
:
8307 "application/octet-stream");
8308 cupsdLogMessage(CUPSD_LOG_INFO
,
8309 "Hint: Do you have the raw file printing rules enabled?");
8312 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8313 "document-format", NULL
, format
->values
[0].string
.text
);
8319 * Read any embedded job ticket info from PS files...
8322 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8323 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8324 !_cups_strcasecmp(filetype
->type
, "pdf")))
8325 read_job_ticket(con
);
8328 * Create the job object...
8331 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8335 * Update quota data...
8338 if (stat(con
->filename
, &fileinfo
))
8341 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8343 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8345 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8346 IPP_TAG_INTEGER
)) != NULL
)
8347 attr
->values
[0].integer
+= kbytes
;
8350 * Add the job file...
8353 if (add_file(con
, job
, filetype
, compression
))
8356 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8358 rename(con
->filename
, filename
);
8359 cupsdClearString(&con
->filename
);
8362 * See if we need to add the ending sheet...
8365 if (cupsdTimeoutJob(job
))
8369 * Log and save the job...
8372 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8373 "File of type %s/%s queued by \"%s\".",
8374 filetype
->super
, filetype
->type
, job
->username
);
8375 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8376 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8377 job
->dest
, job
->username
);
8380 * Start the job if possible...
8388 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8390 * This function only gets called when printing a single PDF or PostScript
8391 * file using the Print-Job operation. It doesn't work for Create-Job +
8392 * Send-File, since the job attributes need to be set at job creation
8393 * time for banners to work. The embedded job ticket stuff is here
8394 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8395 * options and IPP attributes which otherwise would be lost.
8397 * The format of a job ticket is simple:
8399 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8401 * %cupsJobTicket: attr1=value1
8402 * %cupsJobTicket: attr2=value2
8404 * %cupsJobTicket: attrN=valueN
8406 * Job ticket lines must appear immediately after the first line that
8407 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8408 * stops looking for job ticket info when it finds a line that does not begin
8409 * with "%cupsJobTicket:".
8411 * The maximum length of a job ticket line, including the prefix, is
8412 * 255 characters to conform with the Adobe DSC.
8414 * Read-only attributes are rejected with a notice to the error log in
8415 * case a malicious user tries anything. Since the job ticket is read
8416 * prior to attribute validation in print_job(), job ticket attributes
8417 * will go through the same validation as IPP attributes...
8421 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8423 cups_file_t
*fp
; /* File to read from */
8424 char line
[256]; /* Line data */
8425 int num_options
; /* Number of options */
8426 cups_option_t
*options
; /* Options */
8427 ipp_t
*ticket
; /* New attributes */
8428 ipp_attribute_t
*attr
, /* Current attribute */
8429 *attr2
, /* Job attribute */
8430 *prev2
; /* Previous job attribute */
8434 * First open the print file...
8437 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8439 cupsdLogMessage(CUPSD_LOG_ERROR
,
8440 "Unable to open print file for job ticket - %s",
8446 * Skip the first line...
8449 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8451 cupsdLogMessage(CUPSD_LOG_ERROR
,
8452 "Unable to read from print file for job ticket - %s",
8458 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8461 * Not a DSC-compliant file, so no job ticket info will be available...
8469 * Read job ticket info from the file...
8475 while (cupsFileGets(fp
, line
, sizeof(line
)))
8478 * Stop at the first non-ticket line...
8481 if (strncmp(line
, "%cupsJobTicket:", 15))
8485 * Add the options to the option array...
8488 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8492 * Done with the file; see if we have any options...
8497 if (num_options
== 0)
8501 * OK, convert the options to an attribute list, and apply them to
8506 cupsEncodeOptions(ticket
, num_options
, options
);
8509 * See what the user wants to change.
8512 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8514 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8517 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8518 !strcmp(attr
->name
, "job-originating-user-name") ||
8519 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8520 !strcmp(attr
->name
, "job-k-octets") ||
8521 !strcmp(attr
->name
, "job-id") ||
8522 !strncmp(attr
->name
, "job-state", 9) ||
8523 !strncmp(attr
->name
, "time-at-", 8))
8524 continue; /* Read-only attrs */
8526 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8527 IPP_TAG_ZERO
)) != NULL
)
8530 * Some other value; first free the old value...
8533 if (con
->request
->attrs
== attr2
)
8535 con
->request
->attrs
= attr2
->next
;
8540 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8541 if (prev2
->next
== attr2
)
8543 prev2
->next
= attr2
->next
;
8548 if (con
->request
->last
== attr2
)
8549 con
->request
->last
= prev2
;
8551 ippDeleteAttribute(NULL
, attr2
);
8555 * Add new option by copying it...
8558 ippCopyAttribute(con
->request
, attr
, 0);
8562 * Then free the attribute list and option array...
8566 cupsFreeOptions(num_options
, options
);
8571 * 'reject_jobs()' - Reject print jobs to a printer.
8575 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8576 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8578 http_status_t status
; /* Policy status */
8579 cups_ptype_t dtype
; /* Destination type (printer/class) */
8580 cupsd_printer_t
*printer
; /* Printer data */
8581 ipp_attribute_t
*attr
; /* printer-state-message text */
8584 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8585 con
->http
.fd
, uri
->values
[0].string
.text
);
8588 * Is the destination valid?
8591 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8597 send_ipp_status(con
, IPP_NOT_FOUND
,
8598 _("The printer or class does not exist."));
8606 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8608 send_http_error(con
, status
, printer
);
8613 * Reject jobs sent to the printer...
8616 printer
->accepting
= 0;
8618 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8619 IPP_TAG_TEXT
)) == NULL
)
8620 strcpy(printer
->state_message
, "Rejecting Jobs");
8622 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8623 sizeof(printer
->state_message
));
8625 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8626 "No longer accepting jobs.");
8628 if (dtype
& CUPS_PRINTER_CLASS
)
8630 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8632 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8633 printer
->name
, get_username(con
));
8637 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8639 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8640 printer
->name
, get_username(con
));
8644 * Everything was ok, so return OK status...
8647 con
->response
->request
.status
.status_code
= IPP_OK
;
8652 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8656 release_held_new_jobs(
8657 cupsd_client_t
*con
, /* I - Connection */
8658 ipp_attribute_t
*uri
) /* I - Printer URI */
8660 http_status_t status
; /* Policy status */
8661 cups_ptype_t dtype
; /* Destination type (printer/class) */
8662 cupsd_printer_t
*printer
; /* Printer data */
8665 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8666 con
->http
.fd
, uri
->values
[0].string
.text
);
8669 * Is the destination valid?
8672 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8678 send_ipp_status(con
, IPP_NOT_FOUND
,
8679 _("The printer or class does not exist."));
8687 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8689 send_http_error(con
, status
, printer
);
8694 * Hold pending/new jobs sent to the printer...
8697 printer
->holding_new_jobs
= 0;
8699 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8701 if (dtype
& CUPS_PRINTER_CLASS
)
8702 cupsdLogMessage(CUPSD_LOG_INFO
,
8703 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8704 printer
->name
, get_username(con
));
8706 cupsdLogMessage(CUPSD_LOG_INFO
,
8707 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8708 printer
->name
, get_username(con
));
8711 * Everything was ok, so return OK status...
8714 con
->response
->request
.status
.status_code
= IPP_OK
;
8719 * 'release_job()' - Release a held print job.
8723 release_job(cupsd_client_t
*con
, /* I - Client connection */
8724 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8726 ipp_attribute_t
*attr
; /* Current attribute */
8727 int jobid
; /* Job ID */
8728 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8729 username
[HTTP_MAX_URI
], /* Username portion of URI */
8730 host
[HTTP_MAX_URI
], /* Host portion of URI */
8731 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8732 int port
; /* Port portion of URI */
8733 cupsd_job_t
*job
; /* Job information */
8736 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8737 con
->http
.fd
, uri
->values
[0].string
.text
);
8740 * See if we have a job URI or a printer URI...
8743 if (!strcmp(uri
->name
, "printer-uri"))
8746 * Got a printer URI; see if we also have a job-id attribute...
8749 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8750 IPP_TAG_INTEGER
)) == NULL
)
8752 send_ipp_status(con
, IPP_BAD_REQUEST
,
8753 _("Got a printer-uri attribute but no job-id."));
8757 jobid
= attr
->values
[0].integer
;
8762 * Got a job URI; parse it to get the job ID...
8765 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8766 sizeof(scheme
), username
, sizeof(username
), host
,
8767 sizeof(host
), &port
, resource
, sizeof(resource
));
8769 if (strncmp(resource
, "/jobs/", 6))
8775 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8776 uri
->values
[0].string
.text
);
8780 jobid
= atoi(resource
+ 6);
8784 * See if the job exists...
8787 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8790 * Nope - return a "not found" error...
8793 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8798 * See if job is "held"...
8801 if (job
->state_value
!= IPP_JOB_HELD
)
8804 * Nope - return a "not possible" error...
8807 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
8812 * See if the job is owned by the requesting user...
8815 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8817 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8818 cupsdFindDest(job
->dest
));
8823 * Reset the job-hold-until value to "no-hold"...
8826 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8827 IPP_TAG_KEYWORD
)) == NULL
)
8828 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8832 _cupsStrFree(attr
->values
[0].string
.text
);
8834 attr
->value_tag
= IPP_TAG_KEYWORD
;
8835 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8837 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8838 "Job job-hold-until value changed by user.");
8839 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
8843 * Release the job and return...
8846 cupsdReleaseJob(job
);
8848 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8849 "Job released by user.");
8851 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
8853 con
->response
->request
.status
.status_code
= IPP_OK
;
8860 * 'renew_subscription()' - Renew an existing subscription...
8865 cupsd_client_t
*con
, /* I - Client connection */
8866 int sub_id
) /* I - Subscription ID */
8868 http_status_t status
; /* Policy status */
8869 cupsd_subscription_t
*sub
; /* Subscription */
8870 ipp_attribute_t
*lease
; /* notify-lease-duration */
8873 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8874 "renew_subscription(con=%p[%d], sub_id=%d)",
8875 con
, con
->http
.fd
, sub_id
);
8878 * Is the subscription ID valid?
8881 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8884 * Bad subscription ID...
8887 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8895 * Job subscriptions cannot be renewed...
8898 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8899 _("Job subscriptions cannot be renewed."));
8907 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8909 con
, sub
->owner
)) != HTTP_OK
)
8911 send_http_error(con
, status
, sub
->dest
);
8916 * Renew the subscription...
8919 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8922 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
8924 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
8926 cupsdLogMessage(CUPSD_LOG_INFO
,
8927 "renew_subscription: Limiting notify-lease-duration to "
8930 sub
->lease
= MaxLeaseDuration
;
8933 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
8935 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
8937 con
->response
->request
.status
.status_code
= IPP_OK
;
8939 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
8940 "notify-lease-duration", sub
->lease
);
8945 * 'restart_job()' - Restart an old print job.
8949 restart_job(cupsd_client_t
*con
, /* I - Client connection */
8950 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8952 ipp_attribute_t
*attr
; /* Current attribute */
8953 int jobid
; /* Job ID */
8954 cupsd_job_t
*job
; /* Job information */
8955 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8956 username
[HTTP_MAX_URI
], /* Username portion of URI */
8957 host
[HTTP_MAX_URI
], /* Host portion of URI */
8958 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8959 int port
; /* Port portion of URI */
8962 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
8963 con
->http
.fd
, uri
->values
[0].string
.text
);
8966 * See if we have a job URI or a printer URI...
8969 if (!strcmp(uri
->name
, "printer-uri"))
8972 * Got a printer URI; see if we also have a job-id attribute...
8975 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8976 IPP_TAG_INTEGER
)) == NULL
)
8978 send_ipp_status(con
, IPP_BAD_REQUEST
,
8979 _("Got a printer-uri attribute but no job-id."));
8983 jobid
= attr
->values
[0].integer
;
8988 * Got a job URI; parse it to get the job ID...
8991 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8992 sizeof(scheme
), username
, sizeof(username
), host
,
8993 sizeof(host
), &port
, resource
, sizeof(resource
));
8995 if (strncmp(resource
, "/jobs/", 6))
9001 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9002 uri
->values
[0].string
.text
);
9006 jobid
= atoi(resource
+ 6);
9010 * See if the job exists...
9013 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9016 * Nope - return a "not found" error...
9019 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9024 * See if job is in any of the "completed" states...
9027 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9030 * Nope - return a "not possible" error...
9033 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9039 * See if we have retained the job files...
9044 if (!job
->attrs
|| job
->num_files
== 0)
9047 * Nope - return a "not possible" error...
9050 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9051 _("Job #%d cannot be restarted - no files."), jobid
);
9056 * See if the job is owned by the requesting user...
9059 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9061 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9062 cupsdFindDest(job
->dest
));
9067 * See if the job-hold-until attribute is specified...
9070 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9071 IPP_TAG_KEYWORD
)) == NULL
)
9072 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9074 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9077 * Return the job to a held state...
9080 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9081 "Restarted by \"%s\" with job-hold-until=%s.",
9082 username
, attr
->values
[0].string
.text
);
9083 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9085 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9086 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9087 attr
->values
[0].string
.text
);
9092 * Restart the job...
9095 cupsdRestartJob(job
);
9099 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9101 con
->response
->request
.status
.status_code
= IPP_OK
;
9106 * 'save_auth_info()' - Save authentication information for a job.
9111 cupsd_client_t
*con
, /* I - Client connection */
9112 cupsd_job_t
*job
, /* I - Job */
9113 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9115 int i
; /* Looping var */
9116 char filename
[1024]; /* Job authentication filename */
9117 cups_file_t
*fp
; /* Job authentication file */
9118 char line
[65536]; /* Line for file */
9119 cupsd_printer_t
*dest
; /* Destination printer/class */
9123 * This function saves the in-memory authentication information for
9124 * a job so that it can be used to authenticate with a remote host.
9125 * The information is stored in a file that is readable only by the
9126 * root user. The fields are Base-64 encoded, each on a separate line,
9127 * followed by random number (up to 1024) of newlines to limit the
9128 * amount of information that is exposed.
9130 * Because of the potential for exposing of authentication information,
9131 * this functionality is only enabled when running cupsd as root.
9133 * This caching only works for the Basic and BasicDigest authentication
9134 * types. Digest authentication cannot be cached this way, and in
9135 * the future Kerberos authentication may make all of this obsolete.
9137 * Authentication information is saved whenever an authenticated
9138 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9141 * This information is deleted after a job is completed or canceled,
9142 * so reprints may require subsequent re-authentication.
9148 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9152 * Create the authentication file and change permissions...
9155 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9156 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9158 cupsdLogMessage(CUPSD_LOG_ERROR
,
9159 "Unable to save authentication info to \"%s\" - %s",
9160 filename
, strerror(errno
));
9164 fchown(cupsFileNumber(fp
), 0, 0);
9165 fchmod(cupsFileNumber(fp
), 0400);
9167 cupsFilePuts(fp
, "CUPSD-AUTH-V2\n");
9170 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9172 cupsdClearString(job
->auth_env
+ i
);
9174 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9177 * Write 1 to 3 auth values...
9181 i
< auth_info
->num_values
&&
9182 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9185 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9186 strlen(auth_info
->values
[i
].string
.text
));
9187 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9189 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9190 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9191 auth_info
->values
[i
].string
.text
);
9192 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9193 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9194 auth_info
->values
[i
].string
.text
);
9195 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9196 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9197 auth_info
->values
[i
].string
.text
);
9198 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9199 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9200 auth_info
->values
[i
].string
.text
);
9205 else if (auth_info
&& auth_info
->num_values
== 2 &&
9206 dest
->num_auth_info_required
== 1 &&
9207 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9210 * Allow fallback to username+password for Kerberized queues...
9213 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
,
9214 strlen(auth_info
->values
[0].string
.text
));
9215 cupsFilePutConf(fp
, "username", line
);
9217 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9218 auth_info
->values
[0].string
.text
);
9220 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
,
9221 strlen(auth_info
->values
[1].string
.text
));
9222 cupsFilePutConf(fp
, "password", line
);
9224 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9225 auth_info
->values
[1].string
.text
);
9227 else if (con
->username
[0])
9230 * Write the authenticated username...
9233 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9234 cupsFilePutConf(fp
, "username", line
);
9236 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9239 * Write the authenticated password...
9242 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9243 cupsFilePutConf(fp
, "password", line
);
9245 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9249 if (con
->gss_uid
> 0)
9251 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9252 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9254 #endif /* HAVE_GSSAPI */
9257 * Write a random number of newlines to the end of the file...
9260 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9261 cupsFilePutChar(fp
, '\n');
9264 * Close the file and return...
9272 * 'send_document()' - Send a file to a printer or class.
9276 send_document(cupsd_client_t
*con
, /* I - Client connection */
9277 ipp_attribute_t
*uri
) /* I - Printer URI */
9279 ipp_attribute_t
*attr
; /* Current attribute */
9280 ipp_attribute_t
*format
; /* Request's document-format attribute */
9281 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9282 const char *default_format
;/* document-format-default value */
9283 int jobid
; /* Job ID number */
9284 cupsd_job_t
*job
; /* Current job */
9285 char job_uri
[HTTP_MAX_URI
],
9287 scheme
[HTTP_MAX_URI
],
9288 /* Method portion of URI */
9289 username
[HTTP_MAX_URI
],
9290 /* Username portion of URI */
9292 /* Host portion of URI */
9293 resource
[HTTP_MAX_URI
];
9294 /* Resource portion of URI */
9295 int port
; /* Port portion of URI */
9296 mime_type_t
*filetype
; /* Type of file */
9297 char super
[MIME_MAX_SUPER
],
9298 /* Supertype of file */
9299 type
[MIME_MAX_TYPE
],
9300 /* Subtype of file */
9301 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9302 /* Textual name of mime type */
9303 char filename
[1024]; /* Job filename */
9304 cupsd_printer_t
*printer
; /* Current printer */
9305 struct stat fileinfo
; /* File information */
9306 int kbytes
; /* Size of file */
9307 int compression
; /* Type of compression */
9308 int start_job
; /* Start the job? */
9311 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9312 con
->http
.fd
, uri
->values
[0].string
.text
);
9315 * See if we have a job URI or a printer URI...
9318 if (!strcmp(uri
->name
, "printer-uri"))
9321 * Got a printer URI; see if we also have a job-id attribute...
9324 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9325 IPP_TAG_INTEGER
)) == NULL
)
9327 send_ipp_status(con
, IPP_BAD_REQUEST
,
9328 _("Got a printer-uri attribute but no job-id."));
9332 jobid
= attr
->values
[0].integer
;
9337 * Got a job URI; parse it to get the job ID...
9340 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9341 sizeof(scheme
), username
, sizeof(username
), host
,
9342 sizeof(host
), &port
, resource
, sizeof(resource
));
9344 if (strncmp(resource
, "/jobs/", 6))
9350 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9351 uri
->values
[0].string
.text
);
9355 jobid
= atoi(resource
+ 6);
9359 * See if the job exists...
9362 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9365 * Nope - return a "not found" error...
9368 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9372 printer
= cupsdFindDest(job
->dest
);
9375 * See if the job is owned by the requesting user...
9378 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9380 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9381 cupsdFindDest(job
->dest
));
9386 * OK, see if the client is sending the document compressed - CUPS
9387 * only supports "none" and "gzip".
9390 compression
= CUPS_FILE_NONE
;
9392 if ((attr
= ippFindAttribute(con
->request
, "compression",
9393 IPP_TAG_KEYWORD
)) != NULL
)
9395 if (strcmp(attr
->values
[0].string
.text
, "none")
9397 && strcmp(attr
->values
[0].string
.text
, "gzip")
9398 #endif /* HAVE_LIBZ */
9401 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9402 attr
->values
[0].string
.text
);
9403 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9404 "compression", NULL
, attr
->values
[0].string
.text
);
9409 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9410 compression
= CUPS_FILE_GZIP
;
9411 #endif /* HAVE_LIBZ */
9415 * Do we have a file to print?
9418 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9419 IPP_TAG_BOOLEAN
)) == NULL
)
9421 send_ipp_status(con
, IPP_BAD_REQUEST
,
9422 _("Missing last-document attribute in request."));
9429 * Check for an empty request with "last-document" set to true, which is
9430 * used to close an "open" job by RFC 2911, section 3.3.2.
9433 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9436 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9441 * Is it a format we support?
9444 if ((format
= ippFindAttribute(con
->request
, "document-format",
9445 IPP_TAG_MIMETYPE
)) != NULL
)
9448 * Grab format from client...
9451 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9454 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9455 format
->values
[0].string
.text
);
9459 else if ((default_format
= cupsGetOption("document-format",
9460 printer
->num_options
,
9461 printer
->options
)) != NULL
)
9464 * Use default document format...
9467 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9469 send_ipp_status(con
, IPP_BAD_REQUEST
,
9470 _("Bad document-format-default \"%s\"."), default_format
);
9477 * No document format attribute? Auto-type it!
9480 strcpy(super
, "application");
9481 strcpy(type
, "octet-stream");
9484 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9487 * Auto-type the file...
9490 ipp_attribute_t
*doc_name
; /* document-name attribute */
9493 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9495 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9496 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9497 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9501 filetype
= mimeType(MimeDatabase
, super
, type
);
9504 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9505 filetype
->super
, filetype
->type
);
9508 filetype
= mimeType(MimeDatabase
, super
, type
);
9513 * Replace the document-format attribute value with the auto-typed or
9517 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9520 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9521 IPP_TAG_MIMETYPE
)) != NULL
)
9523 _cupsStrFree(jformat
->values
[0].string
.text
);
9525 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9528 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9529 "document-format", NULL
, mimetype
);
9533 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9534 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9535 cupsdLogMessage(CUPSD_LOG_INFO
,
9536 "Hint: Do you have the raw file printing rules enabled?");
9539 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9540 "document-format", NULL
, format
->values
[0].string
.text
);
9545 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9547 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9550 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9551 _("Unsupported document-format \"%s\"."), mimetype
);
9553 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9554 "document-format", NULL
, mimetype
);
9560 * Add the file to the job...
9565 if (add_file(con
, job
, filetype
, compression
))
9568 if (stat(con
->filename
, &fileinfo
))
9571 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9573 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9575 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9576 IPP_TAG_INTEGER
)) != NULL
)
9577 attr
->values
[0].integer
+= kbytes
;
9579 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9581 rename(con
->filename
, filename
);
9583 cupsdClearString(&con
->filename
);
9585 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9586 filetype
->super
, filetype
->type
, job
->username
);
9589 * Start the job if this is the last document...
9594 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9595 IPP_TAG_BOOLEAN
)) != NULL
&&
9596 attr
->values
[0].boolean
)
9599 * See if we need to add the ending sheet...
9602 if (cupsdTimeoutJob(job
))
9605 if (job
->state_value
== IPP_JOB_STOPPED
)
9607 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9608 job
->state_value
= IPP_JOB_PENDING
;
9610 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9612 else if (job
->state_value
== IPP_JOB_HELD
)
9614 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9615 IPP_TAG_KEYWORD
)) == NULL
)
9616 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9618 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9620 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9621 job
->state_value
= IPP_JOB_PENDING
;
9623 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9626 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9630 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9636 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9637 IPP_TAG_KEYWORD
)) == NULL
)
9638 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9640 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9642 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9643 job
->state_value
= IPP_JOB_HELD
;
9644 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9646 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9649 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9656 * Fill in the response info...
9659 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9660 con
->servername
, con
->serverport
, "/jobs/%d", jobid
);
9661 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9664 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9666 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9668 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9669 NULL
, job
->reasons
->values
[0].string
.text
);
9671 con
->response
->request
.status
.status_code
= IPP_OK
;
9674 * Start the job if necessary...
9683 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9688 cupsd_client_t
*con
, /* I - Client connection */
9689 http_status_t status
, /* I - HTTP status code */
9690 cupsd_printer_t
*printer
) /* I - Printer, if any */
9692 ipp_attribute_t
*uri
; /* Request URI, if any */
9695 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9696 IPP_TAG_URI
)) == NULL
)
9697 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9699 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9700 "Returning HTTP %s for %s (%s) from %s",
9703 ippOpString(con
->request
->request
.op
.operation_id
) :
9705 uri
? uri
->values
[0].string
.text
: "no URI",
9706 con
->http
.hostname
);
9710 int auth_type
; /* Type of authentication required */
9713 auth_type
= CUPSD_AUTH_NONE
;
9715 if (status
== HTTP_UNAUTHORIZED
&&
9716 printer
->num_auth_info_required
> 0 &&
9717 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9719 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9720 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9721 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9724 * Creating and authenticating jobs requires Kerberos...
9727 auth_type
= CUPSD_AUTH_NEGOTIATE
;
9732 * Use policy/location-defined authentication requirements...
9735 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9736 cupsd_location_t
*auth
; /* Pointer to authentication element */
9739 if (printer
->type
& CUPS_PRINTER_CLASS
)
9740 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9742 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9744 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9745 auth
->type
== CUPSD_AUTH_NONE
)
9746 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9748 con
->request
->request
.op
.operation_id
:
9753 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9754 auth_type
= cupsdDefaultAuthType();
9756 auth_type
= auth
->type
;
9760 cupsdSendError(con
, status
, auth_type
);
9763 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9765 ippDelete(con
->response
);
9766 con
->response
= NULL
;
9773 * 'send_ipp_status()' - Send a status back to the IPP client.
9777 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9778 ipp_status_t status
, /* I - IPP status code */
9779 const char *message
,/* I - Status message */
9780 ...) /* I - Additional args as needed */
9782 va_list ap
; /* Pointer to additional args */
9783 char formatted
[1024]; /* Formatted errror message */
9786 va_start(ap
, message
);
9787 vsnprintf(formatted
, sizeof(formatted
),
9788 _cupsLangString(con
->language
, message
), ap
);
9791 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9792 ippOpString(con
->request
->request
.op
.operation_id
),
9793 ippErrorString(status
), formatted
);
9795 con
->response
->request
.status
.status_code
= status
;
9797 if (ippFindAttribute(con
->response
, "attributes-charset",
9798 IPP_TAG_ZERO
) == NULL
)
9799 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9800 "attributes-charset", NULL
, "utf-8");
9802 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9803 IPP_TAG_ZERO
) == NULL
)
9804 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9805 "attributes-natural-language", NULL
, DefaultLanguage
);
9807 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9808 "status-message", NULL
, formatted
);
9813 * 'set_default()' - Set the default destination...
9817 set_default(cupsd_client_t
*con
, /* I - Client connection */
9818 ipp_attribute_t
*uri
) /* I - Printer URI */
9820 http_status_t status
; /* Policy status */
9821 cups_ptype_t dtype
; /* Destination type (printer/class) */
9822 cupsd_printer_t
*printer
, /* Printer */
9823 *oldprinter
; /* Old default printer */
9826 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9827 con
->http
.fd
, uri
->values
[0].string
.text
);
9830 * Is the destination valid?
9833 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9839 send_ipp_status(con
, IPP_NOT_FOUND
,
9840 _("The printer or class does not exist."));
9848 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9850 send_http_error(con
, status
, NULL
);
9855 * Set it as the default...
9858 oldprinter
= DefaultPrinter
;
9859 DefaultPrinter
= printer
;
9862 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
9863 "%s is no longer the default printer.", oldprinter
->name
);
9865 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9866 "%s is now the default printer.", printer
->name
);
9868 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
9869 CUPSD_DIRTY_PRINTCAP
);
9871 cupsdLogMessage(CUPSD_LOG_INFO
,
9872 "Default destination set to \"%s\" by \"%s\".",
9873 printer
->name
, get_username(con
));
9876 * Everything was ok, so return OK status...
9879 con
->response
->request
.status
.status_code
= IPP_OK
;
9884 * 'set_job_attrs()' - Set job attributes.
9888 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9889 ipp_attribute_t
*uri
) /* I - Job URI */
9891 ipp_attribute_t
*attr
, /* Current attribute */
9892 *attr2
; /* Job attribute */
9893 int jobid
; /* Job ID */
9894 cupsd_job_t
*job
; /* Current job */
9895 char scheme
[HTTP_MAX_URI
],
9896 /* Method portion of URI */
9897 username
[HTTP_MAX_URI
],
9898 /* Username portion of URI */
9900 /* Host portion of URI */
9901 resource
[HTTP_MAX_URI
];
9902 /* Resource portion of URI */
9903 int port
; /* Port portion of URI */
9904 int event
; /* Events? */
9905 int check_jobs
; /* Check jobs? */
9908 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9909 con
->http
.fd
, uri
->values
[0].string
.text
);
9912 * Start with "everything is OK" status...
9915 con
->response
->request
.status
.status_code
= IPP_OK
;
9918 * See if we have a job URI or a printer URI...
9921 if (!strcmp(uri
->name
, "printer-uri"))
9924 * Got a printer URI; see if we also have a job-id attribute...
9927 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9928 IPP_TAG_INTEGER
)) == NULL
)
9930 send_ipp_status(con
, IPP_BAD_REQUEST
,
9931 _("Got a printer-uri attribute but no job-id."));
9935 jobid
= attr
->values
[0].integer
;
9940 * Got a job URI; parse it to get the job ID...
9943 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9944 sizeof(scheme
), username
, sizeof(username
), host
,
9945 sizeof(host
), &port
, resource
, sizeof(resource
));
9947 if (strncmp(resource
, "/jobs/", 6))
9953 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9954 uri
->values
[0].string
.text
);
9958 jobid
= atoi(resource
+ 6);
9962 * See if the job exists...
9965 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9968 * Nope - return a "not found" error...
9971 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9976 * See if the job has been completed...
9979 if (job
->state_value
> IPP_JOB_STOPPED
)
9982 * Return a "not-possible" error...
9985 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9986 _("Job #%d is finished and cannot be altered."), jobid
);
9991 * See if the job is owned by the requesting user...
9994 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9996 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9997 cupsdFindDest(job
->dest
));
10002 * See what the user wants to change.
10010 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10012 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10015 if (!strcmp(attr
->name
, "attributes-charset") ||
10016 !strcmp(attr
->name
, "attributes-natural-language") ||
10017 !strcmp(attr
->name
, "document-compression") ||
10018 !strcmp(attr
->name
, "document-format") ||
10019 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10020 !strcmp(attr
->name
, "job-document-access-errors") ||
10021 !strcmp(attr
->name
, "job-id") ||
10022 !strcmp(attr
->name
, "job-impressions-completed") ||
10023 !strcmp(attr
->name
, "job-k-octets") ||
10024 !strcmp(attr
->name
, "job-originating-host-name") ||
10025 !strcmp(attr
->name
, "job-originating-user-name") ||
10026 !strcmp(attr
->name
, "job-printer-up-time") ||
10027 !strcmp(attr
->name
, "job-printer-uri") ||
10028 !strcmp(attr
->name
, "job-sheets") ||
10029 !strcmp(attr
->name
, "job-state-message") ||
10030 !strcmp(attr
->name
, "job-state-reasons") ||
10031 !strcmp(attr
->name
, "job-uri") ||
10032 !strcmp(attr
->name
, "number-of-documents") ||
10033 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10034 !strcmp(attr
->name
, "output-device-assigned") ||
10035 !strncmp(attr
->name
, "date-time-at-", 13) ||
10036 !strncmp(attr
->name
, "job-k-octets", 12) ||
10037 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10038 !strncmp(attr
->name
, "time-at-", 8))
10044 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10045 _("%s cannot be changed."), attr
->name
);
10047 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10048 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10052 if (!strcmp(attr
->name
, "job-priority"))
10055 * Change the job priority...
10058 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10060 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10062 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10063 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10065 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10067 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10068 _("Job is completed and cannot be changed."));
10071 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10073 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10074 attr
->values
[0].integer
);
10075 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10078 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10079 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10082 else if (!strcmp(attr
->name
, "job-state"))
10085 * Change the job state...
10088 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10090 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10092 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10093 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10097 switch (attr
->values
[0].integer
)
10099 case IPP_JOB_PENDING
:
10100 case IPP_JOB_HELD
:
10101 if (job
->state_value
> IPP_JOB_HELD
)
10103 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10104 _("Job state cannot be changed."));
10107 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10109 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10110 attr
->values
[0].integer
);
10111 cupsdSetJobState(job
, attr
->values
[0].integer
,
10113 "Job state changed by \"%s\"", username
);
10118 case IPP_JOB_PROCESSING
:
10119 case IPP_JOB_STOPPED
:
10120 if (job
->state_value
!= attr
->values
[0].integer
)
10122 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10123 _("Job state cannot be changed."));
10128 case IPP_JOB_CANCELED
:
10129 case IPP_JOB_ABORTED
:
10130 case IPP_JOB_COMPLETED
:
10131 if (job
->state_value
> IPP_JOB_PROCESSING
)
10133 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10134 _("Job state cannot be changed."));
10137 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10139 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10140 attr
->values
[0].integer
);
10141 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10143 "Job state changed by \"%s\"", username
);
10150 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10152 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10153 IPP_TAG_ZERO
)) != NULL
)
10156 * Some other value; first free the old value...
10159 if (job
->attrs
->prev
)
10160 job
->attrs
->prev
->next
= attr2
->next
;
10162 job
->attrs
->attrs
= attr2
->next
;
10164 if (job
->attrs
->last
== attr2
)
10165 job
->attrs
->last
= job
->attrs
->prev
;
10167 ippDeleteAttribute(NULL
, attr2
);
10170 * Then copy the attribute...
10173 ippCopyAttribute(job
->attrs
, attr
, 0);
10176 * See if the job-name or job-hold-until is being changed.
10179 if (!strcmp(attr
->name
, "job-hold-until"))
10181 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10182 attr
->values
[0].string
.text
);
10183 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10185 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10187 cupsdReleaseJob(job
);
10191 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10192 "Job held by \"%s\".", username
);
10194 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10197 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10200 * Delete the attribute...
10203 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10204 IPP_TAG_ZERO
)) != NULL
)
10206 if (job
->attrs
->prev
)
10207 job
->attrs
->prev
->next
= attr2
->next
;
10209 job
->attrs
->attrs
= attr2
->next
;
10211 if (attr2
== job
->attrs
->last
)
10212 job
->attrs
->last
= job
->attrs
->prev
;
10214 ippDeleteAttribute(NULL
, attr2
);
10216 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10222 * Add new option by copying it...
10225 ippCopyAttribute(job
->attrs
, attr
, 0);
10227 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10236 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10239 * Send events as needed...
10242 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10243 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10244 cupsdFindDest(job
->dest
), job
,
10245 "Job priority changed by user.");
10247 if (event
& CUPSD_EVENT_JOB_STATE
)
10248 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10249 job
->state_value
== IPP_JOB_HELD
?
10250 "Job held by user." : "Job restarted by user.");
10252 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10253 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10254 "Job options changed by user.");
10257 * Start jobs if possible...
10266 * 'set_printer_attrs()' - Set printer attributes.
10270 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10271 ipp_attribute_t
*uri
) /* I - Printer */
10273 http_status_t status
; /* Policy status */
10274 cups_ptype_t dtype
; /* Destination type (printer/class) */
10275 cupsd_printer_t
*printer
; /* Printer/class */
10276 ipp_attribute_t
*attr
; /* Printer attribute */
10277 int changed
= 0; /* Was anything changed? */
10280 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10281 con
->http
.fd
, uri
->values
[0].string
.text
);
10284 * Is the destination valid?
10287 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10293 send_ipp_status(con
, IPP_NOT_FOUND
,
10294 _("The printer or class does not exist."));
10302 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10304 send_http_error(con
, status
, printer
);
10309 * Return a list of attributes that can be set via Set-Printer-Attributes.
10312 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10313 IPP_TAG_TEXT
)) != NULL
)
10315 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10319 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10320 IPP_TAG_TEXT
)) != NULL
)
10322 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10327 * Update the printer attributes and return...
10332 cupsdSetPrinterAttrs(printer
);
10333 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10335 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10336 "Printer \"%s\" description or location changed by \"%s\".",
10337 printer
->name
, get_username(con
));
10339 cupsdLogMessage(CUPSD_LOG_INFO
,
10340 "Printer \"%s\" description or location changed by \"%s\".",
10341 printer
->name
, get_username(con
));
10344 con
->response
->request
.status
.status_code
= IPP_OK
;
10349 * 'set_printer_defaults()' - Set printer default options from a request.
10353 set_printer_defaults(
10354 cupsd_client_t
*con
, /* I - Client connection */
10355 cupsd_printer_t
*printer
) /* I - Printer */
10357 int i
; /* Looping var */
10358 ipp_attribute_t
*attr
; /* Current attribute */
10359 int namelen
; /* Length of attribute name */
10360 char name
[256], /* New attribute name */
10361 value
[256]; /* String version of integer attrs */
10364 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10367 * Skip non-printer attributes...
10370 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10373 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10375 if (!strcmp(attr
->name
, "job-sheets-default"))
10378 * Only allow keywords and names...
10381 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10385 * Only allow job-sheets-default to be set when running without a
10386 * system high classification level...
10389 if (Classification
)
10392 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10394 if (attr
->num_values
> 1)
10395 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10397 cupsdSetString(&printer
->job_sheets
[1], "none");
10399 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10401 cupsdFreeStrings(&(printer
->users
));
10403 printer
->deny_users
= 0;
10405 if (attr
->value_tag
== IPP_TAG_NAME
&&
10406 (attr
->num_values
> 1 ||
10407 strcmp(attr
->values
[0].string
.text
, "all")))
10409 for (i
= 0; i
< attr
->num_values
; i
++)
10410 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10413 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10415 cupsdFreeStrings(&(printer
->users
));
10417 printer
->deny_users
= 1;
10419 if (attr
->value_tag
== IPP_TAG_NAME
&&
10420 (attr
->num_values
> 1 ||
10421 strcmp(attr
->values
[0].string
.text
, "none")))
10423 for (i
= 0; i
< attr
->num_values
; i
++)
10424 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10427 else if (!strcmp(attr
->name
, "job-quota-period"))
10429 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10432 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10433 attr
->values
[0].integer
);
10434 cupsdFreeQuotas(printer
);
10436 printer
->quota_period
= attr
->values
[0].integer
;
10438 else if (!strcmp(attr
->name
, "job-k-limit"))
10440 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10443 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10444 attr
->values
[0].integer
);
10445 cupsdFreeQuotas(printer
);
10447 printer
->k_limit
= attr
->values
[0].integer
;
10449 else if (!strcmp(attr
->name
, "job-page-limit"))
10451 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10454 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10455 attr
->values
[0].integer
);
10456 cupsdFreeQuotas(printer
);
10458 printer
->page_limit
= attr
->values
[0].integer
;
10460 else if (!strcmp(attr
->name
, "printer-op-policy"))
10462 cupsd_policy_t
*p
; /* Policy */
10465 if (attr
->value_tag
!= IPP_TAG_NAME
)
10468 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10470 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10471 "Setting printer-op-policy to \"%s\"...",
10472 attr
->values
[0].string
.text
);
10473 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10474 printer
->op_policy_ptr
= p
;
10478 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10479 _("Unknown printer-op-policy \"%s\"."),
10480 attr
->values
[0].string
.text
);
10484 else if (!strcmp(attr
->name
, "printer-error-policy"))
10486 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10489 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10490 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10491 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10492 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10493 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10495 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10496 _("Unknown printer-error-policy \"%s\"."),
10497 attr
->values
[0].string
.text
);
10501 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10502 "Setting printer-error-policy to \"%s\"...",
10503 attr
->values
[0].string
.text
);
10504 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10508 * Skip any other non-default attributes...
10511 namelen
= strlen(attr
->name
);
10512 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10513 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10517 * OK, anything else must be a user-defined default...
10520 strlcpy(name
, attr
->name
, sizeof(name
));
10521 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10523 switch (attr
->value_tag
)
10525 case IPP_TAG_DELETEATTR
:
10526 printer
->num_options
= cupsRemoveOption(name
,
10527 printer
->num_options
,
10528 &(printer
->options
));
10529 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10530 "Deleting %s", attr
->name
);
10533 case IPP_TAG_NAME
:
10534 case IPP_TAG_KEYWORD
:
10536 printer
->num_options
= cupsAddOption(name
,
10537 attr
->values
[0].string
.text
,
10538 printer
->num_options
,
10539 &(printer
->options
));
10540 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10541 "Setting %s to \"%s\"...", attr
->name
,
10542 attr
->values
[0].string
.text
);
10545 case IPP_TAG_BOOLEAN
:
10546 printer
->num_options
= cupsAddOption(name
,
10547 attr
->values
[0].boolean
?
10549 printer
->num_options
,
10550 &(printer
->options
));
10551 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10552 "Setting %s to %s...", attr
->name
,
10553 attr
->values
[0].boolean
? "true" : "false");
10556 case IPP_TAG_INTEGER
:
10557 case IPP_TAG_ENUM
:
10558 sprintf(value
, "%d", attr
->values
[0].integer
);
10559 printer
->num_options
= cupsAddOption(name
, value
,
10560 printer
->num_options
,
10561 &(printer
->options
));
10562 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10563 "Setting %s to %s...", attr
->name
, value
);
10566 case IPP_TAG_RANGE
:
10567 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10568 attr
->values
[0].range
.upper
);
10569 printer
->num_options
= cupsAddOption(name
, value
,
10570 printer
->num_options
,
10571 &(printer
->options
));
10572 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10573 "Setting %s to %s...", attr
->name
, value
);
10576 case IPP_TAG_RESOLUTION
:
10577 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10578 attr
->values
[0].resolution
.yres
,
10579 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10581 printer
->num_options
= cupsAddOption(name
, value
,
10582 printer
->num_options
,
10583 &(printer
->options
));
10584 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10585 "Setting %s to %s...", attr
->name
, value
);
10589 /* Do nothing for other values */
10597 * 'start_printer()' - Start a printer.
10601 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10602 ipp_attribute_t
*uri
) /* I - Printer URI */
10604 int i
; /* Temporary variable */
10605 http_status_t status
; /* Policy status */
10606 cups_ptype_t dtype
; /* Destination type (printer/class) */
10607 cupsd_printer_t
*printer
; /* Printer data */
10610 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10611 con
->http
.fd
, uri
->values
[0].string
.text
);
10614 * Is the destination valid?
10617 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10623 send_ipp_status(con
, IPP_NOT_FOUND
,
10624 _("The printer or class does not exist."));
10632 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10634 send_http_error(con
, status
, printer
);
10639 * Start the printer...
10642 printer
->state_message
[0] = '\0';
10644 cupsdStartPrinter(printer
, 1);
10646 if (dtype
& CUPS_PRINTER_CLASS
)
10647 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10648 printer
->name
, get_username(con
));
10650 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10651 printer
->name
, get_username(con
));
10659 if ((i
= check_quotas(con
, printer
)) < 0)
10661 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10666 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10671 * Everything was ok, so return OK status...
10674 con
->response
->request
.status
.status_code
= IPP_OK
;
10679 * 'stop_printer()' - Stop a printer.
10683 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10684 ipp_attribute_t
*uri
) /* I - Printer URI */
10686 http_status_t status
; /* Policy status */
10687 cups_ptype_t dtype
; /* Destination type (printer/class) */
10688 cupsd_printer_t
*printer
; /* Printer data */
10689 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10692 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10693 con
->http
.fd
, uri
->values
[0].string
.text
);
10696 * Is the destination valid?
10699 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10705 send_ipp_status(con
, IPP_NOT_FOUND
,
10706 _("The printer or class does not exist."));
10714 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10716 send_http_error(con
, status
, printer
);
10721 * Stop the printer...
10724 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10725 IPP_TAG_TEXT
)) == NULL
)
10726 strcpy(printer
->state_message
, "Paused");
10729 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10730 sizeof(printer
->state_message
));
10733 cupsdStopPrinter(printer
, 1);
10735 if (dtype
& CUPS_PRINTER_CLASS
)
10736 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10737 printer
->name
, get_username(con
));
10739 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10740 printer
->name
, get_username(con
));
10743 * Everything was ok, so return OK status...
10746 con
->response
->request
.status
.status_code
= IPP_OK
;
10751 * 'url_encode_attr()' - URL-encode a string attribute.
10755 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10756 char *buffer
,/* I - String buffer */
10757 int bufsize
)/* I - Size of buffer */
10759 int i
; /* Looping var */
10760 char *bufptr
, /* Pointer into buffer */
10761 *bufend
; /* End of buffer */
10764 strlcpy(buffer
, attr
->name
, bufsize
);
10765 bufptr
= buffer
+ strlen(buffer
);
10766 bufend
= buffer
+ bufsize
- 1;
10768 for (i
= 0; i
< attr
->num_values
; i
++)
10770 if (bufptr
>= bufend
)
10778 if (bufptr
>= bufend
)
10783 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
10784 bufptr
, bufend
- bufptr
+ 1);
10786 if (bufptr
>= bufend
)
10797 * 'url_encode_string()' - URL-encode a string.
10800 static char * /* O - End of string */
10801 url_encode_string(const char *s
, /* I - String */
10802 char *buffer
, /* I - String buffer */
10803 int bufsize
) /* I - Size of buffer */
10805 char *bufptr
, /* Pointer into buffer */
10806 *bufend
; /* End of buffer */
10807 static const char *hex
= "0123456789ABCDEF";
10812 bufend
= buffer
+ bufsize
- 1;
10814 while (*s
&& bufptr
< bufend
)
10816 if (*s
== ' ' || *s
== '%' || *s
== '+')
10818 if (bufptr
>= (bufend
- 2))
10822 *bufptr
++ = hex
[(*s
>> 4) & 15];
10823 *bufptr
++ = hex
[*s
& 15];
10827 else if (*s
== '\'' || *s
== '\\')
10829 if (bufptr
>= (bufend
- 1))
10846 * 'user_allowed()' - See if a user is allowed to print to a queue.
10849 static int /* O - 0 if not allowed, 1 if allowed */
10850 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10851 const char *username
) /* I - Username */
10853 struct passwd
*pw
; /* User password data */
10854 char baseuser
[256], /* Base username */
10855 *baseptr
, /* Pointer to "@" in base username */
10856 *name
; /* Current user name */
10859 if (cupsArrayCount(p
->users
) == 0)
10862 if (!strcmp(username
, "root"))
10865 if (strchr(username
, '@'))
10868 * Strip @REALM for username check...
10871 strlcpy(baseuser
, username
, sizeof(baseuser
));
10873 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10876 username
= baseuser
;
10879 pw
= getpwnam(username
);
10882 for (name
= (char *)cupsArrayFirst(p
->users
);
10884 name
= (char *)cupsArrayNext(p
->users
))
10886 if (name
[0] == '@')
10889 * Check group membership...
10892 if (cupsdCheckGroup(username
, pw
, name
+ 1))
10895 else if (name
[0] == '#')
10901 if (cupsdCheckGroup(username
, pw
, name
))
10904 else if (!_cups_strcasecmp(username
, name
))
10908 return ((name
!= NULL
) != p
->deny_users
);
10913 * 'validate_job()' - Validate printer options and destination.
10917 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10918 ipp_attribute_t
*uri
) /* I - Printer URI */
10920 http_status_t status
; /* Policy status */
10921 ipp_attribute_t
*attr
, /* Current attribute */
10922 *auth_info
; /* auth-info attribute */
10923 ipp_attribute_t
*format
; /* Document-format attribute */
10924 cups_ptype_t dtype
; /* Destination type (printer/class) */
10925 char super
[MIME_MAX_SUPER
],
10926 /* Supertype of file */
10927 type
[MIME_MAX_TYPE
];
10928 /* Subtype of file */
10929 cupsd_printer_t
*printer
; /* Printer */
10932 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10933 con
->http
.fd
, uri
->values
[0].string
.text
);
10936 * OK, see if the client is sending the document compressed - CUPS
10937 * doesn't support compression yet...
10940 if ((attr
= ippFindAttribute(con
->request
, "compression",
10941 IPP_TAG_KEYWORD
)) != NULL
)
10943 if (strcmp(attr
->values
[0].string
.text
, "none")
10945 && strcmp(attr
->values
[0].string
.text
, "gzip")
10946 #endif /* HAVE_LIBZ */
10949 send_ipp_status(con
, IPP_ATTRIBUTES
,
10950 _("Unsupported compression \"%s\"."),
10951 attr
->values
[0].string
.text
);
10952 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10953 "compression", NULL
, attr
->values
[0].string
.text
);
10959 * Is it a format we support?
10962 if ((format
= ippFindAttribute(con
->request
, "document-format",
10963 IPP_TAG_MIMETYPE
)) != NULL
)
10965 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10968 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
10969 format
->values
[0].string
.text
);
10973 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
10974 !mimeType(MimeDatabase
, super
, type
))
10976 cupsdLogMessage(CUPSD_LOG_INFO
,
10977 "Hint: Do you have the raw file printing rules enabled?");
10978 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10979 _("Unsupported document-format \"%s\"."),
10980 format
->values
[0].string
.text
);
10981 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10982 "document-format", NULL
, format
->values
[0].string
.text
);
10988 * Is the destination valid?
10991 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10997 send_ipp_status(con
, IPP_NOT_FOUND
,
10998 _("The printer or class does not exist."));
11006 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11008 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11010 send_http_error(con
, status
, printer
);
11013 else if (printer
->num_auth_info_required
== 1 &&
11014 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11017 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11021 else if (auth_info
&& !con
->http
.tls
&&
11022 !httpAddrLocalhost(con
->http
.hostaddr
))
11025 * Require encryption of auth-info over non-local connections...
11028 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11031 #endif /* HAVE_SSL */
11034 * Everything was ok, so return OK status...
11037 con
->response
->request
.status
.status_code
= IPP_OK
;
11042 * 'validate_name()' - Make sure the printer name only contains valid chars.
11045 static int /* O - 0 if name is no good, 1 if good */
11046 validate_name(const char *name
) /* I - Name to check */
11048 const char *ptr
; /* Pointer into name */
11052 * Scan the whole name...
11055 for (ptr
= name
; *ptr
; ptr
++)
11056 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11060 * All the characters are good; validate the length, too...
11063 return ((ptr
- name
) < 128);
11068 * 'validate_user()' - Validate the user for the request.
11071 static int /* O - 1 if permitted, 0 otherwise */
11072 validate_user(cupsd_job_t
*job
, /* I - Job */
11073 cupsd_client_t
*con
, /* I - Client connection */
11074 const char *owner
, /* I - Owner of job/resource */
11075 char *username
, /* O - Authenticated username */
11076 int userlen
) /* I - Length of username */
11078 cupsd_printer_t
*printer
; /* Printer for job */
11081 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11082 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11084 job
->id
, con
? con
->http
.fd
: 0,
11085 owner
? owner
: "(null)", username
, userlen
);
11088 * Validate input...
11091 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11095 * Get the best authenticated username that is available.
11098 strlcpy(username
, get_username(con
), userlen
);
11101 * Check the username against the owner...
11104 printer
= cupsdFindDest(job
->dest
);
11106 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11107 con
, owner
) == HTTP_OK
);
11112 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".