4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2012 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * This file contains Kerberos support code, copyright 2006 by
12 * These coded instructions, statements, and computer programs are the
13 * property of Apple Inc. and are protected by Federal copyright
14 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 * which should have been included with this file. If this file is
16 * file is missing or damaged, see the license at "http://www.cups.org/".
20 * cupsdProcessIPPRequest() - Process an incoming IPP request.
21 * cupsdTimeoutJob() - Timeout a job waiting on job files.
22 * accept_jobs() - Accept print jobs to a printer.
23 * add_class() - Add a class to the system.
24 * add_file() - Add a file to a job.
25 * add_job() - Add a job to a print queue.
26 * add_job_subscriptions() - Add any subscriptions for a job.
27 * add_job_uuid() - Add job-uuid attribute to a job.
28 * add_printer() - Add a printer to the system.
29 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
30 * based upon the printer state...
31 * add_queued_job_count() - Add the "queued-job-count" attribute for the
32 * specified printer or class.
33 * apply_printer_defaults() - Apply printer default options to a job.
34 * authenticate_job() - Set job authentication info.
35 * cancel_all_jobs() - Cancel all or selected print jobs.
36 * cancel_job() - Cancel a print job.
37 * cancel_subscription() - Cancel a subscription.
38 * check_rss_recipient() - Check that we do not have a duplicate RSS
40 * check_quotas() - Check quotas for a printer and user.
41 * close_job() - Close a multi-file job.
42 * copy_attrs() - Copy attributes from one request to another.
43 * copy_banner() - Copy a banner file to the requests directory
44 * for the specified job.
45 * copy_file() - Copy a PPD file or interface script...
46 * copy_model() - Copy a PPD model file, substituting default
48 * copy_job_attrs() - Copy job attributes.
49 * copy_printer_attrs() - Copy printer attributes.
50 * copy_subscription_attrs() - Copy subscription attributes.
51 * create_job() - Print a file to a printer or class.
52 * create_requested_array() - Create an array for the requested-attributes.
53 * create_subscription() - Create a notification subscription.
54 * delete_printer() - Remove a printer or class from the system.
55 * get_default() - Get the default destination.
56 * get_devices() - Get the list of available devices on the
58 * get_document() - Get a copy of a job file.
59 * get_job_attrs() - Get job attributes.
60 * get_jobs() - Get a list of jobs for the specified printer.
61 * get_notifications() - Get events for a subscription.
62 * get_ppd() - Get a named PPD from the local system.
63 * get_ppds() - Get the list of PPD files on the local
65 * get_printer_attrs() - Get printer attributes.
66 * get_printer_supported() - Get printer supported values.
67 * get_printers() - Get a list of printers or classes.
68 * get_subscription_attrs() - Get subscription attributes.
69 * get_subscriptions() - Get subscriptions.
70 * get_username() - Get the username associated with a request.
71 * hold_job() - Hold a print job.
72 * hold_new_jobs() - Hold pending/new jobs on a printer or class.
73 * move_job() - Move a job to a new destination.
74 * ppd_parse_line() - Parse a PPD default line.
75 * print_job() - Print a file to a printer or class.
76 * read_job_ticket() - Read a job ticket embedded in a print file.
77 * reject_jobs() - Reject print jobs to a printer.
78 * release_held_new_jobs() - Release pending/new jobs on a printer or
80 * release_job() - Release a held print job.
81 * renew_subscription() - Renew an existing subscription...
82 * restart_job() - Restart an old print job.
83 * save_auth_info() - Save authentication information for a job.
84 * send_document() - Send a file to a printer or class.
85 * send_http_error() - Send a HTTP error back to the IPP client.
86 * send_ipp_status() - Send a status back to the IPP client.
87 * set_default() - Set the default destination...
88 * set_job_attrs() - Set job attributes.
89 * set_printer_attrs() - Set printer attributes.
90 * set_printer_defaults() - Set printer default options from a request.
91 * start_printer() - Start a printer.
92 * stop_printer() - Stop a printer.
93 * url_encode_attr() - URL-encode a string attribute.
94 * url_encode_string() - URL-encode a string.
95 * user_allowed() - See if a user is allowed to print to a queue.
96 * validate_job() - Validate printer options and destination.
97 * validate_name() - Make sure the printer name only contains
99 * validate_user() - Validate the user for the request.
103 * Include necessary headers...
107 #include <cups/ppd-private.h>
110 /*# include <ApplicationServices/ApplicationServices.h>
111 extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
112 # include <CoreFoundation/CoreFoundation.h>*/
113 # ifdef HAVE_MEMBERSHIP_H
114 # include <membership.h>
115 # endif /* HAVE_MEMBERSHIP_H */
116 # ifdef HAVE_MEMBERSHIPPRIV_H
117 # include <membershipPriv.h>
119 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
120 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
121 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
122 # endif /* HAVE_MEMBERSHIPPRIV_H */
123 #endif /* __APPLE__ */
130 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
131 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
132 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
133 mime_type_t
*filetype
, int compression
);
134 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
135 mime_type_t
*filetype
);
136 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
137 static void add_job_uuid(cupsd_job_t
*job
);
138 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
139 static void add_printer_state_reasons(cupsd_client_t
*con
,
141 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
142 static void apply_printer_defaults(cupsd_printer_t
*printer
,
144 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
145 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
146 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
147 static void cancel_subscription(cupsd_client_t
*con
, int id
);
148 static int check_rss_recipient(const char *recipient
);
149 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
150 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
151 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
152 ipp_tag_t group
, int quickcopy
,
153 cups_array_t
*exclude
);
154 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
156 static int copy_file(const char *from
, const char *to
);
157 static int copy_model(cupsd_client_t
*con
, const char *from
,
159 static void copy_job_attrs(cupsd_client_t
*con
,
161 cups_array_t
*ra
, cups_array_t
*exclude
);
162 static void copy_printer_attrs(cupsd_client_t
*con
,
163 cupsd_printer_t
*printer
,
165 static void copy_subscription_attrs(cupsd_client_t
*con
,
166 cupsd_subscription_t
*sub
,
168 cups_array_t
*exclude
);
169 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
170 static cups_array_t
*create_requested_array(ipp_t
*request
);
171 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
172 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
173 static void get_default(cupsd_client_t
*con
);
174 static void get_devices(cupsd_client_t
*con
);
175 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
176 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
177 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
178 static void get_notifications(cupsd_client_t
*con
);
179 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
180 static void get_ppds(cupsd_client_t
*con
);
181 static void get_printers(cupsd_client_t
*con
, int type
);
182 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
183 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
184 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
185 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static const char *get_username(cupsd_client_t
*con
);
187 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
188 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
189 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static int ppd_parse_line(const char *line
, char *option
, int olen
,
191 char *choice
, int clen
);
192 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
193 static void read_job_ticket(cupsd_client_t
*con
);
194 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
195 static void release_held_new_jobs(cupsd_client_t
*con
,
196 ipp_attribute_t
*uri
);
197 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
199 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
200 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
201 ipp_attribute_t
*auth_info
);
202 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
203 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
204 cupsd_printer_t
*printer
);
205 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
206 const char *message
, ...)
207 __attribute__((__format__(__printf__
, 3, 4)));
208 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
209 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
210 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
211 static void set_printer_defaults(cupsd_client_t
*con
,
212 cupsd_printer_t
*printer
);
213 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
214 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
215 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
217 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
218 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
219 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
220 static int validate_name(const char *name
);
221 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
222 const char *owner
, char *username
,
227 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
230 int /* O - 1 on success, 0 on failure */
231 cupsdProcessIPPRequest(
232 cupsd_client_t
*con
) /* I - Client connection */
234 ipp_tag_t group
; /* Current group tag */
235 ipp_attribute_t
*attr
; /* Current attribute */
236 ipp_attribute_t
*charset
; /* Character set attribute */
237 ipp_attribute_t
*language
; /* Language attribute */
238 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
239 ipp_attribute_t
*username
; /* requesting-user-name attr */
240 int sub_id
; /* Subscription ID */
243 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
244 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
245 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
248 * First build an empty response message for this request...
251 con
->response
= ippNew();
253 con
->response
->request
.status
.version
[0] =
254 con
->request
->request
.op
.version
[0];
255 con
->response
->request
.status
.version
[1] =
256 con
->request
->request
.op
.version
[1];
257 con
->response
->request
.status
.request_id
=
258 con
->request
->request
.op
.request_id
;
261 * Then validate the request header and required attributes...
264 if (con
->request
->request
.any
.version
[0] != 1 &&
265 con
->request
->request
.any
.version
[0] != 2)
268 * Return an error, since we only support IPP 1.x and 2.x.
271 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
272 "%04X %s Bad request version number %d.%d",
273 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
274 con
->request
->request
.any
.version
[0],
275 con
->request
->request
.any
.version
[1]);
277 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
278 _("Bad request version number %d.%d."),
279 con
->request
->request
.any
.version
[0],
280 con
->request
->request
.any
.version
[1]);
282 else if (con
->request
->request
.any
.request_id
< 1)
285 * Return an error, since request IDs must be between 1 and 2^31-1
288 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
289 "%04X %s Bad request ID %d",
290 IPP_BAD_REQUEST
, con
->http
.hostname
,
291 con
->request
->request
.any
.request_id
);
293 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
294 con
->request
->request
.any
.request_id
);
296 else if (!con
->request
->attrs
)
298 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
299 "%04X %s No attributes in request",
300 IPP_BAD_REQUEST
, con
->http
.hostname
);
302 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
307 * Make sure that the attributes are provided in the correct order and
308 * don't repeat groups...
311 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
314 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
317 * Out of order; return an error...
320 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
321 "%04X %s Attribute groups are out of order",
322 IPP_BAD_REQUEST
, con
->http
.hostname
);
324 send_ipp_status(con
, IPP_BAD_REQUEST
,
325 _("Attribute groups are out of order (%x < %x)."),
326 attr
->group_tag
, group
);
330 group
= attr
->group_tag
;
335 * Then make sure that the first three attributes are:
338 * attributes-natural-language
339 * printer-uri/job-uri
342 attr
= con
->request
->attrs
;
343 if (attr
&& attr
->name
&&
344 !strcmp(attr
->name
, "attributes-charset") &&
345 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
353 if (attr
&& attr
->name
&&
354 !strcmp(attr
->name
, "attributes-natural-language") &&
355 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
360 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
361 IPP_TAG_URI
)) != NULL
)
363 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
364 IPP_TAG_URI
)) != NULL
)
366 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
367 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
372 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
373 "attributes-charset", NULL
,
374 charset
->values
[0].string
.text
);
376 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
377 "attributes-charset", NULL
, "utf-8");
380 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
381 "attributes-natural-language", NULL
,
382 language
->values
[0].string
.text
);
384 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
385 "attributes-natural-language", NULL
, DefaultLanguage
);
388 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
389 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
392 * Bad character set...
395 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
396 charset
->values
[0].string
.text
);
397 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
398 "%04X %s Unsupported attributes-charset value \"%s\"",
399 IPP_CHARSET
, con
->http
.hostname
,
400 charset
->values
[0].string
.text
);
401 send_ipp_status(con
, IPP_BAD_REQUEST
,
402 _("Unsupported character set \"%s\"."),
403 charset
->values
[0].string
.text
);
405 else if (!charset
|| !language
||
407 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
408 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
409 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
410 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
411 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
414 * Return an error, since attributes-charset,
415 * attributes-natural-language, and printer-uri/job-uri are required
416 * for all operations.
421 cupsdLogMessage(CUPSD_LOG_ERROR
,
422 "Missing attributes-charset attribute");
424 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
425 "%04X %s Missing attributes-charset attribute",
426 IPP_BAD_REQUEST
, con
->http
.hostname
);
431 cupsdLogMessage(CUPSD_LOG_ERROR
,
432 "Missing attributes-natural-language attribute");
434 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
435 "%04X %s Missing attributes-natural-language attribute",
436 IPP_BAD_REQUEST
, con
->http
.hostname
);
441 cupsdLogMessage(CUPSD_LOG_ERROR
,
442 "Missing printer-uri, job-uri, or ppd-name "
445 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
446 "%04X %s Missing printer-uri, job-uri, or ppd-name "
447 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
450 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
452 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
453 cupsdLogMessage(CUPSD_LOG_DEBUG
,
454 "attr \"%s\": group_tag = %x, value_tag = %x",
455 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
458 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
460 send_ipp_status(con
, IPP_BAD_REQUEST
,
461 _("Missing required attributes."));
466 * OK, all the checks pass so far; make sure requesting-user-name is
467 * not "root" from a remote host...
470 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
471 IPP_TAG_NAME
)) != NULL
)
474 * Check for root user...
477 if (!strcmp(username
->values
[0].string
.text
, "root") &&
478 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
479 strcmp(con
->username
, "root"))
482 * Remote unauthenticated user masquerading as local root...
485 _cupsStrFree(username
->values
[0].string
.text
);
486 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
490 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
491 IPP_TAG_INTEGER
)) != NULL
)
492 sub_id
= attr
->values
[0].integer
;
497 * Then try processing the operation...
501 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
502 ippOpString(con
->request
->request
.op
.operation_id
),
503 uri
->values
[0].string
.text
);
505 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
506 ippOpString(con
->request
->request
.op
.operation_id
));
508 switch (con
->request
->request
.op
.operation_id
)
514 case IPP_VALIDATE_JOB
:
515 validate_job(con
, uri
);
518 case IPP_CREATE_JOB
:
519 create_job(con
, uri
);
522 case IPP_SEND_DOCUMENT
:
523 send_document(con
, uri
);
526 case IPP_CANCEL_JOB
:
527 cancel_job(con
, uri
);
530 case IPP_GET_JOB_ATTRIBUTES
:
531 get_job_attrs(con
, uri
);
538 case IPP_GET_PRINTER_ATTRIBUTES
:
539 get_printer_attrs(con
, uri
);
542 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
543 get_printer_supported(con
, uri
);
550 case IPP_RELEASE_JOB
:
551 release_job(con
, uri
);
554 case IPP_RESTART_JOB
:
555 restart_job(con
, uri
);
558 case IPP_PAUSE_PRINTER
:
559 stop_printer(con
, uri
);
562 case IPP_RESUME_PRINTER
:
563 start_printer(con
, uri
);
566 case IPP_PURGE_JOBS
:
567 case IPP_CANCEL_JOBS
:
568 case IPP_CANCEL_MY_JOBS
:
569 cancel_all_jobs(con
, uri
);
572 case IPP_SET_JOB_ATTRIBUTES
:
573 set_job_attrs(con
, uri
);
576 case IPP_SET_PRINTER_ATTRIBUTES
:
577 set_printer_attrs(con
, uri
);
580 case IPP_HOLD_NEW_JOBS
:
581 hold_new_jobs(con
, uri
);
584 case IPP_RELEASE_HELD_NEW_JOBS
:
585 release_held_new_jobs(con
, uri
);
592 case CUPS_GET_DEFAULT
:
596 case CUPS_GET_PRINTERS
:
597 get_printers(con
, 0);
600 case CUPS_GET_CLASSES
:
601 get_printers(con
, CUPS_PRINTER_CLASS
);
604 case CUPS_ADD_PRINTER
:
605 add_printer(con
, uri
);
608 case CUPS_DELETE_PRINTER
:
609 delete_printer(con
, uri
);
612 case CUPS_ADD_CLASS
:
616 case CUPS_DELETE_CLASS
:
617 delete_printer(con
, uri
);
620 case CUPS_ACCEPT_JOBS
:
621 case IPP_ENABLE_PRINTER
:
622 accept_jobs(con
, uri
);
625 case CUPS_REJECT_JOBS
:
626 case IPP_DISABLE_PRINTER
:
627 reject_jobs(con
, uri
);
630 case CUPS_SET_DEFAULT
:
631 set_default(con
, uri
);
634 case CUPS_GET_DEVICES
:
638 case CUPS_GET_DOCUMENT
:
639 get_document(con
, uri
);
654 case CUPS_AUTHENTICATE_JOB
:
655 authenticate_job(con
, uri
);
658 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
659 case IPP_CREATE_JOB_SUBSCRIPTION
:
660 create_subscription(con
, uri
);
663 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
664 get_subscription_attrs(con
, sub_id
);
667 case IPP_GET_SUBSCRIPTIONS
:
668 get_subscriptions(con
, uri
);
671 case IPP_RENEW_SUBSCRIPTION
:
672 renew_subscription(con
, sub_id
);
675 case IPP_CANCEL_SUBSCRIPTION
:
676 cancel_subscription(con
, sub_id
);
679 case IPP_GET_NOTIFICATIONS
:
680 get_notifications(con
);
684 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
685 "%04X %s Operation %04X (%s) not supported",
686 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
687 con
->request
->request
.op
.operation_id
,
688 ippOpString(con
->request
->request
.op
.operation_id
));
690 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
691 _("%s not supported."),
693 con
->request
->request
.op
.operation_id
));
703 * Sending data from the scheduler...
706 cupsdLogMessage(con
->response
->request
.status
.status_code
707 >= IPP_BAD_REQUEST
&&
708 con
->response
->request
.status
.status_code
709 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
710 "Returning IPP %s for %s (%s) from %s",
711 ippErrorString(con
->response
->request
.status
.status_code
),
712 ippOpString(con
->request
->request
.op
.operation_id
),
713 uri
? uri
->values
[0].string
.text
: "no URI",
716 if (LogLevel
== CUPSD_LOG_DEBUG2
)
717 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
718 "cupsdProcessIPPRequest: ippLength(response)=%ld",
719 (long)ippLength(con
->response
));
721 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
723 #ifdef CUPSD_USE_CHUNKING
725 * Because older versions of CUPS (1.1.17 and older) and some IPP
726 * clients do not implement chunking properly, we cannot use
727 * chunking by default. This may become the default in future
728 * CUPS releases, or we might add a configuration directive for
732 if (con
->http
.version
== HTTP_1_1
)
734 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
737 if (cupsdFlushHeader(con
) < 0)
740 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
743 #endif /* CUPSD_USE_CHUNKING */
745 size_t length
; /* Length of response */
748 length
= ippLength(con
->response
);
750 if (con
->file
>= 0 && !con
->pipe_pid
)
752 struct stat fileinfo
; /* File information */
754 if (!fstat(con
->file
, &fileinfo
))
755 length
+= fileinfo
.st_size
;
758 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
759 CUPS_LLCAST length
) < 0)
762 if (cupsdFlushHeader(con
) < 0)
765 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
766 con
->http
.data_remaining
= length
;
768 if (con
->http
.data_remaining
<= INT_MAX
)
769 con
->http
._data_remaining
= con
->http
.data_remaining
;
771 con
->http
._data_remaining
= INT_MAX
;
774 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
775 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
778 * Tell the caller the response header was sent successfully...
786 * Tell the caller the response header could not be sent...
795 * Sending data from a subprocess like cups-deviced; tell the caller
796 * everything is A-OK so far...
805 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
808 int /* O - 0 on success, -1 on error */
809 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
811 cupsd_printer_t
*printer
; /* Destination printer or class */
812 ipp_attribute_t
*attr
; /* job-sheets attribute */
813 int kbytes
; /* Kilobytes in banner */
816 job
->pending_timeout
= 0;
819 * See if we need to add the ending sheet...
822 if (!cupsdLoadJob(job
))
825 printer
= cupsdFindDest(job
->dest
);
826 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
828 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
829 attr
&& attr
->num_values
> 1)
835 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
836 attr
->values
[1].string
.text
);
838 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
841 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
849 * 'accept_jobs()' - Accept print jobs to a printer.
853 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
854 ipp_attribute_t
*uri
) /* I - Printer or class URI */
856 http_status_t status
; /* Policy status */
857 cups_ptype_t dtype
; /* Destination type (printer/class) */
858 cupsd_printer_t
*printer
; /* Printer data */
861 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
862 con
->http
.fd
, uri
->values
[0].string
.text
);
865 * Is the destination valid?
868 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
874 send_ipp_status(con
, IPP_NOT_FOUND
,
875 _("The printer or class does not exist."));
883 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
885 send_http_error(con
, status
, printer
);
890 * Accept jobs sent to the printer...
893 printer
->accepting
= 1;
894 printer
->state_message
[0] = '\0';
896 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
897 "Now accepting jobs.");
899 if (dtype
& CUPS_PRINTER_CLASS
)
901 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
903 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
904 printer
->name
, get_username(con
));
908 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
910 cupsdLogMessage(CUPSD_LOG_INFO
,
911 "Printer \"%s\" now accepting jobs (\"%s\").",
912 printer
->name
, get_username(con
));
916 * Everything was ok, so return OK status...
919 con
->response
->request
.status
.status_code
= IPP_OK
;
924 * 'add_class()' - Add a class to the system.
928 add_class(cupsd_client_t
*con
, /* I - Client connection */
929 ipp_attribute_t
*uri
) /* I - URI of class */
931 http_status_t status
; /* Policy status */
932 int i
; /* Looping var */
933 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
934 username
[HTTP_MAX_URI
], /* Username portion of URI */
935 host
[HTTP_MAX_URI
], /* Host portion of URI */
936 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
937 int port
; /* Port portion of URI */
938 cupsd_printer_t
*pclass
, /* Class */
939 *member
; /* Member printer/class */
940 cups_ptype_t dtype
; /* Destination type */
941 ipp_attribute_t
*attr
; /* Printer attribute */
942 int modify
; /* Non-zero if we just modified */
943 int need_restart_job
; /* Need to restart job? */
946 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
947 con
->http
.fd
, uri
->values
[0].string
.text
);
950 * Do we have a valid URI?
953 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
954 sizeof(scheme
), username
, sizeof(username
), host
,
955 sizeof(host
), &port
, resource
, sizeof(resource
));
958 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
961 * No, return an error...
964 send_ipp_status(con
, IPP_BAD_REQUEST
,
965 _("The printer-uri must be of the form "
966 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
971 * Do we have a valid printer name?
974 if (!validate_name(resource
+ 9))
977 * No, return an error...
980 send_ipp_status(con
, IPP_BAD_REQUEST
,
981 _("The printer-uri \"%s\" contains invalid characters."),
982 uri
->values
[0].string
.text
);
987 * See if the class already exists; if not, create a new class...
990 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
993 * Class doesn't exist; see if we have a printer of the same name...
996 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
999 * Yes, return an error...
1002 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1003 _("A printer named \"%s\" already exists."),
1009 * No, check the default policy and then add the class...
1012 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1014 send_http_error(con
, status
, NULL
);
1018 pclass
= cupsdAddClass(resource
+ 9);
1021 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1024 send_http_error(con
, status
, pclass
);
1031 * Look for attributes and copy them over as needed...
1034 need_restart_job
= 0;
1036 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1037 IPP_TAG_TEXT
)) != NULL
)
1038 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1040 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1041 IPP_TAG_TEXT
)) != NULL
)
1042 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1044 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1045 IPP_TAG_BOOLEAN
)) != NULL
&&
1046 attr
->values
[0].boolean
!= pclass
->accepting
)
1048 cupsdLogMessage(CUPSD_LOG_INFO
,
1049 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1050 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1052 pclass
->accepting
= attr
->values
[0].boolean
;
1054 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1055 pclass
->accepting
? "Now" : "No longer");
1058 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1059 IPP_TAG_BOOLEAN
)) != NULL
)
1061 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1062 cupsdDeregisterPrinter(pclass
, 1);
1064 cupsdLogMessage(CUPSD_LOG_INFO
,
1065 "Setting %s printer-is-shared to %d (was %d.)",
1066 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1068 pclass
->shared
= attr
->values
[0].boolean
;
1071 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1072 IPP_TAG_ENUM
)) != NULL
)
1074 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1075 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1077 send_ipp_status(con
, IPP_BAD_REQUEST
,
1078 _("Attempt to set %s printer-state to bad value %d."),
1079 pclass
->name
, attr
->values
[0].integer
);
1083 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1084 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1086 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1087 cupsdStopPrinter(pclass
, 0);
1090 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1091 need_restart_job
= 1;
1094 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1095 IPP_TAG_TEXT
)) != NULL
)
1097 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1098 sizeof(pclass
->state_message
));
1100 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1101 pclass
->state_message
);
1103 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1104 IPP_TAG_URI
)) != NULL
)
1107 * Clear the printer array as needed...
1110 need_restart_job
= 1;
1112 if (pclass
->num_printers
> 0)
1114 free(pclass
->printers
);
1115 pclass
->num_printers
= 0;
1119 * Add each printer or class that is listed...
1122 for (i
= 0; i
< attr
->num_values
; i
++)
1125 * Search for the printer or class URI...
1128 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1134 send_ipp_status(con
, IPP_NOT_FOUND
,
1135 _("The printer or class does not exist."));
1138 else if (dtype
& CUPS_PRINTER_CLASS
)
1140 send_ipp_status(con
, IPP_BAD_REQUEST
,
1141 _("Nested classes are not allowed."));
1146 * Add it to the class...
1149 cupsdAddPrinterToClass(pclass
, member
);
1153 set_printer_defaults(con
, pclass
);
1155 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1156 IPP_TAG_KEYWORD
)) != NULL
)
1157 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1160 * Update the printer class attributes and return...
1163 cupsdSetPrinterAttrs(pclass
);
1164 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1166 if (need_restart_job
&& pclass
->job
)
1169 * Reset the current job to a "pending" status...
1172 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1173 "Job restarted because the class was modified.");
1176 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1180 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1181 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1182 pclass
->name
, get_username(con
));
1184 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1185 pclass
->name
, get_username(con
));
1189 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1190 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1191 pclass
->name
, get_username(con
));
1193 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1194 pclass
->name
, get_username(con
));
1197 con
->response
->request
.status
.status_code
= IPP_OK
;
1202 * 'add_file()' - Add a file to a job.
1205 static int /* O - 0 on success, -1 on error */
1206 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1207 cupsd_job_t
*job
, /* I - Job to add to */
1208 mime_type_t
*filetype
, /* I - Type of file */
1209 int compression
) /* I - Compression */
1211 mime_type_t
**filetypes
; /* New filetypes array... */
1212 int *compressions
; /* New compressions array... */
1215 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1216 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1217 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1218 filetype
->super
, filetype
->type
, compression
);
1221 * Add the file to the job...
1224 if (job
->num_files
== 0)
1226 compressions
= (int *)malloc(sizeof(int));
1227 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1231 compressions
= (int *)realloc(job
->compressions
,
1232 (job
->num_files
+ 1) * sizeof(int));
1233 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1234 (job
->num_files
+ 1) *
1235 sizeof(mime_type_t
*));
1238 if (!compressions
|| !filetypes
)
1240 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1241 "Job aborted because the scheduler ran out of memory.");
1244 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1245 _("Unable to allocate memory for file types."));
1250 job
->compressions
= compressions
;
1251 job
->compressions
[job
->num_files
] = compression
;
1252 job
->filetypes
= filetypes
;
1253 job
->filetypes
[job
->num_files
] = filetype
;
1258 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1265 * 'add_job()' - Add a job to a print queue.
1268 static cupsd_job_t
* /* O - Job object */
1269 add_job(cupsd_client_t
*con
, /* I - Client connection */
1270 cupsd_printer_t
*printer
, /* I - Destination printer */
1271 mime_type_t
*filetype
) /* I - First print file type, if any */
1273 http_status_t status
; /* Policy status */
1274 ipp_attribute_t
*attr
, /* Current attribute */
1275 *auth_info
; /* auth-info attribute */
1276 const char *mandatory
; /* Current mandatory job attribute */
1277 const char *val
; /* Default option value */
1278 int priority
; /* Job priority */
1279 cupsd_job_t
*job
; /* Current job */
1280 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1281 int kbytes
; /* Size of print file */
1282 int i
; /* Looping var */
1283 int lowerpagerange
; /* Page range bound */
1284 int exact
; /* Did we have an exact match? */
1285 ipp_attribute_t
*media_col
, /* media-col attribute */
1286 *media_margin
; /* media-*-margin attribute */
1287 ipp_t
*unsup_col
; /* media-col in unsupported response */
1288 static const char * const readonly
[] =/* List of read-only attributes */
1291 "job-k-octets-completed",
1292 "job-impressions-completed",
1293 "job-media-sheets-completed",
1295 "job-state-message",
1296 "job-state-reasons",
1297 "time-at-completed",
1299 "time-at-processing"
1303 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1304 con
, con
->http
.fd
, printer
, printer
->name
,
1305 filetype
, filetype
? filetype
->super
: "none",
1306 filetype
? filetype
->type
: "none");
1309 * Check remote printing to non-shared printer...
1312 if (!printer
->shared
&&
1313 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
1314 _cups_strcasecmp(con
->http
.hostname
, ServerName
))
1316 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1317 _("The printer or class is not shared."));
1325 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1327 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1329 send_http_error(con
, status
, printer
);
1332 else if (printer
->num_auth_info_required
== 1 &&
1333 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1336 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1340 else if (auth_info
&& !con
->http
.tls
&&
1341 !httpAddrLocalhost(con
->http
.hostaddr
))
1344 * Require encryption of auth-info over non-local connections...
1347 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1350 #endif /* HAVE_SSL */
1353 * See if the printer is accepting jobs...
1356 if (!printer
->accepting
)
1358 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1359 _("Destination \"%s\" is not accepting jobs."),
1365 * Validate job template attributes; for now just document-format,
1366 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1370 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1372 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
],
1373 IPP_TAG_ZERO
)) != NULL
)
1375 ippDeleteAttribute(con
->request
, attr
);
1377 if (StrictConformance
)
1379 send_ipp_status(con
, IPP_BAD_REQUEST
,
1380 _("The '%s' Job Description attribute cannot be "
1381 "supplied in a job creation request."), readonly
[i
]);
1385 cupsdLogMessage(CUPSD_LOG_WARN
,
1386 "Unexpected '%s' Job Description attribute in a job "
1387 "creation request.", readonly
[i
]);
1393 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1395 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1397 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1400 * Missing a required attribute...
1403 send_ipp_status(con
, IPP_CONFLICT
,
1404 _("The \"%s\" attribute is required for print jobs."),
1411 if (filetype
&& printer
->filetypes
&&
1412 !cupsArrayFind(printer
->filetypes
, filetype
))
1414 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1415 /* MIME media type string */
1418 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1421 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1422 _("Unsupported format \"%s\"."), mimetype
);
1424 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1425 "document-format", NULL
, mimetype
);
1430 if ((attr
= ippFindAttribute(con
->request
, "copies",
1431 IPP_TAG_INTEGER
)) != NULL
)
1433 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1435 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1436 attr
->values
[0].integer
);
1437 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1438 "copies", attr
->values
[0].integer
);
1443 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1444 IPP_TAG_ZERO
)) != NULL
)
1446 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1447 attr
->value_tag
!= IPP_TAG_NAME
)
1449 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1453 if (attr
->num_values
> 2)
1455 send_ipp_status(con
, IPP_BAD_REQUEST
,
1456 _("Too many job-sheets values (%d > 2)."),
1461 for (i
= 0; i
< attr
->num_values
; i
++)
1462 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1463 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1465 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1466 attr
->values
[i
].string
.text
);
1471 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1472 IPP_TAG_INTEGER
)) != NULL
)
1474 if (attr
->values
[0].integer
!= 1 &&
1475 attr
->values
[0].integer
!= 2 &&
1476 attr
->values
[0].integer
!= 4 &&
1477 attr
->values
[0].integer
!= 6 &&
1478 attr
->values
[0].integer
!= 9 &&
1479 attr
->values
[0].integer
!= 16)
1481 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1482 attr
->values
[0].integer
);
1483 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1484 "number-up", attr
->values
[0].integer
);
1489 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1490 IPP_TAG_RANGE
)) != NULL
)
1492 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1494 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1495 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1497 send_ipp_status(con
, IPP_BAD_REQUEST
,
1498 _("Bad page-ranges values %d-%d."),
1499 attr
->values
[i
].range
.lower
,
1500 attr
->values
[i
].range
.upper
);
1504 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1509 * Do media selection as needed...
1512 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1513 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1514 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1517 (media_col
= ippFindAttribute(con
->request
, "media-col",
1518 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1520 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1522 unsup_col
= ippNew();
1523 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1524 "media-bottom-margin",
1525 IPP_TAG_INTEGER
)) != NULL
)
1526 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1527 "media-bottom-margin", media_margin
->values
[0].integer
);
1529 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1530 "media-left-margin",
1531 IPP_TAG_INTEGER
)) != NULL
)
1532 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1533 "media-left-margin", media_margin
->values
[0].integer
);
1535 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1536 "media-right-margin",
1537 IPP_TAG_INTEGER
)) != NULL
)
1538 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1539 "media-right-margin", media_margin
->values
[0].integer
);
1541 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1543 IPP_TAG_INTEGER
)) != NULL
)
1544 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1545 "media-top-margin", media_margin
->values
[0].integer
);
1547 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1549 ippDelete(unsup_col
);
1554 * Make sure we aren't over our limit...
1557 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1560 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1562 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1566 if ((i
= check_quotas(con
, printer
)) < 0)
1568 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1573 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1578 * Create the job and set things up...
1581 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1582 IPP_TAG_INTEGER
)) != NULL
)
1583 priority
= attr
->values
[0].integer
;
1586 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1587 printer
->options
)) != NULL
)
1588 priority
= atoi(val
);
1592 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1596 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1597 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1599 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1600 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1601 attr
->num_values
!= 1)
1603 send_ipp_status(con
, IPP_ATTRIBUTES
,
1604 _("Bad job-name value: Wrong type or count."));
1605 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1606 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1609 else if (!ippValidateAttribute(attr
))
1611 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1612 cupsLastErrorString());
1613 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1614 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1618 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1620 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1621 _("Unable to add job for destination \"%s\"."),
1626 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1627 job
->attrs
= con
->request
;
1629 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1631 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1634 apply_printer_defaults(printer
, job
);
1636 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1638 if (con
->username
[0])
1640 cupsdSetString(&job
->username
, con
->username
);
1643 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1647 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1648 "add_job: requesting-user-name=\"%s\"",
1649 attr
->values
[0].string
.text
);
1651 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1654 cupsdSetString(&job
->username
, "anonymous");
1657 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1658 "job-originating-user-name", NULL
, job
->username
);
1661 attr
->group_tag
= IPP_TAG_JOB
;
1662 _cupsStrFree(attr
->name
);
1663 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1666 if (con
->username
[0] || auth_info
)
1668 save_auth_info(con
, job
, auth_info
);
1671 * Remove the auth-info attribute from the attribute data...
1675 ippDeleteAttribute(job
->attrs
, auth_info
);
1678 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1679 IPP_TAG_ZERO
)) != NULL
)
1682 * Request contains a job-originating-host-name attribute; validate it...
1685 if (attr
->value_tag
!= IPP_TAG_NAME
||
1686 attr
->num_values
!= 1 ||
1687 strcmp(con
->http
.hostname
, "localhost"))
1690 * Can't override the value if we aren't connected via localhost.
1691 * Also, we can only have 1 value and it must be a name value.
1694 switch (attr
->value_tag
)
1696 case IPP_TAG_STRING
:
1697 case IPP_TAG_TEXTLANG
:
1698 case IPP_TAG_NAMELANG
:
1701 case IPP_TAG_KEYWORD
:
1703 case IPP_TAG_URISCHEME
:
1704 case IPP_TAG_CHARSET
:
1705 case IPP_TAG_LANGUAGE
:
1706 case IPP_TAG_MIMETYPE
:
1708 * Free old strings...
1711 for (i
= 0; i
< attr
->num_values
; i
++)
1713 _cupsStrFree(attr
->values
[i
].string
.text
);
1714 attr
->values
[i
].string
.text
= NULL
;
1715 if (attr
->values
[i
].string
.language
)
1717 _cupsStrFree(attr
->values
[i
].string
.language
);
1718 attr
->values
[i
].string
.language
= NULL
;
1727 * Use the default connection hostname instead...
1730 attr
->value_tag
= IPP_TAG_NAME
;
1731 attr
->num_values
= 1;
1732 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1735 attr
->group_tag
= IPP_TAG_JOB
;
1740 * No job-originating-host-name attribute, so use the hostname from
1744 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1745 "job-originating-host-name", NULL
, con
->http
.hostname
);
1748 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1750 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1751 "time-at-processing", 0);
1752 attr
->value_tag
= IPP_TAG_NOVALUE
;
1753 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1754 "time-at-completed", 0);
1755 attr
->value_tag
= IPP_TAG_NOVALUE
;
1758 * Add remaining job attributes...
1761 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1762 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1763 "job-state", IPP_JOB_STOPPED
);
1764 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1765 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1766 "job-state-reasons", NULL
, "job-incoming");
1767 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1768 "job-media-sheets-completed", 0);
1769 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1772 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1773 IPP_TAG_INTEGER
)) != NULL
)
1774 attr
->values
[0].integer
= 0;
1776 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1778 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1779 IPP_TAG_KEYWORD
)) == NULL
)
1780 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1783 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1784 printer
->options
)) == NULL
)
1787 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1788 "job-hold-until", NULL
, val
);
1790 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1793 * Hold job until specified time...
1796 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1798 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1799 job
->state_value
= IPP_JOB_HELD
;
1801 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1803 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1805 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1806 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1807 job
->state_value
= IPP_JOB_HELD
;
1811 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1812 job
->state_value
= IPP_JOB_PENDING
;
1814 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1817 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1820 * Add job sheets options...
1823 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1824 IPP_TAG_ZERO
)) == NULL
)
1826 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1827 "Adding default job-sheets values \"%s,%s\"...",
1828 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1830 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1832 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1833 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1836 job
->job_sheets
= attr
;
1839 * Enforce classification level if set...
1844 cupsdLogMessage(CUPSD_LOG_INFO
,
1845 "Classification=\"%s\", ClassifyOverride=%d",
1846 Classification
? Classification
: "(null)",
1849 if (ClassifyOverride
)
1851 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1852 (attr
->num_values
== 1 ||
1853 !strcmp(attr
->values
[1].string
.text
, "none")))
1856 * Force the leading banner to have the classification on it...
1859 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1861 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1862 "job-sheets=\"%s,none\", "
1863 "job-originating-user-name=\"%s\"",
1864 Classification
, job
->username
);
1866 else if (attr
->num_values
== 2 &&
1867 strcmp(attr
->values
[0].string
.text
,
1868 attr
->values
[1].string
.text
) &&
1869 strcmp(attr
->values
[0].string
.text
, "none") &&
1870 strcmp(attr
->values
[1].string
.text
, "none"))
1873 * Can't put two different security markings on the same document!
1876 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1878 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1879 "job-sheets=\"%s,%s\", "
1880 "job-originating-user-name=\"%s\"",
1881 attr
->values
[0].string
.text
,
1882 attr
->values
[1].string
.text
, job
->username
);
1884 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1885 strcmp(attr
->values
[0].string
.text
, "none") &&
1886 (attr
->num_values
== 1 ||
1887 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1888 strcmp(attr
->values
[1].string
.text
, "none"))))
1890 if (attr
->num_values
== 1)
1891 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1892 "CLASSIFICATION OVERRIDDEN "
1893 "job-sheets=\"%s\", "
1894 "job-originating-user-name=\"%s\"",
1895 attr
->values
[0].string
.text
, job
->username
);
1897 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1898 "CLASSIFICATION OVERRIDDEN "
1899 "job-sheets=\"%s,%s\",fffff "
1900 "job-originating-user-name=\"%s\"",
1901 attr
->values
[0].string
.text
,
1902 attr
->values
[1].string
.text
, job
->username
);
1905 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1906 (attr
->num_values
== 1 ||
1907 strcmp(attr
->values
[1].string
.text
, Classification
)))
1910 * Force the banner to have the classification on it...
1913 if (attr
->num_values
> 1 &&
1914 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1916 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1917 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1921 if (attr
->num_values
== 1 ||
1922 strcmp(attr
->values
[0].string
.text
, "none"))
1923 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1925 if (attr
->num_values
> 1 &&
1926 strcmp(attr
->values
[1].string
.text
, "none"))
1927 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1930 if (attr
->num_values
> 1)
1931 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1932 "CLASSIFICATION FORCED "
1933 "job-sheets=\"%s,%s\", "
1934 "job-originating-user-name=\"%s\"",
1935 attr
->values
[0].string
.text
,
1936 attr
->values
[1].string
.text
, job
->username
);
1938 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1939 "CLASSIFICATION FORCED "
1940 "job-sheets=\"%s\", "
1941 "job-originating-user-name=\"%s\"",
1942 Classification
, job
->username
);
1947 * See if we need to add the starting sheet...
1950 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1952 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1953 attr
->values
[0].string
.text
);
1955 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1957 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1958 "Aborting job because the start banner could not be "
1963 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1966 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1967 IPP_TAG_ZERO
)) != NULL
)
1968 job
->job_sheets
= attr
;
1971 * Fill in the response info...
1974 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1975 con
->servername
, con
->serverport
, "/jobs/%d", job
->id
);
1976 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1979 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1981 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1983 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1984 NULL
, job
->reasons
->values
[0].string
.text
);
1986 con
->response
->request
.status
.status_code
= IPP_OK
;
1989 * Add any job subscriptions...
1992 add_job_subscriptions(con
, job
);
1995 * Set all but the first two attributes to the job attributes group...
1998 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1999 attr
->group_tag
= IPP_TAG_JOB
;
2002 * Fire the "job created" event...
2005 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
2008 * Return the new job...
2016 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2020 add_job_subscriptions(
2021 cupsd_client_t
*con
, /* I - Client connection */
2022 cupsd_job_t
*job
) /* I - Newly created job */
2024 int i
; /* Looping var */
2025 ipp_attribute_t
*prev
, /* Previous attribute */
2026 *next
, /* Next attribute */
2027 *attr
; /* Current attribute */
2028 cupsd_subscription_t
*sub
; /* Subscription object */
2029 const char *recipient
, /* notify-recipient-uri */
2030 *pullmethod
; /* notify-pull-method */
2031 ipp_attribute_t
*user_data
; /* notify-user-data */
2032 int interval
; /* notify-time-interval */
2033 unsigned mask
; /* notify-events */
2037 * Find the first subscription group attribute; return if we have
2041 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2042 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2049 * Process the subscription attributes in the request...
2058 mask
= CUPSD_EVENT_NONE
;
2060 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2062 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2063 attr
->value_tag
== IPP_TAG_URI
)
2066 * Validate the recipient scheme against the ServerBin/notifier
2070 char notifier
[1024], /* Notifier filename */
2071 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2072 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2073 host
[HTTP_MAX_URI
], /* Host portion of URI */
2074 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2075 int port
; /* Port portion of URI */
2078 recipient
= attr
->values
[0].string
.text
;
2080 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2081 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2082 host
, sizeof(host
), &port
,
2083 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2085 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2086 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2087 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2088 "notify-status-code", IPP_URI_SCHEME
);
2092 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2094 if (access(notifier
, X_OK
))
2096 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2097 _("notify-recipient-uri URI \"%s\" uses unknown "
2098 "scheme."), recipient
);
2099 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2100 "notify-status-code", IPP_URI_SCHEME
);
2104 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2106 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2107 _("notify-recipient-uri URI \"%s\" is already used."),
2109 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2110 "notify-status-code", IPP_ATTRIBUTES
);
2114 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2115 attr
->value_tag
== IPP_TAG_KEYWORD
)
2117 pullmethod
= attr
->values
[0].string
.text
;
2119 if (strcmp(pullmethod
, "ippget"))
2121 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2122 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2123 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2124 "notify-status-code", IPP_ATTRIBUTES
);
2128 else if (!strcmp(attr
->name
, "notify-charset") &&
2129 attr
->value_tag
== IPP_TAG_CHARSET
&&
2130 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2131 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2133 send_ipp_status(con
, IPP_CHARSET
,
2134 _("Character set \"%s\" not supported."),
2135 attr
->values
[0].string
.text
);
2138 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2139 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2140 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2142 send_ipp_status(con
, IPP_CHARSET
,
2143 _("Language \"%s\" not supported."),
2144 attr
->values
[0].string
.text
);
2147 else if (!strcmp(attr
->name
, "notify-user-data") &&
2148 attr
->value_tag
== IPP_TAG_STRING
)
2150 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2152 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2153 _("The notify-user-data value is too large "
2154 "(%d > 63 octets)."),
2155 attr
->values
[0].unknown
.length
);
2161 else if (!strcmp(attr
->name
, "notify-events") &&
2162 attr
->value_tag
== IPP_TAG_KEYWORD
)
2164 for (i
= 0; i
< attr
->num_values
; i
++)
2165 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2167 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2169 send_ipp_status(con
, IPP_BAD_REQUEST
,
2170 _("The notify-lease-duration attribute cannot be "
2171 "used with job subscriptions."));
2174 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2175 attr
->value_tag
== IPP_TAG_INTEGER
)
2176 interval
= attr
->values
[0].integer
;
2181 if (!recipient
&& !pullmethod
)
2184 if (mask
== CUPSD_EVENT_NONE
)
2185 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2187 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2188 recipient
, 0)) != NULL
)
2190 sub
->interval
= interval
;
2192 cupsdSetString(&sub
->owner
, job
->username
);
2196 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2197 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2198 sub
->user_data_len
);
2201 ippAddSeparator(con
->response
);
2202 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2203 "notify-subscription-id", sub
->id
);
2205 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2213 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2216 * Remove all of the subscription attributes from the job request...
2218 * TODO: Optimize this since subscription groups have to come at the
2219 * end of the request...
2222 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2226 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2227 attr
->group_tag
== IPP_TAG_ZERO
)
2230 * Free and remove this attribute...
2233 ippDeleteAttribute(NULL
, attr
);
2238 job
->attrs
->attrs
= next
;
2244 job
->attrs
->last
= prev
;
2245 job
->attrs
->current
= prev
;
2250 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2252 * See RFC 4122 for the definition of UUIDs and the format.
2256 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2258 char uuid
[64]; /* job-uuid string */
2262 * Add a job-uuid attribute if none exists...
2265 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2266 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2267 _httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2268 uuid
, sizeof(uuid
)));
2273 * 'add_printer()' - Add a printer to the system.
2277 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2278 ipp_attribute_t
*uri
) /* I - URI of printer */
2280 http_status_t status
; /* Policy status */
2281 int i
; /* Looping var */
2282 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2283 username
[HTTP_MAX_URI
], /* Username portion of URI */
2284 host
[HTTP_MAX_URI
], /* Host portion of URI */
2285 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2286 int port
; /* Port portion of URI */
2287 cupsd_printer_t
*printer
; /* Printer/class */
2288 ipp_attribute_t
*attr
; /* Printer attribute */
2289 cups_file_t
*fp
; /* Script/PPD file */
2290 char line
[1024]; /* Line from file... */
2291 char srcfile
[1024], /* Source Script/PPD file */
2292 dstfile
[1024]; /* Destination Script/PPD file */
2293 int modify
; /* Non-zero if we are modifying */
2294 int changed_driver
, /* Changed the PPD/interface script? */
2295 need_restart_job
, /* Need to restart job? */
2296 set_device_uri
, /* Did we set the device URI? */
2297 set_port_monitor
; /* Did we set the port monitor? */
2300 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2301 con
->http
.fd
, uri
->values
[0].string
.text
);
2304 * Do we have a valid URI?
2307 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2308 sizeof(scheme
), username
, sizeof(username
), host
,
2309 sizeof(host
), &port
, resource
, sizeof(resource
));
2311 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2314 * No, return an error...
2317 send_ipp_status(con
, IPP_BAD_REQUEST
,
2318 _("The printer-uri must be of the form "
2319 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2324 * Do we have a valid printer name?
2327 if (!validate_name(resource
+ 10))
2330 * No, return an error...
2333 send_ipp_status(con
, IPP_BAD_REQUEST
,
2334 _("The printer-uri \"%s\" contains invalid characters."),
2335 uri
->values
[0].string
.text
);
2340 * See if the printer already exists; if not, create a new printer...
2343 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2346 * Printer doesn't exist; see if we have a class of the same name...
2349 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2352 * Yes, return an error...
2355 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2356 _("A class named \"%s\" already exists."),
2362 * No, check the default policy then add the printer...
2365 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2367 send_http_error(con
, status
, NULL
);
2371 printer
= cupsdAddPrinter(resource
+ 10);
2374 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2377 send_http_error(con
, status
, printer
);
2384 * Look for attributes and copy them over as needed...
2388 need_restart_job
= 0;
2390 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2391 IPP_TAG_TEXT
)) != NULL
)
2392 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2394 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2395 IPP_TAG_TEXT
)) != NULL
)
2396 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2400 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2401 IPP_TAG_URI
)) != NULL
)
2404 * Do we have a valid device URI?
2407 http_uri_status_t uri_status
; /* URI separation status */
2408 char old_device_uri
[1024];
2409 /* Old device URI */
2412 need_restart_job
= 1;
2414 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2415 attr
->values
[0].string
.text
,
2416 scheme
, sizeof(scheme
),
2417 username
, sizeof(username
),
2418 host
, sizeof(host
), &port
,
2419 resource
, sizeof(resource
));
2421 if (uri_status
< HTTP_URI_OK
)
2423 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2424 attr
->values
[0].string
.text
);
2425 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2426 "add_printer: httpSeparateURI returned %d", uri_status
);
2430 if (!strcmp(scheme
, "file"))
2433 * See if the administrator has enabled file devices...
2436 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2439 * File devices are disabled and the URL is not file:/dev/null...
2442 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2443 _("File device URIs have been disabled. "
2444 "To enable, see the FileDevice directive in "
2445 "\"%s/cups-files.conf\"."),
2453 * See if the backend exists and is executable...
2456 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2457 if (access(srcfile
, X_OK
))
2460 * Could not find device in list!
2463 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2464 _("Bad device-uri scheme \"%s\"."), scheme
);
2469 if (printer
->sanitized_device_uri
)
2470 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2471 sizeof(old_device_uri
));
2473 old_device_uri
[0] = '\0';
2475 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2477 cupsdLogMessage(CUPSD_LOG_INFO
,
2478 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2479 printer
->name
, printer
->sanitized_device_uri
,
2485 set_port_monitor
= 0;
2487 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2488 IPP_TAG_NAME
)) != NULL
)
2490 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2493 need_restart_job
= 1;
2495 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2499 for (i
= 0; i
< supported
->num_values
; i
++)
2500 if (!strcmp(supported
->values
[i
].string
.text
,
2501 attr
->values
[0].string
.text
))
2505 if (!supported
|| i
>= supported
->num_values
)
2507 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2508 attr
->values
[0].string
.text
);
2512 cupsdLogMessage(CUPSD_LOG_INFO
,
2513 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2514 printer
->name
, attr
->values
[0].string
.text
,
2515 printer
->port_monitor
? printer
->port_monitor
: "none");
2517 if (strcmp(attr
->values
[0].string
.text
, "none"))
2518 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2520 cupsdClearString(&printer
->port_monitor
);
2522 set_port_monitor
= 1;
2525 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2526 IPP_TAG_BOOLEAN
)) != NULL
&&
2527 attr
->values
[0].boolean
!= printer
->accepting
)
2529 cupsdLogMessage(CUPSD_LOG_INFO
,
2530 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2531 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2533 printer
->accepting
= attr
->values
[0].boolean
;
2535 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2536 "%s accepting jobs.",
2537 printer
->accepting
? "Now" : "No longer");
2540 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2541 IPP_TAG_BOOLEAN
)) != NULL
)
2543 if (attr
->values
[0].boolean
&&
2544 printer
->num_auth_info_required
== 1 &&
2545 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2547 send_ipp_status(con
, IPP_BAD_REQUEST
,
2548 _("Cannot share a remote Kerberized printer."));
2552 if (printer
->shared
&& !attr
->values
[0].boolean
)
2553 cupsdDeregisterPrinter(printer
, 1);
2555 cupsdLogMessage(CUPSD_LOG_INFO
,
2556 "Setting %s printer-is-shared to %d (was %d.)",
2557 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2559 printer
->shared
= attr
->values
[0].boolean
;
2562 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2563 IPP_TAG_ENUM
)) != NULL
)
2565 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2566 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2568 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2569 attr
->values
[0].integer
);
2573 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2574 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2576 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2577 cupsdStopPrinter(printer
, 0);
2580 need_restart_job
= 1;
2581 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2585 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2586 IPP_TAG_TEXT
)) != NULL
)
2588 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2589 sizeof(printer
->state_message
));
2591 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2592 printer
->state_message
);
2595 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2596 IPP_TAG_KEYWORD
)) != NULL
)
2598 if (attr
->num_values
>
2599 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2601 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2602 _("Too many printer-state-reasons values (%d > %d)."),
2604 (int)(sizeof(printer
->reasons
) /
2605 sizeof(printer
->reasons
[0])));
2609 for (i
= 0; i
< printer
->num_reasons
; i
++)
2610 _cupsStrFree(printer
->reasons
[i
]);
2612 printer
->num_reasons
= 0;
2613 for (i
= 0; i
< attr
->num_values
; i
++)
2615 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2618 printer
->reasons
[printer
->num_reasons
] =
2619 _cupsStrRetain(attr
->values
[i
].string
.text
);
2620 printer
->num_reasons
++;
2622 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2623 printer
->state
!= IPP_PRINTER_STOPPED
)
2625 cupsdLogMessage(CUPSD_LOG_INFO
,
2626 "Setting %s printer-state to %d (was %d.)",
2627 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2628 cupsdStopPrinter(printer
, 0);
2632 if (PrintcapFormat
== PRINTCAP_PLIST
)
2633 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2635 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2636 "Printer \"%s\" state changed.", printer
->name
);
2639 set_printer_defaults(con
, printer
);
2641 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2642 IPP_TAG_KEYWORD
)) != NULL
)
2643 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2646 * See if we have all required attributes...
2649 if (!printer
->device_uri
)
2650 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2653 * See if we have an interface script or PPD file attached to the request...
2658 need_restart_job
= 1;
2661 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2663 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2666 * Yes; get the first line from it...
2670 cupsFileGets(fp
, line
, sizeof(line
));
2674 * Then see what kind of file it is...
2677 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2680 if (!strncmp(line
, "*PPD-Adobe", 10))
2683 * The new file is a PPD file, so remove any old interface script
2684 * that might be lying around...
2692 * This must be an interface script, so move the file over to the
2693 * interfaces directory and make it executable...
2696 if (copy_file(srcfile
, dstfile
))
2698 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2699 _("Unable to copy interface script - %s"),
2704 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2705 "Copied interface script successfully");
2706 chmod(dstfile
, 0755);
2709 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2712 if (!strncmp(line
, "*PPD-Adobe", 10))
2715 * The new file is a PPD file, so move the file over to the
2716 * ppd directory and make it readable by all...
2719 if (copy_file(srcfile
, dstfile
))
2721 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2722 _("Unable to copy PPD file - %s"),
2727 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2728 "Copied PPD file successfully");
2729 chmod(dstfile
, 0644);
2734 * This must be an interface script, so remove any old PPD file that
2735 * may be lying around...
2742 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2743 IPP_TAG_NAME
)) != NULL
)
2745 need_restart_job
= 1;
2748 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2751 * Raw driver, remove any existing PPD or interface script files.
2754 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2758 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2768 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2772 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2775 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2777 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2781 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2782 "Copied PPD file successfully");
2783 chmod(dstfile
, 0644);
2790 * If we changed the PPD/interface script, then remove the printer's cache
2791 * file and clear the printer-state-reasons...
2794 char cache_name
[1024]; /* Cache filename for printer attrs */
2796 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2800 cupsdSetPrinterReasons(printer
, "none");
2803 * (Re)register color profiles...
2806 cupsdRegisterColor(printer
);
2810 * If we set the device URI but not the port monitor, check which port
2811 * monitor to use by default...
2814 if (set_device_uri
&& !set_port_monitor
)
2816 ppd_file_t
*ppd
; /* PPD file */
2817 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2820 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2821 sizeof(scheme
), username
, sizeof(username
), host
,
2822 sizeof(host
), &port
, resource
, sizeof(resource
));
2824 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2826 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2828 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2830 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2831 if (!strcmp(scheme
, ppdattr
->spec
))
2833 cupsdLogMessage(CUPSD_LOG_INFO
,
2834 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2835 printer
->name
, ppdattr
->value
,
2836 printer
->port_monitor
? printer
->port_monitor
2839 if (strcmp(ppdattr
->value
, "none"))
2840 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2842 cupsdClearString(&printer
->port_monitor
);
2852 * Update the printer attributes and return...
2855 cupsdSetPrinterAttrs(printer
);
2856 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2858 if (need_restart_job
&& printer
->job
)
2861 * Restart the current job...
2864 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2865 "Job restarted because the printer was modified.");
2868 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2872 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2873 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2874 printer
->name
, get_username(con
));
2876 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2877 printer
->name
, get_username(con
));
2881 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2882 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2883 printer
->name
, get_username(con
));
2885 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2886 printer
->name
, get_username(con
));
2889 con
->response
->request
.status
.status_code
= IPP_OK
;
2894 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2895 * based upon the printer state...
2899 add_printer_state_reasons(
2900 cupsd_client_t
*con
, /* I - Client connection */
2901 cupsd_printer_t
*p
) /* I - Printer info */
2903 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2904 "add_printer_state_reasons(%p[%d], %p[%s])",
2905 con
, con
->http
.fd
, p
, p
->name
);
2907 if (p
->num_reasons
== 0)
2908 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2909 "printer-state-reasons", NULL
, "none");
2911 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2912 "printer-state-reasons", p
->num_reasons
, NULL
,
2913 (const char * const *)p
->reasons
);
2918 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2919 * the specified printer or class.
2923 add_queued_job_count(
2924 cupsd_client_t
*con
, /* I - Client connection */
2925 cupsd_printer_t
*p
) /* I - Printer or class */
2927 int count
; /* Number of jobs on destination */
2930 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2931 con
, con
->http
.fd
, p
, p
->name
);
2933 count
= cupsdGetPrinterJobCount(p
->name
);
2935 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2936 "queued-job-count", count
);
2941 * 'apply_printer_defaults()' - Apply printer default options to a job.
2945 apply_printer_defaults(
2946 cupsd_printer_t
*printer
, /* I - Printer */
2947 cupsd_job_t
*job
) /* I - Job */
2949 int i
, /* Looping var */
2950 num_options
; /* Number of default options */
2951 cups_option_t
*options
, /* Default options */
2952 *option
; /* Current option */
2956 * Collect all of the default options and add the missing ones to the
2960 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2961 option
= printer
->options
;
2964 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2966 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2971 * Encode these options as attributes in the job object...
2974 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2975 cupsFreeOptions(num_options
, options
);
2980 * 'authenticate_job()' - Set job authentication info.
2984 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2985 ipp_attribute_t
*uri
) /* I - Job URI */
2987 ipp_attribute_t
*attr
, /* job-id attribute */
2988 *auth_info
; /* auth-info attribute */
2989 int jobid
; /* Job ID */
2990 cupsd_job_t
*job
; /* Current job */
2991 char scheme
[HTTP_MAX_URI
],
2992 /* Method portion of URI */
2993 username
[HTTP_MAX_URI
],
2994 /* Username portion of URI */
2996 /* Host portion of URI */
2997 resource
[HTTP_MAX_URI
];
2998 /* Resource portion of URI */
2999 int port
; /* Port portion of URI */
3002 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3003 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3006 * Start with "everything is OK" status...
3009 con
->response
->request
.status
.status_code
= IPP_OK
;
3012 * See if we have a job URI or a printer URI...
3015 if (!strcmp(uri
->name
, "printer-uri"))
3018 * Got a printer URI; see if we also have a job-id attribute...
3021 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3022 IPP_TAG_INTEGER
)) == NULL
)
3024 send_ipp_status(con
, IPP_BAD_REQUEST
,
3025 _("Got a printer-uri attribute but no job-id."));
3029 jobid
= attr
->values
[0].integer
;
3034 * Got a job URI; parse it to get the job ID...
3037 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3038 sizeof(scheme
), username
, sizeof(username
), host
,
3039 sizeof(host
), &port
, resource
, sizeof(resource
));
3041 if (strncmp(resource
, "/jobs/", 6))
3047 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3048 uri
->values
[0].string
.text
);
3052 jobid
= atoi(resource
+ 6);
3056 * See if the job exists...
3059 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3062 * Nope - return a "not found" error...
3065 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3070 * See if the job has been completed...
3073 if (job
->state_value
!= IPP_JOB_HELD
)
3076 * Return a "not-possible" error...
3079 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3080 _("Job #%d is not held for authentication."),
3086 * See if we have already authenticated...
3089 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3091 if (!con
->username
[0] && !auth_info
)
3093 cupsd_printer_t
*printer
; /* Job destination */
3096 * No auth data. If we need to authenticate via Kerberos, send a
3097 * HTTP auth challenge, otherwise just return an IPP error...
3100 printer
= cupsdFindDest(job
->dest
);
3102 if (printer
&& printer
->num_auth_info_required
> 0 &&
3103 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3104 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3106 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3107 _("No authentication information provided."));
3112 * See if the job is owned by the requesting user...
3115 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3117 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3118 cupsdFindDest(job
->dest
));
3123 * Save the authentication information for this job...
3126 save_auth_info(con
, job
, auth_info
);
3129 * Reset the job-hold-until value to "no-hold"...
3132 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3133 IPP_TAG_KEYWORD
)) == NULL
)
3134 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3138 attr
->value_tag
= IPP_TAG_KEYWORD
;
3139 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3143 * Release the job and return...
3146 cupsdReleaseJob(job
);
3148 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3150 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3157 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3161 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3162 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3164 int i
; /* Looping var */
3165 http_status_t status
; /* Policy status */
3166 cups_ptype_t dtype
; /* Destination type */
3167 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3168 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3169 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3170 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3171 int port
; /* Port portion of URI */
3172 ipp_attribute_t
*attr
; /* Attribute in request */
3173 const char *username
= NULL
; /* Username */
3174 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3176 cupsd_printer_t
*printer
; /* Printer */
3177 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3178 cupsd_job_t
*job
; /* Job */
3181 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3182 con
->http
.fd
, uri
->values
[0].string
.text
);
3185 * Get the jobs to cancel/purge...
3188 switch (con
->request
->request
.op
.operation_id
)
3190 case IPP_PURGE_JOBS
:
3192 * Get the username (if any) for the jobs we want to cancel (only if
3193 * "my-jobs" is specified...
3196 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3197 IPP_TAG_BOOLEAN
)) != NULL
&&
3198 attr
->values
[0].boolean
)
3200 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3201 IPP_TAG_NAME
)) != NULL
)
3202 username
= attr
->values
[0].string
.text
;
3205 send_ipp_status(con
, IPP_BAD_REQUEST
,
3206 _("Missing requesting-user-name attribute."));
3212 * Look for the "purge-jobs" attribute...
3215 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3216 IPP_TAG_BOOLEAN
)) != NULL
)
3217 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3219 purge
= CUPSD_JOB_PURGE
;
3222 case IPP_CANCEL_MY_JOBS
:
3223 if (con
->username
[0])
3224 username
= con
->username
;
3225 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3226 IPP_TAG_NAME
)) != NULL
)
3227 username
= attr
->values
[0].string
.text
;
3230 send_ipp_status(con
, IPP_BAD_REQUEST
,
3231 _("Missing requesting-user-name attribute."));
3239 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3242 * See if we have a printer URI...
3245 if (strcmp(uri
->name
, "printer-uri"))
3247 send_ipp_status(con
, IPP_BAD_REQUEST
,
3248 _("The printer-uri attribute is required."));
3253 * And if the destination is valid...
3256 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3262 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3263 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3264 hostname
, sizeof(hostname
), &port
,
3265 resource
, sizeof(resource
));
3267 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3268 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3270 send_ipp_status(con
, IPP_NOT_FOUND
,
3271 _("The printer or class does not exist."));
3279 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3281 send_http_error(con
, status
, NULL
);
3287 for (i
= 0; i
< job_ids
->num_values
; i
++)
3289 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
3293 if (i
< job_ids
->num_values
)
3295 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3296 job_ids
->values
[i
].integer
);
3300 for (i
= 0; i
< job_ids
->num_values
; i
++)
3302 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3304 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3305 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3306 "Job canceled by user.");
3309 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3310 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3316 * Cancel all jobs on all printers...
3319 cupsdCancelJobs(NULL
, username
, purge
);
3321 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3322 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3332 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3335 send_http_error(con
, status
, printer
);
3341 for (i
= 0; i
< job_ids
->num_values
; i
++)
3343 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3344 _cups_strcasecmp(job
->dest
, printer
->name
))
3348 if (i
< job_ids
->num_values
)
3350 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3351 job_ids
->values
[i
].integer
);
3355 for (i
= 0; i
< job_ids
->num_values
; i
++)
3357 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3359 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3360 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3361 "Job canceled by user.");
3364 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3365 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3371 * Cancel all of the jobs on the named printer...
3374 cupsdCancelJobs(printer
->name
, username
, purge
);
3376 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3378 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3383 con
->response
->request
.status
.status_code
= IPP_OK
;
3388 * 'cancel_job()' - Cancel a print job.
3392 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3393 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3395 ipp_attribute_t
*attr
; /* Current attribute */
3396 int jobid
; /* Job ID */
3397 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3398 username
[HTTP_MAX_URI
], /* Username portion of URI */
3399 host
[HTTP_MAX_URI
], /* Host portion of URI */
3400 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3401 int port
; /* Port portion of URI */
3402 cupsd_job_t
*job
; /* Job information */
3403 cups_ptype_t dtype
; /* Destination type (printer/class) */
3404 cupsd_printer_t
*printer
; /* Printer data */
3405 cupsd_jobaction_t purge
; /* Purge the job? */
3408 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3409 con
->http
.fd
, uri
->values
[0].string
.text
);
3412 * See if we have a job URI or a printer URI...
3415 if (!strcmp(uri
->name
, "printer-uri"))
3418 * Got a printer URI; see if we also have a job-id attribute...
3421 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3422 IPP_TAG_INTEGER
)) == NULL
)
3424 send_ipp_status(con
, IPP_BAD_REQUEST
,
3425 _("Got a printer-uri attribute but no job-id."));
3429 if ((jobid
= attr
->values
[0].integer
) == 0)
3432 * Find the current job on the specified printer...
3435 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3441 send_ipp_status(con
, IPP_NOT_FOUND
,
3442 _("The printer or class does not exist."));
3447 * See if there are any pending jobs...
3450 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3452 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3453 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3454 !_cups_strcasecmp(job
->dest
, printer
->name
))
3462 * No, try stopped jobs...
3465 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3467 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3468 if (job
->state_value
== IPP_JOB_STOPPED
&&
3469 !_cups_strcasecmp(job
->dest
, printer
->name
))
3476 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3486 * Got a job URI; parse it to get the job ID...
3489 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3490 sizeof(scheme
), username
, sizeof(username
), host
,
3491 sizeof(host
), &port
, resource
, sizeof(resource
));
3493 if (strncmp(resource
, "/jobs/", 6))
3499 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3500 uri
->values
[0].string
.text
);
3504 jobid
= atoi(resource
+ 6);
3508 * Look for the "purge-job" attribute...
3511 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3512 IPP_TAG_BOOLEAN
)) != NULL
)
3513 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3515 purge
= CUPSD_JOB_DEFAULT
;
3518 * See if the job exists...
3521 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3524 * Nope - return a "not found" error...
3527 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3532 * See if the job is owned by the requesting user...
3535 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3537 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3538 cupsdFindDest(job
->dest
));
3543 * See if the job is already completed, canceled, or aborted; if so,
3544 * we can't cancel...
3547 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3549 switch (job
->state_value
)
3551 case IPP_JOB_CANCELED
:
3552 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3553 _("Job #%d is already canceled - can\'t cancel."),
3557 case IPP_JOB_ABORTED
:
3558 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3559 _("Job #%d is already aborted - can\'t cancel."),
3564 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3565 _("Job #%d is already completed - can\'t cancel."),
3574 * Cancel the job and return...
3577 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3578 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3579 "Job canceled by \"%s\"",
3583 if (purge
== CUPSD_JOB_PURGE
)
3584 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3587 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3590 con
->response
->request
.status
.status_code
= IPP_OK
;
3595 * 'cancel_subscription()' - Cancel a subscription.
3599 cancel_subscription(
3600 cupsd_client_t
*con
, /* I - Client connection */
3601 int sub_id
) /* I - Subscription ID */
3603 http_status_t status
; /* Policy status */
3604 cupsd_subscription_t
*sub
; /* Subscription */
3607 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3608 "cancel_subscription(con=%p[%d], sub_id=%d)",
3609 con
, con
->http
.fd
, sub_id
);
3612 * Is the subscription ID valid?
3615 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3618 * Bad subscription ID...
3621 send_ipp_status(con
, IPP_NOT_FOUND
,
3622 _("Subscription #%d does not exist."), sub_id
);
3630 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3632 con
, sub
->owner
)) != HTTP_OK
)
3634 send_http_error(con
, status
, sub
->dest
);
3639 * Cancel the subscription...
3642 cupsdDeleteSubscription(sub
, 1);
3644 con
->response
->request
.status
.status_code
= IPP_OK
;
3649 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3652 static int /* O - 1 if OK, 0 if not */
3653 check_rss_recipient(
3654 const char *recipient
) /* I - Recipient URI */
3656 cupsd_subscription_t
*sub
; /* Current subscription */
3659 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3661 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3665 * Compare the URIs up to the first ?...
3668 const char *r1
, *r2
;
3670 for (r1
= recipient
, r2
= sub
->recipient
;
3671 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3683 * 'check_quotas()' - Check quotas for a printer and user.
3686 static int /* O - 1 if OK, 0 if forbidden,
3687 -1 if limit reached */
3688 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3689 cupsd_printer_t
*p
) /* I - Printer or class */
3691 char username
[33], /* Username */
3692 *name
; /* Current user name */
3693 cupsd_quota_t
*q
; /* Quota data */
3694 #ifdef HAVE_MBR_UID_TO_UUID
3696 * Use Apple membership APIs which require that all names represent
3697 * valid user account or group records accessible by the server.
3700 uuid_t usr_uuid
; /* UUID for job requesting user */
3701 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3702 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3703 int mbr_err
; /* Error from membership function */
3704 int is_member
; /* Is this user a member? */
3707 * Use standard POSIX APIs for checking users and groups...
3710 struct passwd
*pw
; /* User password data */
3711 #endif /* HAVE_MBR_UID_TO_UUID */
3714 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3715 con
, con
->http
.fd
, p
, p
->name
);
3718 * Figure out who is printing...
3721 strlcpy(username
, get_username(con
), sizeof(username
));
3723 if ((name
= strchr(username
, '@')) != NULL
)
3724 *name
= '\0'; /* Strip @REALM */
3727 * Check global active job limits for printers and users...
3730 if (MaxJobsPerPrinter
)
3733 * Check if there are too many pending jobs on this printer...
3736 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3738 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3747 * Check if there are too many pending jobs for this user...
3750 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3752 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3759 * Check against users...
3762 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3765 if (cupsArrayCount(p
->users
))
3767 #ifdef HAVE_MBR_UID_TO_UUID
3769 * Get UUID for job requesting user...
3772 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3778 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3779 "check_quotas: UUID lookup failed for user \"%s\"",
3781 cupsdLogMessage(CUPSD_LOG_INFO
,
3782 "Denying user \"%s\" access to printer \"%s\" "
3783 "(unknown user)...",
3789 * Get UID and GID of requesting user...
3792 pw
= getpwnam(username
);
3794 #endif /* HAVE_MBR_UID_TO_UUID */
3796 for (name
= (char *)cupsArrayFirst(p
->users
);
3798 name
= (char *)cupsArrayNext(p
->users
))
3802 * Check group membership...
3805 #ifdef HAVE_MBR_UID_TO_UUID
3808 if (uuid_parse(name
+ 2, grp_uuid
))
3809 uuid_clear(grp_uuid
);
3811 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3814 * Invalid ACL entries are ignored for matching; just record a
3815 * warning in the log...
3818 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3819 "check_quotas: UUID lookup failed for ACL entry "
3820 "\"%s\" (err=%d)", name
, mbr_err
);
3821 cupsdLogMessage(CUPSD_LOG_WARN
,
3822 "Access control entry \"%s\" not a valid group name; "
3823 "entry ignored", name
);
3826 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3830 * At this point, there should be no errors, but check anyways...
3833 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3834 "check_quotas: group \"%s\" membership check "
3835 "failed (err=%d)", name
+ 1, mbr_err
);
3840 * Stop if we found a match...
3847 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3849 #endif /* HAVE_MBR_UID_TO_UUID */
3851 #ifdef HAVE_MBR_UID_TO_UUID
3856 if (uuid_parse(name
+ 1, usr2_uuid
))
3857 uuid_clear(usr2_uuid
);
3859 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3862 * Invalid ACL entries are ignored for matching; just record a
3863 * warning in the log...
3866 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3867 "check_quotas: UUID lookup failed for ACL entry "
3868 "\"%s\" (err=%d)", name
, mbr_err
);
3869 cupsdLogMessage(CUPSD_LOG_WARN
,
3870 "Access control entry \"%s\" not a valid user name; "
3871 "entry ignored", name
);
3874 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3878 else if (!_cups_strcasecmp(username
, name
))
3880 #endif /* HAVE_MBR_UID_TO_UUID */
3882 if ((name
!= NULL
) == p
->deny_users
)
3884 cupsdLogMessage(CUPSD_LOG_INFO
,
3885 "Denying user \"%s\" access to printer \"%s\"...",
3895 if (p
->k_limit
|| p
->page_limit
)
3897 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3899 cupsdLogMessage(CUPSD_LOG_ERROR
,
3900 "Unable to allocate quota data for user \"%s\"",
3905 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3906 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3908 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3915 * If we have gotten this far, we're done!
3923 * 'close_job()' - Close a multi-file job.
3927 close_job(cupsd_client_t
*con
, /* I - Client connection */
3928 ipp_attribute_t
*uri
) /* I - Printer URI */
3930 cupsd_job_t
*job
; /* Job */
3931 ipp_attribute_t
*attr
; /* Attribute */
3932 char job_uri
[HTTP_MAX_URI
],
3934 username
[256]; /* User name */
3937 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3938 con
->http
.fd
, uri
->values
[0].string
.text
);
3941 * See if we have a job URI or a printer URI...
3944 if (strcmp(uri
->name
, "printer-uri"))
3947 * job-uri is not supported by Close-Job!
3950 send_ipp_status(con
, IPP_BAD_REQUEST
,
3951 _("Close-Job doesn't support the job-uri attribute."));
3956 * Got a printer URI; see if we also have a job-id attribute...
3959 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3960 IPP_TAG_INTEGER
)) == NULL
)
3962 send_ipp_status(con
, IPP_BAD_REQUEST
,
3963 _("Got a printer-uri attribute but no job-id."));
3967 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3970 * Nope - return a "not found" error...
3973 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3974 attr
->values
[0].integer
);
3979 * See if the job is owned by the requesting user...
3982 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3984 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3985 cupsdFindDest(job
->dest
));
3990 * Add any ending sheet...
3993 if (cupsdTimeoutJob(job
))
3996 if (job
->state_value
== IPP_JOB_STOPPED
)
3998 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3999 job
->state_value
= IPP_JOB_PENDING
;
4001 else if (job
->state_value
== IPP_JOB_HELD
)
4003 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4004 IPP_TAG_KEYWORD
)) == NULL
)
4005 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4007 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
4009 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4010 job
->state_value
= IPP_JOB_PENDING
;
4015 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
4018 * Fill in the response info...
4021 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4022 con
->servername
, con
->serverport
, "/jobs/%d", job
->id
);
4023 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4026 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4028 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4031 con
->response
->request
.status
.status_code
= IPP_OK
;
4034 * Start the job if necessary...
4042 * 'copy_attrs()' - Copy attributes from one request to another.
4046 copy_attrs(ipp_t
*to
, /* I - Destination request */
4047 ipp_t
*from
, /* I - Source request */
4048 cups_array_t
*ra
, /* I - Requested attributes */
4049 ipp_tag_t group
, /* I - Group to copy */
4050 int quickcopy
, /* I - Do a quick copy? */
4051 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4053 ipp_attribute_t
*fromattr
; /* Source attribute */
4056 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4057 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4058 to
, from
, ra
, group
, quickcopy
);
4063 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4066 * Filter attributes as needed...
4069 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4070 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4073 if (!strcmp(fromattr
->name
, "job-printer-uri"))
4077 (cupsArrayFind(exclude
, fromattr
->name
) ||
4078 cupsArrayFind(exclude
, "all")))
4081 * We need to exclude this attribute for security reasons; we require the
4082 * job-id attribute regardless of the security settings for IPP
4085 * The job-printer-uri attribute is handled by copy_job_attrs().
4087 * Subscription attribute security is handled by copy_subscription_attrs().
4090 if (strcmp(fromattr
->name
, "job-id"))
4094 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4097 * Don't send collection attributes by default to IPP/1.x clients
4098 * since many do not support collections. Also don't send
4099 * media-col-database unless specifically requested by the client.
4102 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4104 (to
->request
.status
.version
[0] == 1 ||
4105 !strcmp(fromattr
->name
, "media-col-database")))
4108 ippCopyAttribute(to
, fromattr
, quickcopy
);
4115 * 'copy_banner()' - Copy a banner file to the requests directory for the
4119 static int /* O - Size of banner file in kbytes */
4120 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4121 cupsd_job_t
*job
, /* I - Job information */
4122 const char *name
) /* I - Name of banner */
4124 int i
; /* Looping var */
4125 int kbytes
; /* Size of banner file in kbytes */
4126 char filename
[1024]; /* Job filename */
4127 cupsd_banner_t
*banner
; /* Pointer to banner */
4128 cups_file_t
*in
; /* Input file */
4129 cups_file_t
*out
; /* Output file */
4130 int ch
; /* Character from file */
4131 char attrname
[255], /* Name of attribute */
4132 *s
; /* Pointer into name */
4133 ipp_attribute_t
*attr
; /* Attribute */
4136 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4137 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4138 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4139 name
? name
: "(null)");
4142 * Find the banner; return if not found or "none"...
4145 if (!name
|| !strcmp(name
, "none") ||
4146 (banner
= cupsdFindBanner(name
)) == NULL
)
4150 * Open the banner and job files...
4153 if (add_file(con
, job
, banner
->filetype
, 0))
4156 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4158 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4160 cupsdLogMessage(CUPSD_LOG_ERROR
,
4161 "Unable to create banner job file %s - %s",
4162 filename
, strerror(errno
));
4167 fchmod(cupsFileNumber(out
), 0640);
4168 fchown(cupsFileNumber(out
), RunUser
, Group
);
4171 * Try the localized banner file under the subdirectory...
4174 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4176 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4179 * Convert ll-cc to ll_CC...
4183 attrname
[3] = toupper(attrname
[3] & 255);
4184 attrname
[4] = toupper(attrname
[4] & 255);
4187 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4190 if (access(filename
, 0) && strlen(attrname
) > 2)
4193 * Wasn't able to find "ll_CC" locale file; try the non-national
4194 * localization banner directory.
4199 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4203 if (access(filename
, 0))
4206 * Use the non-localized banner file.
4209 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4212 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4216 cupsdLogMessage(CUPSD_LOG_ERROR
,
4217 "Unable to open banner template file %s - %s",
4218 filename
, strerror(errno
));
4224 * Parse the file to the end...
4227 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4231 * Get an attribute name...
4234 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4235 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4237 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4247 * Ignore { followed by stuff that is not an attribute name...
4250 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4255 * See if it is defined...
4258 if (attrname
[0] == '?')
4263 if (!strcmp(s
, "printer-name"))
4265 cupsFilePuts(out
, job
->dest
);
4268 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4271 * See if we have a leading question mark...
4274 if (attrname
[0] != '?')
4277 * Nope, write to file as-is; probably a PostScript procedure...
4280 cupsFilePrintf(out
, "{%s}", attrname
);
4287 * Output value(s)...
4290 for (i
= 0; i
< attr
->num_values
; i
++)
4293 cupsFilePutChar(out
, ',');
4295 switch (attr
->value_tag
)
4297 case IPP_TAG_INTEGER
:
4299 if (!strncmp(s
, "time-at-", 8))
4301 struct timeval tv
; /* Time value */
4303 tv
.tv_sec
= attr
->values
[i
].integer
;
4306 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4309 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4312 case IPP_TAG_BOOLEAN
:
4313 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4316 case IPP_TAG_NOVALUE
:
4317 cupsFilePuts(out
, "novalue");
4320 case IPP_TAG_RANGE
:
4321 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4322 attr
->values
[i
].range
.upper
);
4325 case IPP_TAG_RESOLUTION
:
4326 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4327 attr
->values
[i
].resolution
.yres
,
4328 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4333 case IPP_TAG_STRING
:
4336 case IPP_TAG_KEYWORD
:
4337 case IPP_TAG_CHARSET
:
4338 case IPP_TAG_LANGUAGE
:
4339 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4342 * Need to quote strings for PS banners...
4347 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4349 if (*p
== '(' || *p
== ')' || *p
== '\\')
4351 cupsFilePutChar(out
, '\\');
4352 cupsFilePutChar(out
, *p
);
4354 else if (*p
< 32 || *p
> 126)
4355 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4357 cupsFilePutChar(out
, *p
);
4361 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4365 break; /* anti-compiler-warning-code */
4369 else if (ch
== '\\') /* Quoted char */
4371 ch
= cupsFileGetChar(in
);
4373 if (ch
!= '{') /* Only do special handling for \{ */
4374 cupsFilePutChar(out
, '\\');
4376 cupsFilePutChar(out
, ch
);
4379 cupsFilePutChar(out
, ch
);
4383 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4385 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4386 IPP_TAG_INTEGER
)) != NULL
)
4387 attr
->values
[0].integer
+= kbytes
;
4396 * 'copy_file()' - Copy a PPD file or interface script...
4399 static int /* O - 0 = success, -1 = error */
4400 copy_file(const char *from
, /* I - Source file */
4401 const char *to
) /* I - Destination file */
4403 cups_file_t
*src
, /* Source file */
4404 *dst
; /* Destination file */
4405 int bytes
; /* Bytes to read/write */
4406 char buffer
[2048]; /* Copy buffer */
4409 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4412 * Open the source and destination file for a copy...
4415 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4418 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4425 * Copy the source file to the destination...
4428 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4429 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
4437 * Close both files and return...
4442 return (cupsFileClose(dst
));
4447 * 'copy_model()' - Copy a PPD model file, substituting default values
4451 static int /* O - 0 = success, -1 = error */
4452 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4453 const char *from
, /* I - Source file */
4454 const char *to
) /* I - Destination file */
4456 fd_set input
; /* select() input set */
4457 struct timeval timeout
; /* select() timeout */
4458 int maxfd
; /* Max file descriptor for select() */
4459 char tempfile
[1024]; /* Temporary PPD file */
4460 int tempfd
; /* Temporary PPD file descriptor */
4461 int temppid
; /* Process ID of cups-driverd */
4462 int temppipe
[2]; /* Temporary pipes */
4463 char *argv
[4], /* Command-line arguments */
4464 *envp
[MAX_ENV
]; /* Environment */
4465 cups_file_t
*src
, /* Source file */
4466 *dst
; /* Destination file */
4467 ppd_file_t
*ppd
; /* PPD file */
4468 int bytes
, /* Bytes from pipe */
4469 total
; /* Total bytes from pipe */
4470 char buffer
[2048]; /* Copy buffer */
4471 int i
; /* Looping var */
4472 char option
[PPD_MAX_NAME
], /* Option name */
4473 choice
[PPD_MAX_NAME
]; /* Choice name */
4474 ppd_size_t
*size
; /* Default size */
4475 int num_defaults
; /* Number of default options */
4476 cups_option_t
*defaults
; /* Default options */
4477 char cups_protocol
[PPD_MAX_LINE
];
4478 /* cupsProtocol attribute */
4481 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4482 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4486 * Run cups-driverd to get the PPD file...
4489 argv
[0] = "cups-driverd";
4491 argv
[2] = (char *)from
;
4494 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4496 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4497 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
4498 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4499 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4502 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4503 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4505 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4506 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4517 * Wait up to 30 seconds for the PPD file to be copied...
4522 if (temppipe
[0] > CGIPipes
[0])
4523 maxfd
= temppipe
[0] + 1;
4525 maxfd
= CGIPipes
[0] + 1;
4530 * See if we have data ready...
4534 FD_SET(temppipe
[0], &input
);
4535 FD_SET(CGIPipes
[0], &input
);
4537 timeout
.tv_sec
= 30;
4538 timeout
.tv_usec
= 0;
4540 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4550 * We have timed out...
4556 if (FD_ISSET(temppipe
[0], &input
))
4559 * Read the PPD file from the pipe, and write it to the PPD file.
4562 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4564 if (write(tempfd
, buffer
, bytes
) < bytes
)
4573 if (FD_ISSET(CGIPipes
[0], &input
))
4583 * No data from cups-deviced...
4586 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4592 * Open the source file for a copy...
4595 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4602 * Read the source file and see what page sizes are supported...
4605 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4613 * Open the destination (if possible) and set the default options...
4618 cups_protocol
[0] = '\0';
4620 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4623 * Read all of the default lines from the old PPD...
4626 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4627 if (!strncmp(buffer
, "*Default", 8))
4630 * Add the default option...
4633 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4634 choice
, sizeof(choice
)))
4636 ppd_option_t
*ppdo
; /* PPD option */
4640 * Only add the default if the default hasn't already been
4641 * set and the choice exists in the new PPD...
4644 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4645 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4646 ppdFindChoice(ppdo
, choice
))
4647 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4651 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4652 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4656 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4659 * Add the default media sizes...
4662 num_defaults
= cupsAddOption("PageSize", size
->name
,
4663 num_defaults
, &defaults
);
4664 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4665 num_defaults
, &defaults
);
4666 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4667 num_defaults
, &defaults
);
4668 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4669 num_defaults
, &defaults
);
4675 * Open the destination file for a copy...
4678 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4680 cupsFreeOptions(num_defaults
, defaults
);
4687 * Copy the source file to the destination...
4690 cupsFileRewind(src
);
4692 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4694 if (!strncmp(buffer
, "*Default", 8))
4697 * Check for an previous default option choice...
4700 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4701 choice
, sizeof(choice
)))
4703 const char *val
; /* Default option value */
4706 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4709 * Substitute the previous choice...
4712 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4717 cupsFilePrintf(dst
, "%s\n", buffer
);
4720 if (cups_protocol
[0])
4721 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4723 cupsFreeOptions(num_defaults
, defaults
);
4726 * Close both files and return...
4733 return (cupsFileClose(dst
));
4738 * 'copy_job_attrs()' - Copy job attributes.
4742 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4743 cupsd_job_t
*job
, /* I - Job */
4744 cups_array_t
*ra
, /* I - Requested attributes array */
4745 cups_array_t
*exclude
) /* I - Private attributes array */
4747 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4751 * Send the requested attributes for each job...
4754 if (!cupsArrayFind(exclude
, "all"))
4756 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4757 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4758 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4759 "number-of-documents", job
->num_files
);
4761 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4762 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4763 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4764 "job-media-progress", job
->progress
);
4766 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4767 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4769 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4770 NULL
, con
->servername
, con
->serverport
, "/jobs/%d",
4772 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4773 "job-more-info", NULL
, job_uri
);
4776 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4777 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4778 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4779 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4780 job
->num_files
> 0);
4782 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4783 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4784 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4785 "job-printer-up-time", time(NULL
));
4788 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4790 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4791 con
->servername
, con
->serverport
,
4792 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4795 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4796 "job-printer-uri", NULL
, job_uri
);
4799 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4801 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4802 con
->servername
, con
->serverport
, "/jobs/%d",
4804 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4805 "job-uri", NULL
, job_uri
);
4808 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4813 * 'copy_printer_attrs()' - Copy printer attributes.
4818 cupsd_client_t
*con
, /* I - Client connection */
4819 cupsd_printer_t
*printer
, /* I - Printer */
4820 cups_array_t
*ra
) /* I - Requested attributes array */
4822 char printer_uri
[HTTP_MAX_URI
];
4824 char printer_icons
[HTTP_MAX_URI
];
4826 time_t curtime
; /* Current time */
4827 int i
; /* Looping var */
4831 * Copy the printer attributes to the response using requested-attributes
4832 * and document-format attributes that may be provided by the client.
4835 curtime
= time(NULL
);
4837 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4838 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4839 "marker-change-time", printer
->marker_time
);
4841 if (printer
->num_printers
> 0 &&
4842 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4844 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4845 cupsd_printer_t
*p2
; /* Printer in class */
4846 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4849 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4850 IPP_TAG_URI
, "member-uris",
4851 printer
->num_printers
, NULL
,
4854 for (i
= 0; i
< printer
->num_printers
; i
++)
4856 p2
= printer
->printers
[i
];
4858 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4859 IPP_TAG_URI
)) != NULL
)
4860 member_uris
->values
[i
].string
.text
=
4861 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4864 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4865 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
4867 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4868 "/classes/%s" : "/printers/%s", p2
->name
);
4869 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4875 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4876 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4877 "printer-alert", NULL
, printer
->alert
);
4879 if (printer
->alert_description
&&
4880 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4881 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4882 "printer-alert-description", NULL
,
4883 printer
->alert_description
);
4885 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4886 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4887 ippTimeToDate(curtime
));
4889 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4890 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4892 if (printer
->reg_name
)
4893 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4894 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4896 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4897 "printer-dns-sd-name", 0);
4899 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4901 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4902 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4903 "printer-error-policy", NULL
, printer
->error_policy
);
4905 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4907 static const char * const errors
[] =/* printer-error-policy-supported values */
4910 "retry-current-job",
4915 if (printer
->type
& CUPS_PRINTER_CLASS
)
4916 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4917 "printer-error-policy-supported", NULL
, "retry-current-job");
4919 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4920 "printer-error-policy-supported",
4921 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4924 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4926 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4927 "http", NULL
, con
->servername
, con
->serverport
,
4928 "/icons/%s.png", printer
->name
);
4929 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4930 NULL
, printer_icons
);
4931 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4934 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4935 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
4936 printer
->accepting
);
4938 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4939 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
4942 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4944 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4945 "http", NULL
, con
->servername
, con
->serverport
,
4946 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4947 "/classes/%s" : "/printers/%s", printer
->name
);
4948 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4949 "printer-more-info", NULL
, printer_uri
);
4952 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4953 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4954 "printer-op-policy", NULL
, printer
->op_policy
);
4956 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4957 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4960 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4961 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4962 "printer-state-change-time", printer
->state_time
);
4964 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4965 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4966 "printer-state-message", NULL
, printer
->state_message
);
4968 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4969 add_printer_state_reasons(con
, printer
);
4971 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4973 int type
; /* printer-type value */
4976 * Add the CUPS-specific printer-type attribute...
4979 type
= printer
->type
;
4981 if (printer
== DefaultPrinter
)
4982 type
|= CUPS_PRINTER_DEFAULT
;
4984 if (!printer
->accepting
)
4985 type
|= CUPS_PRINTER_REJECTING
;
4987 if (!printer
->shared
)
4988 type
|= CUPS_PRINTER_NOT_SHARED
;
4990 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
4994 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
4995 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4996 "printer-up-time", curtime
);
4998 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
5000 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5001 "ipp", NULL
, con
->servername
, con
->serverport
,
5002 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5003 "/classes/%s" : "/printers/%s", printer
->name
);
5004 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5005 "printer-uri-supported", NULL
, printer_uri
);
5006 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5010 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5011 add_queued_job_count(con
, printer
);
5013 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5014 if (printer
->ppd_attrs
)
5015 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5016 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5021 * 'copy_subscription_attrs()' - Copy subscription attributes.
5025 copy_subscription_attrs(
5026 cupsd_client_t
*con
, /* I - Client connection */
5027 cupsd_subscription_t
*sub
, /* I - Subscription */
5028 cups_array_t
*ra
, /* I - Requested attributes array */
5029 cups_array_t
*exclude
) /* I - Private attributes array */
5031 ipp_attribute_t
*attr
; /* Current attribute */
5032 char printer_uri
[HTTP_MAX_URI
];
5034 int count
; /* Number of events */
5035 unsigned mask
; /* Current event mask */
5036 const char *name
; /* Current event name */
5039 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5040 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5041 con
, sub
, ra
, exclude
);
5044 * Copy the subscription attributes to the response using the
5045 * requested-attributes attribute that may be provided by the client.
5048 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5050 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5051 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5053 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5055 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5058 * Simple event list...
5061 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5062 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5063 "notify-events", NULL
, name
);
5068 * Complex event list...
5071 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5072 if (sub
->mask
& mask
)
5075 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5076 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5077 "notify-events", count
, NULL
, NULL
);
5079 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5080 if (sub
->mask
& mask
)
5082 attr
->values
[count
].string
.text
=
5083 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5090 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5091 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5092 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5093 "notify-lease-duration", sub
->lease
);
5095 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5096 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5097 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5098 "notify-recipient-uri", NULL
, sub
->recipient
);
5099 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5100 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5101 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5102 "notify-pull-method", NULL
, "ippget");
5104 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5105 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5106 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5107 "notify-subscriber-user-name", NULL
, sub
->owner
);
5109 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5110 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5111 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5112 "notify-time-interval", sub
->interval
);
5114 if (sub
->user_data_len
> 0 &&
5115 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5116 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5117 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5118 sub
->user_data
, sub
->user_data_len
);
5121 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5122 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5123 "notify-job-id", sub
->job
->id
);
5125 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5127 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5128 "ipp", NULL
, con
->servername
, con
->serverport
,
5129 "/printers/%s", sub
->dest
->name
);
5130 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5131 "notify-printer-uri", NULL
, printer_uri
);
5134 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5135 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5136 "notify-subscription-id", sub
->id
);
5141 * 'create_job()' - Print a file to a printer or class.
5145 create_job(cupsd_client_t
*con
, /* I - Client connection */
5146 ipp_attribute_t
*uri
) /* I - Printer URI */
5148 int i
; /* Looping var */
5149 cupsd_printer_t
*printer
; /* Printer */
5150 cupsd_job_t
*job
; /* New job */
5151 static const char * const forbidden_attrs
[] =
5152 { /* List of forbidden attributes */
5156 "document-natural-language"
5160 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5161 con
->http
.fd
, uri
->values
[0].string
.text
);
5164 * Is the destination valid?
5167 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5173 send_ipp_status(con
, IPP_NOT_FOUND
,
5174 _("The printer or class does not exist."));
5179 * Check for invalid Create-Job attributes and log a warning or error depending
5180 * on whether cupsd is running in "strict conformance" mode...
5184 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5186 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5188 if (StrictConformance
)
5190 send_ipp_status(con
, IPP_BAD_REQUEST
,
5191 _("The '%s' operation attribute cannot be supplied in a "
5192 "Create-Job request."), forbidden_attrs
[i
]);
5196 cupsdLogMessage(CUPSD_LOG_WARN
,
5197 "Unexpected '%s' operation attribute in a Create-Job "
5198 "request.", forbidden_attrs
[i
]);
5202 * Create the job object...
5205 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5208 job
->pending_timeout
= 1;
5211 * Save and log the job...
5214 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5215 job
->dest
, job
->username
);
5220 * 'create_requested_array()' - Create an array for the requested-attributes.
5223 static cups_array_t
* /* O - Array of attributes or NULL */
5224 create_requested_array(ipp_t
*request
) /* I - IPP request */
5226 int i
; /* Looping var */
5227 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5228 cups_array_t
*ra
; /* Requested attributes array */
5229 char *value
; /* Current value */
5233 * Get the requested-attributes attribute, and return NULL if we don't
5237 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5238 IPP_TAG_KEYWORD
)) == NULL
)
5242 * If the attribute contains a single "all" keyword, return NULL...
5245 if (requested
->num_values
== 1 &&
5246 !strcmp(requested
->values
[0].string
.text
, "all"))
5250 * Create an array using "strcmp" as the comparison function...
5253 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5255 for (i
= 0; i
< requested
->num_values
; i
++)
5257 value
= requested
->values
[i
].string
.text
;
5259 if (!strcmp(value
, "job-template"))
5261 /* Only includes the set of Job Template attributes supported by CUPS */
5262 cupsArrayAdd(ra
, "copies");
5263 cupsArrayAdd(ra
, "copies-default");
5264 cupsArrayAdd(ra
, "copies-supported");
5265 cupsArrayAdd(ra
, "finishings");
5266 cupsArrayAdd(ra
, "finishings-default");
5267 cupsArrayAdd(ra
, "finishings-supported");
5268 cupsArrayAdd(ra
, "job-hold-until");
5269 cupsArrayAdd(ra
, "job-hold-until-default");
5270 cupsArrayAdd(ra
, "job-hold-until-supported");
5271 cupsArrayAdd(ra
, "job-priority");
5272 cupsArrayAdd(ra
, "job-priority-default");
5273 cupsArrayAdd(ra
, "job-priority-supported");
5274 cupsArrayAdd(ra
, "job-sheets");
5275 cupsArrayAdd(ra
, "job-sheets-default");
5276 cupsArrayAdd(ra
, "job-sheets-supported");
5277 cupsArrayAdd(ra
, "media");
5278 cupsArrayAdd(ra
, "media-col");
5279 cupsArrayAdd(ra
, "media-col-default");
5280 cupsArrayAdd(ra
, "media-default");
5281 cupsArrayAdd(ra
, "media-supported");
5282 cupsArrayAdd(ra
, "multiple-document-handling");
5283 cupsArrayAdd(ra
, "multiple-document-handling-default");
5284 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5285 cupsArrayAdd(ra
, "number-up");
5286 cupsArrayAdd(ra
, "number-up-default");
5287 cupsArrayAdd(ra
, "number-up-layout");
5288 cupsArrayAdd(ra
, "number-up-layout-default");
5289 cupsArrayAdd(ra
, "number-up-layout-supported");
5290 cupsArrayAdd(ra
, "number-up-supported");
5291 cupsArrayAdd(ra
, "orientation-requested");
5292 cupsArrayAdd(ra
, "orientation-requested-default");
5293 cupsArrayAdd(ra
, "orientation-requested-supported");
5294 cupsArrayAdd(ra
, "output-bin");
5295 cupsArrayAdd(ra
, "output-bin-default");
5296 cupsArrayAdd(ra
, "output-bin-supported");
5297 cupsArrayAdd(ra
, "page-delivery");
5298 cupsArrayAdd(ra
, "page-delivery-default");
5299 cupsArrayAdd(ra
, "page-delivery-supported");
5300 cupsArrayAdd(ra
, "page-order-received");
5301 cupsArrayAdd(ra
, "page-order-received-default");
5302 cupsArrayAdd(ra
, "page-order-received-supported");
5303 cupsArrayAdd(ra
, "page-ranges");
5304 cupsArrayAdd(ra
, "page-ranges-supported");
5305 cupsArrayAdd(ra
, "presentation-direction-number-up");
5306 cupsArrayAdd(ra
, "presentation-direction-number-up-default");
5307 cupsArrayAdd(ra
, "presentation-direction-number-up-supported");
5308 cupsArrayAdd(ra
, "print-color-mode");
5309 cupsArrayAdd(ra
, "print-color-mode-default");
5310 cupsArrayAdd(ra
, "print-color-mode-supported");
5311 cupsArrayAdd(ra
, "print-content-optimize");
5312 cupsArrayAdd(ra
, "print-content-optimize-default");
5313 cupsArrayAdd(ra
, "print-content-optimize-supported");
5314 cupsArrayAdd(ra
, "print-quality");
5315 cupsArrayAdd(ra
, "print-quality-default");
5316 cupsArrayAdd(ra
, "print-quality-supported");
5317 cupsArrayAdd(ra
, "printer-resolution");
5318 cupsArrayAdd(ra
, "printer-resolution-default");
5319 cupsArrayAdd(ra
, "printer-resolution-supported");
5320 cupsArrayAdd(ra
, "sheet-collate");
5321 cupsArrayAdd(ra
, "sheet-collate-default");
5322 cupsArrayAdd(ra
, "sheet-collate-supported");
5323 cupsArrayAdd(ra
, "sides");
5324 cupsArrayAdd(ra
, "sides-default");
5325 cupsArrayAdd(ra
, "sides-supported");
5327 else if (!strcmp(value
, "job-description"))
5329 /* Only includes the set of Job Description attributes supported by CUPS */
5330 cupsArrayAdd(ra
, "date-time-at-completed");
5331 cupsArrayAdd(ra
, "date-time-at-creation");
5332 cupsArrayAdd(ra
, "date-time-at-processing");
5333 cupsArrayAdd(ra
, "job-charge-info");
5334 cupsArrayAdd(ra
, "job-detailed-status-message");
5335 cupsArrayAdd(ra
, "job-document-access-errors");
5336 cupsArrayAdd(ra
, "job-id");
5337 cupsArrayAdd(ra
, "job-impressions");
5338 cupsArrayAdd(ra
, "job-impressions-completed");
5339 cupsArrayAdd(ra
, "job-k-octets");
5340 cupsArrayAdd(ra
, "job-k-octets-processed");
5341 cupsArrayAdd(ra
, "job-mandatory-attributes");
5342 cupsArrayAdd(ra
, "job-media-progress");
5343 cupsArrayAdd(ra
, "job-media-sheets");
5344 cupsArrayAdd(ra
, "job-media-sheets-completed");
5345 cupsArrayAdd(ra
, "job-message-from-operator");
5346 cupsArrayAdd(ra
, "job-more-info");
5347 cupsArrayAdd(ra
, "job-name");
5348 cupsArrayAdd(ra
, "job-originating-user-name");
5349 cupsArrayAdd(ra
, "job-printer-up-time");
5350 cupsArrayAdd(ra
, "job-printer-uri");
5351 cupsArrayAdd(ra
, "job-state");
5352 cupsArrayAdd(ra
, "job-state-message");
5353 cupsArrayAdd(ra
, "job-state-reasons");
5354 cupsArrayAdd(ra
, "job-uri");
5355 cupsArrayAdd(ra
, "number-of-documents");
5356 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5357 cupsArrayAdd(ra
, "output-device-assigned");
5358 cupsArrayAdd(ra
, "time-at-completed");
5359 cupsArrayAdd(ra
, "time-at-creation");
5360 cupsArrayAdd(ra
, "time-at-processing");
5362 else if (!strcmp(value
, "printer-description"))
5364 /* Only includes the set of Printer Description attributes supported by CUPS */
5365 cupsArrayAdd(ra
, "charset-configured");
5366 cupsArrayAdd(ra
, "charset-supported");
5367 cupsArrayAdd(ra
, "color-supported");
5368 cupsArrayAdd(ra
, "compression-supported");
5369 cupsArrayAdd(ra
, "document-format-default");
5370 cupsArrayAdd(ra
, "document-format-supported");
5371 cupsArrayAdd(ra
, "generated-natural-language-supported");
5372 cupsArrayAdd(ra
, "ipp-versions-supported");
5373 cupsArrayAdd(ra
, "job-creation-attributes-supported");
5374 cupsArrayAdd(ra
, "job-ids-supported");
5375 cupsArrayAdd(ra
, "job-impressions-supported");
5376 cupsArrayAdd(ra
, "job-k-octets-supported");
5377 cupsArrayAdd(ra
, "job-media-sheets-supported");
5378 cupsArrayAdd(ra
, "job-settable-attributes-supported");
5379 cupsArrayAdd(ra
, "jpeg-k-octets-supported");
5380 cupsArrayAdd(ra
, "jpeg-x-dimension-supported");
5381 cupsArrayAdd(ra
, "jpeg-y-dimension-supported");
5382 cupsArrayAdd(ra
, "media-bottom-margin-supported");
5383 cupsArrayAdd(ra
, "media-col-supported");
5384 cupsArrayAdd(ra
, "media-key-supported");
5385 cupsArrayAdd(ra
, "media-left-margin-supported");
5386 cupsArrayAdd(ra
, "media-right-margin-supported");
5387 cupsArrayAdd(ra
, "media-size-supported");
5388 cupsArrayAdd(ra
, "media-source-supported");
5389 cupsArrayAdd(ra
, "media-top-margin-supported");
5390 cupsArrayAdd(ra
, "media-type-supported");
5391 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5392 cupsArrayAdd(ra
, "multiple-operation-time-out");
5393 cupsArrayAdd(ra
, "natural-language-configured");
5394 cupsArrayAdd(ra
, "notify-max-events-supported");
5395 cupsArrayAdd(ra
, "notify-schemes-supported");
5396 cupsArrayAdd(ra
, "operations-supported");
5397 cupsArrayAdd(ra
, "pages-per-minute");
5398 cupsArrayAdd(ra
, "pages-per-minute-color");
5399 cupsArrayAdd(ra
, "pdf-k-octets-supported");
5400 cupsArrayAdd(ra
, "pdl-override-supported");
5401 cupsArrayAdd(ra
, "printer-alert");
5402 cupsArrayAdd(ra
, "printer-alert-description");
5403 cupsArrayAdd(ra
, "printer-charge-info-uri");
5404 cupsArrayAdd(ra
, "printer-commands");
5405 cupsArrayAdd(ra
, "printer-current-time");
5406 cupsArrayAdd(ra
, "printer-dns-sd-name");
5407 cupsArrayAdd(ra
, "printer-info");
5408 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5409 cupsArrayAdd(ra
, "printer-is-shared");
5410 cupsArrayAdd(ra
, "printer-location");
5411 cupsArrayAdd(ra
, "printer-make-and-model");
5412 cupsArrayAdd(ra
, "printer-message-from-operator");
5413 cupsArrayAdd(ra
, "printer-more-info");
5414 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5415 cupsArrayAdd(ra
, "printer-name");
5416 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
5417 cupsArrayAdd(ra
, "printer-state");
5418 cupsArrayAdd(ra
, "printer-state-change-date-time");
5419 cupsArrayAdd(ra
, "printer-state-change-time");
5420 cupsArrayAdd(ra
, "printer-state-message");
5421 cupsArrayAdd(ra
, "printer-state-reasons");
5422 cupsArrayAdd(ra
, "printer-type");
5423 cupsArrayAdd(ra
, "printer-up-time");
5424 cupsArrayAdd(ra
, "printer-uri-supported");
5425 cupsArrayAdd(ra
, "queued-job-count");
5426 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5427 cupsArrayAdd(ra
, "uri-authentication-supported");
5428 cupsArrayAdd(ra
, "uri-security-supported");
5429 cupsArrayAdd(ra
, "which-jobs-supported");
5431 else if (!strcmp(value
, "printer-defaults"))
5433 char *name
; /* Option name */
5436 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5438 name
= (char *)cupsArrayNext(CommonDefaults
))
5439 cupsArrayAdd(ra
, name
);
5441 else if (!strcmp(value
, "subscription-description"))
5443 /* Only includes the set of Subscription Description attributes supported by CUPS */
5444 cupsArrayAdd(ra
, "notify-job-id");
5445 cupsArrayAdd(ra
, "notify-lease-expiration-time");
5446 cupsArrayAdd(ra
, "notify-printer-up-time");
5447 cupsArrayAdd(ra
, "notify-printer-uri");
5448 cupsArrayAdd(ra
, "notify-sequence-number");
5449 cupsArrayAdd(ra
, "notify-subscriber-user-name");
5450 cupsArrayAdd(ra
, "notify-subscription-id");
5452 else if (!strcmp(value
, "subscription-template"))
5454 /* Only includes the set of Subscription Template attributes supported by CUPS */
5455 cupsArrayAdd(ra
, "notify-attributes");
5456 cupsArrayAdd(ra
, "notify-attributes-supported");
5457 cupsArrayAdd(ra
, "notify-charset");
5458 cupsArrayAdd(ra
, "notify-events");
5459 cupsArrayAdd(ra
, "notify-events-default");
5460 cupsArrayAdd(ra
, "notify-events-supported");
5461 cupsArrayAdd(ra
, "notify-lease-duration");
5462 cupsArrayAdd(ra
, "notify-lease-duration-default");
5463 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5464 cupsArrayAdd(ra
, "notify-natural-language");
5465 cupsArrayAdd(ra
, "notify-pull-method");
5466 cupsArrayAdd(ra
, "notify-pull-method-supported");
5467 cupsArrayAdd(ra
, "notify-recipient-uri");
5468 cupsArrayAdd(ra
, "notify-time-interval");
5469 cupsArrayAdd(ra
, "notify-user-data");
5472 cupsArrayAdd(ra
, value
);
5480 * 'create_subscription()' - Create a notification subscription.
5484 create_subscription(
5485 cupsd_client_t
*con
, /* I - Client connection */
5486 ipp_attribute_t
*uri
) /* I - Printer URI */
5488 http_status_t status
; /* Policy status */
5489 int i
; /* Looping var */
5490 ipp_attribute_t
*attr
; /* Current attribute */
5491 cups_ptype_t dtype
; /* Destination type (printer/class) */
5492 char scheme
[HTTP_MAX_URI
],
5493 /* Scheme portion of URI */
5494 userpass
[HTTP_MAX_URI
],
5495 /* Username portion of URI */
5497 /* Host portion of URI */
5498 resource
[HTTP_MAX_URI
];
5499 /* Resource portion of URI */
5500 int port
; /* Port portion of URI */
5501 cupsd_printer_t
*printer
; /* Printer/class */
5502 cupsd_job_t
*job
; /* Job */
5503 int jobid
; /* Job ID */
5504 cupsd_subscription_t
*sub
; /* Subscription object */
5505 const char *username
, /* requesting-user-name or
5506 authenticated username */
5507 *recipient
, /* notify-recipient-uri */
5508 *pullmethod
; /* notify-pull-method */
5509 ipp_attribute_t
*user_data
; /* notify-user-data */
5510 int interval
, /* notify-time-interval */
5511 lease
; /* notify-lease-duration */
5512 unsigned mask
; /* notify-events */
5513 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5514 *notify_lease
; /* notify-lease-duration(-default) */
5518 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5520 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5521 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5522 attr
->value_tag
, attr
->name
);
5524 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5529 * Is the destination valid?
5532 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5533 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
5534 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
5536 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5537 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5538 sizeof(host
), &port
, resource
, sizeof(resource
));
5540 if (!strcmp(resource
, "/"))
5542 dtype
= (cups_ptype_t
)0;
5545 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5547 dtype
= (cups_ptype_t
)0;
5550 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5552 dtype
= CUPS_PRINTER_CLASS
;
5555 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5561 send_ipp_status(con
, IPP_NOT_FOUND
,
5562 _("The printer or class does not exist."));
5572 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5575 send_http_error(con
, status
, printer
);
5579 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5581 send_http_error(con
, status
, NULL
);
5586 * Get the user that is requesting the subscription...
5589 username
= get_username(con
);
5592 * Find the first subscription group attribute; return if we have
5596 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5597 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5602 send_ipp_status(con
, IPP_BAD_REQUEST
,
5603 _("No subscription attributes in request."));
5608 * Process the subscription attributes in the request...
5611 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5619 lease
= DefaultLeaseDuration
;
5621 mask
= CUPSD_EVENT_NONE
;
5625 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5627 notify_lease
= ippFindAttribute(printer
->attrs
,
5628 "notify-lease-duration-default",
5632 lease
= notify_lease
->values
[0].integer
;
5636 notify_events
= NULL
;
5637 notify_lease
= NULL
;
5640 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5642 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5643 attr
->value_tag
== IPP_TAG_URI
)
5646 * Validate the recipient scheme against the ServerBin/notifier
5650 char notifier
[1024]; /* Notifier filename */
5653 recipient
= attr
->values
[0].string
.text
;
5655 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5656 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5657 host
, sizeof(host
), &port
,
5658 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5660 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5661 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5662 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5663 "notify-status-code", IPP_URI_SCHEME
);
5667 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5669 if (access(notifier
, X_OK
))
5671 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5672 _("notify-recipient-uri URI \"%s\" uses unknown "
5673 "scheme."), recipient
);
5674 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5675 "notify-status-code", IPP_URI_SCHEME
);
5679 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5681 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5682 _("notify-recipient-uri URI \"%s\" is already used."),
5684 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5685 "notify-status-code", IPP_ATTRIBUTES
);
5689 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5690 attr
->value_tag
== IPP_TAG_KEYWORD
)
5692 pullmethod
= attr
->values
[0].string
.text
;
5694 if (strcmp(pullmethod
, "ippget"))
5696 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5697 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5698 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5699 "notify-status-code", IPP_ATTRIBUTES
);
5703 else if (!strcmp(attr
->name
, "notify-charset") &&
5704 attr
->value_tag
== IPP_TAG_CHARSET
&&
5705 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5706 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5708 send_ipp_status(con
, IPP_CHARSET
,
5709 _("Character set \"%s\" not supported."),
5710 attr
->values
[0].string
.text
);
5713 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5714 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5715 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5717 send_ipp_status(con
, IPP_CHARSET
,
5718 _("Language \"%s\" not supported."),
5719 attr
->values
[0].string
.text
);
5722 else if (!strcmp(attr
->name
, "notify-user-data") &&
5723 attr
->value_tag
== IPP_TAG_STRING
)
5725 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5727 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5728 _("The notify-user-data value is too large "
5729 "(%d > 63 octets)."),
5730 attr
->values
[0].unknown
.length
);
5736 else if (!strcmp(attr
->name
, "notify-events") &&
5737 attr
->value_tag
== IPP_TAG_KEYWORD
)
5738 notify_events
= attr
;
5739 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5740 attr
->value_tag
== IPP_TAG_INTEGER
)
5741 lease
= attr
->values
[0].integer
;
5742 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5743 attr
->value_tag
== IPP_TAG_INTEGER
)
5744 interval
= attr
->values
[0].integer
;
5745 else if (!strcmp(attr
->name
, "notify-job-id") &&
5746 attr
->value_tag
== IPP_TAG_INTEGER
)
5747 jobid
= attr
->values
[0].integer
;
5754 for (i
= 0; i
< notify_events
->num_values
; i
++)
5755 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5759 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5761 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5762 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5763 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5765 if (!recipient
&& !pullmethod
)
5768 if (mask
== CUPSD_EVENT_NONE
)
5771 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5773 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5776 send_ipp_status(con
, IPP_BAD_REQUEST
,
5777 _("notify-events not specified."));
5782 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5784 cupsdLogMessage(CUPSD_LOG_INFO
,
5785 "create_subscription: Limiting notify-lease-duration to "
5788 lease
= MaxLeaseDuration
;
5793 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5795 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5803 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5805 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5806 _("There are too many subscriptions."));
5811 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5814 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5815 "Added subscription #%d for printer \"%s\".",
5816 sub
->id
, printer
->name
);
5818 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5821 sub
->interval
= interval
;
5823 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5825 cupsdSetString(&sub
->owner
, username
);
5829 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5830 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5831 sub
->user_data_len
);
5834 ippAddSeparator(con
->response
);
5835 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5836 "notify-subscription-id", sub
->id
);
5838 con
->response
->request
.status
.status_code
= IPP_OK
;
5844 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5849 * 'delete_printer()' - Remove a printer or class from the system.
5853 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5854 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5856 http_status_t status
; /* Policy status */
5857 cups_ptype_t dtype
; /* Destination type (printer/class) */
5858 cupsd_printer_t
*printer
; /* Printer/class */
5859 char filename
[1024]; /* Script/PPD filename */
5862 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5863 con
->http
.fd
, uri
->values
[0].string
.text
);
5866 * Do we have a valid URI?
5869 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5875 send_ipp_status(con
, IPP_NOT_FOUND
,
5876 _("The printer or class does not exist."));
5884 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5886 send_http_error(con
, status
, NULL
);
5891 * Remove old jobs...
5894 cupsdCancelJobs(printer
->name
, NULL
, 1);
5897 * Remove old subscriptions and send a "deleted printer" event...
5900 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5901 "%s \"%s\" deleted by \"%s\".",
5902 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5903 printer
->name
, get_username(con
));
5905 cupsdExpireSubscriptions(printer
, NULL
);
5908 * Remove any old PPD or script files...
5911 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
5915 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5919 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
5922 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
5926 * Unregister color profiles...
5929 cupsdUnregisterColor(printer
);
5931 if (dtype
& CUPS_PRINTER_CLASS
)
5933 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5934 printer
->name
, get_username(con
));
5936 cupsdDeletePrinter(printer
, 0);
5937 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5941 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5942 printer
->name
, get_username(con
));
5944 if (cupsdDeletePrinter(printer
, 0))
5945 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5947 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
5950 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
5953 * Return with no errors...
5956 con
->response
->request
.status
.status_code
= IPP_OK
;
5961 * 'get_default()' - Get the default destination.
5965 get_default(cupsd_client_t
*con
) /* I - Client connection */
5967 http_status_t status
; /* Policy status */
5968 cups_array_t
*ra
; /* Requested attributes array */
5971 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
5977 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5979 send_http_error(con
, status
, NULL
);
5985 ra
= create_requested_array(con
->request
);
5987 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5989 cupsArrayDelete(ra
);
5991 con
->response
->request
.status
.status_code
= IPP_OK
;
5994 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
5999 * 'get_devices()' - Get the list of available devices on the local system.
6003 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6005 http_status_t status
; /* Policy status */
6006 ipp_attribute_t
*limit
, /* limit attribute */
6007 *timeout
, /* timeout attribute */
6008 *requested
, /* requested-attributes attribute */
6009 *exclude
, /* exclude-schemes attribute */
6010 *include
; /* include-schemes attribute */
6011 char command
[1024], /* cups-deviced command */
6012 options
[2048], /* Options to pass to command */
6014 /* String for requested attributes */
6016 /* String for excluded schemes */
6018 /* String for included schemes */
6021 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6027 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6029 send_http_error(con
, status
, NULL
);
6034 * Run cups-deviced command with the given options...
6037 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6038 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6039 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6041 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6042 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6045 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6047 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6050 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6052 exclude_str
[0] = '\0';
6055 url_encode_attr(include
, include_str
, sizeof(include_str
));
6057 include_str
[0] = '\0';
6059 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6060 snprintf(options
, sizeof(options
),
6061 "%d+%d+%d+%d+%s%s%s%s%s",
6062 con
->request
->request
.op
.request_id
,
6063 limit
? limit
->values
[0].integer
: 0,
6064 timeout
? timeout
->values
[0].integer
: 15,
6067 exclude_str
[0] ? "%20" : "", exclude_str
,
6068 include_str
[0] ? "%20" : "", include_str
);
6070 if (cupsdSendCommand(con
, command
, options
, 1))
6073 * Command started successfully, don't send an IPP response here...
6076 ippDelete(con
->response
);
6077 con
->response
= NULL
;
6082 * Command failed, return "internal error" so the user knows something
6086 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6087 _("cups-deviced failed to execute."));
6093 * 'get_document()' - Get a copy of a job file.
6097 get_document(cupsd_client_t
*con
, /* I - Client connection */
6098 ipp_attribute_t
*uri
) /* I - Job URI */
6100 http_status_t status
; /* Policy status */
6101 ipp_attribute_t
*attr
; /* Current attribute */
6102 int jobid
; /* Job ID */
6103 int docnum
; /* Document number */
6104 cupsd_job_t
*job
; /* Current job */
6105 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6106 username
[HTTP_MAX_URI
], /* Username portion of URI */
6107 host
[HTTP_MAX_URI
], /* Host portion of URI */
6108 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6109 int port
; /* Port portion of URI */
6110 char filename
[1024], /* Filename for document */
6111 format
[1024]; /* Format for document */
6114 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6115 con
->http
.fd
, uri
->values
[0].string
.text
);
6118 * See if we have a job URI or a printer URI...
6121 if (!strcmp(uri
->name
, "printer-uri"))
6124 * Got a printer URI; see if we also have a job-id attribute...
6127 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6128 IPP_TAG_INTEGER
)) == NULL
)
6130 send_ipp_status(con
, IPP_BAD_REQUEST
,
6131 _("Got a printer-uri attribute but no job-id."));
6135 jobid
= attr
->values
[0].integer
;
6140 * Got a job URI; parse it to get the job ID...
6143 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6144 sizeof(scheme
), username
, sizeof(username
), host
,
6145 sizeof(host
), &port
, resource
, sizeof(resource
));
6147 if (strncmp(resource
, "/jobs/", 6))
6153 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6154 uri
->values
[0].string
.text
);
6158 jobid
= atoi(resource
+ 6);
6162 * See if the job exists...
6165 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6168 * Nope - return a "not found" error...
6171 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6179 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6180 job
->username
)) != HTTP_OK
)
6182 send_http_error(con
, status
, NULL
);
6187 * Get the document number...
6190 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6191 IPP_TAG_INTEGER
)) == NULL
)
6193 send_ipp_status(con
, IPP_BAD_REQUEST
,
6194 _("Missing document-number attribute."));
6198 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6199 attr
->num_values
> 1)
6201 send_ipp_status(con
, IPP_NOT_FOUND
,
6202 _("Document #%d does not exist in job #%d."), docnum
,
6207 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6209 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6211 cupsdLogMessage(CUPSD_LOG_ERROR
,
6212 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6214 send_ipp_status(con
, IPP_NOT_FOUND
,
6215 _("Unable to open document #%d in job #%d."), docnum
,
6220 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6224 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6225 job
->filetypes
[docnum
- 1]->type
);
6227 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6229 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6231 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6232 IPP_TAG_NAME
)) != NULL
)
6233 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6234 NULL
, attr
->values
[0].string
.text
);
6239 * 'get_job_attrs()' - Get job attributes.
6243 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6244 ipp_attribute_t
*uri
) /* I - Job URI */
6246 http_status_t status
; /* Policy status */
6247 ipp_attribute_t
*attr
; /* Current attribute */
6248 int jobid
; /* Job ID */
6249 cupsd_job_t
*job
; /* Current job */
6250 cupsd_printer_t
*printer
; /* Current printer */
6251 cupsd_policy_t
*policy
; /* Current security policy */
6252 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6253 username
[HTTP_MAX_URI
], /* Username portion of URI */
6254 host
[HTTP_MAX_URI
], /* Host portion of URI */
6255 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6256 int port
; /* Port portion of URI */
6257 cups_array_t
*ra
, /* Requested attributes array */
6258 *exclude
; /* Private attributes array */
6261 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6262 con
->http
.fd
, uri
->values
[0].string
.text
);
6265 * See if we have a job URI or a printer URI...
6268 if (!strcmp(uri
->name
, "printer-uri"))
6271 * Got a printer URI; see if we also have a job-id attribute...
6274 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6275 IPP_TAG_INTEGER
)) == NULL
)
6277 send_ipp_status(con
, IPP_BAD_REQUEST
,
6278 _("Got a printer-uri attribute but no job-id."));
6282 jobid
= attr
->values
[0].integer
;
6287 * Got a job URI; parse it to get the job ID...
6290 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6291 sizeof(scheme
), username
, sizeof(username
), host
,
6292 sizeof(host
), &port
, resource
, sizeof(resource
));
6294 if (strncmp(resource
, "/jobs/", 6))
6300 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6301 uri
->values
[0].string
.text
);
6305 jobid
= atoi(resource
+ 6);
6309 * See if the job exists...
6312 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6315 * Nope - return a "not found" error...
6318 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6326 if ((printer
= job
->printer
) == NULL
)
6327 printer
= cupsdFindDest(job
->dest
);
6330 policy
= printer
->op_policy_ptr
;
6332 policy
= DefaultPolicyPtr
;
6334 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6336 send_http_error(con
, status
, NULL
);
6340 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6343 * Copy attributes...
6348 ra
= create_requested_array(con
->request
);
6349 copy_job_attrs(con
, job
, ra
, exclude
);
6350 cupsArrayDelete(ra
);
6352 con
->response
->request
.status
.status_code
= IPP_OK
;
6357 * 'get_jobs()' - Get a list of jobs for the specified printer.
6361 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6362 ipp_attribute_t
*uri
) /* I - Printer URI */
6364 http_status_t status
; /* Policy status */
6365 ipp_attribute_t
*attr
; /* Current attribute */
6366 const char *dest
; /* Destination */
6367 cups_ptype_t dtype
; /* Destination type (printer/class) */
6368 cups_ptype_t dmask
; /* Destination type mask */
6369 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6370 username
[HTTP_MAX_URI
], /* Username portion of URI */
6371 host
[HTTP_MAX_URI
], /* Host portion of URI */
6372 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6373 int port
; /* Port portion of URI */
6374 int job_comparison
; /* Job comparison */
6375 ipp_jstate_t job_state
; /* job-state value */
6376 int first_job_id
; /* First job ID */
6377 int limit
; /* Maximum number of jobs to return */
6378 int count
; /* Number of jobs that match */
6379 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6380 cupsd_job_t
*job
; /* Current job pointer */
6381 cupsd_printer_t
*printer
; /* Printer */
6382 cups_array_t
*list
; /* Which job list... */
6383 cups_array_t
*ra
, /* Requested attributes array */
6384 *exclude
; /* Private attributes array */
6385 cupsd_policy_t
*policy
; /* Current policy */
6388 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6389 uri
->values
[0].string
.text
);
6392 * Is the destination valid?
6395 if (strcmp(uri
->name
, "printer-uri"))
6397 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6401 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6402 sizeof(scheme
), username
, sizeof(username
), host
,
6403 sizeof(host
), &port
, resource
, sizeof(resource
));
6405 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6408 dtype
= (cups_ptype_t
)0;
6409 dmask
= (cups_ptype_t
)0;
6412 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6415 dtype
= (cups_ptype_t
)0;
6416 dmask
= CUPS_PRINTER_CLASS
;
6419 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6422 dtype
= CUPS_PRINTER_CLASS
;
6423 dmask
= CUPS_PRINTER_CLASS
;
6426 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6433 send_ipp_status(con
, IPP_NOT_FOUND
,
6434 _("The printer or class does not exist."));
6439 dtype
&= CUPS_PRINTER_CLASS
;
6440 dmask
= CUPS_PRINTER_CLASS
;
6448 policy
= printer
->op_policy_ptr
;
6450 policy
= DefaultPolicyPtr
;
6452 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6454 send_http_error(con
, status
, NULL
);
6458 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6461 * See if the "which-jobs" attribute have been specified...
6464 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6465 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6467 send_ipp_status(con
, IPP_CONFLICT
,
6468 _("The %s attribute cannot be provided with job-ids."),
6472 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6474 job_comparison
= -1;
6475 job_state
= IPP_JOB_STOPPED
;
6478 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6481 job_state
= IPP_JOB_CANCELED
;
6484 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6487 job_state
= IPP_JOB_ABORTED
;
6490 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6493 job_state
= IPP_JOB_PENDING
;
6496 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6499 job_state
= IPP_JOB_CANCELED
;
6502 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6505 job_state
= IPP_JOB_PENDING
;
6508 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6511 job_state
= IPP_JOB_HELD
;
6514 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6517 job_state
= IPP_JOB_PROCESSING
;
6518 list
= PrintingJobs
;
6520 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6523 job_state
= IPP_JOB_STOPPED
;
6528 send_ipp_status(con
, IPP_ATTRIBUTES
,
6529 _("The which-jobs value \"%s\" is not supported."),
6530 attr
->values
[0].string
.text
);
6531 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6532 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6537 * See if they want to limit the number of jobs reported...
6540 if ((attr
= ippFindAttribute(con
->request
, "limit",
6541 IPP_TAG_INTEGER
)) != NULL
)
6545 send_ipp_status(con
, IPP_CONFLICT
,
6546 _("The %s attribute cannot be provided with job-ids."),
6551 limit
= attr
->values
[0].integer
;
6556 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6557 IPP_TAG_INTEGER
)) != NULL
)
6561 send_ipp_status(con
, IPP_CONFLICT
,
6562 _("The %s attribute cannot be provided with job-ids."),
6567 first_job_id
= attr
->values
[0].integer
;
6573 * See if we only want to see jobs for a specific user...
6576 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6577 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6579 send_ipp_status(con
, IPP_CONFLICT
,
6580 _("The %s attribute cannot be provided with job-ids."),
6584 else if (attr
&& attr
->values
[0].boolean
)
6585 strlcpy(username
, get_username(con
), sizeof(username
));
6589 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
6590 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
6593 * IPP conformance - Get-Jobs has a default requested-attributes value of
6594 * "job-id" and "job-uri".
6597 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6598 cupsArrayAdd(ra
, "job-id");
6599 cupsArrayAdd(ra
, "job-uri");
6603 * OK, build a list of jobs for this printer...
6608 int i
; /* Looping var */
6610 for (i
= 0; i
< job_ids
->num_values
; i
++)
6612 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6616 if (i
< job_ids
->num_values
)
6618 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6619 job_ids
->values
[i
].integer
);
6623 for (i
= 0; i
< job_ids
->num_values
; i
++)
6625 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6631 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6637 ippAddSeparator(con
->response
);
6639 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6640 job
->printer
->op_policy_ptr
:
6641 policy
, con
, job
->printer
,
6644 copy_job_attrs(con
, job
, ra
, exclude
);
6649 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6650 (limit
<= 0 || count
< limit
) && job
;
6651 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6654 * Filter out jobs that don't match...
6657 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6658 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6659 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6660 job
->username
, job
->state_value
, job
->attrs
);
6662 if (!job
->dest
|| !job
->username
)
6665 if (!job
->dest
|| !job
->username
)
6668 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6669 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6671 if ((job
->dtype
& dmask
) != dtype
&&
6672 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6675 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6676 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6677 (job_comparison
> 0 && job
->state_value
< job_state
))
6680 if (job
->id
< first_job_id
)
6687 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6692 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6696 ippAddSeparator(con
->response
);
6700 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6701 job
->printer
->op_policy_ptr
:
6702 policy
, con
, job
->printer
,
6705 copy_job_attrs(con
, job
, ra
, exclude
);
6708 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6711 cupsArrayDelete(ra
);
6713 con
->response
->request
.status
.status_code
= IPP_OK
;
6718 * 'get_notifications()' - Get events for a subscription.
6722 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6724 int i
, j
; /* Looping vars */
6725 http_status_t status
; /* Policy status */
6726 cupsd_subscription_t
*sub
; /* Subscription */
6727 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6728 *sequences
; /* notify-sequence-numbers */
6729 int min_seq
; /* Minimum sequence number */
6730 int interval
; /* Poll interval */
6733 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6737 * Get subscription attributes...
6740 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6742 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6747 send_ipp_status(con
, IPP_BAD_REQUEST
,
6748 _("Missing notify-subscription-ids attribute."));
6753 * Are the subscription IDs valid?
6756 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6758 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6761 * Bad subscription ID...
6764 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6765 ids
->values
[i
].integer
);
6773 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6775 con
, sub
->owner
)) != HTTP_OK
)
6777 send_http_error(con
, status
, sub
->dest
);
6782 * Check the subscription type and update the interval accordingly.
6785 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6788 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6790 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6796 * Tell the client to poll again in N seconds...
6800 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6801 "notify-get-interval", interval
);
6803 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6804 "printer-up-time", time(NULL
));
6807 * Copy the subscription event attributes to the response.
6810 con
->response
->request
.status
.status_code
=
6811 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6813 for (i
= 0; i
< ids
->num_values
; i
++)
6816 * Get the subscription and sequence number...
6819 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6821 if (sequences
&& i
< sequences
->num_values
)
6822 min_seq
= sequences
->values
[i
].integer
;
6827 * If we don't have any new events, nothing to do here...
6830 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6834 * Otherwise copy all of the new events...
6837 if (sub
->first_event_id
> min_seq
)
6840 j
= min_seq
- sub
->first_event_id
;
6842 for (; j
< cupsArrayCount(sub
->events
); j
++)
6844 ippAddSeparator(con
->response
);
6846 copy_attrs(con
->response
,
6847 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
6848 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
6855 * 'get_ppd()' - Get a named PPD from the local system.
6859 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6860 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6862 http_status_t status
; /* Policy status */
6863 cupsd_printer_t
*dest
; /* Destination */
6864 cups_ptype_t dtype
; /* Destination type */
6867 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6868 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6870 if (!strcmp(uri
->name
, "ppd-name"))
6873 * Return a PPD file from cups-driverd...
6876 char command
[1024], /* cups-driverd command */
6877 options
[1024], /* Options to pass to command */
6878 ppd_name
[1024]; /* ppd-name */
6885 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6887 send_http_error(con
, status
, NULL
);
6892 * Run cups-driverd command with the given options...
6895 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6896 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
6897 snprintf(options
, sizeof(options
), "get+%d+%s",
6898 con
->request
->request
.op
.request_id
, ppd_name
);
6900 if (cupsdSendCommand(con
, command
, options
, 0))
6903 * Command started successfully, don't send an IPP response here...
6906 ippDelete(con
->response
);
6907 con
->response
= NULL
;
6912 * Command failed, return "internal error" so the user knows something
6916 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6917 _("cups-driverd failed to execute."));
6920 else if (!strcmp(uri
->name
, "printer-uri") &&
6921 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
6923 int i
; /* Looping var */
6924 char filename
[1024]; /* PPD filename */
6931 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6933 send_http_error(con
, status
, dest
);
6938 * See if we need the PPD for a class or remote printer...
6941 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6944 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
6946 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6947 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6948 "printer-uri", NULL
, dest
->uri
);
6951 else if (dtype
& CUPS_PRINTER_CLASS
)
6953 for (i
= 0; i
< dest
->num_printers
; i
++)
6954 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
6956 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6957 dest
->printers
[i
]->name
);
6959 if (!access(filename
, 0))
6963 if (i
< dest
->num_printers
)
6964 dest
= dest
->printers
[i
];
6967 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6968 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6969 "printer-uri", NULL
, dest
->printers
[0]->uri
);
6975 * Found the printer with the PPD file, now see if there is one...
6978 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
6980 send_ipp_status(con
, IPP_NOT_FOUND
,
6981 _("The PPD file \"%s\" could not be opened: %s"),
6982 uri
->values
[0].string
.text
, strerror(errno
));
6986 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6990 con
->response
->request
.status
.status_code
= IPP_OK
;
6993 send_ipp_status(con
, IPP_NOT_FOUND
,
6994 _("The PPD file \"%s\" could not be found."),
6995 uri
->values
[0].string
.text
);
7000 * 'get_ppds()' - Get the list of PPD files on the local system.
7004 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7006 http_status_t status
; /* Policy status */
7007 ipp_attribute_t
*limit
, /* Limit attribute */
7008 *device
, /* ppd-device-id attribute */
7009 *language
, /* ppd-natural-language attribute */
7010 *make
, /* ppd-make attribute */
7011 *model
, /* ppd-make-and-model attribute */
7012 *model_number
, /* ppd-model-number attribute */
7013 *product
, /* ppd-product attribute */
7014 *psversion
, /* ppd-psverion attribute */
7015 *type
, /* ppd-type attribute */
7016 *requested
, /* requested-attributes attribute */
7017 *exclude
, /* exclude-schemes attribute */
7018 *include
; /* include-schemes attribute */
7019 char command
[1024], /* cups-driverd command */
7020 options
[4096], /* Options to pass to command */
7021 device_str
[256],/* Escaped ppd-device-id string */
7023 /* Escaped ppd-natural-language */
7024 make_str
[256], /* Escaped ppd-make string */
7025 model_str
[256], /* Escaped ppd-make-and-model string */
7026 model_number_str
[256],
7027 /* ppd-model-number string */
7029 /* Escaped ppd-product string */
7031 /* Escaped ppd-psversion string */
7032 type_str
[256], /* Escaped ppd-type string */
7034 /* String for requested attributes */
7036 /* String for excluded schemes */
7038 /* String for included schemes */
7041 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7047 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7049 send_http_error(con
, status
, NULL
);
7054 * Run cups-driverd command with the given options...
7057 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7058 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7059 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7061 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7062 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7064 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7066 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7067 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7068 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7069 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7071 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7073 include
= ippFindAttribute(con
->request
, "include-schemes",
7077 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7079 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7082 url_encode_attr(device
, device_str
, sizeof(device_str
));
7084 device_str
[0] = '\0';
7087 url_encode_attr(language
, language_str
, sizeof(language_str
));
7089 language_str
[0] = '\0';
7092 url_encode_attr(make
, make_str
, sizeof(make_str
));
7097 url_encode_attr(model
, model_str
, sizeof(model_str
));
7099 model_str
[0] = '\0';
7102 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7103 model_number
->values
[0].integer
);
7105 model_number_str
[0] = '\0';
7108 url_encode_attr(product
, product_str
, sizeof(product_str
));
7110 product_str
[0] = '\0';
7113 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7115 psversion_str
[0] = '\0';
7118 url_encode_attr(type
, type_str
, sizeof(type_str
));
7123 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7125 exclude_str
[0] = '\0';
7128 url_encode_attr(include
, include_str
, sizeof(include_str
));
7130 include_str
[0] = '\0';
7132 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7133 snprintf(options
, sizeof(options
),
7134 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7135 con
->request
->request
.op
.request_id
,
7136 limit
? limit
->values
[0].integer
: 0,
7138 device
? "%20" : "", device_str
,
7139 language
? "%20" : "", language_str
,
7140 make
? "%20" : "", make_str
,
7141 model
? "%20" : "", model_str
,
7142 model_number
? "%20" : "", model_number_str
,
7143 product
? "%20" : "", product_str
,
7144 psversion
? "%20" : "", psversion_str
,
7145 type
? "%20" : "", type_str
,
7146 exclude_str
[0] ? "%20" : "", exclude_str
,
7147 include_str
[0] ? "%20" : "", include_str
);
7149 if (cupsdSendCommand(con
, command
, options
, 0))
7152 * Command started successfully, don't send an IPP response here...
7155 ippDelete(con
->response
);
7156 con
->response
= NULL
;
7161 * Command failed, return "internal error" so the user knows something
7165 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7166 _("cups-driverd failed to execute."));
7172 * 'get_printer_attrs()' - Get printer attributes.
7176 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7177 ipp_attribute_t
*uri
) /* I - Printer URI */
7179 http_status_t status
; /* Policy status */
7180 cups_ptype_t dtype
; /* Destination type (printer/class) */
7181 cupsd_printer_t
*printer
; /* Printer/class */
7182 cups_array_t
*ra
; /* Requested attributes array */
7185 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7186 con
->http
.fd
, uri
->values
[0].string
.text
);
7189 * Is the destination valid?
7192 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7198 send_ipp_status(con
, IPP_NOT_FOUND
,
7199 _("The printer or class does not exist."));
7207 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7209 send_http_error(con
, status
, printer
);
7214 * Send the attributes...
7217 ra
= create_requested_array(con
->request
);
7219 copy_printer_attrs(con
, printer
, ra
);
7221 cupsArrayDelete(ra
);
7223 con
->response
->request
.status
.status_code
= IPP_OK
;
7228 * 'get_printer_supported()' - Get printer supported values.
7232 get_printer_supported(
7233 cupsd_client_t
*con
, /* I - Client connection */
7234 ipp_attribute_t
*uri
) /* I - Printer URI */
7236 http_status_t status
; /* Policy status */
7237 cups_ptype_t dtype
; /* Destination type (printer/class) */
7238 cupsd_printer_t
*printer
; /* Printer/class */
7241 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7242 con
->http
.fd
, uri
->values
[0].string
.text
);
7245 * Is the destination valid?
7248 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7254 send_ipp_status(con
, IPP_NOT_FOUND
,
7255 _("The printer or class does not exist."));
7263 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7265 send_http_error(con
, status
, printer
);
7270 * Return a list of attributes that can be set via Set-Printer-Attributes.
7273 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7275 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7276 "printer-location", 0);
7278 con
->response
->request
.status
.status_code
= IPP_OK
;
7283 * 'get_printers()' - Get a list of printers or classes.
7287 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7288 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7290 http_status_t status
; /* Policy status */
7291 ipp_attribute_t
*attr
; /* Current attribute */
7292 int limit
; /* Max number of printers to return */
7293 int count
; /* Number of printers that match */
7294 cupsd_printer_t
*printer
; /* Current printer pointer */
7295 int printer_type
, /* printer-type attribute */
7296 printer_mask
; /* printer-type-mask attribute */
7297 char *location
; /* Location string */
7298 const char *username
; /* Current user */
7299 char *first_printer_name
; /* first-printer-name attribute */
7300 cups_array_t
*ra
; /* Requested attributes array */
7301 int local
; /* Local connection? */
7304 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7305 con
->http
.fd
, type
);
7311 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7313 send_http_error(con
, status
, NULL
);
7318 * Check for printers...
7321 if (!Printers
|| !cupsArrayCount(Printers
))
7323 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7328 * See if they want to limit the number of printers reported...
7331 if ((attr
= ippFindAttribute(con
->request
, "limit",
7332 IPP_TAG_INTEGER
)) != NULL
)
7333 limit
= attr
->values
[0].integer
;
7337 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7338 IPP_TAG_NAME
)) != NULL
)
7339 first_printer_name
= attr
->values
[0].string
.text
;
7341 first_printer_name
= NULL
;
7344 * Support filtering...
7347 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7348 IPP_TAG_ENUM
)) != NULL
)
7349 printer_type
= attr
->values
[0].integer
;
7353 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7354 IPP_TAG_ENUM
)) != NULL
)
7355 printer_mask
= attr
->values
[0].integer
;
7359 local
= httpAddrLocalhost(&(con
->clientaddr
));
7361 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7362 IPP_TAG_TEXT
)) != NULL
)
7363 location
= attr
->values
[0].string
.text
;
7367 if (con
->username
[0])
7368 username
= con
->username
;
7369 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7370 IPP_TAG_NAME
)) != NULL
)
7371 username
= attr
->values
[0].string
.text
;
7375 ra
= create_requested_array(con
->request
);
7378 * OK, build a list of printers for this printer...
7381 if (first_printer_name
)
7383 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7384 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7387 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7390 count
< limit
&& printer
;
7391 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7393 if (!local
&& !printer
->shared
)
7396 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7397 (printer
->type
& printer_mask
) == printer_type
&&
7399 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7402 * If a username is specified, see if it is allowed or denied
7406 if (cupsArrayCount(printer
->users
) && username
&&
7407 !user_allowed(printer
, username
))
7411 * Add the group separator as needed...
7415 ippAddSeparator(con
->response
);
7420 * Send the attributes...
7423 copy_printer_attrs(con
, printer
, ra
);
7427 cupsArrayDelete(ra
);
7429 con
->response
->request
.status
.status_code
= IPP_OK
;
7434 * 'get_subscription_attrs()' - Get subscription attributes.
7438 get_subscription_attrs(
7439 cupsd_client_t
*con
, /* I - Client connection */
7440 int sub_id
) /* I - Subscription ID */
7442 http_status_t status
; /* Policy status */
7443 cupsd_subscription_t
*sub
; /* Subscription */
7444 cupsd_policy_t
*policy
; /* Current security policy */
7445 cups_array_t
*ra
, /* Requested attributes array */
7446 *exclude
; /* Private attributes array */
7449 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7450 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7451 con
, con
->http
.fd
, sub_id
);
7454 * Is the subscription ID valid?
7457 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7460 * Bad subscription ID...
7463 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7473 policy
= sub
->dest
->op_policy_ptr
;
7475 policy
= DefaultPolicyPtr
;
7477 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7479 send_http_error(con
, status
, sub
->dest
);
7483 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7486 * Copy the subscription attributes to the response using the
7487 * requested-attributes attribute that may be provided by the client.
7490 ra
= create_requested_array(con
->request
);
7492 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7494 cupsArrayDelete(ra
);
7496 con
->response
->request
.status
.status_code
= IPP_OK
;
7501 * 'get_subscriptions()' - Get subscriptions.
7505 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7506 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7508 http_status_t status
; /* Policy status */
7509 int count
; /* Number of subscriptions */
7510 int limit
; /* Limit */
7511 cupsd_subscription_t
*sub
; /* Subscription */
7512 cups_array_t
*ra
; /* Requested attributes array */
7513 ipp_attribute_t
*attr
; /* Attribute */
7514 cups_ptype_t dtype
; /* Destination type (printer/class) */
7515 char scheme
[HTTP_MAX_URI
],
7516 /* Scheme portion of URI */
7517 username
[HTTP_MAX_URI
],
7518 /* Username portion of URI */
7520 /* Host portion of URI */
7521 resource
[HTTP_MAX_URI
];
7522 /* Resource portion of URI */
7523 int port
; /* Port portion of URI */
7524 cupsd_job_t
*job
; /* Job pointer */
7525 cupsd_printer_t
*printer
; /* Printer */
7526 cupsd_policy_t
*policy
; /* Policy */
7527 cups_array_t
*exclude
; /* Private attributes array */
7530 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7531 "get_subscriptions(con=%p[%d], uri=%s)",
7532 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7535 * Is the destination valid?
7538 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7539 sizeof(scheme
), username
, sizeof(username
), host
,
7540 sizeof(host
), &port
, resource
, sizeof(resource
));
7542 if (!strcmp(resource
, "/") ||
7543 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7544 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7545 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7550 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7553 job
= cupsdFindJob(atoi(resource
+ 6));
7557 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7558 atoi(resource
+ 6));
7562 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7568 send_ipp_status(con
, IPP_NOT_FOUND
,
7569 _("The printer or class does not exist."));
7572 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7573 IPP_TAG_INTEGER
)) != NULL
)
7575 job
= cupsdFindJob(attr
->values
[0].integer
);
7579 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7580 attr
->values
[0].integer
);
7592 policy
= printer
->op_policy_ptr
;
7594 policy
= DefaultPolicyPtr
;
7596 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7598 send_http_error(con
, status
, printer
);
7603 * Copy the subscription attributes to the response using the
7604 * requested-attributes attribute that may be provided by the client.
7607 ra
= create_requested_array(con
->request
);
7609 if ((attr
= ippFindAttribute(con
->request
, "limit",
7610 IPP_TAG_INTEGER
)) != NULL
)
7611 limit
= attr
->values
[0].integer
;
7616 * See if we only want to see subscriptions for a specific user...
7619 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7620 IPP_TAG_BOOLEAN
)) != NULL
&&
7621 attr
->values
[0].boolean
)
7622 strlcpy(username
, get_username(con
), sizeof(username
));
7626 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7628 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7629 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7630 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7632 ippAddSeparator(con
->response
);
7634 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7635 policy
, con
, sub
->dest
,
7638 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7641 if (limit
&& count
>= limit
)
7645 cupsArrayDelete(ra
);
7648 con
->response
->request
.status
.status_code
= IPP_OK
;
7650 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7655 * 'get_username()' - Get the username associated with a request.
7658 static const char * /* O - Username */
7659 get_username(cupsd_client_t
*con
) /* I - Connection */
7661 ipp_attribute_t
*attr
; /* Attribute */
7664 if (con
->username
[0])
7665 return (con
->username
);
7666 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7667 IPP_TAG_NAME
)) != NULL
)
7668 return (attr
->values
[0].string
.text
);
7670 return ("anonymous");
7675 * 'hold_job()' - Hold a print job.
7679 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7680 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7682 ipp_attribute_t
*attr
; /* Current job-hold-until */
7683 const char *when
; /* New value */
7684 int jobid
; /* Job ID */
7685 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7686 username
[HTTP_MAX_URI
], /* Username portion of URI */
7687 host
[HTTP_MAX_URI
], /* Host portion of URI */
7688 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7689 int port
; /* Port portion of URI */
7690 cupsd_job_t
*job
; /* Job information */
7693 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
7694 uri
->values
[0].string
.text
);
7697 * See if we have a job URI or a printer URI...
7700 if (!strcmp(uri
->name
, "printer-uri"))
7703 * Got a printer URI; see if we also have a job-id attribute...
7706 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7707 IPP_TAG_INTEGER
)) == NULL
)
7709 send_ipp_status(con
, IPP_BAD_REQUEST
,
7710 _("Got a printer-uri attribute but no job-id."));
7714 jobid
= attr
->values
[0].integer
;
7719 * Got a job URI; parse it to get the job ID...
7722 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7723 sizeof(scheme
), username
, sizeof(username
), host
,
7724 sizeof(host
), &port
, resource
, sizeof(resource
));
7726 if (strncmp(resource
, "/jobs/", 6))
7732 send_ipp_status(con
, IPP_BAD_REQUEST
,
7733 _("Bad job-uri \"%s\"."),
7734 uri
->values
[0].string
.text
);
7738 jobid
= atoi(resource
+ 6);
7742 * See if the job exists...
7745 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7748 * Nope - return a "not found" error...
7751 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7756 * See if the job is owned by the requesting user...
7759 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7761 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7762 cupsdFindDest(job
->dest
));
7767 * See if the job is in a state that allows holding...
7770 if (job
->state_value
> IPP_JOB_STOPPED
)
7773 * Return a "not-possible" error...
7776 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7777 _("Job #%d is finished and cannot be altered."),
7783 * Hold the job and return...
7786 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7787 IPP_TAG_KEYWORD
)) == NULL
)
7788 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7792 when
= attr
->values
[0].string
.text
;
7794 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7795 "Job job-hold-until value changed by user.");
7798 when
= "indefinite";
7800 cupsdSetJobHoldUntil(job
, when
, 1);
7801 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7804 con
->response
->request
.status
.status_code
= IPP_OK
;
7809 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7813 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7814 ipp_attribute_t
*uri
) /* I - Printer URI */
7816 http_status_t status
; /* Policy status */
7817 cups_ptype_t dtype
; /* Destination type (printer/class) */
7818 cupsd_printer_t
*printer
; /* Printer data */
7821 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7822 con
->http
.fd
, uri
->values
[0].string
.text
);
7825 * Is the destination valid?
7828 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7834 send_ipp_status(con
, IPP_NOT_FOUND
,
7835 _("The printer or class does not exist."));
7843 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7845 send_http_error(con
, status
, printer
);
7850 * Hold pending/new jobs sent to the printer...
7853 printer
->holding_new_jobs
= 1;
7855 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
7857 if (dtype
& CUPS_PRINTER_CLASS
)
7858 cupsdLogMessage(CUPSD_LOG_INFO
,
7859 "Class \"%s\" now holding pending/new jobs (\"%s\").",
7860 printer
->name
, get_username(con
));
7862 cupsdLogMessage(CUPSD_LOG_INFO
,
7863 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
7864 printer
->name
, get_username(con
));
7867 * Everything was ok, so return OK status...
7870 con
->response
->request
.status
.status_code
= IPP_OK
;
7875 * 'move_job()' - Move a job to a new destination.
7879 move_job(cupsd_client_t
*con
, /* I - Client connection */
7880 ipp_attribute_t
*uri
) /* I - Job URI */
7882 http_status_t status
; /* Policy status */
7883 ipp_attribute_t
*attr
; /* Current attribute */
7884 int jobid
; /* Job ID */
7885 cupsd_job_t
*job
; /* Current job */
7886 const char *src
; /* Source printer/class */
7887 cups_ptype_t stype
, /* Source type (printer or class) */
7888 dtype
; /* Destination type (printer/class) */
7889 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7890 username
[HTTP_MAX_URI
], /* Username portion of URI */
7891 host
[HTTP_MAX_URI
], /* Host portion of URI */
7892 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7893 int port
; /* Port portion of URI */
7894 cupsd_printer_t
*sprinter
, /* Source printer */
7895 *dprinter
; /* Destination printer */
7898 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
7899 uri
->values
[0].string
.text
);
7902 * Get the new printer or class...
7905 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7906 IPP_TAG_URI
)) == NULL
)
7909 * Need job-printer-uri...
7912 send_ipp_status(con
, IPP_BAD_REQUEST
,
7913 _("job-printer-uri attribute missing."));
7917 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
7923 send_ipp_status(con
, IPP_NOT_FOUND
,
7924 _("The printer or class does not exist."));
7929 * See if we have a job URI or a printer URI...
7932 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7933 sizeof(scheme
), username
, sizeof(username
), host
,
7934 sizeof(host
), &port
, resource
, sizeof(resource
));
7936 if (!strcmp(uri
->name
, "printer-uri"))
7939 * Got a printer URI; see if we also have a job-id attribute...
7942 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7943 IPP_TAG_INTEGER
)) == NULL
)
7949 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
7950 &sprinter
)) == NULL
)
7956 send_ipp_status(con
, IPP_NOT_FOUND
,
7957 _("The printer or class does not exist."));
7966 * Otherwise, just move a single job...
7969 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
7972 * Nope - return a "not found" error...
7975 send_ipp_status(con
, IPP_NOT_FOUND
,
7976 _("Job #%d does not exist."), attr
->values
[0].integer
);
7982 * Job found, initialize source pointers...
7993 * Got a job URI; parse it to get the job ID...
7996 if (strncmp(resource
, "/jobs/", 6))
8002 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8003 uri
->values
[0].string
.text
);
8008 * See if the job exists...
8011 jobid
= atoi(resource
+ 6);
8013 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8016 * Nope - return a "not found" error...
8019 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8025 * Job found, initialize source pointers...
8034 * Check the policy of the destination printer...
8037 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8038 job
? job
->username
: NULL
)) != HTTP_OK
)
8040 send_http_error(con
, status
, dprinter
);
8045 * Now move the job or jobs...
8051 * See if the job has been completed...
8054 if (job
->state_value
> IPP_JOB_STOPPED
)
8057 * Return a "not-possible" error...
8060 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8061 _("Job #%d is finished and cannot be altered."),
8067 * See if the job is owned by the requesting user...
8070 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8072 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8073 cupsdFindDest(job
->dest
));
8078 * Move the job to a different printer or class...
8081 cupsdMoveJob(job
, dprinter
);
8086 * Got the source printer, now look through the jobs...
8089 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8091 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8094 * See if the job is pointing at the source printer or has not been
8098 if (_cups_strcasecmp(job
->dest
, src
) ||
8099 job
->state_value
> IPP_JOB_STOPPED
)
8103 * See if the job can be moved by the requesting user...
8106 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8110 * Move the job to a different printer or class...
8113 cupsdMoveJob(job
, dprinter
);
8118 * Start jobs if possible...
8124 * Return with "everything is OK" status...
8127 con
->response
->request
.status
.status_code
= IPP_OK
;
8132 * 'ppd_parse_line()' - Parse a PPD default line.
8135 static int /* O - 0 on success, -1 on failure */
8136 ppd_parse_line(const char *line
, /* I - Line */
8137 char *option
, /* O - Option name */
8138 int olen
, /* I - Size of option name */
8139 char *choice
, /* O - Choice name */
8140 int clen
) /* I - Size of choice name */
8143 * Verify this is a default option line...
8146 if (strncmp(line
, "*Default", 8))
8150 * Read the option name...
8153 for (line
+= 8, olen
--;
8154 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8165 * Skip everything else up to the colon (:)...
8168 while (*line
&& *line
!= ':')
8177 * Now grab the option choice, skipping leading whitespace...
8180 while (isspace(*line
& 255))
8184 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8195 * Return with no errors...
8203 * 'print_job()' - Print a file to a printer or class.
8207 print_job(cupsd_client_t
*con
, /* I - Client connection */
8208 ipp_attribute_t
*uri
) /* I - Printer URI */
8210 ipp_attribute_t
*attr
; /* Current attribute */
8211 ipp_attribute_t
*format
; /* Document-format attribute */
8212 const char *default_format
; /* document-format-default value */
8213 cupsd_job_t
*job
; /* New job */
8214 char filename
[1024]; /* Job filename */
8215 mime_type_t
*filetype
; /* Type of file */
8216 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8217 type
[MIME_MAX_TYPE
], /* Subtype of file */
8218 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8219 /* Textual name of mime type */
8220 cupsd_printer_t
*printer
; /* Printer data */
8221 struct stat fileinfo
; /* File information */
8222 int kbytes
; /* Size of file */
8223 int compression
; /* Document compression */
8226 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8227 uri
->values
[0].string
.text
);
8230 * Validate print file attributes, for now just document-format and
8231 * compression (CUPS only supports "none" and "gzip")...
8234 compression
= CUPS_FILE_NONE
;
8236 if ((attr
= ippFindAttribute(con
->request
, "compression",
8237 IPP_TAG_KEYWORD
)) != NULL
)
8239 if (strcmp(attr
->values
[0].string
.text
, "none")
8241 && strcmp(attr
->values
[0].string
.text
, "gzip")
8242 #endif /* HAVE_LIBZ */
8245 send_ipp_status(con
, IPP_ATTRIBUTES
,
8246 _("Unsupported compression \"%s\"."),
8247 attr
->values
[0].string
.text
);
8248 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8249 "compression", NULL
, attr
->values
[0].string
.text
);
8254 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8255 compression
= CUPS_FILE_GZIP
;
8256 #endif /* HAVE_LIBZ */
8260 * Do we have a file to print?
8265 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8270 * Is the destination valid?
8273 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8279 send_ipp_status(con
, IPP_NOT_FOUND
,
8280 _("The printer or class does not exist."));
8285 * Is it a format we support?
8288 if ((format
= ippFindAttribute(con
->request
, "document-format",
8289 IPP_TAG_MIMETYPE
)) != NULL
)
8292 * Grab format from client...
8295 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8298 send_ipp_status(con
, IPP_BAD_REQUEST
,
8299 _("Bad document-format \"%s\"."),
8300 format
->values
[0].string
.text
);
8304 else if ((default_format
= cupsGetOption("document-format",
8305 printer
->num_options
,
8306 printer
->options
)) != NULL
)
8309 * Use default document format...
8312 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8314 send_ipp_status(con
, IPP_BAD_REQUEST
,
8315 _("Bad document-format \"%s\"."),
8326 strlcpy(super
, "application", sizeof(super
));
8327 strlcpy(type
, "octet-stream", sizeof(type
));
8330 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8333 * Auto-type the file...
8336 ipp_attribute_t
*doc_name
; /* document-name attribute */
8339 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8341 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8342 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8343 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8347 filetype
= mimeType(MimeDatabase
, super
, type
);
8349 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8350 filetype
->super
, filetype
->type
);
8353 filetype
= mimeType(MimeDatabase
, super
, type
);
8357 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8360 * Replace the document-format attribute value with the auto-typed or
8364 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8369 _cupsStrFree(format
->values
[0].string
.text
);
8371 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8374 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8375 "document-format", NULL
, mimetype
);
8379 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8380 _("Unsupported document-format \"%s\"."),
8381 format
? format
->values
[0].string
.text
:
8382 "application/octet-stream");
8383 cupsdLogMessage(CUPSD_LOG_INFO
,
8384 "Hint: Do you have the raw file printing rules enabled?");
8387 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8388 "document-format", NULL
, format
->values
[0].string
.text
);
8394 * Read any embedded job ticket info from PS files...
8397 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8398 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8399 !_cups_strcasecmp(filetype
->type
, "pdf")))
8400 read_job_ticket(con
);
8403 * Create the job object...
8406 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8410 * Update quota data...
8413 if (stat(con
->filename
, &fileinfo
))
8416 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8418 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8420 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8421 IPP_TAG_INTEGER
)) != NULL
)
8422 attr
->values
[0].integer
+= kbytes
;
8425 * Add the job file...
8428 if (add_file(con
, job
, filetype
, compression
))
8431 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8433 rename(con
->filename
, filename
);
8434 cupsdClearString(&con
->filename
);
8437 * See if we need to add the ending sheet...
8440 if (cupsdTimeoutJob(job
))
8444 * Log and save the job...
8447 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8448 "File of type %s/%s queued by \"%s\".",
8449 filetype
->super
, filetype
->type
, job
->username
);
8450 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8451 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8452 job
->dest
, job
->username
);
8455 * Start the job if possible...
8463 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8465 * This function only gets called when printing a single PDF or PostScript
8466 * file using the Print-Job operation. It doesn't work for Create-Job +
8467 * Send-File, since the job attributes need to be set at job creation
8468 * time for banners to work. The embedded job ticket stuff is here
8469 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8470 * options and IPP attributes which otherwise would be lost.
8472 * The format of a job ticket is simple:
8474 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8476 * %cupsJobTicket: attr1=value1
8477 * %cupsJobTicket: attr2=value2
8479 * %cupsJobTicket: attrN=valueN
8481 * Job ticket lines must appear immediately after the first line that
8482 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8483 * stops looking for job ticket info when it finds a line that does not begin
8484 * with "%cupsJobTicket:".
8486 * The maximum length of a job ticket line, including the prefix, is
8487 * 255 characters to conform with the Adobe DSC.
8489 * Read-only attributes are rejected with a notice to the error log in
8490 * case a malicious user tries anything. Since the job ticket is read
8491 * prior to attribute validation in print_job(), job ticket attributes
8492 * will go through the same validation as IPP attributes...
8496 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8498 cups_file_t
*fp
; /* File to read from */
8499 char line
[256]; /* Line data */
8500 int num_options
; /* Number of options */
8501 cups_option_t
*options
; /* Options */
8502 ipp_t
*ticket
; /* New attributes */
8503 ipp_attribute_t
*attr
, /* Current attribute */
8504 *attr2
, /* Job attribute */
8505 *prev2
; /* Previous job attribute */
8509 * First open the print file...
8512 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8514 cupsdLogMessage(CUPSD_LOG_ERROR
,
8515 "Unable to open print file for job ticket - %s",
8521 * Skip the first line...
8524 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8526 cupsdLogMessage(CUPSD_LOG_ERROR
,
8527 "Unable to read from print file for job ticket - %s",
8533 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8536 * Not a DSC-compliant file, so no job ticket info will be available...
8544 * Read job ticket info from the file...
8550 while (cupsFileGets(fp
, line
, sizeof(line
)))
8553 * Stop at the first non-ticket line...
8556 if (strncmp(line
, "%cupsJobTicket:", 15))
8560 * Add the options to the option array...
8563 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8567 * Done with the file; see if we have any options...
8572 if (num_options
== 0)
8576 * OK, convert the options to an attribute list, and apply them to
8581 cupsEncodeOptions(ticket
, num_options
, options
);
8584 * See what the user wants to change.
8587 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8589 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8592 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8593 !strcmp(attr
->name
, "job-originating-user-name") ||
8594 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8595 !strcmp(attr
->name
, "job-k-octets") ||
8596 !strcmp(attr
->name
, "job-id") ||
8597 !strncmp(attr
->name
, "job-state", 9) ||
8598 !strncmp(attr
->name
, "time-at-", 8))
8599 continue; /* Read-only attrs */
8601 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8602 IPP_TAG_ZERO
)) != NULL
)
8605 * Some other value; first free the old value...
8608 if (con
->request
->attrs
== attr2
)
8610 con
->request
->attrs
= attr2
->next
;
8615 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8616 if (prev2
->next
== attr2
)
8618 prev2
->next
= attr2
->next
;
8623 if (con
->request
->last
== attr2
)
8624 con
->request
->last
= prev2
;
8626 ippDeleteAttribute(NULL
, attr2
);
8630 * Add new option by copying it...
8633 ippCopyAttribute(con
->request
, attr
, 0);
8637 * Then free the attribute list and option array...
8641 cupsFreeOptions(num_options
, options
);
8646 * 'reject_jobs()' - Reject print jobs to a printer.
8650 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8651 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8653 http_status_t status
; /* Policy status */
8654 cups_ptype_t dtype
; /* Destination type (printer/class) */
8655 cupsd_printer_t
*printer
; /* Printer data */
8656 ipp_attribute_t
*attr
; /* printer-state-message text */
8659 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8660 con
->http
.fd
, uri
->values
[0].string
.text
);
8663 * Is the destination valid?
8666 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8672 send_ipp_status(con
, IPP_NOT_FOUND
,
8673 _("The printer or class does not exist."));
8681 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8683 send_http_error(con
, status
, printer
);
8688 * Reject jobs sent to the printer...
8691 printer
->accepting
= 0;
8693 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8694 IPP_TAG_TEXT
)) == NULL
)
8695 strlcpy(printer
->state_message
, "Rejecting Jobs",
8696 sizeof(printer
->state_message
));
8698 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8699 sizeof(printer
->state_message
));
8701 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8702 "No longer accepting jobs.");
8704 if (dtype
& CUPS_PRINTER_CLASS
)
8706 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8708 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8709 printer
->name
, get_username(con
));
8713 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8715 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8716 printer
->name
, get_username(con
));
8720 * Everything was ok, so return OK status...
8723 con
->response
->request
.status
.status_code
= IPP_OK
;
8728 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8732 release_held_new_jobs(
8733 cupsd_client_t
*con
, /* I - Connection */
8734 ipp_attribute_t
*uri
) /* I - Printer URI */
8736 http_status_t status
; /* Policy status */
8737 cups_ptype_t dtype
; /* Destination type (printer/class) */
8738 cupsd_printer_t
*printer
; /* Printer data */
8741 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8742 con
->http
.fd
, uri
->values
[0].string
.text
);
8745 * Is the destination valid?
8748 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8754 send_ipp_status(con
, IPP_NOT_FOUND
,
8755 _("The printer or class does not exist."));
8763 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8765 send_http_error(con
, status
, printer
);
8770 * Hold pending/new jobs sent to the printer...
8773 printer
->holding_new_jobs
= 0;
8775 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8777 if (dtype
& CUPS_PRINTER_CLASS
)
8778 cupsdLogMessage(CUPSD_LOG_INFO
,
8779 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8780 printer
->name
, get_username(con
));
8782 cupsdLogMessage(CUPSD_LOG_INFO
,
8783 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8784 printer
->name
, get_username(con
));
8787 * Everything was ok, so return OK status...
8790 con
->response
->request
.status
.status_code
= IPP_OK
;
8795 * 'release_job()' - Release a held print job.
8799 release_job(cupsd_client_t
*con
, /* I - Client connection */
8800 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8802 ipp_attribute_t
*attr
; /* Current attribute */
8803 int jobid
; /* Job ID */
8804 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8805 username
[HTTP_MAX_URI
], /* Username portion of URI */
8806 host
[HTTP_MAX_URI
], /* Host portion of URI */
8807 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8808 int port
; /* Port portion of URI */
8809 cupsd_job_t
*job
; /* Job information */
8812 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8813 con
->http
.fd
, uri
->values
[0].string
.text
);
8816 * See if we have a job URI or a printer URI...
8819 if (!strcmp(uri
->name
, "printer-uri"))
8822 * Got a printer URI; see if we also have a job-id attribute...
8825 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8826 IPP_TAG_INTEGER
)) == NULL
)
8828 send_ipp_status(con
, IPP_BAD_REQUEST
,
8829 _("Got a printer-uri attribute but no job-id."));
8833 jobid
= attr
->values
[0].integer
;
8838 * Got a job URI; parse it to get the job ID...
8841 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8842 sizeof(scheme
), username
, sizeof(username
), host
,
8843 sizeof(host
), &port
, resource
, sizeof(resource
));
8845 if (strncmp(resource
, "/jobs/", 6))
8851 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8852 uri
->values
[0].string
.text
);
8856 jobid
= atoi(resource
+ 6);
8860 * See if the job exists...
8863 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8866 * Nope - return a "not found" error...
8869 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8874 * See if job is "held"...
8877 if (job
->state_value
!= IPP_JOB_HELD
)
8880 * Nope - return a "not possible" error...
8883 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
8888 * See if the job is owned by the requesting user...
8891 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8893 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8894 cupsdFindDest(job
->dest
));
8899 * Reset the job-hold-until value to "no-hold"...
8902 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8903 IPP_TAG_KEYWORD
)) == NULL
)
8904 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8908 _cupsStrFree(attr
->values
[0].string
.text
);
8910 attr
->value_tag
= IPP_TAG_KEYWORD
;
8911 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8913 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8914 "Job job-hold-until value changed by user.");
8915 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
8919 * Release the job and return...
8922 cupsdReleaseJob(job
);
8924 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8925 "Job released by user.");
8927 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
8929 con
->response
->request
.status
.status_code
= IPP_OK
;
8936 * 'renew_subscription()' - Renew an existing subscription...
8941 cupsd_client_t
*con
, /* I - Client connection */
8942 int sub_id
) /* I - Subscription ID */
8944 http_status_t status
; /* Policy status */
8945 cupsd_subscription_t
*sub
; /* Subscription */
8946 ipp_attribute_t
*lease
; /* notify-lease-duration */
8949 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8950 "renew_subscription(con=%p[%d], sub_id=%d)",
8951 con
, con
->http
.fd
, sub_id
);
8954 * Is the subscription ID valid?
8957 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8960 * Bad subscription ID...
8963 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8971 * Job subscriptions cannot be renewed...
8974 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8975 _("Job subscriptions cannot be renewed."));
8983 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8985 con
, sub
->owner
)) != HTTP_OK
)
8987 send_http_error(con
, status
, sub
->dest
);
8992 * Renew the subscription...
8995 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8998 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9000 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9002 cupsdLogMessage(CUPSD_LOG_INFO
,
9003 "renew_subscription: Limiting notify-lease-duration to "
9006 sub
->lease
= MaxLeaseDuration
;
9009 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9011 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9013 con
->response
->request
.status
.status_code
= IPP_OK
;
9015 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9016 "notify-lease-duration", sub
->lease
);
9021 * 'restart_job()' - Restart an old print job.
9025 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9026 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9028 ipp_attribute_t
*attr
; /* Current attribute */
9029 int jobid
; /* Job ID */
9030 cupsd_job_t
*job
; /* Job information */
9031 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9032 username
[HTTP_MAX_URI
], /* Username portion of URI */
9033 host
[HTTP_MAX_URI
], /* Host portion of URI */
9034 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9035 int port
; /* Port portion of URI */
9038 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9039 con
->http
.fd
, uri
->values
[0].string
.text
);
9042 * See if we have a job URI or a printer URI...
9045 if (!strcmp(uri
->name
, "printer-uri"))
9048 * Got a printer URI; see if we also have a job-id attribute...
9051 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9052 IPP_TAG_INTEGER
)) == NULL
)
9054 send_ipp_status(con
, IPP_BAD_REQUEST
,
9055 _("Got a printer-uri attribute but no job-id."));
9059 jobid
= attr
->values
[0].integer
;
9064 * Got a job URI; parse it to get the job ID...
9067 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9068 sizeof(scheme
), username
, sizeof(username
), host
,
9069 sizeof(host
), &port
, resource
, sizeof(resource
));
9071 if (strncmp(resource
, "/jobs/", 6))
9077 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9078 uri
->values
[0].string
.text
);
9082 jobid
= atoi(resource
+ 6);
9086 * See if the job exists...
9089 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9092 * Nope - return a "not found" error...
9095 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9100 * See if job is in any of the "completed" states...
9103 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9106 * Nope - return a "not possible" error...
9109 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9115 * See if we have retained the job files...
9120 if (!job
->attrs
|| job
->num_files
== 0)
9123 * Nope - return a "not possible" error...
9126 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9127 _("Job #%d cannot be restarted - no files."), jobid
);
9132 * See if the job is owned by the requesting user...
9135 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9137 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9138 cupsdFindDest(job
->dest
));
9143 * See if the job-hold-until attribute is specified...
9146 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9147 IPP_TAG_KEYWORD
)) == NULL
)
9148 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9150 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9153 * Return the job to a held state...
9156 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9157 "Restarted by \"%s\" with job-hold-until=%s.",
9158 username
, attr
->values
[0].string
.text
);
9159 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9161 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9162 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9163 attr
->values
[0].string
.text
);
9168 * Restart the job...
9171 cupsdRestartJob(job
);
9175 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9177 con
->response
->request
.status
.status_code
= IPP_OK
;
9182 * 'save_auth_info()' - Save authentication information for a job.
9187 cupsd_client_t
*con
, /* I - Client connection */
9188 cupsd_job_t
*job
, /* I - Job */
9189 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9191 int i
; /* Looping var */
9192 char filename
[1024]; /* Job authentication filename */
9193 cups_file_t
*fp
; /* Job authentication file */
9194 char line
[65536]; /* Line for file */
9195 cupsd_printer_t
*dest
; /* Destination printer/class */
9199 * This function saves the in-memory authentication information for
9200 * a job so that it can be used to authenticate with a remote host.
9201 * The information is stored in a file that is readable only by the
9202 * root user. The fields are Base-64 encoded, each on a separate line,
9203 * followed by random number (up to 1024) of newlines to limit the
9204 * amount of information that is exposed.
9206 * Because of the potential for exposing of authentication information,
9207 * this functionality is only enabled when running cupsd as root.
9209 * This caching only works for the Basic and BasicDigest authentication
9210 * types. Digest authentication cannot be cached this way, and in
9211 * the future Kerberos authentication may make all of this obsolete.
9213 * Authentication information is saved whenever an authenticated
9214 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9217 * This information is deleted after a job is completed or canceled,
9218 * so reprints may require subsequent re-authentication.
9224 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9228 * Create the authentication file and change permissions...
9231 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9232 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9234 cupsdLogMessage(CUPSD_LOG_ERROR
,
9235 "Unable to save authentication info to \"%s\" - %s",
9236 filename
, strerror(errno
));
9240 fchown(cupsFileNumber(fp
), 0, 0);
9241 fchmod(cupsFileNumber(fp
), 0400);
9243 cupsFilePuts(fp
, "CUPSD-AUTH-V2\n");
9246 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9248 cupsdClearString(job
->auth_env
+ i
);
9250 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9253 * Write 1 to 3 auth values...
9257 i
< auth_info
->num_values
&&
9258 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9261 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9262 strlen(auth_info
->values
[i
].string
.text
));
9263 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9265 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9266 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9267 auth_info
->values
[i
].string
.text
);
9268 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9269 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9270 auth_info
->values
[i
].string
.text
);
9271 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9272 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9273 auth_info
->values
[i
].string
.text
);
9274 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9275 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9276 auth_info
->values
[i
].string
.text
);
9281 else if (auth_info
&& auth_info
->num_values
== 2 &&
9282 dest
->num_auth_info_required
== 1 &&
9283 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9286 * Allow fallback to username+password for Kerberized queues...
9289 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
,
9290 strlen(auth_info
->values
[0].string
.text
));
9291 cupsFilePutConf(fp
, "username", line
);
9293 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9294 auth_info
->values
[0].string
.text
);
9296 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
,
9297 strlen(auth_info
->values
[1].string
.text
));
9298 cupsFilePutConf(fp
, "password", line
);
9300 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9301 auth_info
->values
[1].string
.text
);
9303 else if (con
->username
[0])
9306 * Write the authenticated username...
9309 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9310 cupsFilePutConf(fp
, "username", line
);
9312 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9315 * Write the authenticated password...
9318 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9319 cupsFilePutConf(fp
, "password", line
);
9321 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9325 if (con
->gss_uid
> 0)
9327 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9328 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9330 #endif /* HAVE_GSSAPI */
9333 * Write a random number of newlines to the end of the file...
9336 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9337 cupsFilePutChar(fp
, '\n');
9340 * Close the file and return...
9348 * 'send_document()' - Send a file to a printer or class.
9352 send_document(cupsd_client_t
*con
, /* I - Client connection */
9353 ipp_attribute_t
*uri
) /* I - Printer URI */
9355 ipp_attribute_t
*attr
; /* Current attribute */
9356 ipp_attribute_t
*format
; /* Request's document-format attribute */
9357 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9358 const char *default_format
;/* document-format-default value */
9359 int jobid
; /* Job ID number */
9360 cupsd_job_t
*job
; /* Current job */
9361 char job_uri
[HTTP_MAX_URI
],
9363 scheme
[HTTP_MAX_URI
],
9364 /* Method portion of URI */
9365 username
[HTTP_MAX_URI
],
9366 /* Username portion of URI */
9368 /* Host portion of URI */
9369 resource
[HTTP_MAX_URI
];
9370 /* Resource portion of URI */
9371 int port
; /* Port portion of URI */
9372 mime_type_t
*filetype
; /* Type of file */
9373 char super
[MIME_MAX_SUPER
],
9374 /* Supertype of file */
9375 type
[MIME_MAX_TYPE
],
9376 /* Subtype of file */
9377 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9378 /* Textual name of mime type */
9379 char filename
[1024]; /* Job filename */
9380 cupsd_printer_t
*printer
; /* Current printer */
9381 struct stat fileinfo
; /* File information */
9382 int kbytes
; /* Size of file */
9383 int compression
; /* Type of compression */
9384 int start_job
; /* Start the job? */
9387 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9388 con
->http
.fd
, uri
->values
[0].string
.text
);
9391 * See if we have a job URI or a printer URI...
9394 if (!strcmp(uri
->name
, "printer-uri"))
9397 * Got a printer URI; see if we also have a job-id attribute...
9400 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9401 IPP_TAG_INTEGER
)) == NULL
)
9403 send_ipp_status(con
, IPP_BAD_REQUEST
,
9404 _("Got a printer-uri attribute but no job-id."));
9408 jobid
= attr
->values
[0].integer
;
9413 * Got a job URI; parse it to get the job ID...
9416 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9417 sizeof(scheme
), username
, sizeof(username
), host
,
9418 sizeof(host
), &port
, resource
, sizeof(resource
));
9420 if (strncmp(resource
, "/jobs/", 6))
9426 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9427 uri
->values
[0].string
.text
);
9431 jobid
= atoi(resource
+ 6);
9435 * See if the job exists...
9438 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9441 * Nope - return a "not found" error...
9444 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9448 printer
= cupsdFindDest(job
->dest
);
9451 * See if the job is owned by the requesting user...
9454 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9456 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9457 cupsdFindDest(job
->dest
));
9462 * OK, see if the client is sending the document compressed - CUPS
9463 * only supports "none" and "gzip".
9466 compression
= CUPS_FILE_NONE
;
9468 if ((attr
= ippFindAttribute(con
->request
, "compression",
9469 IPP_TAG_KEYWORD
)) != NULL
)
9471 if (strcmp(attr
->values
[0].string
.text
, "none")
9473 && strcmp(attr
->values
[0].string
.text
, "gzip")
9474 #endif /* HAVE_LIBZ */
9477 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9478 attr
->values
[0].string
.text
);
9479 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9480 "compression", NULL
, attr
->values
[0].string
.text
);
9485 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9486 compression
= CUPS_FILE_GZIP
;
9487 #endif /* HAVE_LIBZ */
9491 * Do we have a file to print?
9494 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9495 IPP_TAG_BOOLEAN
)) == NULL
)
9497 send_ipp_status(con
, IPP_BAD_REQUEST
,
9498 _("Missing last-document attribute in request."));
9505 * Check for an empty request with "last-document" set to true, which is
9506 * used to close an "open" job by RFC 2911, section 3.3.2.
9509 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9512 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9517 * Is it a format we support?
9520 if ((format
= ippFindAttribute(con
->request
, "document-format",
9521 IPP_TAG_MIMETYPE
)) != NULL
)
9524 * Grab format from client...
9527 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9530 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9531 format
->values
[0].string
.text
);
9535 else if ((default_format
= cupsGetOption("document-format",
9536 printer
->num_options
,
9537 printer
->options
)) != NULL
)
9540 * Use default document format...
9543 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9545 send_ipp_status(con
, IPP_BAD_REQUEST
,
9546 _("Bad document-format-default \"%s\"."), default_format
);
9553 * No document format attribute? Auto-type it!
9556 strlcpy(super
, "application", sizeof(super
));
9557 strlcpy(type
, "octet-stream", sizeof(type
));
9560 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9563 * Auto-type the file...
9566 ipp_attribute_t
*doc_name
; /* document-name attribute */
9569 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9571 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9572 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9573 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9577 filetype
= mimeType(MimeDatabase
, super
, type
);
9580 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9581 filetype
->super
, filetype
->type
);
9584 filetype
= mimeType(MimeDatabase
, super
, type
);
9589 * Replace the document-format attribute value with the auto-typed or
9593 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9596 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9597 IPP_TAG_MIMETYPE
)) != NULL
)
9599 _cupsStrFree(jformat
->values
[0].string
.text
);
9601 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9604 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9605 "document-format", NULL
, mimetype
);
9609 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9610 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9611 cupsdLogMessage(CUPSD_LOG_INFO
,
9612 "Hint: Do you have the raw file printing rules enabled?");
9615 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9616 "document-format", NULL
, format
->values
[0].string
.text
);
9621 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9623 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9626 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9627 _("Unsupported document-format \"%s\"."), mimetype
);
9629 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9630 "document-format", NULL
, mimetype
);
9636 * Add the file to the job...
9641 if (add_file(con
, job
, filetype
, compression
))
9644 if (stat(con
->filename
, &fileinfo
))
9647 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9649 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9651 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9652 IPP_TAG_INTEGER
)) != NULL
)
9653 attr
->values
[0].integer
+= kbytes
;
9655 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9657 rename(con
->filename
, filename
);
9659 cupsdClearString(&con
->filename
);
9661 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9662 filetype
->super
, filetype
->type
, job
->username
);
9665 * Start the job if this is the last document...
9670 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9671 IPP_TAG_BOOLEAN
)) != NULL
&&
9672 attr
->values
[0].boolean
)
9675 * See if we need to add the ending sheet...
9678 if (cupsdTimeoutJob(job
))
9681 if (job
->state_value
== IPP_JOB_STOPPED
)
9683 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9684 job
->state_value
= IPP_JOB_PENDING
;
9686 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9688 else if (job
->state_value
== IPP_JOB_HELD
)
9690 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9691 IPP_TAG_KEYWORD
)) == NULL
)
9692 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9694 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9696 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9697 job
->state_value
= IPP_JOB_PENDING
;
9699 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9702 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9706 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9712 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9713 IPP_TAG_KEYWORD
)) == NULL
)
9714 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9716 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9718 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9719 job
->state_value
= IPP_JOB_HELD
;
9720 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9722 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9725 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9732 * Fill in the response info...
9735 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9736 con
->servername
, con
->serverport
, "/jobs/%d", jobid
);
9737 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9740 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9742 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9744 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9745 NULL
, job
->reasons
->values
[0].string
.text
);
9747 con
->response
->request
.status
.status_code
= IPP_OK
;
9750 * Start the job if necessary...
9759 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9764 cupsd_client_t
*con
, /* I - Client connection */
9765 http_status_t status
, /* I - HTTP status code */
9766 cupsd_printer_t
*printer
) /* I - Printer, if any */
9768 ipp_attribute_t
*uri
; /* Request URI, if any */
9771 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9772 IPP_TAG_URI
)) == NULL
)
9773 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9775 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9776 "Returning HTTP %s for %s (%s) from %s",
9779 ippOpString(con
->request
->request
.op
.operation_id
) :
9781 uri
? uri
->values
[0].string
.text
: "no URI",
9782 con
->http
.hostname
);
9786 int auth_type
; /* Type of authentication required */
9789 auth_type
= CUPSD_AUTH_NONE
;
9791 if (status
== HTTP_UNAUTHORIZED
&&
9792 printer
->num_auth_info_required
> 0 &&
9793 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9795 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9796 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9797 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9800 * Creating and authenticating jobs requires Kerberos...
9803 auth_type
= CUPSD_AUTH_NEGOTIATE
;
9808 * Use policy/location-defined authentication requirements...
9811 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9812 cupsd_location_t
*auth
; /* Pointer to authentication element */
9815 if (printer
->type
& CUPS_PRINTER_CLASS
)
9816 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9818 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9820 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9821 auth
->type
== CUPSD_AUTH_NONE
)
9822 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9824 con
->request
->request
.op
.operation_id
:
9829 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9830 auth_type
= cupsdDefaultAuthType();
9832 auth_type
= auth
->type
;
9836 cupsdSendError(con
, status
, auth_type
);
9839 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9841 ippDelete(con
->response
);
9842 con
->response
= NULL
;
9849 * 'send_ipp_status()' - Send a status back to the IPP client.
9853 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9854 ipp_status_t status
, /* I - IPP status code */
9855 const char *message
,/* I - Status message */
9856 ...) /* I - Additional args as needed */
9858 va_list ap
; /* Pointer to additional args */
9859 char formatted
[1024]; /* Formatted errror message */
9862 va_start(ap
, message
);
9863 vsnprintf(formatted
, sizeof(formatted
),
9864 _cupsLangString(con
->language
, message
), ap
);
9867 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9868 ippOpString(con
->request
->request
.op
.operation_id
),
9869 ippErrorString(status
), formatted
);
9871 con
->response
->request
.status
.status_code
= status
;
9873 if (ippFindAttribute(con
->response
, "attributes-charset",
9874 IPP_TAG_ZERO
) == NULL
)
9875 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9876 "attributes-charset", NULL
, "utf-8");
9878 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9879 IPP_TAG_ZERO
) == NULL
)
9880 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9881 "attributes-natural-language", NULL
, DefaultLanguage
);
9883 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9884 "status-message", NULL
, formatted
);
9889 * 'set_default()' - Set the default destination...
9893 set_default(cupsd_client_t
*con
, /* I - Client connection */
9894 ipp_attribute_t
*uri
) /* I - Printer URI */
9896 http_status_t status
; /* Policy status */
9897 cups_ptype_t dtype
; /* Destination type (printer/class) */
9898 cupsd_printer_t
*printer
, /* Printer */
9899 *oldprinter
; /* Old default printer */
9902 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9903 con
->http
.fd
, uri
->values
[0].string
.text
);
9906 * Is the destination valid?
9909 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9915 send_ipp_status(con
, IPP_NOT_FOUND
,
9916 _("The printer or class does not exist."));
9924 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9926 send_http_error(con
, status
, NULL
);
9931 * Set it as the default...
9934 oldprinter
= DefaultPrinter
;
9935 DefaultPrinter
= printer
;
9938 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
9939 "%s is no longer the default printer.", oldprinter
->name
);
9941 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9942 "%s is now the default printer.", printer
->name
);
9944 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
9945 CUPSD_DIRTY_PRINTCAP
);
9947 cupsdLogMessage(CUPSD_LOG_INFO
,
9948 "Default destination set to \"%s\" by \"%s\".",
9949 printer
->name
, get_username(con
));
9952 * Everything was ok, so return OK status...
9955 con
->response
->request
.status
.status_code
= IPP_OK
;
9960 * 'set_job_attrs()' - Set job attributes.
9964 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9965 ipp_attribute_t
*uri
) /* I - Job URI */
9967 ipp_attribute_t
*attr
, /* Current attribute */
9968 *attr2
; /* Job attribute */
9969 int jobid
; /* Job ID */
9970 cupsd_job_t
*job
; /* Current job */
9971 char scheme
[HTTP_MAX_URI
],
9972 /* Method portion of URI */
9973 username
[HTTP_MAX_URI
],
9974 /* Username portion of URI */
9976 /* Host portion of URI */
9977 resource
[HTTP_MAX_URI
];
9978 /* Resource portion of URI */
9979 int port
; /* Port portion of URI */
9980 int event
; /* Events? */
9981 int check_jobs
; /* Check jobs? */
9984 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9985 con
->http
.fd
, uri
->values
[0].string
.text
);
9988 * Start with "everything is OK" status...
9991 con
->response
->request
.status
.status_code
= IPP_OK
;
9994 * See if we have a job URI or a printer URI...
9997 if (!strcmp(uri
->name
, "printer-uri"))
10000 * Got a printer URI; see if we also have a job-id attribute...
10003 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10004 IPP_TAG_INTEGER
)) == NULL
)
10006 send_ipp_status(con
, IPP_BAD_REQUEST
,
10007 _("Got a printer-uri attribute but no job-id."));
10011 jobid
= attr
->values
[0].integer
;
10016 * Got a job URI; parse it to get the job ID...
10019 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10020 sizeof(scheme
), username
, sizeof(username
), host
,
10021 sizeof(host
), &port
, resource
, sizeof(resource
));
10023 if (strncmp(resource
, "/jobs/", 6))
10029 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10030 uri
->values
[0].string
.text
);
10034 jobid
= atoi(resource
+ 6);
10038 * See if the job exists...
10041 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10044 * Nope - return a "not found" error...
10047 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10052 * See if the job has been completed...
10055 if (job
->state_value
> IPP_JOB_STOPPED
)
10058 * Return a "not-possible" error...
10061 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10062 _("Job #%d is finished and cannot be altered."), jobid
);
10067 * See if the job is owned by the requesting user...
10070 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10072 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10073 cupsdFindDest(job
->dest
));
10078 * See what the user wants to change.
10086 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10088 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10091 if (!strcmp(attr
->name
, "attributes-charset") ||
10092 !strcmp(attr
->name
, "attributes-natural-language") ||
10093 !strcmp(attr
->name
, "document-compression") ||
10094 !strcmp(attr
->name
, "document-format") ||
10095 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10096 !strcmp(attr
->name
, "job-document-access-errors") ||
10097 !strcmp(attr
->name
, "job-id") ||
10098 !strcmp(attr
->name
, "job-impressions-completed") ||
10099 !strcmp(attr
->name
, "job-k-octets") ||
10100 !strcmp(attr
->name
, "job-originating-host-name") ||
10101 !strcmp(attr
->name
, "job-originating-user-name") ||
10102 !strcmp(attr
->name
, "job-printer-up-time") ||
10103 !strcmp(attr
->name
, "job-printer-uri") ||
10104 !strcmp(attr
->name
, "job-sheets") ||
10105 !strcmp(attr
->name
, "job-state-message") ||
10106 !strcmp(attr
->name
, "job-state-reasons") ||
10107 !strcmp(attr
->name
, "job-uri") ||
10108 !strcmp(attr
->name
, "number-of-documents") ||
10109 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10110 !strcmp(attr
->name
, "output-device-assigned") ||
10111 !strncmp(attr
->name
, "date-time-at-", 13) ||
10112 !strncmp(attr
->name
, "job-k-octets", 12) ||
10113 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10114 !strncmp(attr
->name
, "time-at-", 8))
10120 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10121 _("%s cannot be changed."), attr
->name
);
10123 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10124 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10128 if (!strcmp(attr
->name
, "job-priority"))
10131 * Change the job priority...
10134 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10136 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10138 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10139 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10141 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10143 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10144 _("Job is completed and cannot be changed."));
10147 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10149 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10150 attr
->values
[0].integer
);
10151 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10154 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10155 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10158 else if (!strcmp(attr
->name
, "job-state"))
10161 * Change the job state...
10164 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10166 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10168 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10169 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10173 switch (attr
->values
[0].integer
)
10175 case IPP_JOB_PENDING
:
10176 case IPP_JOB_HELD
:
10177 if (job
->state_value
> IPP_JOB_HELD
)
10179 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10180 _("Job state cannot be changed."));
10183 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10185 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10186 attr
->values
[0].integer
);
10187 cupsdSetJobState(job
, attr
->values
[0].integer
,
10189 "Job state changed by \"%s\"", username
);
10194 case IPP_JOB_PROCESSING
:
10195 case IPP_JOB_STOPPED
:
10196 if (job
->state_value
!= attr
->values
[0].integer
)
10198 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10199 _("Job state cannot be changed."));
10204 case IPP_JOB_CANCELED
:
10205 case IPP_JOB_ABORTED
:
10206 case IPP_JOB_COMPLETED
:
10207 if (job
->state_value
> IPP_JOB_PROCESSING
)
10209 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10210 _("Job state cannot be changed."));
10213 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10215 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10216 attr
->values
[0].integer
);
10217 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10219 "Job state changed by \"%s\"", username
);
10226 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10228 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10229 IPP_TAG_ZERO
)) != NULL
)
10232 * Some other value; first free the old value...
10235 if (job
->attrs
->prev
)
10236 job
->attrs
->prev
->next
= attr2
->next
;
10238 job
->attrs
->attrs
= attr2
->next
;
10240 if (job
->attrs
->last
== attr2
)
10241 job
->attrs
->last
= job
->attrs
->prev
;
10243 ippDeleteAttribute(NULL
, attr2
);
10246 * Then copy the attribute...
10249 ippCopyAttribute(job
->attrs
, attr
, 0);
10252 * See if the job-name or job-hold-until is being changed.
10255 if (!strcmp(attr
->name
, "job-hold-until"))
10257 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10258 attr
->values
[0].string
.text
);
10259 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10261 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10263 cupsdReleaseJob(job
);
10267 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10268 "Job held by \"%s\".", username
);
10270 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10273 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10276 * Delete the attribute...
10279 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10280 IPP_TAG_ZERO
)) != NULL
)
10282 if (job
->attrs
->prev
)
10283 job
->attrs
->prev
->next
= attr2
->next
;
10285 job
->attrs
->attrs
= attr2
->next
;
10287 if (attr2
== job
->attrs
->last
)
10288 job
->attrs
->last
= job
->attrs
->prev
;
10290 ippDeleteAttribute(NULL
, attr2
);
10292 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10298 * Add new option by copying it...
10301 ippCopyAttribute(job
->attrs
, attr
, 0);
10303 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10312 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10315 * Send events as needed...
10318 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10319 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10320 cupsdFindDest(job
->dest
), job
,
10321 "Job priority changed by user.");
10323 if (event
& CUPSD_EVENT_JOB_STATE
)
10324 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10325 job
->state_value
== IPP_JOB_HELD
?
10326 "Job held by user." : "Job restarted by user.");
10328 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10329 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10330 "Job options changed by user.");
10333 * Start jobs if possible...
10342 * 'set_printer_attrs()' - Set printer attributes.
10346 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10347 ipp_attribute_t
*uri
) /* I - Printer */
10349 http_status_t status
; /* Policy status */
10350 cups_ptype_t dtype
; /* Destination type (printer/class) */
10351 cupsd_printer_t
*printer
; /* Printer/class */
10352 ipp_attribute_t
*attr
; /* Printer attribute */
10353 int changed
= 0; /* Was anything changed? */
10356 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10357 con
->http
.fd
, uri
->values
[0].string
.text
);
10360 * Is the destination valid?
10363 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10369 send_ipp_status(con
, IPP_NOT_FOUND
,
10370 _("The printer or class does not exist."));
10378 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10380 send_http_error(con
, status
, printer
);
10385 * Return a list of attributes that can be set via Set-Printer-Attributes.
10388 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10389 IPP_TAG_TEXT
)) != NULL
)
10391 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10395 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10396 IPP_TAG_TEXT
)) != NULL
)
10398 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10403 * Update the printer attributes and return...
10408 cupsdSetPrinterAttrs(printer
);
10409 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10411 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10412 "Printer \"%s\" description or location changed by \"%s\".",
10413 printer
->name
, get_username(con
));
10415 cupsdLogMessage(CUPSD_LOG_INFO
,
10416 "Printer \"%s\" description or location changed by \"%s\".",
10417 printer
->name
, get_username(con
));
10420 con
->response
->request
.status
.status_code
= IPP_OK
;
10425 * 'set_printer_defaults()' - Set printer default options from a request.
10429 set_printer_defaults(
10430 cupsd_client_t
*con
, /* I - Client connection */
10431 cupsd_printer_t
*printer
) /* I - Printer */
10433 int i
; /* Looping var */
10434 ipp_attribute_t
*attr
; /* Current attribute */
10435 int namelen
; /* Length of attribute name */
10436 char name
[256], /* New attribute name */
10437 value
[256]; /* String version of integer attrs */
10440 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10443 * Skip non-printer attributes...
10446 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10449 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10451 if (!strcmp(attr
->name
, "job-sheets-default"))
10454 * Only allow keywords and names...
10457 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10461 * Only allow job-sheets-default to be set when running without a
10462 * system high classification level...
10465 if (Classification
)
10468 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10470 if (attr
->num_values
> 1)
10471 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10473 cupsdSetString(&printer
->job_sheets
[1], "none");
10475 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10477 cupsdFreeStrings(&(printer
->users
));
10479 printer
->deny_users
= 0;
10481 if (attr
->value_tag
== IPP_TAG_NAME
&&
10482 (attr
->num_values
> 1 ||
10483 strcmp(attr
->values
[0].string
.text
, "all")))
10485 for (i
= 0; i
< attr
->num_values
; i
++)
10486 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10489 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10491 cupsdFreeStrings(&(printer
->users
));
10493 printer
->deny_users
= 1;
10495 if (attr
->value_tag
== IPP_TAG_NAME
&&
10496 (attr
->num_values
> 1 ||
10497 strcmp(attr
->values
[0].string
.text
, "none")))
10499 for (i
= 0; i
< attr
->num_values
; i
++)
10500 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10503 else if (!strcmp(attr
->name
, "job-quota-period"))
10505 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10508 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10509 attr
->values
[0].integer
);
10510 cupsdFreeQuotas(printer
);
10512 printer
->quota_period
= attr
->values
[0].integer
;
10514 else if (!strcmp(attr
->name
, "job-k-limit"))
10516 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10519 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10520 attr
->values
[0].integer
);
10521 cupsdFreeQuotas(printer
);
10523 printer
->k_limit
= attr
->values
[0].integer
;
10525 else if (!strcmp(attr
->name
, "job-page-limit"))
10527 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10530 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10531 attr
->values
[0].integer
);
10532 cupsdFreeQuotas(printer
);
10534 printer
->page_limit
= attr
->values
[0].integer
;
10536 else if (!strcmp(attr
->name
, "printer-op-policy"))
10538 cupsd_policy_t
*p
; /* Policy */
10541 if (attr
->value_tag
!= IPP_TAG_NAME
)
10544 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10546 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10547 "Setting printer-op-policy to \"%s\"...",
10548 attr
->values
[0].string
.text
);
10549 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10550 printer
->op_policy_ptr
= p
;
10554 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10555 _("Unknown printer-op-policy \"%s\"."),
10556 attr
->values
[0].string
.text
);
10560 else if (!strcmp(attr
->name
, "printer-error-policy"))
10562 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10565 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10566 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10567 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10568 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10569 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10571 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10572 _("Unknown printer-error-policy \"%s\"."),
10573 attr
->values
[0].string
.text
);
10577 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10578 "Setting printer-error-policy to \"%s\"...",
10579 attr
->values
[0].string
.text
);
10580 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10584 * Skip any other non-default attributes...
10587 namelen
= strlen(attr
->name
);
10588 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10589 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10593 * OK, anything else must be a user-defined default...
10596 strlcpy(name
, attr
->name
, sizeof(name
));
10597 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10599 switch (attr
->value_tag
)
10601 case IPP_TAG_DELETEATTR
:
10602 printer
->num_options
= cupsRemoveOption(name
,
10603 printer
->num_options
,
10604 &(printer
->options
));
10605 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10606 "Deleting %s", attr
->name
);
10609 case IPP_TAG_NAME
:
10610 case IPP_TAG_TEXT
:
10611 case IPP_TAG_KEYWORD
:
10613 printer
->num_options
= cupsAddOption(name
,
10614 attr
->values
[0].string
.text
,
10615 printer
->num_options
,
10616 &(printer
->options
));
10617 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10618 "Setting %s to \"%s\"...", attr
->name
,
10619 attr
->values
[0].string
.text
);
10622 case IPP_TAG_BOOLEAN
:
10623 printer
->num_options
= cupsAddOption(name
,
10624 attr
->values
[0].boolean
?
10626 printer
->num_options
,
10627 &(printer
->options
));
10628 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10629 "Setting %s to %s...", attr
->name
,
10630 attr
->values
[0].boolean
? "true" : "false");
10633 case IPP_TAG_INTEGER
:
10634 case IPP_TAG_ENUM
:
10635 sprintf(value
, "%d", attr
->values
[0].integer
);
10636 printer
->num_options
= cupsAddOption(name
, value
,
10637 printer
->num_options
,
10638 &(printer
->options
));
10639 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10640 "Setting %s to %s...", attr
->name
, value
);
10643 case IPP_TAG_RANGE
:
10644 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10645 attr
->values
[0].range
.upper
);
10646 printer
->num_options
= cupsAddOption(name
, value
,
10647 printer
->num_options
,
10648 &(printer
->options
));
10649 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10650 "Setting %s to %s...", attr
->name
, value
);
10653 case IPP_TAG_RESOLUTION
:
10654 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10655 attr
->values
[0].resolution
.yres
,
10656 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10658 printer
->num_options
= cupsAddOption(name
, value
,
10659 printer
->num_options
,
10660 &(printer
->options
));
10661 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10662 "Setting %s to %s...", attr
->name
, value
);
10666 /* Do nothing for other values */
10674 * 'start_printer()' - Start a printer.
10678 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10679 ipp_attribute_t
*uri
) /* I - Printer URI */
10681 int i
; /* Temporary variable */
10682 http_status_t status
; /* Policy status */
10683 cups_ptype_t dtype
; /* Destination type (printer/class) */
10684 cupsd_printer_t
*printer
; /* Printer data */
10687 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10688 con
->http
.fd
, uri
->values
[0].string
.text
);
10691 * Is the destination valid?
10694 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10700 send_ipp_status(con
, IPP_NOT_FOUND
,
10701 _("The printer or class does not exist."));
10709 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10711 send_http_error(con
, status
, printer
);
10716 * Start the printer...
10719 printer
->state_message
[0] = '\0';
10721 cupsdStartPrinter(printer
, 1);
10723 if (dtype
& CUPS_PRINTER_CLASS
)
10724 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10725 printer
->name
, get_username(con
));
10727 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10728 printer
->name
, get_username(con
));
10736 if ((i
= check_quotas(con
, printer
)) < 0)
10738 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10743 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10748 * Everything was ok, so return OK status...
10751 con
->response
->request
.status
.status_code
= IPP_OK
;
10756 * 'stop_printer()' - Stop a printer.
10760 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10761 ipp_attribute_t
*uri
) /* I - Printer URI */
10763 http_status_t status
; /* Policy status */
10764 cups_ptype_t dtype
; /* Destination type (printer/class) */
10765 cupsd_printer_t
*printer
; /* Printer data */
10766 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10769 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10770 con
->http
.fd
, uri
->values
[0].string
.text
);
10773 * Is the destination valid?
10776 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10782 send_ipp_status(con
, IPP_NOT_FOUND
,
10783 _("The printer or class does not exist."));
10791 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10793 send_http_error(con
, status
, printer
);
10798 * Stop the printer...
10801 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10802 IPP_TAG_TEXT
)) == NULL
)
10803 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
10806 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10807 sizeof(printer
->state_message
));
10810 cupsdStopPrinter(printer
, 1);
10812 if (dtype
& CUPS_PRINTER_CLASS
)
10813 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10814 printer
->name
, get_username(con
));
10816 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10817 printer
->name
, get_username(con
));
10820 * Everything was ok, so return OK status...
10823 con
->response
->request
.status
.status_code
= IPP_OK
;
10828 * 'url_encode_attr()' - URL-encode a string attribute.
10832 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10833 char *buffer
,/* I - String buffer */
10834 int bufsize
)/* I - Size of buffer */
10836 int i
; /* Looping var */
10837 char *bufptr
, /* Pointer into buffer */
10838 *bufend
; /* End of buffer */
10841 strlcpy(buffer
, attr
->name
, bufsize
);
10842 bufptr
= buffer
+ strlen(buffer
);
10843 bufend
= buffer
+ bufsize
- 1;
10845 for (i
= 0; i
< attr
->num_values
; i
++)
10847 if (bufptr
>= bufend
)
10855 if (bufptr
>= bufend
)
10860 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
10861 bufptr
, bufend
- bufptr
+ 1);
10863 if (bufptr
>= bufend
)
10874 * 'url_encode_string()' - URL-encode a string.
10877 static char * /* O - End of string */
10878 url_encode_string(const char *s
, /* I - String */
10879 char *buffer
, /* I - String buffer */
10880 int bufsize
) /* I - Size of buffer */
10882 char *bufptr
, /* Pointer into buffer */
10883 *bufend
; /* End of buffer */
10884 static const char *hex
= "0123456789ABCDEF";
10889 bufend
= buffer
+ bufsize
- 1;
10891 while (*s
&& bufptr
< bufend
)
10893 if (*s
== ' ' || *s
== '%' || *s
== '+')
10895 if (bufptr
>= (bufend
- 2))
10899 *bufptr
++ = hex
[(*s
>> 4) & 15];
10900 *bufptr
++ = hex
[*s
& 15];
10904 else if (*s
== '\'' || *s
== '\\')
10906 if (bufptr
>= (bufend
- 1))
10923 * 'user_allowed()' - See if a user is allowed to print to a queue.
10926 static int /* O - 0 if not allowed, 1 if allowed */
10927 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10928 const char *username
) /* I - Username */
10930 struct passwd
*pw
; /* User password data */
10931 char baseuser
[256], /* Base username */
10932 *baseptr
, /* Pointer to "@" in base username */
10933 *name
; /* Current user name */
10936 if (cupsArrayCount(p
->users
) == 0)
10939 if (!strcmp(username
, "root"))
10942 if (strchr(username
, '@'))
10945 * Strip @REALM for username check...
10948 strlcpy(baseuser
, username
, sizeof(baseuser
));
10950 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10953 username
= baseuser
;
10956 pw
= getpwnam(username
);
10959 for (name
= (char *)cupsArrayFirst(p
->users
);
10961 name
= (char *)cupsArrayNext(p
->users
))
10963 if (name
[0] == '@')
10966 * Check group membership...
10969 if (cupsdCheckGroup(username
, pw
, name
+ 1))
10972 else if (name
[0] == '#')
10978 if (cupsdCheckGroup(username
, pw
, name
))
10981 else if (!_cups_strcasecmp(username
, name
))
10985 return ((name
!= NULL
) != p
->deny_users
);
10990 * 'validate_job()' - Validate printer options and destination.
10994 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10995 ipp_attribute_t
*uri
) /* I - Printer URI */
10997 http_status_t status
; /* Policy status */
10998 ipp_attribute_t
*attr
, /* Current attribute */
10999 *auth_info
; /* auth-info attribute */
11000 ipp_attribute_t
*format
, /* Document-format attribute */
11001 *name
; /* Job-name attribute */
11002 cups_ptype_t dtype
; /* Destination type (printer/class) */
11003 char super
[MIME_MAX_SUPER
],
11004 /* Supertype of file */
11005 type
[MIME_MAX_TYPE
];
11006 /* Subtype of file */
11007 cupsd_printer_t
*printer
; /* Printer */
11010 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11011 con
->http
.fd
, uri
->values
[0].string
.text
);
11014 * OK, see if the client is sending the document compressed - CUPS
11015 * doesn't support compression yet...
11018 if ((attr
= ippFindAttribute(con
->request
, "compression",
11019 IPP_TAG_KEYWORD
)) != NULL
)
11021 if (strcmp(attr
->values
[0].string
.text
, "none")
11023 && strcmp(attr
->values
[0].string
.text
, "gzip")
11024 #endif /* HAVE_LIBZ */
11027 send_ipp_status(con
, IPP_ATTRIBUTES
,
11028 _("Unsupported 'compression' value \"%s\"."),
11029 attr
->values
[0].string
.text
);
11030 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11031 "compression", NULL
, attr
->values
[0].string
.text
);
11037 * Is it a format we support?
11040 if ((format
= ippFindAttribute(con
->request
, "document-format",
11041 IPP_TAG_MIMETYPE
)) != NULL
)
11043 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11046 send_ipp_status(con
, IPP_BAD_REQUEST
,
11047 _("Bad 'document-format' value \"%s\"."),
11048 format
->values
[0].string
.text
);
11052 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11053 !mimeType(MimeDatabase
, super
, type
))
11055 cupsdLogMessage(CUPSD_LOG_INFO
,
11056 "Hint: Do you have the raw file printing rules enabled?");
11057 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11058 _("Unsupported 'document-format' value \"%s\"."),
11059 format
->values
[0].string
.text
);
11060 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11061 "document-format", NULL
, format
->values
[0].string
.text
);
11067 * Is the job-name valid?
11070 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
11072 int bad_name
= 0; /* Is the job-name value bad? */
11074 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
11075 name
->num_values
!= 1)
11082 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
11083 * IPP Everywhere requirements for "name" values...
11086 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
11088 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
11092 if (*nameptr
< ' ' && *nameptr
!= '\t')
11094 else if (*nameptr
== 0x7f)
11096 else if ((*nameptr
& 0xe0) == 0xc0)
11098 if ((nameptr
[1] & 0xc0) != 0x80)
11103 else if ((*nameptr
& 0xf0) == 0xe0)
11105 if ((nameptr
[1] & 0xc0) != 0x80 ||
11106 (nameptr
[2] & 0xc0) != 0x80)
11111 else if ((*nameptr
& 0xf8) == 0xf0)
11113 if ((nameptr
[1] & 0xc0) != 0x80 ||
11114 (nameptr
[2] & 0xc0) != 0x80 ||
11115 (nameptr
[3] & 0xc0) != 0x80)
11120 else if (*nameptr
& 0x80)
11130 if (StrictConformance
)
11132 send_ipp_status(con
, IPP_ATTRIBUTES
,
11133 _("Unsupported 'job-name' value."));
11134 ippCopyAttribute(con
->response
, name
, 0);
11139 cupsdLogMessage(CUPSD_LOG_WARN
,
11140 "Unsupported 'job-name' value, deleting from request.");
11141 ippDeleteAttribute(con
->request
, name
);
11147 * Is the destination valid?
11150 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11156 send_ipp_status(con
, IPP_NOT_FOUND
,
11157 _("The printer or class does not exist."));
11165 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11167 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11169 send_http_error(con
, status
, printer
);
11172 else if (printer
->num_auth_info_required
== 1 &&
11173 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11176 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11180 else if (auth_info
&& !con
->http
.tls
&&
11181 !httpAddrLocalhost(con
->http
.hostaddr
))
11184 * Require encryption of auth-info over non-local connections...
11187 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11190 #endif /* HAVE_SSL */
11193 * Everything was ok, so return OK status...
11196 con
->response
->request
.status
.status_code
= IPP_OK
;
11201 * 'validate_name()' - Make sure the printer name only contains valid chars.
11204 static int /* O - 0 if name is no good, 1 if good */
11205 validate_name(const char *name
) /* I - Name to check */
11207 const char *ptr
; /* Pointer into name */
11211 * Scan the whole name...
11214 for (ptr
= name
; *ptr
; ptr
++)
11215 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11219 * All the characters are good; validate the length, too...
11222 return ((ptr
- name
) < 128);
11227 * 'validate_user()' - Validate the user for the request.
11230 static int /* O - 1 if permitted, 0 otherwise */
11231 validate_user(cupsd_job_t
*job
, /* I - Job */
11232 cupsd_client_t
*con
, /* I - Client connection */
11233 const char *owner
, /* I - Owner of job/resource */
11234 char *username
, /* O - Authenticated username */
11235 int userlen
) /* I - Length of username */
11237 cupsd_printer_t
*printer
; /* Printer for job */
11240 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11241 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11243 job
->id
, con
? con
->http
.fd
: 0,
11244 owner
? owner
: "(null)", username
, userlen
);
11247 * Validate input...
11250 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11254 * Get the best authenticated username that is available.
11257 strlcpy(username
, get_username(con
), userlen
);
11260 * Check the username against the owner...
11263 printer
= cupsdFindDest(job
->dest
);
11265 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11266 con
, owner
) == HTTP_OK
);