2 * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2010 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * This file contains Kerberos support code, copyright 2006 by
12 * These coded instructions, statements, and computer programs are the
13 * property of Apple Inc. and are protected by Federal copyright
14 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 * which should have been included with this file. If this file is
16 * file is missing or damaged, see the license at "http://www.cups.org/".
20 * cupsdProcessIPPRequest() - Process an incoming IPP request.
21 * cupsdTimeoutJob() - Timeout a job waiting on job files.
22 * accept_jobs() - Accept print jobs to a printer.
23 * add_class() - Add a class to the system.
24 * add_file() - Add a file to a job.
25 * add_job() - Add a job to a print queue.
26 * add_job_state_reasons() - Add the "job-state-reasons" attribute based
27 * upon the job and printer state...
28 * add_job_subscriptions() - Add any subscriptions for a job.
29 * add_job_uuid() - Add job-uuid attribute to a job.
30 * add_printer() - Add a printer to the system.
31 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
32 * based upon the printer state...
33 * add_queued_job_count() - Add the "queued-job-count" attribute for the
34 * specified printer or class.
35 * apple_init_profile() - Initialize a color profile.
36 * apple_register_profiles() - Register color profiles for a printer.
37 * apple_unregister_profiles() - Remove color profiles for the specified
39 * apply_printer_defaults() - Apply printer default options to a job.
40 * authenticate_job() - Set job authentication info.
41 * cancel_all_jobs() - Cancel all or selected print jobs.
42 * cancel_job() - Cancel a print job.
43 * cancel_subscription() - Cancel a subscription.
44 * check_rss_recipient() - Check that we do not have a duplicate RSS
46 * check_quotas() - Check quotas for a printer and user.
47 * close_job() - Close a multi-file job.
48 * copy_attribute() - Copy a single attribute.
49 * copy_attrs() - Copy attributes from one request to another.
50 * copy_banner() - Copy a banner file to the requests directory
51 * for the specified job.
52 * copy_file() - Copy a PPD file or interface script...
53 * copy_model() - Copy a PPD model file, substituting default
55 * copy_job_attrs() - Copy job attributes.
56 * copy_printer_attrs() - Copy printer attributes.
57 * copy_subscription_attrs() - Copy subscription attributes.
58 * create_job() - Print a file to a printer or class.
59 * create_requested_array() - Create an array for the requested-attributes.
60 * create_subscription() - Create a notification subscription.
61 * delete_printer() - Remove a printer or class from the system.
62 * get_default() - Get the default destination.
63 * get_devices() - Get the list of available devices on the
65 * get_document() - Get a copy of a job file.
66 * get_job_attrs() - Get job attributes.
67 * get_jobs() - Get a list of jobs for the specified printer.
68 * get_notifications() - Get events for a subscription.
69 * get_ppd() - Get a named PPD from the local system.
70 * get_ppds() - Get the list of PPD files on the local
72 * get_printer_attrs() - Get printer attributes.
73 * get_printer_supported() - Get printer supported values.
74 * get_printers() - Get a list of printers or classes.
75 * get_subscription_attrs() - Get subscription attributes.
76 * get_subscriptions() - Get subscriptions.
77 * get_username() - Get the username associated with a request.
78 * hold_job() - Hold a print job.
79 * hold_new_jobs() - Hold pending/new jobs on a printer or class.
80 * move_job() - Move a job to a new destination.
81 * ppd_parse_line() - Parse a PPD default line.
82 * print_job() - Print a file to a printer or class.
83 * read_job_ticket() - Read a job ticket embedded in a print file.
84 * reject_jobs() - Reject print jobs to a printer.
85 * release_held_new_jobs() - Release pending/new jobs on a printer or
87 * release_job() - Release a held print job.
88 * renew_subscription() - Renew an existing subscription...
89 * restart_job() - Restart an old print job.
90 * save_auth_info() - Save authentication information for a job.
91 * save_krb5_creds() - Save Kerberos credentials for the job.
92 * send_document() - Send a file to a printer or class.
93 * send_http_error() - Send a HTTP error back to the IPP client.
94 * send_ipp_status() - Send a status back to the IPP client.
95 * set_default() - Set the default destination...
96 * set_job_attrs() - Set job attributes.
97 * set_printer_attrs() - Set printer attributes.
98 * set_printer_defaults() - Set printer default options from a request.
99 * start_printer() - Start a printer.
100 * stop_printer() - Stop a printer.
101 * url_encode_attr() - URL-encode a string attribute.
102 * url_encode_string() - URL-encode a string.
103 * user_allowed() - See if a user is allowed to print to a queue.
104 * validate_job() - Validate printer options and destination.
105 * validate_name() - Make sure the printer name only contains
107 * validate_user() - Validate the user for the request.
111 * Include necessary headers...
115 #include <cups/ppd-private.h>
118 # include <ApplicationServices/ApplicationServices.h>
119 # include <CoreFoundation/CoreFoundation.h>
120 # ifdef HAVE_MEMBERSHIP_H
121 # include <membership.h>
122 # endif /* HAVE_MEMBERSHIP_H */
123 # ifdef HAVE_MEMBERSHIPPRIV_H
124 # include <membershipPriv.h>
126 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
127 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
128 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
129 # endif /* HAVE_MEMBERSHIPPRIV_H */
130 #endif /* __APPLE__ */
137 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
138 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
139 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
140 mime_type_t
*filetype
, int compression
);
141 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
142 mime_type_t
*filetype
);
143 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
144 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
145 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
146 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
147 static void add_printer_state_reasons(cupsd_client_t
*con
,
149 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
151 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
152 CMDeviceProfileInfo
*profile
, unsigned id
,
153 const char *name
, const char *text
,
154 const char *iccfile
);
155 static void apple_register_profiles(cupsd_printer_t
*p
);
156 static void apple_unregister_profiles(cupsd_printer_t
*p
);
157 #endif /* __APPLE__ */
158 static void apply_printer_defaults(cupsd_printer_t
*printer
,
160 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
161 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
162 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
163 static void cancel_subscription(cupsd_client_t
*con
, int id
);
164 static int check_rss_recipient(const char *recipient
);
165 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
166 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
168 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
169 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
170 ipp_tag_t group
, int quickcopy
);
171 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
173 static int copy_file(const char *from
, const char *to
);
174 static int copy_model(cupsd_client_t
*con
, const char *from
,
176 static void copy_job_attrs(cupsd_client_t
*con
,
179 static void copy_printer_attrs(cupsd_client_t
*con
,
180 cupsd_printer_t
*printer
,
182 static void copy_subscription_attrs(cupsd_client_t
*con
,
183 cupsd_subscription_t
*sub
,
185 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static cups_array_t
*create_requested_array(ipp_t
*request
);
187 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
188 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
189 static void get_default(cupsd_client_t
*con
);
190 static void get_devices(cupsd_client_t
*con
);
191 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
192 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
193 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
194 static void get_notifications(cupsd_client_t
*con
);
195 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
196 static void get_ppds(cupsd_client_t
*con
);
197 static void get_printers(cupsd_client_t
*con
, int type
);
198 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
199 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
200 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
201 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
202 static const char *get_username(cupsd_client_t
*con
);
203 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
204 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
205 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
206 static int ppd_parse_line(const char *line
, char *option
, int olen
,
207 char *choice
, int clen
);
208 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
209 static void read_job_ticket(cupsd_client_t
*con
);
210 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
211 static void release_held_new_jobs(cupsd_client_t
*con
,
212 ipp_attribute_t
*uri
);
213 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
214 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
215 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
216 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
217 ipp_attribute_t
*auth_info
);
218 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
219 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
220 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
221 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
222 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
223 cupsd_printer_t
*printer
);
224 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
225 const char *message
, ...)
227 __attribute__ ((__format__ (__printf__
, 3, 4)))
228 # endif /* __GNUC__ */
230 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
231 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
232 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
233 static void set_printer_defaults(cupsd_client_t
*con
,
234 cupsd_printer_t
*printer
);
235 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
236 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
237 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
239 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
240 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
241 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
242 static int validate_name(const char *name
);
243 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
244 const char *owner
, char *username
,
249 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
252 int /* O - 1 on success, 0 on failure */
253 cupsdProcessIPPRequest(
254 cupsd_client_t
*con
) /* I - Client connection */
256 ipp_tag_t group
; /* Current group tag */
257 ipp_attribute_t
*attr
; /* Current attribute */
258 ipp_attribute_t
*charset
; /* Character set attribute */
259 ipp_attribute_t
*language
; /* Language attribute */
260 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
261 ipp_attribute_t
*username
; /* requesting-user-name attr */
262 int sub_id
; /* Subscription ID */
265 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
266 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
267 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
270 * First build an empty response message for this request...
273 con
->response
= ippNew();
275 con
->response
->request
.status
.version
[0] =
276 con
->request
->request
.op
.version
[0];
277 con
->response
->request
.status
.version
[1] =
278 con
->request
->request
.op
.version
[1];
279 con
->response
->request
.status
.request_id
=
280 con
->request
->request
.op
.request_id
;
283 * Then validate the request header and required attributes...
286 if (con
->request
->request
.any
.version
[0] != 1 &&
287 con
->request
->request
.any
.version
[0] != 2)
290 * Return an error, since we only support IPP 1.x and 2.x.
293 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
294 "%04X %s Bad request version number %d.%d",
295 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
296 con
->request
->request
.any
.version
[0],
297 con
->request
->request
.any
.version
[1]);
299 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
300 _("Bad request version number %d.%d"),
301 con
->request
->request
.any
.version
[0],
302 con
->request
->request
.any
.version
[1]);
304 else if (con
->request
->request
.any
.request_id
< 1)
307 * Return an error, since request IDs must be between 1 and 2^31-1
310 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
311 "%04X %s Bad request ID %d",
312 IPP_BAD_REQUEST
, con
->http
.hostname
,
313 con
->request
->request
.any
.request_id
);
315 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d"),
316 con
->request
->request
.any
.request_id
);
318 else if (!con
->request
->attrs
)
320 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
321 "%04X %s No attributes in request",
322 IPP_BAD_REQUEST
, con
->http
.hostname
);
324 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request"));
329 * Make sure that the attributes are provided in the correct order and
330 * don't repeat groups...
333 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
336 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
339 * Out of order; return an error...
342 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
343 "%04X %s Attribute groups are out of order",
344 IPP_BAD_REQUEST
, con
->http
.hostname
);
346 send_ipp_status(con
, IPP_BAD_REQUEST
,
347 _("Attribute groups are out of order (%x < %x)"),
348 attr
->group_tag
, group
);
352 group
= attr
->group_tag
;
357 * Then make sure that the first three attributes are:
360 * attributes-natural-language
361 * printer-uri/job-uri
364 attr
= con
->request
->attrs
;
365 if (attr
&& attr
->name
&&
366 !strcmp(attr
->name
, "attributes-charset") &&
367 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
375 if (attr
&& attr
->name
&&
376 !strcmp(attr
->name
, "attributes-natural-language") &&
377 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
382 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
383 IPP_TAG_URI
)) != NULL
)
385 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
386 IPP_TAG_URI
)) != NULL
)
388 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
389 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
394 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
395 "attributes-charset", NULL
,
396 charset
->values
[0].string
.text
);
398 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
399 "attributes-charset", NULL
, "utf-8");
402 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
403 "attributes-natural-language", NULL
,
404 language
->values
[0].string
.text
);
406 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
407 "attributes-natural-language", NULL
, DefaultLanguage
);
410 strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
411 strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
414 * Bad character set...
417 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
418 charset
->values
[0].string
.text
);
419 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
420 "%04X %s Unsupported attributes-charset value \"%s\"",
421 IPP_CHARSET
, con
->http
.hostname
,
422 charset
->values
[0].string
.text
);
423 send_ipp_status(con
, IPP_BAD_REQUEST
,
424 _("Unsupported character set \"%s\""),
425 charset
->values
[0].string
.text
);
427 else if (!charset
|| !language
||
429 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
430 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
431 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
432 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
433 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
436 * Return an error, since attributes-charset,
437 * attributes-natural-language, and printer-uri/job-uri are required
438 * for all operations.
443 cupsdLogMessage(CUPSD_LOG_ERROR
,
444 "Missing attributes-charset attribute");
446 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
447 "%04X %s Missing attributes-charset attribute",
448 IPP_BAD_REQUEST
, con
->http
.hostname
);
453 cupsdLogMessage(CUPSD_LOG_ERROR
,
454 "Missing attributes-natural-language attribute");
456 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
457 "%04X %s Missing attributes-natural-language attribute",
458 IPP_BAD_REQUEST
, con
->http
.hostname
);
463 cupsdLogMessage(CUPSD_LOG_ERROR
,
464 "Missing printer-uri, job-uri, or ppd-name "
467 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
468 "%04X %s Missing printer-uri, job-uri, or ppd-name "
469 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
472 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
474 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
475 cupsdLogMessage(CUPSD_LOG_DEBUG
,
476 "attr \"%s\": group_tag = %x, value_tag = %x",
477 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
480 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
482 send_ipp_status(con
, IPP_BAD_REQUEST
,
483 _("Missing required attributes"));
488 * OK, all the checks pass so far; make sure requesting-user-name is
489 * not "root" from a remote host...
492 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
493 IPP_TAG_NAME
)) != NULL
)
496 * Check for root user...
499 if (!strcmp(username
->values
[0].string
.text
, "root") &&
500 strcasecmp(con
->http
.hostname
, "localhost") &&
501 strcmp(con
->username
, "root"))
504 * Remote unauthenticated user masquerading as local root...
507 _cupsStrFree(username
->values
[0].string
.text
);
508 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
512 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
513 IPP_TAG_INTEGER
)) != NULL
)
514 sub_id
= attr
->values
[0].integer
;
519 * Then try processing the operation...
523 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
524 ippOpString(con
->request
->request
.op
.operation_id
),
525 uri
->values
[0].string
.text
);
527 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
528 ippOpString(con
->request
->request
.op
.operation_id
));
530 switch (con
->request
->request
.op
.operation_id
)
536 case IPP_VALIDATE_JOB
:
537 validate_job(con
, uri
);
540 case IPP_CREATE_JOB
:
541 create_job(con
, uri
);
544 case IPP_SEND_DOCUMENT
:
545 send_document(con
, uri
);
548 case IPP_CANCEL_JOB
:
549 cancel_job(con
, uri
);
552 case IPP_GET_JOB_ATTRIBUTES
:
553 get_job_attrs(con
, uri
);
560 case IPP_GET_PRINTER_ATTRIBUTES
:
561 get_printer_attrs(con
, uri
);
564 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
565 get_printer_supported(con
, uri
);
572 case IPP_RELEASE_JOB
:
573 release_job(con
, uri
);
576 case IPP_RESTART_JOB
:
577 restart_job(con
, uri
);
580 case IPP_PAUSE_PRINTER
:
581 stop_printer(con
, uri
);
584 case IPP_RESUME_PRINTER
:
585 start_printer(con
, uri
);
588 case IPP_PURGE_JOBS
:
589 case IPP_CANCEL_JOBS
:
590 case IPP_CANCEL_MY_JOBS
:
591 cancel_all_jobs(con
, uri
);
594 case IPP_SET_JOB_ATTRIBUTES
:
595 set_job_attrs(con
, uri
);
598 case IPP_SET_PRINTER_ATTRIBUTES
:
599 set_printer_attrs(con
, uri
);
602 case IPP_HOLD_NEW_JOBS
:
603 hold_new_jobs(con
, uri
);
606 case IPP_RELEASE_HELD_NEW_JOBS
:
607 release_held_new_jobs(con
, uri
);
614 case CUPS_GET_DEFAULT
:
618 case CUPS_GET_PRINTERS
:
619 get_printers(con
, 0);
622 case CUPS_GET_CLASSES
:
623 get_printers(con
, CUPS_PRINTER_CLASS
);
626 case CUPS_ADD_PRINTER
:
627 add_printer(con
, uri
);
630 case CUPS_DELETE_PRINTER
:
631 delete_printer(con
, uri
);
634 case CUPS_ADD_CLASS
:
638 case CUPS_DELETE_CLASS
:
639 delete_printer(con
, uri
);
642 case CUPS_ACCEPT_JOBS
:
643 case IPP_ENABLE_PRINTER
:
644 accept_jobs(con
, uri
);
647 case CUPS_REJECT_JOBS
:
648 case IPP_DISABLE_PRINTER
:
649 reject_jobs(con
, uri
);
652 case CUPS_SET_DEFAULT
:
653 set_default(con
, uri
);
656 case CUPS_GET_DEVICES
:
660 case CUPS_GET_DOCUMENT
:
661 get_document(con
, uri
);
676 case CUPS_AUTHENTICATE_JOB
:
677 authenticate_job(con
, uri
);
680 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
681 case IPP_CREATE_JOB_SUBSCRIPTION
:
682 create_subscription(con
, uri
);
685 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
686 get_subscription_attrs(con
, sub_id
);
689 case IPP_GET_SUBSCRIPTIONS
:
690 get_subscriptions(con
, uri
);
693 case IPP_RENEW_SUBSCRIPTION
:
694 renew_subscription(con
, sub_id
);
697 case IPP_CANCEL_SUBSCRIPTION
:
698 cancel_subscription(con
, sub_id
);
701 case IPP_GET_NOTIFICATIONS
:
702 get_notifications(con
);
706 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
707 "%04X %s Operation %04X (%s) not supported",
708 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
709 con
->request
->request
.op
.operation_id
,
710 ippOpString(con
->request
->request
.op
.operation_id
));
712 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
713 _("%s not supported"),
715 con
->request
->request
.op
.operation_id
));
725 * Sending data from the scheduler...
728 cupsdLogMessage(con
->response
->request
.status
.status_code
729 >= IPP_BAD_REQUEST
&&
730 con
->response
->request
.status
.status_code
731 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
732 "Returning IPP %s for %s (%s) from %s",
733 ippErrorString(con
->response
->request
.status
.status_code
),
734 ippOpString(con
->request
->request
.op
.operation_id
),
735 uri
? uri
->values
[0].string
.text
: "no URI",
738 if (LogLevel
== CUPSD_LOG_DEBUG2
)
739 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
740 "cupsdProcessIPPRequest: ippLength(response)=%ld",
741 (long)ippLength(con
->response
));
743 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
745 #ifdef CUPSD_USE_CHUNKING
747 * Because older versions of CUPS (1.1.17 and older) and some IPP
748 * clients do not implement chunking properly, we cannot use
749 * chunking by default. This may become the default in future
750 * CUPS releases, or we might add a configuration directive for
754 if (con
->http
.version
== HTTP_1_1
)
756 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
759 if (cupsdFlushHeader(con
) < 0)
762 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
765 #endif /* CUPSD_USE_CHUNKING */
767 size_t length
; /* Length of response */
770 length
= ippLength(con
->response
);
772 if (con
->file
>= 0 && !con
->pipe_pid
)
774 struct stat fileinfo
; /* File information */
777 if (!fstat(con
->file
, &fileinfo
))
778 length
+= fileinfo
.st_size
;
781 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
782 CUPS_LLCAST length
) < 0)
785 if (cupsdFlushHeader(con
) < 0)
788 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
789 con
->http
.data_remaining
= length
;
791 if (con
->http
.data_remaining
<= INT_MAX
)
792 con
->http
._data_remaining
= con
->http
.data_remaining
;
794 con
->http
._data_remaining
= INT_MAX
;
797 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
798 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
801 * Tell the caller the response header was sent successfully...
809 * Tell the caller the response header could not be sent...
818 * Sending data from a subprocess like cups-deviced; tell the caller
819 * everything is A-OK so far...
828 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
831 int /* O - 0 on success, -1 on error */
832 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
834 cupsd_printer_t
*printer
; /* Destination printer or class */
835 ipp_attribute_t
*attr
; /* job-sheets attribute */
836 int kbytes
; /* Kilobytes in banner */
839 job
->pending_timeout
= 0;
842 * See if we need to add the ending sheet...
845 printer
= cupsdFindDest(job
->dest
);
846 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
849 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
850 attr
&& attr
->num_values
> 1)
856 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
857 attr
->values
[1].string
.text
);
859 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
862 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
870 * 'accept_jobs()' - Accept print jobs to a printer.
874 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
875 ipp_attribute_t
*uri
) /* I - Printer or class URI */
877 http_status_t status
; /* Policy status */
878 cups_ptype_t dtype
; /* Destination type (printer/class) */
879 cupsd_printer_t
*printer
; /* Printer data */
882 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
883 con
->http
.fd
, uri
->values
[0].string
.text
);
886 * Is the destination valid?
889 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
895 send_ipp_status(con
, IPP_NOT_FOUND
,
896 _("The printer or class was not found."));
904 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
906 send_http_error(con
, status
, printer
);
911 * Accept jobs sent to the printer...
914 printer
->accepting
= 1;
915 printer
->state_message
[0] = '\0';
917 cupsdAddPrinterHistory(printer
);
919 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
920 "Now accepting jobs.");
922 if (dtype
& CUPS_PRINTER_CLASS
)
924 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
926 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
927 printer
->name
, get_username(con
));
931 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
933 cupsdLogMessage(CUPSD_LOG_INFO
,
934 "Printer \"%s\" now accepting jobs (\"%s\").",
935 printer
->name
, get_username(con
));
939 * Everything was ok, so return OK status...
942 con
->response
->request
.status
.status_code
= IPP_OK
;
947 * 'add_class()' - Add a class to the system.
951 add_class(cupsd_client_t
*con
, /* I - Client connection */
952 ipp_attribute_t
*uri
) /* I - URI of class */
954 http_status_t status
; /* Policy status */
955 int i
; /* Looping var */
956 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
957 username
[HTTP_MAX_URI
], /* Username portion of URI */
958 host
[HTTP_MAX_URI
], /* Host portion of URI */
959 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
960 int port
; /* Port portion of URI */
961 cupsd_printer_t
*pclass
, /* Class */
962 *member
; /* Member printer/class */
963 cups_ptype_t dtype
; /* Destination type */
964 ipp_attribute_t
*attr
; /* Printer attribute */
965 int modify
; /* Non-zero if we just modified */
966 char newname
[IPP_MAX_NAME
]; /* New class name */
967 int need_restart_job
; /* Need to restart job? */
970 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
971 con
->http
.fd
, uri
->values
[0].string
.text
);
974 * Do we have a valid URI?
977 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
978 sizeof(scheme
), username
, sizeof(username
), host
,
979 sizeof(host
), &port
, resource
, sizeof(resource
));
982 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
985 * No, return an error...
988 send_ipp_status(con
, IPP_BAD_REQUEST
,
989 _("The printer-uri must be of the form "
990 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
995 * Do we have a valid printer name?
998 if (!validate_name(resource
+ 9))
1001 * No, return an error...
1004 send_ipp_status(con
, IPP_BAD_REQUEST
,
1005 _("The printer-uri \"%s\" contains invalid characters."),
1006 uri
->values
[0].string
.text
);
1011 * See if the class already exists; if not, create a new class...
1014 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1017 * Class doesn't exist; see if we have a printer of the same name...
1020 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
1021 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
1024 * Yes, return an error...
1027 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1028 _("A printer named \"%s\" already exists"),
1034 * No, check the default policy and then add the class...
1037 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1039 send_http_error(con
, status
, NULL
);
1043 pclass
= cupsdAddClass(resource
+ 9);
1046 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1049 * Check the default policy, then rename the implicit class to "AnyClass"
1053 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1055 send_http_error(con
, status
, NULL
);
1059 if (ImplicitAnyClasses
)
1061 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1062 cupsdRenamePrinter(pclass
, newname
);
1065 cupsdDeletePrinter(pclass
, 1);
1068 * Add the class as a new local class...
1071 pclass
= cupsdAddClass(resource
+ 9);
1074 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1077 * Check the default policy, then rename the remote class to "Class"...
1080 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1082 send_http_error(con
, status
, NULL
);
1086 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1087 cupsdRenamePrinter(pclass
, newname
);
1090 * Add the class as a new local class...
1093 pclass
= cupsdAddClass(resource
+ 9);
1096 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1099 send_http_error(con
, status
, pclass
);
1106 * Look for attributes and copy them over as needed...
1109 need_restart_job
= 0;
1111 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1112 IPP_TAG_TEXT
)) != NULL
)
1113 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1115 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1116 IPP_TAG_TEXT
)) != NULL
)
1117 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1119 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1120 IPP_TAG_BOOLEAN
)) != NULL
&&
1121 attr
->values
[0].boolean
!= pclass
->accepting
)
1123 cupsdLogMessage(CUPSD_LOG_INFO
,
1124 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1125 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1127 pclass
->accepting
= attr
->values
[0].boolean
;
1128 cupsdAddPrinterHistory(pclass
);
1130 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1131 pclass
->accepting
? "Now" : "No longer");
1134 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1135 IPP_TAG_BOOLEAN
)) != NULL
)
1137 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1138 cupsdDeregisterPrinter(pclass
, 1);
1140 cupsdLogMessage(CUPSD_LOG_INFO
,
1141 "Setting %s printer-is-shared to %d (was %d.)",
1142 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1144 pclass
->shared
= attr
->values
[0].boolean
;
1147 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1148 IPP_TAG_ENUM
)) != NULL
)
1150 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1151 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1153 send_ipp_status(con
, IPP_BAD_REQUEST
,
1154 _("Attempt to set %s printer-state to bad value %d"),
1155 pclass
->name
, attr
->values
[0].integer
);
1159 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1160 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1162 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1163 cupsdStopPrinter(pclass
, 0);
1166 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1167 need_restart_job
= 1;
1170 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1171 IPP_TAG_TEXT
)) != NULL
)
1173 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1174 sizeof(pclass
->state_message
));
1175 cupsdAddPrinterHistory(pclass
);
1177 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1178 pclass
->state_message
);
1180 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1181 IPP_TAG_URI
)) != NULL
)
1184 * Clear the printer array as needed...
1187 need_restart_job
= 1;
1189 if (pclass
->num_printers
> 0)
1191 free(pclass
->printers
);
1192 pclass
->num_printers
= 0;
1196 * Add each printer or class that is listed...
1199 for (i
= 0; i
< attr
->num_values
; i
++)
1202 * Search for the printer or class URI...
1205 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1211 send_ipp_status(con
, IPP_NOT_FOUND
,
1212 _("The printer or class was not found."));
1215 else if (dtype
& CUPS_PRINTER_CLASS
)
1217 send_ipp_status(con
, IPP_BAD_REQUEST
,
1218 _("Nested classes are not allowed"));
1223 * Add it to the class...
1226 cupsdAddPrinterToClass(pclass
, member
);
1230 set_printer_defaults(con
, pclass
);
1232 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1233 IPP_TAG_KEYWORD
)) != NULL
)
1234 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1237 * Update the printer class attributes and return...
1240 cupsdSetPrinterAttrs(pclass
);
1241 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1243 if (need_restart_job
&& pclass
->job
)
1246 * Reset the current job to a "pending" status...
1249 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1250 "Job restarted because the class was modified.");
1253 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1257 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
| CUPSD_EVENT_PRINTER_CONFIG
,
1258 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1259 pclass
->name
, get_username(con
));
1261 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1262 pclass
->name
, get_username(con
));
1266 cupsdAddPrinterHistory(pclass
);
1268 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
| CUPSD_EVENT_PRINTER_CONFIG
,
1269 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1270 pclass
->name
, get_username(con
));
1272 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1273 pclass
->name
, get_username(con
));
1276 con
->response
->request
.status
.status_code
= IPP_OK
;
1281 * 'add_file()' - Add a file to a job.
1284 static int /* O - 0 on success, -1 on error */
1285 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1286 cupsd_job_t
*job
, /* I - Job to add to */
1287 mime_type_t
*filetype
, /* I - Type of file */
1288 int compression
) /* I - Compression */
1290 mime_type_t
**filetypes
; /* New filetypes array... */
1291 int *compressions
; /* New compressions array... */
1294 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1295 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1296 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1297 filetype
->super
, filetype
->type
, compression
);
1300 * Add the file to the job...
1303 if (job
->num_files
== 0)
1305 compressions
= (int *)malloc(sizeof(int));
1306 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1310 compressions
= (int *)realloc(job
->compressions
,
1311 (job
->num_files
+ 1) * sizeof(int));
1312 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1313 (job
->num_files
+ 1) *
1314 sizeof(mime_type_t
*));
1317 if (!compressions
|| !filetypes
)
1319 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1320 "Job aborted because the scheduler ran out of memory.");
1323 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1324 _("Unable to allocate memory for file types"));
1329 job
->compressions
= compressions
;
1330 job
->compressions
[job
->num_files
] = compression
;
1331 job
->filetypes
= filetypes
;
1332 job
->filetypes
[job
->num_files
] = filetype
;
1337 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1344 * 'add_job()' - Add a job to a print queue.
1347 static cupsd_job_t
* /* O - Job object */
1348 add_job(cupsd_client_t
*con
, /* I - Client connection */
1349 cupsd_printer_t
*printer
, /* I - Destination printer */
1350 mime_type_t
*filetype
) /* I - First print file type, if any */
1352 http_status_t status
; /* Policy status */
1353 ipp_attribute_t
*attr
, /* Current attribute */
1354 *auth_info
; /* auth-info attribute */
1355 const char *val
; /* Default option value */
1356 int priority
; /* Job priority */
1357 cupsd_job_t
*job
; /* Current job */
1358 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1359 int kbytes
; /* Size of print file */
1360 int i
; /* Looping var */
1361 int lowerpagerange
; /* Page range bound */
1362 const char *ppd
; /* PPD keyword for media selection */
1363 int exact
; /* Did we have an exact match? */
1364 ipp_attribute_t
*media_col
, /* media-col attribute */
1365 *media_margin
; /* media-*-margin attribute */
1366 ipp_t
*unsup_col
; /* media-col in unsupported response */
1369 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1370 con
, con
->http
.fd
, printer
, printer
->name
,
1371 filetype
, filetype
? filetype
->super
: "none",
1372 filetype
? filetype
->type
: "none");
1375 * Check remote printing to non-shared printer...
1378 if (!printer
->shared
&&
1379 strcasecmp(con
->http
.hostname
, "localhost") &&
1380 strcasecmp(con
->http
.hostname
, ServerName
))
1382 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1383 _("The printer or class is not shared"));
1391 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1393 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1395 send_http_error(con
, status
, printer
);
1398 else if (printer
->num_auth_info_required
== 1 &&
1399 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1402 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1406 else if (auth_info
&& !con
->http
.tls
&&
1407 !httpAddrLocalhost(con
->http
.hostaddr
))
1410 * Require encryption of auth-info over non-local connections...
1413 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1416 #endif /* HAVE_SSL */
1419 * See if the printer is accepting jobs...
1422 if (!printer
->accepting
)
1424 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1425 _("Destination \"%s\" is not accepting jobs."),
1431 * Validate job template attributes; for now just document-format,
1432 * copies, number-up, and page-ranges...
1435 if (filetype
&& printer
->filetypes
&&
1436 !cupsArrayFind(printer
->filetypes
, filetype
))
1438 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1439 /* MIME media type string */
1442 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1445 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1446 _("Unsupported format \'%s\'"), mimetype
);
1448 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1449 "document-format", NULL
, mimetype
);
1454 if ((attr
= ippFindAttribute(con
->request
, "copies",
1455 IPP_TAG_INTEGER
)) != NULL
)
1457 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1459 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1460 attr
->values
[0].integer
);
1461 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1462 "copies", attr
->values
[0].integer
);
1467 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1468 IPP_TAG_ZERO
)) != NULL
)
1470 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1471 attr
->value_tag
!= IPP_TAG_NAME
)
1473 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type"));
1477 if (attr
->num_values
> 2)
1479 send_ipp_status(con
, IPP_BAD_REQUEST
,
1480 _("Too many job-sheets values (%d > 2)"),
1485 for (i
= 0; i
< attr
->num_values
; i
++)
1486 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1487 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1489 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\""),
1490 attr
->values
[i
].string
.text
);
1495 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1496 IPP_TAG_INTEGER
)) != NULL
)
1498 if (attr
->values
[0].integer
!= 1 &&
1499 attr
->values
[0].integer
!= 2 &&
1500 attr
->values
[0].integer
!= 4 &&
1501 attr
->values
[0].integer
!= 6 &&
1502 attr
->values
[0].integer
!= 9 &&
1503 attr
->values
[0].integer
!= 16)
1505 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1506 attr
->values
[0].integer
);
1507 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1508 "number-up", attr
->values
[0].integer
);
1513 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1514 IPP_TAG_RANGE
)) != NULL
)
1516 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1518 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1519 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1521 send_ipp_status(con
, IPP_BAD_REQUEST
,
1522 _("Bad page-ranges values %d-%d."),
1523 attr
->values
[i
].range
.lower
,
1524 attr
->values
[i
].range
.upper
);
1528 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1533 * Do media selection as needed...
1536 if (!ippFindAttribute(con
->request
, "InputSlot", IPP_TAG_ZERO
) &&
1537 (ppd
= _pwgGetInputSlot(printer
->pwg
, con
->request
, NULL
)) != NULL
)
1538 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "InputSlot", NULL
,
1541 if (!ippFindAttribute(con
->request
, "MediaType", IPP_TAG_ZERO
) &&
1542 (ppd
= _pwgGetMediaType(printer
->pwg
, con
->request
, NULL
)) != NULL
)
1543 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "MediaType", NULL
,
1546 if (!ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1547 (ppd
= _pwgGetPageSize(printer
->pwg
, con
->request
, NULL
, &exact
)) != NULL
)
1549 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "PageSize", NULL
,
1553 (media_col
= ippFindAttribute(con
->request
, "media-col",
1554 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1556 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1558 unsup_col
= ippNew();
1559 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1560 "media-bottom-margin",
1561 IPP_TAG_INTEGER
)) != NULL
)
1562 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1563 "media-bottom-margin", media_margin
->values
[0].integer
);
1565 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1566 "media-left-margin",
1567 IPP_TAG_INTEGER
)) != NULL
)
1568 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1569 "media-left-margin", media_margin
->values
[0].integer
);
1571 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1572 "media-right-margin",
1573 IPP_TAG_INTEGER
)) != NULL
)
1574 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1575 "media-right-margin", media_margin
->values
[0].integer
);
1577 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1579 IPP_TAG_INTEGER
)) != NULL
)
1580 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1581 "media-top-margin", media_margin
->values
[0].integer
);
1583 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1585 ippDelete(unsup_col
);
1590 * Make sure we aren't over our limit...
1593 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1596 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1598 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1599 _("Too many active jobs."));
1603 if ((i
= check_quotas(con
, printer
)) < 0)
1605 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1610 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1615 * Create the job and set things up...
1618 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1619 IPP_TAG_INTEGER
)) != NULL
)
1620 priority
= attr
->values
[0].integer
;
1623 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1624 printer
->options
)) != NULL
)
1625 priority
= atoi(val
);
1629 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1633 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1634 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1637 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1639 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1640 _("Unable to add job for destination \"%s\""),
1645 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1646 CUPS_PRINTER_REMOTE
);
1647 job
->attrs
= con
->request
;
1649 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1651 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1653 add_job_uuid(con
, job
);
1654 apply_printer_defaults(printer
, job
);
1656 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1658 if (con
->username
[0])
1660 cupsdSetString(&job
->username
, con
->username
);
1663 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1667 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1668 "add_job: requesting-user-name=\"%s\"",
1669 attr
->values
[0].string
.text
);
1671 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1674 cupsdSetString(&job
->username
, "anonymous");
1677 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1678 "job-originating-user-name", NULL
, job
->username
);
1681 attr
->group_tag
= IPP_TAG_JOB
;
1682 _cupsStrFree(attr
->name
);
1683 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1686 if (con
->username
[0] || auth_info
)
1688 save_auth_info(con
, job
, auth_info
);
1691 * Remove the auth-info attribute from the attribute data...
1695 ippDeleteAttribute(job
->attrs
, auth_info
);
1698 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1699 IPP_TAG_ZERO
)) != NULL
)
1702 * Request contains a job-originating-host-name attribute; validate it...
1705 if (attr
->value_tag
!= IPP_TAG_NAME
||
1706 attr
->num_values
!= 1 ||
1707 strcmp(con
->http
.hostname
, "localhost"))
1710 * Can't override the value if we aren't connected via localhost.
1711 * Also, we can only have 1 value and it must be a name value.
1714 switch (attr
->value_tag
)
1716 case IPP_TAG_STRING
:
1717 case IPP_TAG_TEXTLANG
:
1718 case IPP_TAG_NAMELANG
:
1721 case IPP_TAG_KEYWORD
:
1723 case IPP_TAG_URISCHEME
:
1724 case IPP_TAG_CHARSET
:
1725 case IPP_TAG_LANGUAGE
:
1726 case IPP_TAG_MIMETYPE
:
1728 * Free old strings...
1731 for (i
= 0; i
< attr
->num_values
; i
++)
1733 _cupsStrFree(attr
->values
[i
].string
.text
);
1734 attr
->values
[i
].string
.text
= NULL
;
1735 if (attr
->values
[i
].string
.charset
)
1737 _cupsStrFree(attr
->values
[i
].string
.charset
);
1738 attr
->values
[i
].string
.charset
= NULL
;
1747 * Use the default connection hostname instead...
1750 attr
->value_tag
= IPP_TAG_NAME
;
1751 attr
->num_values
= 1;
1752 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1755 attr
->group_tag
= IPP_TAG_JOB
;
1760 * No job-originating-host-name attribute, so use the hostname from
1764 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1765 "job-originating-host-name", NULL
, con
->http
.hostname
);
1768 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1770 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1771 "time-at-processing", 0);
1772 attr
->value_tag
= IPP_TAG_NOVALUE
;
1773 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1774 "time-at-completed", 0);
1775 attr
->value_tag
= IPP_TAG_NOVALUE
;
1778 * Add remaining job attributes...
1781 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1782 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1783 "job-state", IPP_JOB_STOPPED
);
1784 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1785 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1786 "job-media-sheets-completed", 0);
1787 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1790 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1791 IPP_TAG_INTEGER
)) != NULL
)
1792 attr
->values
[0].integer
= 0;
1794 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1796 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1797 IPP_TAG_KEYWORD
)) == NULL
)
1798 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1801 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1802 printer
->options
)) == NULL
)
1805 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1806 "job-hold-until", NULL
, val
);
1808 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1811 * Hold job until specified time...
1814 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1816 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1817 job
->state_value
= IPP_JOB_HELD
;
1819 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1821 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1822 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1823 job
->state_value
= IPP_JOB_HELD
;
1827 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1828 job
->state_value
= IPP_JOB_PENDING
;
1831 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1835 * Add job sheets options...
1838 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1839 IPP_TAG_ZERO
)) == NULL
)
1841 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1842 "Adding default job-sheets values \"%s,%s\"...",
1843 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1845 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1847 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1848 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1851 job
->job_sheets
= attr
;
1854 * Enforce classification level if set...
1859 cupsdLogMessage(CUPSD_LOG_INFO
,
1860 "Classification=\"%s\", ClassifyOverride=%d",
1861 Classification
? Classification
: "(null)",
1864 if (ClassifyOverride
)
1866 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1867 (attr
->num_values
== 1 ||
1868 !strcmp(attr
->values
[1].string
.text
, "none")))
1871 * Force the leading banner to have the classification on it...
1874 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1876 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1877 "job-sheets=\"%s,none\", "
1878 "job-originating-user-name=\"%s\"",
1879 Classification
, job
->username
);
1881 else if (attr
->num_values
== 2 &&
1882 strcmp(attr
->values
[0].string
.text
,
1883 attr
->values
[1].string
.text
) &&
1884 strcmp(attr
->values
[0].string
.text
, "none") &&
1885 strcmp(attr
->values
[1].string
.text
, "none"))
1888 * Can't put two different security markings on the same document!
1891 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1893 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1894 "job-sheets=\"%s,%s\", "
1895 "job-originating-user-name=\"%s\"",
1896 attr
->values
[0].string
.text
,
1897 attr
->values
[1].string
.text
, job
->username
);
1899 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1900 strcmp(attr
->values
[0].string
.text
, "none") &&
1901 (attr
->num_values
== 1 ||
1902 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1903 strcmp(attr
->values
[1].string
.text
, "none"))))
1905 if (attr
->num_values
== 1)
1906 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1907 "CLASSIFICATION OVERRIDDEN "
1908 "job-sheets=\"%s\", "
1909 "job-originating-user-name=\"%s\"",
1910 attr
->values
[0].string
.text
, job
->username
);
1912 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1913 "CLASSIFICATION OVERRIDDEN "
1914 "job-sheets=\"%s,%s\",fffff "
1915 "job-originating-user-name=\"%s\"",
1916 attr
->values
[0].string
.text
,
1917 attr
->values
[1].string
.text
, job
->username
);
1920 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1921 (attr
->num_values
== 1 ||
1922 strcmp(attr
->values
[1].string
.text
, Classification
)))
1925 * Force the banner to have the classification on it...
1928 if (attr
->num_values
> 1 &&
1929 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1931 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1932 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1936 if (attr
->num_values
== 1 ||
1937 strcmp(attr
->values
[0].string
.text
, "none"))
1938 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1940 if (attr
->num_values
> 1 &&
1941 strcmp(attr
->values
[1].string
.text
, "none"))
1942 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1945 if (attr
->num_values
> 1)
1946 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1947 "CLASSIFICATION FORCED "
1948 "job-sheets=\"%s,%s\", "
1949 "job-originating-user-name=\"%s\"",
1950 attr
->values
[0].string
.text
,
1951 attr
->values
[1].string
.text
, job
->username
);
1953 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1954 "CLASSIFICATION FORCED "
1955 "job-sheets=\"%s\", "
1956 "job-originating-user-name=\"%s\"",
1957 Classification
, job
->username
);
1962 * See if we need to add the starting sheet...
1965 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1967 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1968 attr
->values
[0].string
.text
);
1970 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1972 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1973 "Aborting job because the start banner could not be "
1978 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1981 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1982 IPP_TAG_ZERO
)) != NULL
)
1986 * Fill in the response info...
1989 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1990 LocalPort
, job
->id
);
1992 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1995 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1997 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1999 add_job_state_reasons(con
, job
);
2001 con
->response
->request
.status
.status_code
= IPP_OK
;
2004 * Add any job subscriptions...
2007 add_job_subscriptions(con
, job
);
2010 * Set all but the first two attributes to the job attributes group...
2013 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
2014 attr
->group_tag
= IPP_TAG_JOB
;
2017 * Fire the "job created" event...
2020 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
2023 * Return the new job...
2031 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
2032 * upon the job and printer state...
2036 add_job_state_reasons(
2037 cupsd_client_t
*con
, /* I - Client connection */
2038 cupsd_job_t
*job
) /* I - Job info */
2040 cupsd_printer_t
*dest
; /* Destination printer */
2043 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
2044 con
, con
->http
.fd
, job
? job
->id
: 0);
2046 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
2048 case IPP_JOB_PENDING
:
2049 dest
= cupsdFindDest(job
->dest
);
2051 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
2052 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2053 "job-state-reasons", NULL
, "printer-stopped");
2055 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2056 "job-state-reasons", NULL
, "none");
2060 if (ippFindAttribute(job
->attrs
, "job-hold-until",
2061 IPP_TAG_KEYWORD
) != NULL
||
2062 ippFindAttribute(job
->attrs
, "job-hold-until",
2063 IPP_TAG_NAME
) != NULL
)
2064 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2065 "job-state-reasons", NULL
, "job-hold-until-specified");
2067 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2068 "job-state-reasons", NULL
, "job-incoming");
2071 case IPP_JOB_PROCESSING
:
2072 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2073 "job-state-reasons", NULL
, "job-printing");
2076 case IPP_JOB_STOPPED
:
2077 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2078 "job-state-reasons", NULL
, "job-stopped");
2081 case IPP_JOB_CANCELED
:
2082 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2083 "job-state-reasons", NULL
, "job-canceled-by-user");
2086 case IPP_JOB_ABORTED
:
2087 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2088 "job-state-reasons", NULL
, "aborted-by-system");
2091 case IPP_JOB_COMPLETED
:
2092 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2093 "job-state-reasons", NULL
, "job-completed-successfully");
2100 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2104 add_job_subscriptions(
2105 cupsd_client_t
*con
, /* I - Client connection */
2106 cupsd_job_t
*job
) /* I - Newly created job */
2108 int i
; /* Looping var */
2109 ipp_attribute_t
*prev
, /* Previous attribute */
2110 *next
, /* Next attribute */
2111 *attr
; /* Current attribute */
2112 cupsd_subscription_t
*sub
; /* Subscription object */
2113 const char *recipient
, /* notify-recipient-uri */
2114 *pullmethod
; /* notify-pull-method */
2115 ipp_attribute_t
*user_data
; /* notify-user-data */
2116 int interval
; /* notify-time-interval */
2117 unsigned mask
; /* notify-events */
2121 * Find the first subscription group attribute; return if we have
2125 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2126 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2133 * Process the subscription attributes in the request...
2142 mask
= CUPSD_EVENT_NONE
;
2144 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2146 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2147 attr
->value_tag
== IPP_TAG_URI
)
2150 * Validate the recipient scheme against the ServerBin/notifier
2154 char notifier
[1024], /* Notifier filename */
2155 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2156 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2157 host
[HTTP_MAX_URI
], /* Host portion of URI */
2158 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2159 int port
; /* Port portion of URI */
2162 recipient
= attr
->values
[0].string
.text
;
2164 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2165 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2166 host
, sizeof(host
), &port
,
2167 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2169 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2170 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
2171 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2172 "notify-status-code", IPP_URI_SCHEME
);
2176 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2178 if (access(notifier
, X_OK
))
2180 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2181 _("notify-recipient-uri URI \"%s\" uses unknown "
2182 "scheme"), recipient
);
2183 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2184 "notify-status-code", IPP_URI_SCHEME
);
2188 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2190 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2191 _("notify-recipient-uri URI \"%s\" is already used"),
2193 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2194 "notify-status-code", IPP_ATTRIBUTES
);
2198 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2199 attr
->value_tag
== IPP_TAG_KEYWORD
)
2201 pullmethod
= attr
->values
[0].string
.text
;
2203 if (strcmp(pullmethod
, "ippget"))
2205 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2206 _("Bad notify-pull-method \"%s\""), pullmethod
);
2207 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2208 "notify-status-code", IPP_ATTRIBUTES
);
2212 else if (!strcmp(attr
->name
, "notify-charset") &&
2213 attr
->value_tag
== IPP_TAG_CHARSET
&&
2214 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2215 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2217 send_ipp_status(con
, IPP_CHARSET
,
2218 _("Character set \"%s\" not supported"),
2219 attr
->values
[0].string
.text
);
2222 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2223 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2224 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2226 send_ipp_status(con
, IPP_CHARSET
,
2227 _("Language \"%s\" not supported"),
2228 attr
->values
[0].string
.text
);
2231 else if (!strcmp(attr
->name
, "notify-user-data") &&
2232 attr
->value_tag
== IPP_TAG_STRING
)
2234 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2236 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2237 _("The notify-user-data value is too large "
2238 "(%d > 63 octets)"),
2239 attr
->values
[0].unknown
.length
);
2245 else if (!strcmp(attr
->name
, "notify-events") &&
2246 attr
->value_tag
== IPP_TAG_KEYWORD
)
2248 for (i
= 0; i
< attr
->num_values
; i
++)
2249 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2251 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2253 send_ipp_status(con
, IPP_BAD_REQUEST
,
2254 _("The notify-lease-duration attribute cannot be "
2255 "used with job subscriptions."));
2258 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2259 attr
->value_tag
== IPP_TAG_INTEGER
)
2260 interval
= attr
->values
[0].integer
;
2265 if (!recipient
&& !pullmethod
)
2268 if (mask
== CUPSD_EVENT_NONE
)
2269 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2271 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2272 recipient
, 0)) != NULL
)
2274 sub
->interval
= interval
;
2276 cupsdSetString(&sub
->owner
, job
->username
);
2280 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2281 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2282 sub
->user_data_len
);
2285 ippAddSeparator(con
->response
);
2286 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2287 "notify-subscription-id", sub
->id
);
2289 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2297 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2300 * Remove all of the subscription attributes from the job request...
2302 * TODO: Optimize this since subscription groups have to come at the
2303 * end of the request...
2306 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2310 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2311 attr
->group_tag
== IPP_TAG_ZERO
)
2314 * Free and remove this attribute...
2322 job
->attrs
->attrs
= next
;
2328 job
->attrs
->last
= prev
;
2329 job
->attrs
->current
= prev
;
2334 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2336 * See RFC 4122 for the definition of UUIDs and the format.
2340 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2341 cupsd_job_t
*job
) /* I - Job */
2343 char uuid
[1024]; /* job-uuid string */
2344 _cups_md5_state_t md5state
; /* MD5 state */
2345 unsigned char md5sum
[16]; /* MD5 digest/sum */
2349 * First see if the job already has a job-uuid attribute; if so, return...
2352 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2356 * No job-uuid attribute, so build a version 3 UUID with the local job
2357 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2358 * the ServerName, server name and port that the client connected to,
2359 * and local job ID...
2362 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2363 con
->serverport
, job
->id
);
2365 _cupsMD5Init(&md5state
);
2366 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2367 _cupsMD5Finish(&md5state
, md5sum
);
2370 * Format the UUID URI using the MD5 sum and job ID.
2373 snprintf(uuid
, sizeof(uuid
),
2374 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2375 "%02x%02x%02x%02x%02x%02x",
2376 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2377 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2378 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2379 md5sum
[14], md5sum
[15]);
2381 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2386 * 'add_printer()' - Add a printer to the system.
2390 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2391 ipp_attribute_t
*uri
) /* I - URI of printer */
2393 http_status_t status
; /* Policy status */
2394 int i
; /* Looping var */
2395 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2396 username
[HTTP_MAX_URI
], /* Username portion of URI */
2397 host
[HTTP_MAX_URI
], /* Host portion of URI */
2398 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2399 int port
; /* Port portion of URI */
2400 cupsd_printer_t
*printer
; /* Printer/class */
2401 ipp_attribute_t
*attr
; /* Printer attribute */
2402 cups_file_t
*fp
; /* Script/PPD file */
2403 char line
[1024]; /* Line from file... */
2404 char srcfile
[1024], /* Source Script/PPD file */
2405 dstfile
[1024]; /* Destination Script/PPD file */
2406 int modify
; /* Non-zero if we are modifying */
2407 char newname
[IPP_MAX_NAME
]; /* New printer name */
2408 int changed_driver
, /* Changed the PPD/interface script? */
2409 need_restart_job
, /* Need to restart job? */
2410 set_device_uri
, /* Did we set the device URI? */
2411 set_port_monitor
; /* Did we set the port monitor? */
2414 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2415 con
->http
.fd
, uri
->values
[0].string
.text
);
2418 * Do we have a valid URI?
2421 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2422 sizeof(scheme
), username
, sizeof(username
), host
,
2423 sizeof(host
), &port
, resource
, sizeof(resource
));
2425 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2428 * No, return an error...
2431 send_ipp_status(con
, IPP_BAD_REQUEST
,
2432 _("The printer-uri must be of the form "
2433 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2438 * Do we have a valid printer name?
2441 if (!validate_name(resource
+ 10))
2444 * No, return an error...
2447 send_ipp_status(con
, IPP_BAD_REQUEST
,
2448 _("The printer-uri \"%s\" contains invalid characters."),
2449 uri
->values
[0].string
.text
);
2454 * See if the printer already exists; if not, create a new printer...
2457 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2460 * Printer doesn't exist; see if we have a class of the same name...
2463 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2464 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2467 * Yes, return an error...
2470 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2471 _("A class named \"%s\" already exists"),
2477 * No, check the default policy then add the printer...
2480 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2482 send_http_error(con
, status
, NULL
);
2486 printer
= cupsdAddPrinter(resource
+ 10);
2489 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2492 * Check the default policy, then rename the implicit printer to
2493 * "AnyPrinter" or delete it...
2496 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2498 send_http_error(con
, status
, NULL
);
2502 if (ImplicitAnyClasses
)
2504 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2505 cupsdRenamePrinter(printer
, newname
);
2508 cupsdDeletePrinter(printer
, 1);
2511 * Add the printer as a new local printer...
2514 printer
= cupsdAddPrinter(resource
+ 10);
2517 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2520 * Check the default policy, then rename the remote printer to
2521 * "Printer@server"...
2524 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2526 send_http_error(con
, status
, NULL
);
2530 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2532 cupsdRenamePrinter(printer
, newname
);
2535 * Add the printer as a new local printer...
2538 printer
= cupsdAddPrinter(resource
+ 10);
2541 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2544 send_http_error(con
, status
, printer
);
2551 * Look for attributes and copy them over as needed...
2555 need_restart_job
= 0;
2557 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2558 IPP_TAG_TEXT
)) != NULL
)
2559 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2561 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2562 IPP_TAG_TEXT
)) != NULL
)
2563 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2567 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2568 IPP_TAG_URI
)) != NULL
)
2571 * Do we have a valid device URI?
2574 http_uri_status_t uri_status
; /* URI separation status */
2575 char old_device_uri
[1024];
2576 /* Old device URI */
2579 need_restart_job
= 1;
2581 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2582 attr
->values
[0].string
.text
,
2583 scheme
, sizeof(scheme
),
2584 username
, sizeof(username
),
2585 host
, sizeof(host
), &port
,
2586 resource
, sizeof(resource
));
2588 if (uri_status
< HTTP_URI_OK
)
2590 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\""),
2591 attr
->values
[0].string
.text
);
2592 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2593 "add_printer: httpSeparateURI returned %d", uri_status
);
2597 if (!strcmp(scheme
, "file"))
2600 * See if the administrator has enabled file devices...
2603 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2606 * File devices are disabled and the URL is not file:/dev/null...
2609 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2610 _("File device URIs have been disabled! "
2611 "To enable, see the FileDevice directive in "
2612 "\"%s/cupsd.conf\"."),
2620 * See if the backend exists and is executable...
2623 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2624 if (access(srcfile
, X_OK
))
2627 * Could not find device in list!
2630 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\""),
2636 if (printer
->sanitized_device_uri
)
2637 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2638 sizeof(old_device_uri
));
2640 old_device_uri
[0] = '\0';
2642 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2644 cupsdLogMessage(CUPSD_LOG_INFO
,
2645 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2646 printer
->name
, printer
->sanitized_device_uri
,
2652 set_port_monitor
= 0;
2654 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2655 IPP_TAG_NAME
)) != NULL
)
2657 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2660 need_restart_job
= 1;
2662 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2666 for (i
= 0; i
< supported
->num_values
; i
++)
2667 if (!strcmp(supported
->values
[i
].string
.text
,
2668 attr
->values
[0].string
.text
))
2672 if (!supported
|| i
>= supported
->num_values
)
2674 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\""),
2675 attr
->values
[0].string
.text
);
2679 cupsdLogMessage(CUPSD_LOG_INFO
,
2680 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2681 printer
->name
, attr
->values
[0].string
.text
,
2682 printer
->port_monitor
? printer
->port_monitor
: "none");
2684 if (strcmp(attr
->values
[0].string
.text
, "none"))
2685 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2687 cupsdClearString(&printer
->port_monitor
);
2689 set_port_monitor
= 1;
2692 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2693 IPP_TAG_BOOLEAN
)) != NULL
&&
2694 attr
->values
[0].boolean
!= printer
->accepting
)
2696 cupsdLogMessage(CUPSD_LOG_INFO
,
2697 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2698 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2700 printer
->accepting
= attr
->values
[0].boolean
;
2701 cupsdAddPrinterHistory(printer
);
2703 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2704 "%s accepting jobs.",
2705 printer
->accepting
? "Now" : "No longer");
2708 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2709 IPP_TAG_BOOLEAN
)) != NULL
)
2711 if (printer
->shared
&& !attr
->values
[0].boolean
)
2712 cupsdDeregisterPrinter(printer
, 1);
2714 cupsdLogMessage(CUPSD_LOG_INFO
,
2715 "Setting %s printer-is-shared to %d (was %d.)",
2716 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2718 printer
->shared
= attr
->values
[0].boolean
;
2721 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2722 IPP_TAG_ENUM
)) != NULL
)
2724 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2725 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2727 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d"),
2728 attr
->values
[0].integer
);
2732 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2733 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2735 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2736 cupsdStopPrinter(printer
, 0);
2739 need_restart_job
= 1;
2740 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2744 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2745 IPP_TAG_TEXT
)) != NULL
)
2747 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2748 sizeof(printer
->state_message
));
2749 cupsdAddPrinterHistory(printer
);
2751 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2752 printer
->state_message
);
2755 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2756 IPP_TAG_KEYWORD
)) != NULL
)
2758 if (attr
->num_values
>
2759 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2761 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2762 _("Too many printer-state-reasons values (%d > %d)"),
2764 (int)(sizeof(printer
->reasons
) /
2765 sizeof(printer
->reasons
[0])));
2769 for (i
= 0; i
< printer
->num_reasons
; i
++)
2770 _cupsStrFree(printer
->reasons
[i
]);
2772 printer
->num_reasons
= 0;
2773 for (i
= 0; i
< attr
->num_values
; i
++)
2775 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2778 printer
->reasons
[printer
->num_reasons
] =
2779 _cupsStrRetain(attr
->values
[i
].string
.text
);
2780 printer
->num_reasons
++;
2782 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2783 printer
->state
!= IPP_PRINTER_STOPPED
)
2785 cupsdLogMessage(CUPSD_LOG_INFO
,
2786 "Setting %s printer-state to %d (was %d.)",
2787 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2788 cupsdStopPrinter(printer
, 0);
2792 if (PrintcapFormat
== PRINTCAP_PLIST
)
2793 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2795 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2796 "Printer \"%s\" state changed.", printer
->name
);
2799 set_printer_defaults(con
, printer
);
2801 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2802 IPP_TAG_KEYWORD
)) != NULL
)
2803 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2806 * See if we have all required attributes...
2809 if (!printer
->device_uri
)
2810 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2813 * See if we have an interface script or PPD file attached to the request...
2818 need_restart_job
= 1;
2821 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2823 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2826 * Yes; get the first line from it...
2830 cupsFileGets(fp
, line
, sizeof(line
));
2834 * Then see what kind of file it is...
2837 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2840 if (!strncmp(line
, "*PPD-Adobe", 10))
2843 * The new file is a PPD file, so remove any old interface script
2844 * that might be lying around...
2852 * This must be an interface script, so move the file over to the
2853 * interfaces directory and make it executable...
2856 if (copy_file(srcfile
, dstfile
))
2858 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2859 _("Unable to copy interface script - %s"),
2864 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2865 "Copied interface script successfully");
2866 chmod(dstfile
, 0755);
2869 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2872 if (!strncmp(line
, "*PPD-Adobe", 10))
2875 * The new file is a PPD file, so move the file over to the
2876 * ppd directory and make it readable by all...
2879 if (copy_file(srcfile
, dstfile
))
2881 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2882 _("Unable to copy PPD file - %s"),
2887 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2888 "Copied PPD file successfully");
2889 chmod(dstfile
, 0644);
2894 * This must be an interface script, so remove any old PPD file that
2895 * may be lying around...
2902 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2903 IPP_TAG_NAME
)) != NULL
)
2905 need_restart_job
= 1;
2908 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2911 * Raw driver, remove any existing PPD or interface script files.
2914 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2918 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2928 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2932 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2935 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2937 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file"));
2941 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2942 "Copied PPD file successfully");
2943 chmod(dstfile
, 0644);
2950 * If we changed the PPD/interface script, then remove the printer's cache
2954 char cache_name
[1024]; /* Cache filename for printer attrs */
2956 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp2", CacheDir
,
2960 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.pwg", CacheDir
,
2966 * (Re)register color profiles...
2971 apple_unregister_profiles(printer
);
2972 apple_register_profiles(printer
);
2974 #endif /* __APPLE__ */
2978 * If we set the device URI but not the port monitor, check which port
2979 * monitor to use by default...
2982 if (set_device_uri
&& !set_port_monitor
)
2984 ppd_file_t
*ppd
; /* PPD file */
2985 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2988 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2989 sizeof(scheme
), username
, sizeof(username
), host
,
2990 sizeof(host
), &port
, resource
, sizeof(resource
));
2992 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2994 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2996 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2998 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2999 if (!strcmp(scheme
, ppdattr
->spec
))
3001 cupsdLogMessage(CUPSD_LOG_INFO
,
3002 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
3003 printer
->name
, ppdattr
->value
,
3004 printer
->port_monitor
? printer
->port_monitor
3007 if (strcmp(ppdattr
->value
, "none"))
3008 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
3010 cupsdClearString(&printer
->port_monitor
);
3020 * Update the printer attributes and return...
3023 cupsdSetPrinterAttrs(printer
);
3024 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3026 if (need_restart_job
&& printer
->job
)
3029 * Restart the current job...
3032 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
3033 "Job restarted because the printer was modified.");
3036 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3040 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
| CUPSD_EVENT_PRINTER_CONFIG
,
3041 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
3042 printer
->name
, get_username(con
));
3044 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
3045 printer
->name
, get_username(con
));
3049 cupsdAddPrinterHistory(printer
);
3051 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
| CUPSD_EVENT_PRINTER_CONFIG
,
3052 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
3053 printer
->name
, get_username(con
));
3055 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
3056 printer
->name
, get_username(con
));
3059 con
->response
->request
.status
.status_code
= IPP_OK
;
3064 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
3065 * based upon the printer state...
3069 add_printer_state_reasons(
3070 cupsd_client_t
*con
, /* I - Client connection */
3071 cupsd_printer_t
*p
) /* I - Printer info */
3073 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3074 "add_printer_state_reasons(%p[%d], %p[%s])",
3075 con
, con
->http
.fd
, p
, p
->name
);
3077 if (p
->num_reasons
== 0)
3078 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3079 "printer-state-reasons", NULL
, "none");
3081 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3082 "printer-state-reasons", p
->num_reasons
, NULL
,
3083 (const char * const *)p
->reasons
);
3088 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
3089 * the specified printer or class.
3093 add_queued_job_count(
3094 cupsd_client_t
*con
, /* I - Client connection */
3095 cupsd_printer_t
*p
) /* I - Printer or class */
3097 int count
; /* Number of jobs on destination */
3100 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3101 con
, con
->http
.fd
, p
, p
->name
);
3103 count
= cupsdGetPrinterJobCount(p
->name
);
3105 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3106 "queued-job-count", count
);
3112 * 'apple_init_profile()' - Initialize a color profile.
3117 ppd_file_t
*ppd
, /* I - PPD file */
3118 cups_array_t
*languages
, /* I - Languages in the PPD file */
3119 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3120 unsigned id
, /* I - Profile ID */
3121 const char *name
, /* I - Profile name */
3122 const char *text
, /* I - Profile UI text */
3123 const char *iccfile
) /* I - ICC filename */
3125 char url
[1024]; /* URL for profile filename */
3126 CFMutableDictionaryRef dict
; /* Dictionary for name */
3127 char *language
; /* Current language */
3128 ppd_attr_t
*attr
; /* Profile attribute */
3129 CFStringRef cflang
, /* Language string */
3130 cftext
; /* Localized text */
3134 * Build the profile name dictionary...
3137 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3138 &kCFTypeDictionaryKeyCallBacks
,
3139 &kCFTypeDictionaryValueCallBacks
);
3141 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3142 kCFStringEncodingUTF8
);
3146 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
3153 * Find localized names for the color profiles...
3156 cupsArraySave(ppd
->sorted_attrs
);
3158 for (language
= (char *)cupsArrayFirst(languages
);
3160 language
= (char *)cupsArrayNext(languages
))
3164 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3166 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3169 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3171 if (attr
&& attr
->text
[0])
3173 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3174 kCFStringEncodingUTF8
);
3175 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3176 kCFStringEncodingUTF8
);
3178 if (cflang
&& cftext
)
3179 CFDictionarySetValue(dict
, cflang
, cftext
);
3189 cupsArrayRestore(ppd
->sorted_attrs
);
3193 * Fill in the profile data...
3197 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3200 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3201 profile
->profileID
= id
;
3202 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3203 profile
->profileName
= dict
;
3206 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3207 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3212 * 'apple_register_profiles()' - Register color profiles for a printer.
3216 apple_register_profiles(
3217 cupsd_printer_t
*p
) /* I - Printer */
3219 int i
; /* Looping var */
3220 char ppdfile
[1024], /* PPD filename */
3221 iccfile
[1024], /* ICC filename */
3222 selector
[PPD_MAX_NAME
];
3223 /* Profile selection string */
3224 ppd_file_t
*ppd
; /* PPD file */
3225 ppd_attr_t
*attr
, /* Profile attributes */
3226 *profileid_attr
,/* cupsProfileID attribute */
3227 *q1_attr
, /* ColorModel (or other) qualifier */
3228 *q2_attr
, /* MediaType (or other) qualifier */
3229 *q3_attr
; /* Resolution (or other) qualifier */
3230 char q_keyword
[PPD_MAX_NAME
];
3231 /* Qualifier keyword */
3232 const char *q1_choice
, /* ColorModel (or other) choice */
3233 *q2_choice
, /* MediaType (or other) choice */
3234 *q3_choice
; /* Resolution (or other) choice */
3235 const char *profile_key
; /* Profile keyword */
3236 ppd_option_t
*cm_option
; /* Color model option */
3237 ppd_choice_t
*cm_choice
; /* Color model choice */
3238 int num_profiles
; /* Number of profiles */
3239 CMError error
; /* Last error */
3240 unsigned device_id
, /* Printer device ID */
3241 profile_id
, /* Profile ID */
3242 default_profile_id
= 0;
3243 /* Default profile ID */
3244 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3245 CFStringRef printer_name
; /* Printer name string */
3246 CMDeviceScope scope
= /* Scope of the registration */
3248 kCFPreferencesAnyUser
,
3249 kCFPreferencesCurrentHost
3251 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3252 CMDeviceProfileInfo
*profile
; /* Current profile */
3253 cups_array_t
*languages
; /* Languages array */
3257 * Make sure ColorSync is available...
3260 if (CMRegisterColorDevice
== NULL
)
3264 * Try opening the PPD file for this printer...
3267 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3268 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3272 * See if we have any profiles...
3275 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3276 profile_key
= "APTiogaProfile";
3279 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3280 profile_key
= "cupsICCProfile";
3283 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3284 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3286 if (attr
->value
[0] != '/')
3287 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3290 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3292 if (access(iccfile
, 0))
3300 * If we have profiles, add them...
3303 if (num_profiles
> 0)
3305 if (profile_key
[0] == 'A')
3308 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3312 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3314 default_profile_id
= atoi(attr
->value
);
3316 q1_choice
= q2_choice
= q3_choice
= NULL
;
3321 * For CUPS PPDs, figure out the default profile selector values...
3324 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3325 attr
->value
&& attr
->value
[0])
3327 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3328 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3330 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3331 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3333 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3334 q1_choice
= q1_attr
->value
;
3338 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3339 attr
->value
&& attr
->value
[0])
3341 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3342 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3345 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3347 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3348 q2_choice
= q2_attr
->value
;
3352 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3353 attr
->value
&& attr
->value
[0])
3355 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3356 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3359 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3361 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3362 q3_choice
= q3_attr
->value
;
3368 * Build the array of profiles...
3370 * Note: This calloc actually requests slightly more memory than needed.
3373 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3375 cupsdLogMessage(CUPSD_LOG_ERROR
,
3376 "Unable to allocate memory for %d profiles",
3382 profiles
->profileCount
= num_profiles
;
3383 languages
= _ppdGetLanguages(ppd
);
3385 for (profile
= profiles
->profiles
,
3386 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3388 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3389 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3392 * Add this profile...
3395 if (attr
->value
[0] != '/')
3396 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3399 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3401 if (access(iccfile
, 0))
3404 if (profile_key
[0] == 'c')
3406 cupsArraySave(ppd
->sorted_attrs
);
3408 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3409 attr
->spec
)) != NULL
&&
3410 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3411 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3413 profile_id
= _ppdHashName(attr
->spec
);
3415 cupsArrayRestore(ppd
->sorted_attrs
);
3418 profile_id
= atoi(attr
->spec
);
3420 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3421 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3426 * See if this is the default profile...
3429 if (!default_profile_id
)
3435 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3436 q1_choice
, q2_choice
, q3_choice
);
3437 if (!strcmp(selector
, attr
->spec
))
3438 default_profile_id
= profile_id
;
3441 if (!default_profile_id
)
3443 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3445 if (!strcmp(selector
, attr
->spec
))
3446 default_profile_id
= profile_id
;
3450 if (!default_profile_id
&& q3_choice
)
3452 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3454 if (!strcmp(selector
, attr
->spec
))
3455 default_profile_id
= profile_id
;
3458 if (!default_profile_id
)
3460 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3461 if (!strcmp(selector
, attr
->spec
))
3462 default_profile_id
= profile_id
;
3467 _ppdFreeLanguages(languages
);
3469 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3472 * Extract profiles from ColorModel option...
3475 const char *profile_name
; /* Name of generic profile */
3478 num_profiles
= cm_option
->num_choices
;
3480 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3482 cupsdLogMessage(CUPSD_LOG_ERROR
,
3483 "Unable to allocate memory for %d profiles",
3489 profiles
->profileCount
= num_profiles
;
3491 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3492 cm_choice
= cm_option
->choices
;
3494 i
--, cm_choice
++, profile
++)
3496 if (!strcmp(cm_choice
->choice
, "Gray") ||
3497 !strcmp(cm_choice
->choice
, "Black"))
3498 profile_name
= "Gray";
3499 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3500 !strcmp(cm_choice
->choice
, "CMY"))
3501 profile_name
= "RGB";
3502 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3503 !strcmp(cm_choice
->choice
, "KCMY"))
3504 profile_name
= "CMYK";
3506 profile_name
= "DeviceN";
3508 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3509 profile_id
= _ppdHashName(selector
);
3511 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3512 cm_choice
->text
, NULL
);
3514 if (cm_choice
->marked
)
3515 default_profile_id
= profile_id
;
3521 * Use the default colorspace...
3524 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3526 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3528 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3530 cupsdLogMessage(CUPSD_LOG_ERROR
,
3531 "Unable to allocate memory for %d profiles",
3537 profiles
->profileCount
= num_profiles
;
3539 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3540 "Gray", "Gray", NULL
);
3542 switch (ppd
->colorspace
)
3546 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3547 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3551 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3552 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3560 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3561 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3567 if (num_profiles
> 0)
3570 * Make sure we have a default profile ID...
3573 if (!default_profile_id
)
3574 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3577 * Get the device ID hash and pathelogical name dictionary.
3580 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3583 device_id
= _ppdHashName(p
->name
);
3584 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3585 &kCFTypeDictionaryKeyCallBacks
,
3586 &kCFTypeDictionaryValueCallBacks
);
3587 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3588 p
->name
, kCFStringEncodingUTF8
);
3590 if (device_name
&& printer_name
)
3592 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3595 * Register the device with ColorSync...
3598 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3599 device_name
, &scope
);
3602 * Register the profiles...
3606 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3607 default_profile_id
, profiles
);
3617 cupsdLogMessage(CUPSD_LOG_ERROR
,
3618 "Unable to register ICC color profiles for \"%s\" - %d",
3619 p
->name
, (int)error
);
3621 for (profile
= profiles
->profiles
;
3623 profile
++, num_profiles
--)
3624 CFRelease(profile
->profileName
);
3629 CFRelease(printer_name
);
3632 CFRelease(device_name
);
3640 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3645 apple_unregister_profiles(
3646 cupsd_printer_t
*p
) /* I - Printer */
3649 * Make sure ColorSync is available...
3652 if (CMUnregisterColorDevice
!= NULL
)
3653 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3655 #endif /* __APPLE__ */
3658 * 'apply_printer_defaults()' - Apply printer default options to a job.
3662 apply_printer_defaults(
3663 cupsd_printer_t
*printer
, /* I - Printer */
3664 cupsd_job_t
*job
) /* I - Job */
3666 int i
, /* Looping var */
3667 num_options
; /* Number of default options */
3668 cups_option_t
*options
, /* Default options */
3669 *option
; /* Current option */
3673 * Collect all of the default options and add the missing ones to the
3677 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3678 option
= printer
->options
;
3681 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3683 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3688 * Encode these options as attributes in the job object...
3691 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3692 cupsFreeOptions(num_options
, options
);
3697 * 'authenticate_job()' - Set job authentication info.
3701 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3702 ipp_attribute_t
*uri
) /* I - Job URI */
3704 ipp_attribute_t
*attr
, /* job-id attribute */
3705 *auth_info
; /* auth-info attribute */
3706 int jobid
; /* Job ID */
3707 cupsd_job_t
*job
; /* Current job */
3708 char scheme
[HTTP_MAX_URI
],
3709 /* Method portion of URI */
3710 username
[HTTP_MAX_URI
],
3711 /* Username portion of URI */
3713 /* Host portion of URI */
3714 resource
[HTTP_MAX_URI
];
3715 /* Resource portion of URI */
3716 int port
; /* Port portion of URI */
3719 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3720 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3723 * Start with "everything is OK" status...
3726 con
->response
->request
.status
.status_code
= IPP_OK
;
3729 * See if we have a job URI or a printer URI...
3732 if (!strcmp(uri
->name
, "printer-uri"))
3735 * Got a printer URI; see if we also have a job-id attribute...
3738 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3739 IPP_TAG_INTEGER
)) == NULL
)
3741 send_ipp_status(con
, IPP_BAD_REQUEST
,
3742 _("Got a printer-uri attribute but no job-id"));
3746 jobid
= attr
->values
[0].integer
;
3751 * Got a job URI; parse it to get the job ID...
3754 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3755 sizeof(scheme
), username
, sizeof(username
), host
,
3756 sizeof(host
), &port
, resource
, sizeof(resource
));
3758 if (strncmp(resource
, "/jobs/", 6))
3764 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\""),
3765 uri
->values
[0].string
.text
);
3769 jobid
= atoi(resource
+ 6);
3773 * See if the job exists...
3776 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3779 * Nope - return a "not found" error...
3782 send_ipp_status(con
, IPP_NOT_FOUND
,
3783 _("Job #%d does not exist"), jobid
);
3788 * See if the job has been completed...
3791 if (job
->state_value
!= IPP_JOB_HELD
)
3794 * Return a "not-possible" error...
3797 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3798 _("Job #%d is not held for authentication"),
3804 * See if we have already authenticated...
3807 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3809 if (!con
->username
[0] && !auth_info
)
3811 cupsd_printer_t
*printer
; /* Job destination */
3815 * No auth data. If we need to authenticate via Kerberos, send a
3816 * HTTP auth challenge, otherwise just return an IPP error...
3819 printer
= cupsdFindDest(job
->dest
);
3821 if (printer
&& printer
->num_auth_info_required
> 0 &&
3822 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3823 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3825 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3826 _("No authentication information provided"));
3831 * See if the job is owned by the requesting user...
3834 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3836 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3837 cupsdFindDest(job
->dest
));
3842 * Save the authentication information for this job...
3845 save_auth_info(con
, job
, auth_info
);
3848 * Reset the job-hold-until value to "no-hold"...
3851 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3852 IPP_TAG_KEYWORD
)) == NULL
)
3853 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3857 attr
->value_tag
= IPP_TAG_KEYWORD
;
3858 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3862 * Release the job and return...
3865 cupsdReleaseJob(job
);
3867 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3872 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3876 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3877 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3879 int i
; /* Looping var */
3880 http_status_t status
; /* Policy status */
3881 cups_ptype_t dtype
; /* Destination type */
3882 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3883 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3884 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3885 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3886 int port
; /* Port portion of URI */
3887 ipp_attribute_t
*attr
; /* Attribute in request */
3888 const char *username
= NULL
; /* Username */
3889 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3891 cupsd_printer_t
*printer
; /* Printer */
3892 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3893 cupsd_job_t
*job
; /* Job */
3896 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3897 con
->http
.fd
, uri
->values
[0].string
.text
);
3900 * Get the jobs to cancel/purge...
3903 switch (con
->request
->request
.op
.operation_id
)
3905 case IPP_PURGE_JOBS
:
3907 * Get the username (if any) for the jobs we want to cancel (only if
3908 * "my-jobs" is specified...
3911 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3912 IPP_TAG_BOOLEAN
)) != NULL
&&
3913 attr
->values
[0].boolean
)
3915 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3916 IPP_TAG_NAME
)) != NULL
)
3917 username
= attr
->values
[0].string
.text
;
3920 send_ipp_status(con
, IPP_BAD_REQUEST
,
3921 _("Missing requesting-user-name attribute"));
3927 * Look for the "purge-jobs" attribute...
3930 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3931 IPP_TAG_BOOLEAN
)) != NULL
)
3932 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3934 purge
= CUPSD_JOB_PURGE
;
3937 case IPP_CANCEL_MY_JOBS
:
3938 if (con
->username
[0])
3939 username
= con
->username
;
3940 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3941 IPP_TAG_NAME
)) != NULL
)
3942 username
= attr
->values
[0].string
.text
;
3945 send_ipp_status(con
, IPP_BAD_REQUEST
,
3946 _("Missing requesting-user-name attribute"));
3954 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3957 * See if we have a printer URI...
3960 if (strcmp(uri
->name
, "printer-uri"))
3962 send_ipp_status(con
, IPP_BAD_REQUEST
,
3963 _("The printer-uri attribute is required"));
3968 * And if the destination is valid...
3971 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3977 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3978 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3979 hostname
, sizeof(hostname
), &port
,
3980 resource
, sizeof(resource
));
3982 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3983 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3985 send_ipp_status(con
, IPP_NOT_FOUND
,
3986 _("The printer or class was not found."));
3994 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3996 send_http_error(con
, status
, NULL
);
4002 for (i
= 0; i
< job_ids
->num_values
; i
++)
4004 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
4008 if (i
< job_ids
->num_values
)
4010 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
4011 job_ids
->values
[i
].integer
);
4015 for (i
= 0; i
< job_ids
->num_values
; i
++)
4017 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4019 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4020 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4021 "Job canceled by user.");
4024 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4025 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4031 * Cancel all jobs on all printers...
4034 cupsdCancelJobs(NULL
, username
, purge
);
4036 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
4037 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4047 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4050 send_http_error(con
, status
, printer
);
4056 for (i
= 0; i
< job_ids
->num_values
; i
++)
4058 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
4059 strcasecmp(job
->dest
, printer
->name
))
4063 if (i
< job_ids
->num_values
)
4065 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
4066 job_ids
->values
[i
].integer
);
4070 for (i
= 0; i
< job_ids
->num_values
; i
++)
4072 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4074 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4075 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4076 "Job canceled by user.");
4079 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4080 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4086 * Cancel all of the jobs on the named printer...
4089 cupsdCancelJobs(printer
->name
, username
, purge
);
4091 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
4093 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4098 con
->response
->request
.status
.status_code
= IPP_OK
;
4103 * 'cancel_job()' - Cancel a print job.
4107 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
4108 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4110 ipp_attribute_t
*attr
; /* Current attribute */
4111 int jobid
; /* Job ID */
4112 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4113 username
[HTTP_MAX_URI
], /* Username portion of URI */
4114 host
[HTTP_MAX_URI
], /* Host portion of URI */
4115 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4116 int port
; /* Port portion of URI */
4117 cupsd_job_t
*job
; /* Job information */
4118 cups_ptype_t dtype
; /* Destination type (printer/class) */
4119 cupsd_printer_t
*printer
; /* Printer data */
4120 cupsd_jobaction_t purge
; /* Purge the job? */
4123 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
4124 con
->http
.fd
, uri
->values
[0].string
.text
);
4127 * See if we have a job URI or a printer URI...
4130 if (!strcmp(uri
->name
, "printer-uri"))
4133 * Got a printer URI; see if we also have a job-id attribute...
4136 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4137 IPP_TAG_INTEGER
)) == NULL
)
4139 send_ipp_status(con
, IPP_BAD_REQUEST
,
4140 _("Got a printer-uri attribute but no job-id"));
4144 if ((jobid
= attr
->values
[0].integer
) == 0)
4147 * Find the current job on the specified printer...
4150 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4156 send_ipp_status(con
, IPP_NOT_FOUND
,
4157 _("The printer or class was not found."));
4162 * See if there are any pending jobs...
4165 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4167 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4168 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
4169 !strcasecmp(job
->dest
, printer
->name
))
4177 * No, try stopped jobs...
4180 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4182 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4183 if (job
->state_value
== IPP_JOB_STOPPED
&&
4184 !strcasecmp(job
->dest
, printer
->name
))
4191 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s"),
4201 * Got a job URI; parse it to get the job ID...
4204 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4205 sizeof(scheme
), username
, sizeof(username
), host
,
4206 sizeof(host
), &port
, resource
, sizeof(resource
));
4208 if (strncmp(resource
, "/jobs/", 6))
4214 send_ipp_status(con
, IPP_BAD_REQUEST
,
4215 _("Bad job-uri attribute \"%s\""),
4216 uri
->values
[0].string
.text
);
4220 jobid
= atoi(resource
+ 6);
4224 * Look for the "purge-job" attribute...
4227 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4228 IPP_TAG_BOOLEAN
)) != NULL
)
4229 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4231 purge
= CUPSD_JOB_DEFAULT
;
4234 * See if the job exists...
4237 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4240 * Nope - return a "not found" error...
4243 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
4248 * See if the job is owned by the requesting user...
4251 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4253 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4254 cupsdFindDest(job
->dest
));
4259 * See if the job is already completed, canceled, or aborted; if so,
4260 * we can't cancel...
4263 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4265 switch (job
->state_value
)
4267 case IPP_JOB_CANCELED
:
4268 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4269 _("Job #%d is already canceled - can\'t cancel."),
4273 case IPP_JOB_ABORTED
:
4274 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4275 _("Job #%d is already aborted - can\'t cancel."),
4280 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4281 _("Job #%d is already completed - can\'t cancel."),
4290 * Cancel the job and return...
4293 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4294 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4295 "Job canceled by \"%s\"",
4299 if (purge
== CUPSD_JOB_PURGE
)
4300 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4303 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4306 con
->response
->request
.status
.status_code
= IPP_OK
;
4311 * 'cancel_subscription()' - Cancel a subscription.
4315 cancel_subscription(
4316 cupsd_client_t
*con
, /* I - Client connection */
4317 int sub_id
) /* I - Subscription ID */
4319 http_status_t status
; /* Policy status */
4320 cupsd_subscription_t
*sub
; /* Subscription */
4323 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4324 "cancel_subscription(con=%p[%d], sub_id=%d)",
4325 con
, con
->http
.fd
, sub_id
);
4328 * Is the subscription ID valid?
4331 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4334 * Bad subscription ID...
4337 send_ipp_status(con
, IPP_NOT_FOUND
,
4338 _("notify-subscription-id %d no good"), sub_id
);
4346 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4348 con
, sub
->owner
)) != HTTP_OK
)
4350 send_http_error(con
, status
, sub
->dest
);
4355 * Cancel the subscription...
4358 cupsdDeleteSubscription(sub
, 1);
4360 con
->response
->request
.status
.status_code
= IPP_OK
;
4365 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4368 static int /* O - 1 if OK, 0 if not */
4369 check_rss_recipient(
4370 const char *recipient
) /* I - Recipient URI */
4372 cupsd_subscription_t
*sub
; /* Current subscription */
4375 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4377 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4381 * Compare the URIs up to the first ?...
4384 const char *r1
, *r2
;
4386 for (r1
= recipient
, r2
= sub
->recipient
;
4387 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4399 * 'check_quotas()' - Check quotas for a printer and user.
4402 static int /* O - 1 if OK, 0 if not */
4403 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4404 cupsd_printer_t
*p
) /* I - Printer or class */
4406 int i
; /* Looping var */
4407 char username
[33]; /* Username */
4408 cupsd_quota_t
*q
; /* Quota data */
4409 #ifdef HAVE_MBR_UID_TO_UUID
4411 * Use Apple membership APIs which require that all names represent
4412 * valid user account or group records accessible by the server.
4415 uuid_t usr_uuid
; /* UUID for job requesting user */
4416 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4417 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4418 int mbr_err
; /* Error from membership function */
4419 int is_member
; /* Is this user a member? */
4422 * Use standard POSIX APIs for checking users and groups...
4425 struct passwd
*pw
; /* User password data */
4426 #endif /* HAVE_MBR_UID_TO_UUID */
4429 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4430 con
, con
->http
.fd
, p
, p
->name
);
4433 * Figure out who is printing...
4436 strlcpy(username
, get_username(con
), sizeof(username
));
4439 * Check global active job limits for printers and users...
4442 if (MaxJobsPerPrinter
)
4445 * Check if there are too many pending jobs on this printer...
4448 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4450 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4459 * Check if there are too many pending jobs for this user...
4462 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4464 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4471 * Check against users...
4474 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4479 #ifdef HAVE_MBR_UID_TO_UUID
4481 * Get UUID for job requesting user...
4484 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4490 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4491 "check_quotas: UUID lookup failed for user \"%s\"",
4493 cupsdLogMessage(CUPSD_LOG_INFO
,
4494 "Denying user \"%s\" access to printer \"%s\" "
4495 "(unknown user)...",
4501 * Get UID and GID of requesting user...
4504 pw
= getpwnam(username
);
4506 #endif /* HAVE_MBR_UID_TO_UUID */
4508 for (i
= 0; i
< p
->num_users
; i
++)
4509 if (p
->users
[i
][0] == '@')
4512 * Check group membership...
4515 #ifdef HAVE_MBR_UID_TO_UUID
4516 if (p
->users
[i
][1] == '#')
4518 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4519 uuid_clear(grp_uuid
);
4521 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4525 * Invalid ACL entries are ignored for matching; just record a
4526 * warning in the log...
4529 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4530 "check_quotas: UUID lookup failed for ACL entry "
4531 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4532 cupsdLogMessage(CUPSD_LOG_WARN
,
4533 "Access control entry \"%s\" not a valid group name; "
4534 "entry ignored", p
->users
[i
]);
4537 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4541 * At this point, there should be no errors, but check anyways...
4544 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4545 "check_quotas: group \"%s\" membership check "
4546 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4551 * Stop if we found a match...
4558 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4560 #endif /* HAVE_MBR_UID_TO_UUID */
4562 #ifdef HAVE_MBR_UID_TO_UUID
4565 if (p
->users
[i
][0] == '#')
4567 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4568 uuid_clear(usr2_uuid
);
4570 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4574 * Invalid ACL entries are ignored for matching; just record a
4575 * warning in the log...
4578 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4579 "check_quotas: UUID lookup failed for ACL entry "
4580 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4581 cupsdLogMessage(CUPSD_LOG_WARN
,
4582 "Access control entry \"%s\" not a valid user name; "
4583 "entry ignored", p
->users
[i
]);
4586 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4590 else if (!strcasecmp(username
, p
->users
[i
]))
4592 #endif /* HAVE_MBR_UID_TO_UUID */
4594 if ((i
< p
->num_users
) == p
->deny_users
)
4596 cupsdLogMessage(CUPSD_LOG_INFO
,
4597 "Denying user \"%s\" access to printer \"%s\"...",
4607 if (p
->k_limit
|| p
->page_limit
)
4609 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4611 cupsdLogMessage(CUPSD_LOG_ERROR
,
4612 "Unable to allocate quota data for user \"%s\"",
4617 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4618 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4620 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4627 * If we have gotten this far, we're done!
4635 * 'close_job()' - Close a multi-file job.
4639 close_job(cupsd_client_t
*con
, /* I - Client connection */
4640 ipp_attribute_t
*uri
) /* I - Printer URI */
4642 cupsd_job_t
*job
; /* Job */
4643 cupsd_printer_t
*printer
; /* Printer */
4644 ipp_attribute_t
*attr
; /* Attribute */
4645 char job_uri
[HTTP_MAX_URI
],
4647 username
[256]; /* User name */
4650 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4651 con
->http
.fd
, uri
->values
[0].string
.text
);
4654 * See if we have a job URI or a printer URI...
4657 if (strcmp(uri
->name
, "printer-uri"))
4660 * job-uri is not supported by Close-Job!
4663 send_ipp_status(con
, IPP_BAD_REQUEST
,
4664 _("Close-Job doesn't support the job-uri attribute."));
4669 * Got a printer URI; see if we also have a job-id attribute...
4672 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4673 IPP_TAG_INTEGER
)) == NULL
)
4675 send_ipp_status(con
, IPP_BAD_REQUEST
,
4676 _("Got a printer-uri attribute but no job-id"));
4680 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4683 * Nope - return a "not found" error...
4686 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
4687 attr
->values
[0].integer
);
4691 printer
= cupsdFindDest(job
->dest
);
4694 * See if the job is owned by the requesting user...
4697 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4699 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4700 cupsdFindDest(job
->dest
));
4705 * Add any ending sheet...
4708 if (cupsdTimeoutJob(job
))
4711 if (job
->state_value
== IPP_JOB_STOPPED
)
4713 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4714 job
->state_value
= IPP_JOB_PENDING
;
4716 else if (job
->state_value
== IPP_JOB_HELD
)
4718 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4719 IPP_TAG_KEYWORD
)) == NULL
)
4720 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4722 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
4724 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4725 job
->state_value
= IPP_JOB_PENDING
;
4730 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
4733 * Fill in the response info...
4736 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
4737 LocalPort
, job
->id
);
4738 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4741 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4743 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4746 add_job_state_reasons(con
, job
);
4748 con
->response
->request
.status
.status_code
= IPP_OK
;
4751 * Start the job if necessary...
4759 * 'copy_attribute()' - Copy a single attribute.
4762 static ipp_attribute_t
* /* O - New attribute */
4764 ipp_t
*to
, /* O - Destination request/response */
4765 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4766 int quickcopy
) /* I - Do a quick copy? */
4768 int i
; /* Looping var */
4769 ipp_attribute_t
*toattr
; /* Destination attribute */
4772 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4773 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4774 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4777 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4780 toattr
= ippAddSeparator(to
);
4783 case IPP_TAG_INTEGER
:
4785 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4786 attr
->name
, attr
->num_values
, NULL
);
4788 for (i
= 0; i
< attr
->num_values
; i
++)
4789 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4792 case IPP_TAG_BOOLEAN
:
4793 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4794 attr
->num_values
, NULL
);
4796 for (i
= 0; i
< attr
->num_values
; i
++)
4797 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4800 case IPP_TAG_STRING
:
4803 case IPP_TAG_KEYWORD
:
4805 case IPP_TAG_URISCHEME
:
4806 case IPP_TAG_CHARSET
:
4807 case IPP_TAG_LANGUAGE
:
4808 case IPP_TAG_MIMETYPE
:
4809 toattr
= ippAddStrings(to
, attr
->group_tag
,
4810 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4811 attr
->name
, attr
->num_values
, NULL
, NULL
);
4815 for (i
= 0; i
< attr
->num_values
; i
++)
4816 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4818 else if (attr
->value_tag
& IPP_TAG_COPY
)
4820 for (i
= 0; i
< attr
->num_values
; i
++)
4821 toattr
->values
[i
].string
.text
=
4822 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4826 for (i
= 0; i
< attr
->num_values
; i
++)
4827 toattr
->values
[i
].string
.text
=
4828 _cupsStrRetain(attr
->values
[i
].string
.text
);
4833 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4834 attr
->values
[0].date
);
4837 case IPP_TAG_RESOLUTION
:
4838 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4839 attr
->num_values
, IPP_RES_PER_INCH
,
4842 for (i
= 0; i
< attr
->num_values
; i
++)
4844 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4845 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4846 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4850 case IPP_TAG_RANGE
:
4851 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4852 attr
->num_values
, NULL
, NULL
);
4854 for (i
= 0; i
< attr
->num_values
; i
++)
4856 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4857 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4861 case IPP_TAG_TEXTLANG
:
4862 case IPP_TAG_NAMELANG
:
4863 toattr
= ippAddStrings(to
, attr
->group_tag
,
4864 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4865 attr
->name
, attr
->num_values
, NULL
, NULL
);
4869 for (i
= 0; i
< attr
->num_values
; i
++)
4871 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4872 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4875 else if (attr
->value_tag
& IPP_TAG_COPY
)
4877 for (i
= 0; i
< attr
->num_values
; i
++)
4880 toattr
->values
[i
].string
.charset
=
4881 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4883 toattr
->values
[i
].string
.charset
=
4884 toattr
->values
[0].string
.charset
;
4886 toattr
->values
[i
].string
.text
=
4887 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4892 for (i
= 0; i
< attr
->num_values
; i
++)
4895 toattr
->values
[i
].string
.charset
=
4896 _cupsStrRetain(attr
->values
[i
].string
.charset
);
4898 toattr
->values
[i
].string
.charset
=
4899 toattr
->values
[0].string
.charset
;
4901 toattr
->values
[i
].string
.text
=
4902 _cupsStrRetain(attr
->values
[i
].string
.text
);
4907 case IPP_TAG_BEGIN_COLLECTION
:
4908 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4909 attr
->num_values
, NULL
);
4911 for (i
= 0; i
< attr
->num_values
; i
++)
4913 toattr
->values
[i
].collection
= attr
->values
[i
].collection
;
4914 attr
->values
[i
].collection
->use
++;
4919 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4920 attr
->name
, attr
->num_values
, NULL
);
4922 for (i
= 0; i
< attr
->num_values
; i
++)
4924 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4926 if (toattr
->values
[i
].unknown
.length
> 0)
4928 if ((toattr
->values
[i
].unknown
.data
=
4929 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4930 toattr
->values
[i
].unknown
.length
= 0;
4932 memcpy(toattr
->values
[i
].unknown
.data
,
4933 attr
->values
[i
].unknown
.data
,
4934 toattr
->values
[i
].unknown
.length
);
4937 break; /* anti-compiler-warning-code */
4945 * 'copy_attrs()' - Copy attributes from one request to another.
4949 copy_attrs(ipp_t
*to
, /* I - Destination request */
4950 ipp_t
*from
, /* I - Source request */
4951 cups_array_t
*ra
, /* I - Requested attributes */
4952 ipp_tag_t group
, /* I - Group to copy */
4953 int quickcopy
) /* I - Do a quick copy? */
4955 ipp_attribute_t
*fromattr
; /* Source attribute */
4958 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4959 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4960 to
, from
, ra
, group
, quickcopy
);
4965 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4968 * Filter attributes as needed...
4971 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4972 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4975 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4978 * Don't send collection attributes by default to IPP/1.x clients
4979 * since many do not support collections. Also don't send
4980 * media-col-database unless specifically requested by the client.
4983 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4985 (to
->request
.status
.version
[0] == 1 ||
4986 !strcmp(fromattr
->name
, "media-col-database")))
4989 copy_attribute(to
, fromattr
, quickcopy
);
4996 * 'copy_banner()' - Copy a banner file to the requests directory for the
5000 static int /* O - Size of banner file in kbytes */
5001 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
5002 cupsd_job_t
*job
, /* I - Job information */
5003 const char *name
) /* I - Name of banner */
5005 int i
; /* Looping var */
5006 int kbytes
; /* Size of banner file in kbytes */
5007 char filename
[1024]; /* Job filename */
5008 cupsd_banner_t
*banner
; /* Pointer to banner */
5009 cups_file_t
*in
; /* Input file */
5010 cups_file_t
*out
; /* Output file */
5011 int ch
; /* Character from file */
5012 char attrname
[255], /* Name of attribute */
5013 *s
; /* Pointer into name */
5014 ipp_attribute_t
*attr
; /* Attribute */
5017 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5018 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
5019 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
5020 name
? name
: "(null)");
5023 * Find the banner; return if not found or "none"...
5026 if (!name
|| !strcmp(name
, "none") ||
5027 (banner
= cupsdFindBanner(name
)) == NULL
)
5031 * Open the banner and job files...
5034 if (add_file(con
, job
, banner
->filetype
, 0))
5037 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
5039 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
5041 cupsdLogMessage(CUPSD_LOG_ERROR
,
5042 "Unable to create banner job file %s - %s",
5043 filename
, strerror(errno
));
5048 fchmod(cupsFileNumber(out
), 0640);
5049 fchown(cupsFileNumber(out
), RunUser
, Group
);
5052 * Try the localized banner file under the subdirectory...
5055 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5057 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5060 * Convert ll-cc to ll_CC...
5064 attrname
[3] = toupper(attrname
[3] & 255);
5065 attrname
[4] = toupper(attrname
[4] & 255);
5068 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5071 if (access(filename
, 0) && strlen(attrname
) > 2)
5074 * Wasn't able to find "ll_CC" locale file; try the non-national
5075 * localization banner directory.
5080 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5084 if (access(filename
, 0))
5087 * Use the non-localized banner file.
5090 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5093 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5097 cupsdLogMessage(CUPSD_LOG_ERROR
,
5098 "Unable to open banner template file %s - %s",
5099 filename
, strerror(errno
));
5105 * Parse the file to the end...
5108 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5112 * Get an attribute name...
5115 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5116 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5118 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5128 * Ignore { followed by stuff that is not an attribute name...
5131 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5136 * See if it is defined...
5139 if (attrname
[0] == '?')
5144 if (!strcmp(s
, "printer-name"))
5146 cupsFilePuts(out
, job
->dest
);
5149 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5152 * See if we have a leading question mark...
5155 if (attrname
[0] != '?')
5158 * Nope, write to file as-is; probably a PostScript procedure...
5161 cupsFilePrintf(out
, "{%s}", attrname
);
5168 * Output value(s)...
5171 for (i
= 0; i
< attr
->num_values
; i
++)
5174 cupsFilePutChar(out
, ',');
5176 switch (attr
->value_tag
)
5178 case IPP_TAG_INTEGER
:
5180 if (!strncmp(s
, "time-at-", 8))
5182 struct timeval tv
= { attr
->values
[i
].integer
, 0 };
5183 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5186 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5189 case IPP_TAG_BOOLEAN
:
5190 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5193 case IPP_TAG_NOVALUE
:
5194 cupsFilePuts(out
, "novalue");
5197 case IPP_TAG_RANGE
:
5198 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5199 attr
->values
[i
].range
.upper
);
5202 case IPP_TAG_RESOLUTION
:
5203 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5204 attr
->values
[i
].resolution
.yres
,
5205 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5210 case IPP_TAG_STRING
:
5213 case IPP_TAG_KEYWORD
:
5214 case IPP_TAG_CHARSET
:
5215 case IPP_TAG_LANGUAGE
:
5216 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
5219 * Need to quote strings for PS banners...
5224 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5226 if (*p
== '(' || *p
== ')' || *p
== '\\')
5228 cupsFilePutChar(out
, '\\');
5229 cupsFilePutChar(out
, *p
);
5231 else if (*p
< 32 || *p
> 126)
5232 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5234 cupsFilePutChar(out
, *p
);
5238 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5242 break; /* anti-compiler-warning-code */
5246 else if (ch
== '\\') /* Quoted char */
5248 ch
= cupsFileGetChar(in
);
5250 if (ch
!= '{') /* Only do special handling for \{ */
5251 cupsFilePutChar(out
, '\\');
5253 cupsFilePutChar(out
, ch
);
5256 cupsFilePutChar(out
, ch
);
5260 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5262 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5263 IPP_TAG_INTEGER
)) != NULL
)
5264 attr
->values
[0].integer
+= kbytes
;
5273 * 'copy_file()' - Copy a PPD file or interface script...
5276 static int /* O - 0 = success, -1 = error */
5277 copy_file(const char *from
, /* I - Source file */
5278 const char *to
) /* I - Destination file */
5280 cups_file_t
*src
, /* Source file */
5281 *dst
; /* Destination file */
5282 int bytes
; /* Bytes to read/write */
5283 char buffer
[2048]; /* Copy buffer */
5286 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5289 * Open the source and destination file for a copy...
5292 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5295 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5302 * Copy the source file to the destination...
5305 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5306 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5314 * Close both files and return...
5319 return (cupsFileClose(dst
));
5324 * 'copy_model()' - Copy a PPD model file, substituting default values
5328 static int /* O - 0 = success, -1 = error */
5329 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5330 const char *from
, /* I - Source file */
5331 const char *to
) /* I - Destination file */
5333 fd_set input
; /* select() input set */
5334 struct timeval timeout
; /* select() timeout */
5335 int maxfd
; /* Max file descriptor for select() */
5336 char tempfile
[1024]; /* Temporary PPD file */
5337 int tempfd
; /* Temporary PPD file descriptor */
5338 int temppid
; /* Process ID of cups-driverd */
5339 int temppipe
[2]; /* Temporary pipes */
5340 char *argv
[4], /* Command-line arguments */
5341 *envp
[MAX_ENV
]; /* Environment */
5342 cups_file_t
*src
, /* Source file */
5343 *dst
; /* Destination file */
5344 ppd_file_t
*ppd
; /* PPD file */
5345 int bytes
, /* Bytes from pipe */
5346 total
; /* Total bytes from pipe */
5347 char buffer
[2048]; /* Copy buffer */
5348 int i
; /* Looping var */
5349 char option
[PPD_MAX_NAME
], /* Option name */
5350 choice
[PPD_MAX_NAME
]; /* Choice name */
5351 ppd_size_t
*size
; /* Default size */
5352 int num_defaults
; /* Number of default options */
5353 cups_option_t
*defaults
; /* Default options */
5354 char cups_protocol
[PPD_MAX_LINE
];
5355 /* cupsProtocol attribute */
5358 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5359 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5363 * Run cups-driverd to get the PPD file...
5366 argv
[0] = "cups-driverd";
5368 argv
[2] = (char *)from
;
5371 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5373 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5374 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5375 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5379 cupsdOpenPipe(temppipe
);
5381 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5382 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5384 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5385 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5396 * Wait up to 30 seconds for the PPD file to be copied...
5401 if (temppipe
[0] > CGIPipes
[0])
5402 maxfd
= temppipe
[0] + 1;
5404 maxfd
= CGIPipes
[0] + 1;
5409 * See if we have data ready...
5413 FD_SET(temppipe
[0], &input
);
5414 FD_SET(CGIPipes
[0], &input
);
5416 timeout
.tv_sec
= 30;
5417 timeout
.tv_usec
= 0;
5419 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5429 * We have timed out...
5435 if (FD_ISSET(temppipe
[0], &input
))
5438 * Read the PPD file from the pipe, and write it to the PPD file.
5441 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5443 if (write(tempfd
, buffer
, bytes
) < bytes
)
5452 if (FD_ISSET(CGIPipes
[0], &input
))
5462 * No data from cups-deviced...
5465 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5471 * Read the source file and see what page sizes are supported...
5474 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5481 * Open the destination (if possible) and set the default options...
5486 cups_protocol
[0] = '\0';
5488 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5491 * Read all of the default lines from the old PPD...
5494 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5495 if (!strncmp(buffer
, "*Default", 8))
5498 * Add the default option...
5501 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5502 choice
, sizeof(choice
)))
5504 ppd_option_t
*ppdo
; /* PPD option */
5508 * Only add the default if the default hasn't already been
5509 * set and the choice exists in the new PPD...
5512 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5513 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5514 ppdFindChoice(ppdo
, choice
))
5515 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5519 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5520 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5524 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5527 * Add the default media sizes...
5530 num_defaults
= cupsAddOption("PageSize", size
->name
,
5531 num_defaults
, &defaults
);
5532 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5533 num_defaults
, &defaults
);
5534 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5535 num_defaults
, &defaults
);
5536 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5537 num_defaults
, &defaults
);
5543 * Open the source file for a copy...
5546 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5548 cupsFreeOptions(num_defaults
, defaults
);
5554 * Open the destination file for a copy...
5557 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5559 cupsFreeOptions(num_defaults
, defaults
);
5566 * Copy the source file to the destination...
5569 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5571 if (!strncmp(buffer
, "*Default", 8))
5574 * Check for an previous default option choice...
5577 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5578 choice
, sizeof(choice
)))
5580 const char *val
; /* Default option value */
5583 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5586 * Substitute the previous choice...
5589 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5594 cupsFilePrintf(dst
, "%s\n", buffer
);
5597 if (cups_protocol
[0])
5598 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5600 cupsFreeOptions(num_defaults
, defaults
);
5603 * Close both files and return...
5610 return (cupsFileClose(dst
));
5615 * 'copy_job_attrs()' - Copy job attributes.
5619 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5620 cupsd_job_t
*job
, /* I - Job */
5621 cups_array_t
*ra
) /* I - Requested attributes array */
5623 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5627 * Send the requested attributes for each job...
5630 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5631 con
->servername
, con
->serverport
, "/jobs/%d",
5634 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5635 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5636 "document-count", job
->num_files
);
5638 if (!ra
|| cupsArrayFind(ra
, "job-media-progress"))
5639 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5640 "job-media-progress", job
->progress
);
5642 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5643 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5644 "job-more-info", NULL
, job_uri
);
5646 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5647 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5648 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5649 job
->num_files
> 0);
5651 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5652 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5653 "job-printer-up-time", time(NULL
));
5655 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5656 add_job_state_reasons(con
, job
);
5658 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5659 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5660 "job-uri", NULL
, job_uri
);
5662 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5667 * 'copy_printer_attrs()' - Copy printer attributes.
5672 cupsd_client_t
*con
, /* I - Client connection */
5673 cupsd_printer_t
*printer
, /* I - Printer */
5674 cups_array_t
*ra
) /* I - Requested attributes array */
5676 char printer_uri
[HTTP_MAX_URI
];
5678 time_t curtime
; /* Current time */
5679 int i
; /* Looping var */
5680 ipp_attribute_t
*history
; /* History collection */
5684 * Copy the printer attributes to the response using requested-attributes
5685 * and document-format attributes that may be provided by the client.
5688 curtime
= time(NULL
);
5690 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5691 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5692 "marker-change-time", printer
->marker_time
);
5694 if (printer
->num_printers
> 0 &&
5695 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5697 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5698 cupsd_printer_t
*p2
; /* Printer in class */
5699 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5702 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5703 IPP_TAG_URI
, "member-uris",
5704 printer
->num_printers
, NULL
,
5707 for (i
= 0; i
< printer
->num_printers
; i
++)
5709 p2
= printer
->printers
[i
];
5711 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5712 IPP_TAG_URI
)) != NULL
)
5713 member_uris
->values
[i
].string
.text
=
5714 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5717 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5718 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5720 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5721 "/classes/%s" : "/printers/%s", p2
->name
);
5722 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5728 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5729 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5730 "printer-alert", NULL
, printer
->alert
);
5732 if (printer
->alert_description
&&
5733 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5734 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5735 "printer-alert-description", NULL
,
5736 printer
->alert_description
);
5738 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5739 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5740 ippTimeToDate(curtime
));
5743 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5745 if (printer
->reg_name
)
5746 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5747 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5749 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5750 "printer-dns-sd-name", 0);
5752 #endif /* HAVE_DNSSD */
5754 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5755 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5756 "printer-error-policy", NULL
, printer
->error_policy
);
5758 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
5760 static const char * const errors
[] =/* printer-error-policy-supported values */
5763 "retry-current-job",
5768 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
5769 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5770 "printer-error-policy-supported", NULL
, "retry-current-job");
5772 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5773 "printer-error-policy-supported",
5774 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
5777 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5778 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5779 printer
->accepting
);
5781 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5782 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5785 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5786 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5788 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5789 "http", NULL
, con
->servername
, con
->serverport
,
5790 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5791 "/classes/%s" : "/printers/%s", printer
->name
);
5792 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5793 "printer-more-info", NULL
, printer_uri
);
5796 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5797 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5798 "printer-op-policy", NULL
, printer
->op_policy
);
5800 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5801 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5804 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5805 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5806 "printer-state-change-time", printer
->state_time
);
5808 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5809 cupsArrayFind(ra
, "printer-state-history"))
5812 * Printer history is only sent if specifically requested, so that
5813 * older CUPS/IPP clients won't barf on the collection attributes.
5816 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5817 "printer-state-history",
5818 printer
->num_history
, NULL
);
5820 for (i
= 0; i
< printer
->num_history
; i
++)
5821 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5822 NULL
, IPP_TAG_ZERO
, 0);
5825 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5826 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5827 "printer-state-message", NULL
, printer
->state_message
);
5829 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5830 add_printer_state_reasons(con
, printer
);
5832 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5834 int type
; /* printer-type value */
5838 * Add the CUPS-specific printer-type attribute...
5841 type
= printer
->type
;
5843 if (printer
== DefaultPrinter
)
5844 type
|= CUPS_PRINTER_DEFAULT
;
5846 if (!printer
->accepting
)
5847 type
|= CUPS_PRINTER_REJECTING
;
5849 if (!printer
->shared
)
5850 type
|= CUPS_PRINTER_NOT_SHARED
;
5852 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5856 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5857 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5858 "printer-up-time", curtime
);
5860 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5861 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5863 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5864 "ipp", NULL
, con
->servername
, con
->serverport
,
5865 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5866 "/classes/%s" : "/printers/%s", printer
->name
);
5867 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5868 "printer-uri-supported", NULL
, printer_uri
);
5869 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5873 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5874 add_queued_job_count(con
, printer
);
5876 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5877 if (printer
->ppd_attrs
)
5878 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0);
5879 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5884 * 'copy_subscription_attrs()' - Copy subscription attributes.
5888 copy_subscription_attrs(
5889 cupsd_client_t
*con
, /* I - Client connection */
5890 cupsd_subscription_t
*sub
, /* I - Subscription */
5891 cups_array_t
*ra
) /* I - Requested attributes array */
5893 ipp_attribute_t
*attr
; /* Current attribute */
5894 char printer_uri
[HTTP_MAX_URI
];
5896 int count
; /* Number of events */
5897 unsigned mask
; /* Current event mask */
5898 const char *name
; /* Current event name */
5902 * Copy the subscription attributes to the response using the
5903 * requested-attributes attribute that may be provided by the client.
5906 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5908 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5911 * Simple event list...
5914 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5915 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5916 "notify-events", NULL
, name
);
5921 * Complex event list...
5924 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5925 if (sub
->mask
& mask
)
5928 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5929 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5930 "notify-events", count
, NULL
, NULL
);
5932 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5933 if (sub
->mask
& mask
)
5935 attr
->values
[count
].string
.text
=
5936 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5943 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5944 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5945 "notify-job-id", sub
->job
->id
);
5947 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5948 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5949 "notify-lease-duration", sub
->lease
);
5951 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5953 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5954 "ipp", NULL
, con
->servername
, con
->serverport
,
5955 "/printers/%s", sub
->dest
->name
);
5956 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5957 "notify-printer-uri", NULL
, printer_uri
);
5960 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5961 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5962 "notify-recipient-uri", NULL
, sub
->recipient
);
5963 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5964 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5965 "notify-pull-method", NULL
, "ippget");
5967 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5968 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5969 "notify-subscriber-user-name", NULL
, sub
->owner
);
5971 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5972 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5973 "notify-subscription-id", sub
->id
);
5975 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5976 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5977 "notify-time-interval", sub
->interval
);
5979 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5980 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5981 sub
->user_data
, sub
->user_data_len
);
5986 * 'create_job()' - Print a file to a printer or class.
5990 create_job(cupsd_client_t
*con
, /* I - Client connection */
5991 ipp_attribute_t
*uri
) /* I - Printer URI */
5993 cupsd_printer_t
*printer
; /* Printer */
5994 cupsd_job_t
*job
; /* New job */
5997 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5998 con
->http
.fd
, uri
->values
[0].string
.text
);
6001 * Is the destination valid?
6004 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6010 send_ipp_status(con
, IPP_NOT_FOUND
,
6011 _("The printer or class was not found."));
6016 * Create the job object...
6019 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6022 job
->pending_timeout
= 1;
6025 * Save and log the job...
6028 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6029 job
->dest
, job
->username
);
6034 * 'create_requested_array()' - Create an array for the requested-attributes.
6037 static cups_array_t
* /* O - Array of attributes or NULL */
6038 create_requested_array(ipp_t
*request
) /* I - IPP request */
6040 int i
; /* Looping var */
6041 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6042 cups_array_t
*ra
; /* Requested attributes array */
6043 char *value
; /* Current value */
6047 * Get the requested-attributes attribute, and return NULL if we don't
6051 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6052 IPP_TAG_KEYWORD
)) == NULL
)
6056 * If the attribute contains a single "all" keyword, return NULL...
6059 if (requested
->num_values
== 1 &&
6060 !strcmp(requested
->values
[0].string
.text
, "all"))
6064 * Create an array using "strcmp" as the comparison function...
6067 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6069 for (i
= 0; i
< requested
->num_values
; i
++)
6071 value
= requested
->values
[i
].string
.text
;
6073 if (!strcmp(value
, "job-template"))
6075 cupsArrayAdd(ra
, "copies");
6076 cupsArrayAdd(ra
, "copies-default");
6077 cupsArrayAdd(ra
, "copies-supported");
6078 cupsArrayAdd(ra
, "finishings");
6079 cupsArrayAdd(ra
, "finishings-default");
6080 cupsArrayAdd(ra
, "finishings-supported");
6081 cupsArrayAdd(ra
, "job-hold-until");
6082 cupsArrayAdd(ra
, "job-hold-until-default");
6083 cupsArrayAdd(ra
, "job-hold-until-supported");
6084 cupsArrayAdd(ra
, "job-priority");
6085 cupsArrayAdd(ra
, "job-priority-default");
6086 cupsArrayAdd(ra
, "job-priority-supported");
6087 cupsArrayAdd(ra
, "job-sheets");
6088 cupsArrayAdd(ra
, "job-sheets-default");
6089 cupsArrayAdd(ra
, "job-sheets-supported");
6090 cupsArrayAdd(ra
, "media");
6091 cupsArrayAdd(ra
, "media-default");
6092 cupsArrayAdd(ra
, "media-supported");
6093 cupsArrayAdd(ra
, "multiple-document-handling");
6094 cupsArrayAdd(ra
, "multiple-document-handling-default");
6095 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6096 cupsArrayAdd(ra
, "number-up");
6097 cupsArrayAdd(ra
, "number-up-default");
6098 cupsArrayAdd(ra
, "number-up-supported");
6099 cupsArrayAdd(ra
, "orientation-requested");
6100 cupsArrayAdd(ra
, "orientation-requested-default");
6101 cupsArrayAdd(ra
, "orientation-requested-supported");
6102 cupsArrayAdd(ra
, "page-ranges");
6103 cupsArrayAdd(ra
, "page-ranges-supported");
6104 cupsArrayAdd(ra
, "printer-resolution");
6105 cupsArrayAdd(ra
, "printer-resolution-default");
6106 cupsArrayAdd(ra
, "printer-resolution-supported");
6107 cupsArrayAdd(ra
, "print-quality");
6108 cupsArrayAdd(ra
, "print-quality-default");
6109 cupsArrayAdd(ra
, "print-quality-supported");
6110 cupsArrayAdd(ra
, "sides");
6111 cupsArrayAdd(ra
, "sides-default");
6112 cupsArrayAdd(ra
, "sides-supported");
6114 else if (!strcmp(value
, "job-description"))
6116 cupsArrayAdd(ra
, "date-time-at-completed");
6117 cupsArrayAdd(ra
, "date-time-at-creation");
6118 cupsArrayAdd(ra
, "date-time-at-processing");
6119 cupsArrayAdd(ra
, "job-detailed-status-message");
6120 cupsArrayAdd(ra
, "job-document-access-errors");
6121 cupsArrayAdd(ra
, "job-id");
6122 cupsArrayAdd(ra
, "job-impressions");
6123 cupsArrayAdd(ra
, "job-impressions-completed");
6124 cupsArrayAdd(ra
, "job-k-octets");
6125 cupsArrayAdd(ra
, "job-k-octets-processed");
6126 cupsArrayAdd(ra
, "job-media-progress");
6127 cupsArrayAdd(ra
, "job-media-sheets");
6128 cupsArrayAdd(ra
, "job-media-sheets-completed");
6129 cupsArrayAdd(ra
, "job-message-from-operator");
6130 cupsArrayAdd(ra
, "job-more-info");
6131 cupsArrayAdd(ra
, "job-name");
6132 cupsArrayAdd(ra
, "job-originating-user-name");
6133 cupsArrayAdd(ra
, "job-printer-up-time");
6134 cupsArrayAdd(ra
, "job-printer-uri");
6135 cupsArrayAdd(ra
, "job-state");
6136 cupsArrayAdd(ra
, "job-state-message");
6137 cupsArrayAdd(ra
, "job-state-reasons");
6138 cupsArrayAdd(ra
, "job-uri");
6139 cupsArrayAdd(ra
, "number-of-documents");
6140 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6141 cupsArrayAdd(ra
, "output-device-assigned");
6142 cupsArrayAdd(ra
, "time-at-completed");
6143 cupsArrayAdd(ra
, "time-at-creation");
6144 cupsArrayAdd(ra
, "time-at-processing");
6146 else if (!strcmp(value
, "printer-description"))
6148 cupsArrayAdd(ra
, "charset-configured");
6149 cupsArrayAdd(ra
, "charset-supported");
6150 cupsArrayAdd(ra
, "color-supported");
6151 cupsArrayAdd(ra
, "compression-supported");
6152 cupsArrayAdd(ra
, "document-format-default");
6153 cupsArrayAdd(ra
, "document-format-supported");
6154 cupsArrayAdd(ra
, "generated-natural-language-supported");
6155 cupsArrayAdd(ra
, "ipp-versions-supported");
6156 cupsArrayAdd(ra
, "job-impressions-supported");
6157 cupsArrayAdd(ra
, "job-k-octets-supported");
6158 cupsArrayAdd(ra
, "job-media-sheets-supported");
6159 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6160 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6161 cupsArrayAdd(ra
, "multiple-operation-time-out");
6162 cupsArrayAdd(ra
, "natural-language-configured");
6163 cupsArrayAdd(ra
, "notify-attributes-supported");
6164 cupsArrayAdd(ra
, "notify-lease-duration-default");
6165 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6166 cupsArrayAdd(ra
, "notify-max-events-supported");
6167 cupsArrayAdd(ra
, "notify-events-default");
6168 cupsArrayAdd(ra
, "notify-events-supported");
6169 cupsArrayAdd(ra
, "notify-pull-method-supported");
6170 cupsArrayAdd(ra
, "notify-schemes-supported");
6171 cupsArrayAdd(ra
, "operations-supported");
6172 cupsArrayAdd(ra
, "pages-per-minute");
6173 cupsArrayAdd(ra
, "pages-per-minute-color");
6174 cupsArrayAdd(ra
, "pdl-override-supported");
6175 cupsArrayAdd(ra
, "printer-alert");
6176 cupsArrayAdd(ra
, "printer-alert-description");
6177 cupsArrayAdd(ra
, "printer-commands");
6178 cupsArrayAdd(ra
, "printer-current-time");
6179 cupsArrayAdd(ra
, "printer-driver-installer");
6180 cupsArrayAdd(ra
, "printer-dns-sd-name");
6181 cupsArrayAdd(ra
, "printer-info");
6182 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6183 cupsArrayAdd(ra
, "printer-location");
6184 cupsArrayAdd(ra
, "printer-make-and-model");
6185 cupsArrayAdd(ra
, "printer-message-from-operator");
6186 cupsArrayAdd(ra
, "printer-more-info");
6187 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6188 cupsArrayAdd(ra
, "printer-name");
6189 cupsArrayAdd(ra
, "printer-state");
6190 cupsArrayAdd(ra
, "printer-state-message");
6191 cupsArrayAdd(ra
, "printer-state-reasons");
6192 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6193 cupsArrayAdd(ra
, "printer-type");
6194 cupsArrayAdd(ra
, "printer-up-time");
6195 cupsArrayAdd(ra
, "printer-uri-supported");
6196 cupsArrayAdd(ra
, "queued-job-count");
6197 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6198 cupsArrayAdd(ra
, "uri-authentication-supported");
6199 cupsArrayAdd(ra
, "uri-security-supported");
6201 else if (!strcmp(value
, "printer-defaults"))
6203 char *name
; /* Option name */
6206 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6208 name
= (char *)cupsArrayNext(CommonDefaults
))
6209 cupsArrayAdd(ra
, name
);
6211 else if (!strcmp(value
, "subscription-template"))
6213 cupsArrayAdd(ra
, "notify-attributes");
6214 cupsArrayAdd(ra
, "notify-charset");
6215 cupsArrayAdd(ra
, "notify-events");
6216 cupsArrayAdd(ra
, "notify-lease-duration");
6217 cupsArrayAdd(ra
, "notify-natural-language");
6218 cupsArrayAdd(ra
, "notify-pull-method");
6219 cupsArrayAdd(ra
, "notify-recipient-uri");
6220 cupsArrayAdd(ra
, "notify-time-interval");
6221 cupsArrayAdd(ra
, "notify-user-data");
6224 cupsArrayAdd(ra
, value
);
6232 * 'create_subscription()' - Create a notification subscription.
6236 create_subscription(
6237 cupsd_client_t
*con
, /* I - Client connection */
6238 ipp_attribute_t
*uri
) /* I - Printer URI */
6240 http_status_t status
; /* Policy status */
6241 int i
; /* Looping var */
6242 ipp_attribute_t
*attr
; /* Current attribute */
6243 cups_ptype_t dtype
; /* Destination type (printer/class) */
6244 char scheme
[HTTP_MAX_URI
],
6245 /* Scheme portion of URI */
6246 userpass
[HTTP_MAX_URI
],
6247 /* Username portion of URI */
6249 /* Host portion of URI */
6250 resource
[HTTP_MAX_URI
];
6251 /* Resource portion of URI */
6252 int port
; /* Port portion of URI */
6253 cupsd_printer_t
*printer
; /* Printer/class */
6254 cupsd_job_t
*job
; /* Job */
6255 int jobid
; /* Job ID */
6256 cupsd_subscription_t
*sub
; /* Subscription object */
6257 const char *username
, /* requesting-user-name or
6258 authenticated username */
6259 *recipient
, /* notify-recipient-uri */
6260 *pullmethod
; /* notify-pull-method */
6261 ipp_attribute_t
*user_data
; /* notify-user-data */
6262 int interval
, /* notify-time-interval */
6263 lease
; /* notify-lease-duration */
6264 unsigned mask
; /* notify-events */
6265 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6266 *notify_lease
; /* notify-lease-duration(-default) */
6270 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6272 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6273 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6274 attr
->value_tag
, attr
->name
);
6276 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6281 * Is the destination valid?
6284 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6285 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6286 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6288 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6289 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6290 sizeof(host
), &port
, resource
, sizeof(resource
));
6292 if (!strcmp(resource
, "/"))
6294 dtype
= (cups_ptype_t
)0;
6297 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6299 dtype
= (cups_ptype_t
)0;
6302 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6304 dtype
= CUPS_PRINTER_CLASS
;
6307 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6313 send_ipp_status(con
, IPP_NOT_FOUND
,
6314 _("The printer or class was not found."));
6324 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6327 send_http_error(con
, status
, printer
);
6331 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6333 send_http_error(con
, status
, NULL
);
6338 * Get the user that is requesting the subscription...
6341 username
= get_username(con
);
6344 * Find the first subscription group attribute; return if we have
6348 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6349 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6354 send_ipp_status(con
, IPP_BAD_REQUEST
,
6355 _("No subscription attributes in request"));
6360 * Process the subscription attributes in the request...
6363 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6371 lease
= DefaultLeaseDuration
;
6373 mask
= CUPSD_EVENT_NONE
;
6377 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6379 notify_lease
= ippFindAttribute(printer
->attrs
,
6380 "notify-lease-duration-default",
6384 lease
= notify_lease
->values
[0].integer
;
6388 notify_events
= NULL
;
6389 notify_lease
= NULL
;
6392 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6394 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6395 attr
->value_tag
== IPP_TAG_URI
)
6398 * Validate the recipient scheme against the ServerBin/notifier
6402 char notifier
[1024]; /* Notifier filename */
6405 recipient
= attr
->values
[0].string
.text
;
6407 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6408 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6409 host
, sizeof(host
), &port
,
6410 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6412 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6413 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
6414 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6415 "notify-status-code", IPP_URI_SCHEME
);
6419 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6421 if (access(notifier
, X_OK
))
6423 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6424 _("notify-recipient-uri URI \"%s\" uses unknown "
6425 "scheme"), recipient
);
6426 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6427 "notify-status-code", IPP_URI_SCHEME
);
6431 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6433 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6434 _("notify-recipient-uri URI \"%s\" is already used"),
6436 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6437 "notify-status-code", IPP_ATTRIBUTES
);
6441 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6442 attr
->value_tag
== IPP_TAG_KEYWORD
)
6444 pullmethod
= attr
->values
[0].string
.text
;
6446 if (strcmp(pullmethod
, "ippget"))
6448 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6449 _("Bad notify-pull-method \"%s\""), pullmethod
);
6450 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6451 "notify-status-code", IPP_ATTRIBUTES
);
6455 else if (!strcmp(attr
->name
, "notify-charset") &&
6456 attr
->value_tag
== IPP_TAG_CHARSET
&&
6457 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6458 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6460 send_ipp_status(con
, IPP_CHARSET
,
6461 _("Character set \"%s\" not supported"),
6462 attr
->values
[0].string
.text
);
6465 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6466 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6467 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6469 send_ipp_status(con
, IPP_CHARSET
,
6470 _("Language \"%s\" not supported"),
6471 attr
->values
[0].string
.text
);
6474 else if (!strcmp(attr
->name
, "notify-user-data") &&
6475 attr
->value_tag
== IPP_TAG_STRING
)
6477 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6479 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6480 _("The notify-user-data value is too large "
6481 "(%d > 63 octets)"),
6482 attr
->values
[0].unknown
.length
);
6488 else if (!strcmp(attr
->name
, "notify-events") &&
6489 attr
->value_tag
== IPP_TAG_KEYWORD
)
6490 notify_events
= attr
;
6491 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6492 attr
->value_tag
== IPP_TAG_INTEGER
)
6493 lease
= attr
->values
[0].integer
;
6494 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6495 attr
->value_tag
== IPP_TAG_INTEGER
)
6496 interval
= attr
->values
[0].integer
;
6497 else if (!strcmp(attr
->name
, "notify-job-id") &&
6498 attr
->value_tag
== IPP_TAG_INTEGER
)
6499 jobid
= attr
->values
[0].integer
;
6506 for (i
= 0; i
< notify_events
->num_values
; i
++)
6507 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6511 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6513 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6514 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6515 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6517 if (!recipient
&& !pullmethod
)
6520 if (mask
== CUPSD_EVENT_NONE
)
6523 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6525 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6528 send_ipp_status(con
, IPP_BAD_REQUEST
,
6529 _("notify-events not specified"));
6534 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6536 cupsdLogMessage(CUPSD_LOG_INFO
,
6537 "create_subscription: Limiting notify-lease-duration to "
6540 lease
= MaxLeaseDuration
;
6545 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6547 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found"), jobid
);
6554 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6556 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6557 _("There are too many subscriptions."));
6562 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6565 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6566 "Added subscription %d for printer \"%s\"",
6567 sub
->id
, printer
->name
);
6569 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6572 sub
->interval
= interval
;
6574 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6576 cupsdSetString(&sub
->owner
, username
);
6580 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6581 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6582 sub
->user_data_len
);
6585 ippAddSeparator(con
->response
);
6586 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6587 "notify-subscription-id", sub
->id
);
6589 con
->response
->request
.status
.status_code
= IPP_OK
;
6595 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6600 * 'delete_printer()' - Remove a printer or class from the system.
6604 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6605 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6607 http_status_t status
; /* Policy status */
6608 cups_ptype_t dtype
; /* Destination type (printer/class) */
6609 cupsd_printer_t
*printer
; /* Printer/class */
6610 char filename
[1024]; /* Script/PPD filename */
6613 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6614 con
->http
.fd
, uri
->values
[0].string
.text
);
6617 * Do we have a valid URI?
6620 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6626 send_ipp_status(con
, IPP_NOT_FOUND
,
6627 _("The printer or class was not found."));
6635 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6637 send_http_error(con
, status
, NULL
);
6642 * Remove old jobs...
6645 cupsdCancelJobs(printer
->name
, NULL
, 1);
6648 * Remove old subscriptions and send a "deleted printer" event...
6651 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6652 "%s \"%s\" deleted by \"%s\".",
6653 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6654 printer
->name
, get_username(con
));
6656 cupsdExpireSubscriptions(printer
, NULL
);
6659 * Remove any old PPD or script files...
6662 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6666 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6670 snprintf(filename
, sizeof(filename
), "%s/%s.ipp2", CacheDir
, printer
->name
);
6673 snprintf(filename
, sizeof(filename
), "%s/%s.pwg", CacheDir
, printer
->name
);
6678 * Unregister color profiles...
6681 apple_unregister_profiles(printer
);
6682 #endif /* __APPLE__ */
6684 if (dtype
& CUPS_PRINTER_CLASS
)
6686 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6687 printer
->name
, get_username(con
));
6689 cupsdDeletePrinter(printer
, 0);
6690 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6694 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6695 printer
->name
, get_username(con
));
6697 if (cupsdDeletePrinter(printer
, 0))
6698 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6700 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6703 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6706 * Return with no errors...
6709 con
->response
->request
.status
.status_code
= IPP_OK
;
6714 * 'get_default()' - Get the default destination.
6718 get_default(cupsd_client_t
*con
) /* I - Client connection */
6720 http_status_t status
; /* Policy status */
6721 cups_array_t
*ra
; /* Requested attributes array */
6724 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6730 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6732 send_http_error(con
, status
, NULL
);
6738 ra
= create_requested_array(con
->request
);
6740 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6742 cupsArrayDelete(ra
);
6744 con
->response
->request
.status
.status_code
= IPP_OK
;
6747 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6752 * 'get_devices()' - Get the list of available devices on the local system.
6756 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6758 http_status_t status
; /* Policy status */
6759 ipp_attribute_t
*limit
, /* limit attribute */
6760 *timeout
, /* timeout attribute */
6761 *requested
, /* requested-attributes attribute */
6762 *exclude
, /* exclude-schemes attribute */
6763 *include
; /* include-schemes attribute */
6764 char command
[1024], /* cups-deviced command */
6765 options
[2048], /* Options to pass to command */
6767 /* String for requested attributes */
6769 /* String for excluded schemes */
6771 /* String for included schemes */
6774 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6780 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6782 send_http_error(con
, status
, NULL
);
6787 * Run cups-deviced command with the given options...
6790 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6791 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6792 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6794 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6795 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6798 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6800 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6803 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6805 exclude_str
[0] = '\0';
6808 url_encode_attr(include
, include_str
, sizeof(include_str
));
6810 include_str
[0] = '\0';
6812 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6813 snprintf(options
, sizeof(options
),
6814 "%d+%d+%d+%d+%s%s%s%s%s",
6815 con
->request
->request
.op
.request_id
,
6816 limit
? limit
->values
[0].integer
: 0,
6817 timeout
? timeout
->values
[0].integer
: 15,
6820 exclude_str
[0] ? "%20" : "", exclude_str
,
6821 include_str
[0] ? "%20" : "", include_str
);
6823 if (cupsdSendCommand(con
, command
, options
, 1))
6826 * Command started successfully, don't send an IPP response here...
6829 ippDelete(con
->response
);
6830 con
->response
= NULL
;
6835 * Command failed, return "internal error" so the user knows something
6839 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6840 _("cups-deviced failed to execute."));
6846 * 'get_document()' - Get a copy of a job file.
6850 get_document(cupsd_client_t
*con
, /* I - Client connection */
6851 ipp_attribute_t
*uri
) /* I - Job URI */
6853 http_status_t status
; /* Policy status */
6854 ipp_attribute_t
*attr
; /* Current attribute */
6855 int jobid
; /* Job ID */
6856 int docnum
; /* Document number */
6857 cupsd_job_t
*job
; /* Current job */
6858 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6859 username
[HTTP_MAX_URI
], /* Username portion of URI */
6860 host
[HTTP_MAX_URI
], /* Host portion of URI */
6861 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6862 int port
; /* Port portion of URI */
6863 char filename
[1024], /* Filename for document */
6864 format
[1024]; /* Format for document */
6867 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6868 con
->http
.fd
, uri
->values
[0].string
.text
);
6871 * See if we have a job URI or a printer URI...
6874 if (!strcmp(uri
->name
, "printer-uri"))
6877 * Got a printer URI; see if we also have a job-id attribute...
6880 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6881 IPP_TAG_INTEGER
)) == NULL
)
6883 send_ipp_status(con
, IPP_BAD_REQUEST
,
6884 _("Got a printer-uri attribute but no job-id"));
6888 jobid
= attr
->values
[0].integer
;
6893 * Got a job URI; parse it to get the job ID...
6896 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6897 sizeof(scheme
), username
, sizeof(username
), host
,
6898 sizeof(host
), &port
, resource
, sizeof(resource
));
6900 if (strncmp(resource
, "/jobs/", 6))
6906 send_ipp_status(con
, IPP_BAD_REQUEST
,
6907 _("Bad job-uri attribute \"%s\""),
6908 uri
->values
[0].string
.text
);
6912 jobid
= atoi(resource
+ 6);
6916 * See if the job exists...
6919 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6922 * Nope - return a "not found" error...
6925 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
6933 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6935 send_http_error(con
, status
, NULL
);
6940 * Get the document number...
6943 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6944 IPP_TAG_INTEGER
)) == NULL
)
6946 send_ipp_status(con
, IPP_BAD_REQUEST
,
6947 _("Missing document-number attribute"));
6951 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6952 attr
->num_values
> 1)
6954 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6959 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6961 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6963 cupsdLogMessage(CUPSD_LOG_ERROR
,
6964 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6966 send_ipp_status(con
, IPP_NOT_FOUND
,
6967 _("Unable to open document %d in job %d"), docnum
, jobid
);
6971 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6975 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6976 job
->filetypes
[docnum
- 1]->type
);
6978 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6980 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6982 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6983 IPP_TAG_NAME
)) != NULL
)
6984 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6985 NULL
, attr
->values
[0].string
.text
);
6990 * 'get_job_attrs()' - Get job attributes.
6994 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6995 ipp_attribute_t
*uri
) /* I - Job URI */
6997 http_status_t status
; /* Policy status */
6998 ipp_attribute_t
*attr
; /* Current attribute */
6999 int jobid
; /* Job ID */
7000 cupsd_job_t
*job
; /* Current job */
7001 cupsd_printer_t
*printer
; /* Current printer */
7002 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7003 username
[HTTP_MAX_URI
], /* Username portion of URI */
7004 host
[HTTP_MAX_URI
], /* Host portion of URI */
7005 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7006 int port
; /* Port portion of URI */
7007 cups_array_t
*ra
; /* Requested attributes array */
7010 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7011 con
->http
.fd
, uri
->values
[0].string
.text
);
7014 * See if we have a job URI or a printer URI...
7017 if (!strcmp(uri
->name
, "printer-uri"))
7020 * Got a printer URI; see if we also have a job-id attribute...
7023 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7024 IPP_TAG_INTEGER
)) == NULL
)
7026 send_ipp_status(con
, IPP_BAD_REQUEST
,
7027 _("Got a printer-uri attribute but no job-id"));
7031 jobid
= attr
->values
[0].integer
;
7036 * Got a job URI; parse it to get the job ID...
7039 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7040 sizeof(scheme
), username
, sizeof(username
), host
,
7041 sizeof(host
), &port
, resource
, sizeof(resource
));
7043 if (strncmp(resource
, "/jobs/", 6))
7049 send_ipp_status(con
, IPP_BAD_REQUEST
,
7050 _("Bad job-uri attribute \"%s\""),
7051 uri
->values
[0].string
.text
);
7055 jobid
= atoi(resource
+ 6);
7059 * See if the job exists...
7062 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7065 * Nope - return a "not found" error...
7068 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
7076 if ((printer
= job
->printer
) == NULL
)
7077 printer
= cupsdFindDest(job
->dest
);
7081 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
7084 send_http_error(con
, status
, printer
);
7088 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7090 send_http_error(con
, status
, NULL
);
7095 * Copy attributes...
7100 ra
= create_requested_array(con
->request
);
7101 copy_job_attrs(con
, job
, ra
);
7102 cupsArrayDelete(ra
);
7104 con
->response
->request
.status
.status_code
= IPP_OK
;
7109 * 'get_jobs()' - Get a list of jobs for the specified printer.
7113 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7114 ipp_attribute_t
*uri
) /* I - Printer URI */
7116 http_status_t status
; /* Policy status */
7117 ipp_attribute_t
*attr
; /* Current attribute */
7118 const char *dest
; /* Destination */
7119 cups_ptype_t dtype
; /* Destination type (printer/class) */
7120 cups_ptype_t dmask
; /* Destination type mask */
7121 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7122 username
[HTTP_MAX_URI
], /* Username portion of URI */
7123 host
[HTTP_MAX_URI
], /* Host portion of URI */
7124 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7125 int port
; /* Port portion of URI */
7126 int job_comparison
; /* Job comparison */
7127 ipp_jstate_t job_state
; /* job-state value */
7128 int first_job_id
; /* First job ID */
7129 int limit
; /* Maximum number of jobs to return */
7130 int count
; /* Number of jobs that match */
7131 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7132 cupsd_job_t
*job
; /* Current job pointer */
7133 cupsd_printer_t
*printer
; /* Printer */
7134 cups_array_t
*list
; /* Which job list... */
7135 cups_array_t
*ra
; /* Requested attributes array */
7138 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7139 uri
->values
[0].string
.text
);
7142 * Is the destination valid?
7145 if (strcmp(uri
->name
, "printer-uri"))
7147 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request"));
7151 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7152 sizeof(scheme
), username
, sizeof(username
), host
,
7153 sizeof(host
), &port
, resource
, sizeof(resource
));
7155 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7158 dtype
= (cups_ptype_t
)0;
7159 dmask
= (cups_ptype_t
)0;
7162 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7165 dtype
= (cups_ptype_t
)0;
7166 dmask
= CUPS_PRINTER_CLASS
;
7169 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7172 dtype
= CUPS_PRINTER_CLASS
;
7173 dmask
= CUPS_PRINTER_CLASS
;
7176 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7183 send_ipp_status(con
, IPP_NOT_FOUND
,
7184 _("The printer or class was not found."));
7189 dtype
&= CUPS_PRINTER_CLASS
;
7190 dmask
= CUPS_PRINTER_CLASS
;
7199 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
7202 send_http_error(con
, status
, printer
);
7206 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7208 send_http_error(con
, status
, NULL
);
7212 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7215 * See if the "which-jobs" attribute have been specified...
7218 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7219 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7221 send_ipp_status(con
, IPP_CONFLICT
,
7222 _("The %s attribute cannot be provided with job-ids."),
7226 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7228 job_comparison
= -1;
7229 job_state
= IPP_JOB_STOPPED
;
7232 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7235 job_state
= IPP_JOB_CANCELED
;
7238 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7241 job_state
= IPP_JOB_ABORTED
;
7244 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7247 job_state
= IPP_JOB_PENDING
;
7250 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7253 job_state
= IPP_JOB_CANCELED
;
7256 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7259 job_state
= IPP_JOB_PENDING
;
7262 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7265 job_state
= IPP_JOB_HELD
;
7268 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7271 job_state
= IPP_JOB_PROCESSING
;
7272 list
= PrintingJobs
;
7274 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7277 job_state
= IPP_JOB_STOPPED
;
7282 send_ipp_status(con
, IPP_ATTRIBUTES
,
7283 _("The which-jobs value \"%s\" is not supported."),
7284 attr
->values
[0].string
.text
);
7285 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7286 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7291 * See if they want to limit the number of jobs reported...
7294 if ((attr
= ippFindAttribute(con
->request
, "limit",
7295 IPP_TAG_INTEGER
)) != NULL
)
7299 send_ipp_status(con
, IPP_CONFLICT
,
7300 _("The %s attribute cannot be provided with job-ids."),
7305 limit
= attr
->values
[0].integer
;
7310 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7311 IPP_TAG_INTEGER
)) != NULL
)
7315 send_ipp_status(con
, IPP_CONFLICT
,
7316 _("The %s attribute cannot be provided with job-ids."),
7321 first_job_id
= attr
->values
[0].integer
;
7327 * See if we only want to see jobs for a specific user...
7330 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7331 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7333 send_ipp_status(con
, IPP_CONFLICT
,
7334 _("The %s attribute cannot be provided with job-ids."),
7338 else if (attr
&& attr
->values
[0].boolean
)
7339 strlcpy(username
, get_username(con
), sizeof(username
));
7343 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7344 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7347 * IPP conformance - Get-Jobs has a default requested-attributes value of
7348 * "job-id" and "job-uri".
7351 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7352 cupsArrayAdd(ra
, "job-id");
7353 cupsArrayAdd(ra
, "job-uri");
7357 * OK, build a list of jobs for this printer...
7362 int i
; /* Looping var */
7364 for (i
= 0; i
< job_ids
->num_values
; i
++)
7366 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
7370 if (i
< job_ids
->num_values
)
7372 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
7373 job_ids
->values
[i
].integer
);
7377 for (i
= 0; i
< job_ids
->num_values
; i
++)
7379 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7385 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7391 ippAddSeparator(con
->response
);
7393 copy_job_attrs(con
, job
, ra
);
7398 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7399 (limit
<= 0 || count
< limit
) && job
;
7400 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7403 * Filter out jobs that don't match...
7406 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7407 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7408 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7409 job
->username
, job
->state_value
, job
->attrs
);
7411 if (!job
->dest
|| !job
->username
)
7414 if (!job
->dest
|| !job
->username
)
7417 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7418 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7420 if ((job
->dtype
& dmask
) != dtype
&&
7421 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7424 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7425 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7426 (job_comparison
> 0 && job
->state_value
< job_state
))
7429 if (job
->id
< first_job_id
)
7436 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7441 if (username
[0] && strcasecmp(username
, job
->username
))
7445 ippAddSeparator(con
->response
);
7449 copy_job_attrs(con
, job
, ra
);
7452 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7455 cupsArrayDelete(ra
);
7457 con
->response
->request
.status
.status_code
= IPP_OK
;
7462 * 'get_notifications()' - Get events for a subscription.
7466 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7468 int i
, j
; /* Looping vars */
7469 http_status_t status
; /* Policy status */
7470 cupsd_subscription_t
*sub
; /* Subscription */
7471 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7472 *sequences
; /* notify-sequence-numbers */
7473 int min_seq
; /* Minimum sequence number */
7474 int interval
; /* Poll interval */
7477 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7481 * Get subscription attributes...
7484 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7486 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7491 send_ipp_status(con
, IPP_BAD_REQUEST
,
7492 _("Missing notify-subscription-ids attribute"));
7497 * Are the subscription IDs valid?
7500 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7502 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7505 * Bad subscription ID...
7508 send_ipp_status(con
, IPP_NOT_FOUND
,
7509 _("notify-subscription-id %d no good"),
7510 ids
->values
[i
].integer
);
7518 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7520 con
, sub
->owner
)) != HTTP_OK
)
7522 send_http_error(con
, status
, sub
->dest
);
7527 * Check the subscription type and update the interval accordingly.
7530 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7533 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7535 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7541 * Tell the client to poll again in N seconds...
7545 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7546 "notify-get-interval", interval
);
7548 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7549 "printer-up-time", time(NULL
));
7552 * Copy the subscription event attributes to the response.
7555 con
->response
->request
.status
.status_code
=
7556 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7558 for (i
= 0; i
< ids
->num_values
; i
++)
7561 * Get the subscription and sequence number...
7564 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7566 if (sequences
&& i
< sequences
->num_values
)
7567 min_seq
= sequences
->values
[i
].integer
;
7572 * If we don't have any new events, nothing to do here...
7575 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7579 * Otherwise copy all of the new events...
7582 if (sub
->first_event_id
> min_seq
)
7585 j
= min_seq
- sub
->first_event_id
;
7587 for (; j
< sub
->num_events
; j
++)
7589 ippAddSeparator(con
->response
);
7591 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7592 IPP_TAG_EVENT_NOTIFICATION
, 0);
7599 * 'get_ppd()' - Get a named PPD from the local system.
7603 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7604 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7606 http_status_t status
; /* Policy status */
7607 cupsd_printer_t
*dest
; /* Destination */
7608 cups_ptype_t dtype
; /* Destination type */
7611 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7612 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7614 if (!strcmp(uri
->name
, "ppd-name"))
7617 * Return a PPD file from cups-driverd...
7620 char command
[1024], /* cups-driverd command */
7621 options
[1024], /* Options to pass to command */
7622 ppd_name
[1024]; /* ppd-name */
7629 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7631 send_http_error(con
, status
, NULL
);
7636 * Run cups-driverd command with the given options...
7639 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7640 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7641 snprintf(options
, sizeof(options
), "get+%d+%s",
7642 con
->request
->request
.op
.request_id
, ppd_name
);
7644 if (cupsdSendCommand(con
, command
, options
, 0))
7647 * Command started successfully, don't send an IPP response here...
7650 ippDelete(con
->response
);
7651 con
->response
= NULL
;
7656 * Command failed, return "internal error" so the user knows something
7660 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7661 _("cups-driverd failed to execute."));
7664 else if (!strcmp(uri
->name
, "printer-uri") &&
7665 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7667 int i
; /* Looping var */
7668 char filename
[1024]; /* PPD filename */
7675 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7677 send_http_error(con
, status
, dest
);
7682 * See if we need the PPD for a class or remote printer...
7685 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7688 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7690 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7691 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7692 "printer-uri", NULL
, dest
->uri
);
7695 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7697 for (i
= 0; i
< dest
->num_printers
; i
++)
7698 if (!(dest
->printers
[i
]->type
&
7699 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7701 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7702 dest
->printers
[i
]->name
);
7704 if (!access(filename
, 0))
7708 if (i
< dest
->num_printers
)
7709 dest
= dest
->printers
[i
];
7712 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7713 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7714 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7720 * Found the printer with the PPD file, now see if there is one...
7723 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7725 send_ipp_status(con
, IPP_NOT_FOUND
,
7726 _("The PPD file \"%s\" could not be opened: %s"),
7727 uri
->values
[0].string
.text
, strerror(errno
));
7731 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7735 con
->response
->request
.status
.status_code
= IPP_OK
;
7738 send_ipp_status(con
, IPP_NOT_FOUND
,
7739 _("The PPD file \"%s\" could not be found."),
7740 uri
->values
[0].string
.text
);
7745 * 'get_ppds()' - Get the list of PPD files on the local system.
7749 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7751 http_status_t status
; /* Policy status */
7752 ipp_attribute_t
*limit
, /* Limit attribute */
7753 *device
, /* ppd-device-id attribute */
7754 *language
, /* ppd-natural-language attribute */
7755 *make
, /* ppd-make attribute */
7756 *model
, /* ppd-make-and-model attribute */
7757 *model_number
, /* ppd-model-number attribute */
7758 *product
, /* ppd-product attribute */
7759 *psversion
, /* ppd-psverion attribute */
7760 *type
, /* ppd-type attribute */
7761 *requested
, /* requested-attributes attribute */
7762 *exclude
, /* exclude-schemes attribute */
7763 *include
; /* include-schemes attribute */
7764 char command
[1024], /* cups-driverd command */
7765 options
[4096], /* Options to pass to command */
7766 device_str
[256],/* Escaped ppd-device-id string */
7768 /* Escaped ppd-natural-language */
7769 make_str
[256], /* Escaped ppd-make string */
7770 model_str
[256], /* Escaped ppd-make-and-model string */
7771 model_number_str
[256],
7772 /* ppd-model-number string */
7774 /* Escaped ppd-product string */
7776 /* Escaped ppd-psversion string */
7777 type_str
[256], /* Escaped ppd-type string */
7779 /* String for requested attributes */
7781 /* String for excluded schemes */
7783 /* String for included schemes */
7786 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7792 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7794 send_http_error(con
, status
, NULL
);
7799 * Run cups-driverd command with the given options...
7802 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7803 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7804 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7806 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7807 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7809 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7811 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7812 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7813 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7814 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7816 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7818 include
= ippFindAttribute(con
->request
, "include-schemes",
7822 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7824 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7827 url_encode_attr(device
, device_str
, sizeof(device_str
));
7829 device_str
[0] = '\0';
7832 url_encode_attr(language
, language_str
, sizeof(language_str
));
7834 language_str
[0] = '\0';
7837 url_encode_attr(make
, make_str
, sizeof(make_str
));
7842 url_encode_attr(model
, model_str
, sizeof(model_str
));
7844 model_str
[0] = '\0';
7847 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7848 model_number
->values
[0].integer
);
7850 model_number_str
[0] = '\0';
7853 url_encode_attr(product
, product_str
, sizeof(product_str
));
7855 product_str
[0] = '\0';
7858 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7860 psversion_str
[0] = '\0';
7863 url_encode_attr(type
, type_str
, sizeof(type_str
));
7868 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7870 exclude_str
[0] = '\0';
7873 url_encode_attr(include
, include_str
, sizeof(include_str
));
7875 include_str
[0] = '\0';
7877 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7878 snprintf(options
, sizeof(options
),
7879 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7880 con
->request
->request
.op
.request_id
,
7881 limit
? limit
->values
[0].integer
: 0,
7883 device
? "%20" : "", device_str
,
7884 language
? "%20" : "", language_str
,
7885 make
? "%20" : "", make_str
,
7886 model
? "%20" : "", model_str
,
7887 model_number
? "%20" : "", model_number_str
,
7888 product
? "%20" : "", product_str
,
7889 psversion
? "%20" : "", psversion_str
,
7890 type
? "%20" : "", type_str
,
7891 exclude_str
[0] ? "%20" : "", exclude_str
,
7892 include_str
[0] ? "%20" : "", include_str
);
7894 if (cupsdSendCommand(con
, command
, options
, 0))
7897 * Command started successfully, don't send an IPP response here...
7900 ippDelete(con
->response
);
7901 con
->response
= NULL
;
7906 * Command failed, return "internal error" so the user knows something
7910 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7911 _("cups-driverd failed to execute."));
7917 * 'get_printer_attrs()' - Get printer attributes.
7921 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7922 ipp_attribute_t
*uri
) /* I - Printer URI */
7924 http_status_t status
; /* Policy status */
7925 cups_ptype_t dtype
; /* Destination type (printer/class) */
7926 cupsd_printer_t
*printer
; /* Printer/class */
7927 cups_array_t
*ra
; /* Requested attributes array */
7930 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7931 con
->http
.fd
, uri
->values
[0].string
.text
);
7934 * Is the destination valid?
7937 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7943 send_ipp_status(con
, IPP_NOT_FOUND
,
7944 _("The printer or class was not found."));
7952 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7954 send_http_error(con
, status
, printer
);
7959 * Send the attributes...
7962 ra
= create_requested_array(con
->request
);
7964 copy_printer_attrs(con
, printer
, ra
);
7966 cupsArrayDelete(ra
);
7968 con
->response
->request
.status
.status_code
= IPP_OK
;
7973 * 'get_printer_supported()' - Get printer supported values.
7977 get_printer_supported(
7978 cupsd_client_t
*con
, /* I - Client connection */
7979 ipp_attribute_t
*uri
) /* I - Printer URI */
7981 http_status_t status
; /* Policy status */
7982 cups_ptype_t dtype
; /* Destination type (printer/class) */
7983 cupsd_printer_t
*printer
; /* Printer/class */
7986 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7987 con
->http
.fd
, uri
->values
[0].string
.text
);
7990 * Is the destination valid?
7993 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7999 send_ipp_status(con
, IPP_NOT_FOUND
,
8000 _("The printer or class was not found."));
8008 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8010 send_http_error(con
, status
, printer
);
8015 * Return a list of attributes that can be set via Set-Printer-Attributes.
8018 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8020 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8021 "printer-location", 0);
8023 con
->response
->request
.status
.status_code
= IPP_OK
;
8028 * 'get_printers()' - Get a list of printers or classes.
8032 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8033 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8035 http_status_t status
; /* Policy status */
8036 ipp_attribute_t
*attr
; /* Current attribute */
8037 int limit
; /* Max number of printers to return */
8038 int count
; /* Number of printers that match */
8039 cupsd_printer_t
*printer
; /* Current printer pointer */
8040 int printer_type
, /* printer-type attribute */
8041 printer_mask
; /* printer-type-mask attribute */
8042 char *location
; /* Location string */
8043 const char *username
; /* Current user */
8044 char *first_printer_name
; /* first-printer-name attribute */
8045 cups_array_t
*ra
; /* Requested attributes array */
8046 int local
; /* Local connection? */
8049 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8050 con
->http
.fd
, type
);
8056 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8058 send_http_error(con
, status
, NULL
);
8063 * Check for printers...
8066 if (!Printers
|| !cupsArrayCount(Printers
))
8068 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8073 * See if they want to limit the number of printers reported...
8076 if ((attr
= ippFindAttribute(con
->request
, "limit",
8077 IPP_TAG_INTEGER
)) != NULL
)
8078 limit
= attr
->values
[0].integer
;
8082 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8083 IPP_TAG_NAME
)) != NULL
)
8084 first_printer_name
= attr
->values
[0].string
.text
;
8086 first_printer_name
= NULL
;
8089 * Support filtering...
8092 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8093 IPP_TAG_ENUM
)) != NULL
)
8094 printer_type
= attr
->values
[0].integer
;
8098 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8099 IPP_TAG_ENUM
)) != NULL
)
8100 printer_mask
= attr
->values
[0].integer
;
8104 local
= httpAddrLocalhost(&(con
->clientaddr
));
8106 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8107 IPP_TAG_TEXT
)) != NULL
)
8108 location
= attr
->values
[0].string
.text
;
8112 if (con
->username
[0])
8113 username
= con
->username
;
8114 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8115 IPP_TAG_NAME
)) != NULL
)
8116 username
= attr
->values
[0].string
.text
;
8120 ra
= create_requested_array(con
->request
);
8123 * OK, build a list of printers for this printer...
8126 if (first_printer_name
)
8128 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8129 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8132 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8135 count
< limit
&& printer
;
8136 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8138 if (!local
&& !printer
->shared
)
8141 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8142 (printer
->type
& printer_mask
) == printer_type
&&
8144 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
8147 * If HideImplicitMembers is enabled, see if this printer or class
8148 * is a member of an implicit class...
8151 if (ImplicitClasses
&& HideImplicitMembers
&&
8152 printer
->in_implicit_class
)
8156 * If a username is specified, see if it is allowed or denied
8160 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
8164 * Add the group separator as needed...
8168 ippAddSeparator(con
->response
);
8173 * Send the attributes...
8176 copy_printer_attrs(con
, printer
, ra
);
8180 cupsArrayDelete(ra
);
8182 con
->response
->request
.status
.status_code
= IPP_OK
;
8187 * 'get_subscription_attrs()' - Get subscription attributes.
8191 get_subscription_attrs(
8192 cupsd_client_t
*con
, /* I - Client connection */
8193 int sub_id
) /* I - Subscription ID */
8195 http_status_t status
; /* Policy status */
8196 cupsd_subscription_t
*sub
; /* Subscription */
8197 cups_array_t
*ra
; /* Requested attributes array */
8200 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8201 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8202 con
, con
->http
.fd
, sub_id
);
8205 * Is the subscription ID valid?
8208 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8211 * Bad subscription ID...
8214 send_ipp_status(con
, IPP_NOT_FOUND
,
8215 _("notify-subscription-id %d no good"), sub_id
);
8223 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8225 con
, sub
->owner
)) != HTTP_OK
)
8227 send_http_error(con
, status
, sub
->dest
);
8232 * Copy the subscription attributes to the response using the
8233 * requested-attributes attribute that may be provided by the client.
8236 ra
= create_requested_array(con
->request
);
8238 copy_subscription_attrs(con
, sub
, ra
);
8240 cupsArrayDelete(ra
);
8242 con
->response
->request
.status
.status_code
= IPP_OK
;
8247 * 'get_subscriptions()' - Get subscriptions.
8251 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8252 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8254 http_status_t status
; /* Policy status */
8255 int count
; /* Number of subscriptions */
8256 int limit
; /* Limit */
8257 cupsd_subscription_t
*sub
; /* Subscription */
8258 cups_array_t
*ra
; /* Requested attributes array */
8259 ipp_attribute_t
*attr
; /* Attribute */
8260 cups_ptype_t dtype
; /* Destination type (printer/class) */
8261 char scheme
[HTTP_MAX_URI
],
8262 /* Scheme portion of URI */
8263 username
[HTTP_MAX_URI
],
8264 /* Username portion of URI */
8266 /* Host portion of URI */
8267 resource
[HTTP_MAX_URI
];
8268 /* Resource portion of URI */
8269 int port
; /* Port portion of URI */
8270 cupsd_job_t
*job
; /* Job pointer */
8271 cupsd_printer_t
*printer
; /* Printer */
8274 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8275 "get_subscriptions(con=%p[%d], uri=%s)",
8276 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8279 * Is the destination valid?
8282 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8283 sizeof(scheme
), username
, sizeof(username
), host
,
8284 sizeof(host
), &port
, resource
, sizeof(resource
));
8286 if (!strcmp(resource
, "/") ||
8287 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8288 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8289 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8294 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8297 job
= cupsdFindJob(atoi(resource
+ 6));
8301 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist"),
8306 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8312 send_ipp_status(con
, IPP_NOT_FOUND
,
8313 _("The printer or class was not found."));
8316 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8317 IPP_TAG_INTEGER
)) != NULL
)
8319 job
= cupsdFindJob(attr
->values
[0].integer
);
8323 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
8324 attr
->values
[0].integer
);
8335 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
8337 con
, NULL
)) != HTTP_OK
)
8339 send_http_error(con
, status
, printer
);
8344 * Copy the subscription attributes to the response using the
8345 * requested-attributes attribute that may be provided by the client.
8348 ra
= create_requested_array(con
->request
);
8350 if ((attr
= ippFindAttribute(con
->request
, "limit",
8351 IPP_TAG_INTEGER
)) != NULL
)
8352 limit
= attr
->values
[0].integer
;
8357 * See if we only want to see subscriptions for a specific user...
8360 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8361 IPP_TAG_BOOLEAN
)) != NULL
&&
8362 attr
->values
[0].boolean
)
8363 strlcpy(username
, get_username(con
), sizeof(username
));
8367 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8369 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8370 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8371 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
8373 ippAddSeparator(con
->response
);
8374 copy_subscription_attrs(con
, sub
, ra
);
8377 if (limit
&& count
>= limit
)
8381 cupsArrayDelete(ra
);
8384 con
->response
->request
.status
.status_code
= IPP_OK
;
8386 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8391 * 'get_username()' - Get the username associated with a request.
8394 static const char * /* O - Username */
8395 get_username(cupsd_client_t
*con
) /* I - Connection */
8397 ipp_attribute_t
*attr
; /* Attribute */
8400 if (con
->username
[0])
8401 return (con
->username
);
8402 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8403 IPP_TAG_NAME
)) != NULL
)
8404 return (attr
->values
[0].string
.text
);
8406 return ("anonymous");
8411 * 'hold_job()' - Hold a print job.
8415 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8416 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8418 ipp_attribute_t
*attr
; /* Current job-hold-until */
8419 const char *when
; /* New value */
8420 int jobid
; /* Job ID */
8421 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8422 username
[HTTP_MAX_URI
], /* Username portion of URI */
8423 host
[HTTP_MAX_URI
], /* Host portion of URI */
8424 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8425 int port
; /* Port portion of URI */
8426 cupsd_job_t
*job
; /* Job information */
8429 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8430 uri
->values
[0].string
.text
);
8433 * See if we have a job URI or a printer URI...
8436 if (!strcmp(uri
->name
, "printer-uri"))
8439 * Got a printer URI; see if we also have a job-id attribute...
8442 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8443 IPP_TAG_INTEGER
)) == NULL
)
8445 send_ipp_status(con
, IPP_BAD_REQUEST
,
8446 _("Got a printer-uri attribute but no job-id"));
8450 jobid
= attr
->values
[0].integer
;
8455 * Got a job URI; parse it to get the job ID...
8458 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8459 sizeof(scheme
), username
, sizeof(username
), host
,
8460 sizeof(host
), &port
, resource
, sizeof(resource
));
8462 if (strncmp(resource
, "/jobs/", 6))
8468 send_ipp_status(con
, IPP_BAD_REQUEST
,
8469 _("Bad job-uri attribute \"%s\""),
8470 uri
->values
[0].string
.text
);
8474 jobid
= atoi(resource
+ 6);
8478 * See if the job exists...
8481 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8484 * Nope - return a "not found" error...
8487 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
8492 * See if the job is owned by the requesting user...
8495 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8497 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8498 cupsdFindDest(job
->dest
));
8503 * Hold the job and return...
8506 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8507 IPP_TAG_KEYWORD
)) == NULL
)
8508 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8512 when
= attr
->values
[0].string
.text
;
8514 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8515 "Job job-hold-until value changed by user.");
8518 when
= "indefinite";
8520 cupsdSetJobHoldUntil(job
, when
, 1);
8521 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8524 con
->response
->request
.status
.status_code
= IPP_OK
;
8529 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8533 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8534 ipp_attribute_t
*uri
) /* I - Printer URI */
8536 http_status_t status
; /* Policy status */
8537 cups_ptype_t dtype
; /* Destination type (printer/class) */
8538 cupsd_printer_t
*printer
; /* Printer data */
8541 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8542 con
->http
.fd
, uri
->values
[0].string
.text
);
8545 * Is the destination valid?
8548 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8554 send_ipp_status(con
, IPP_NOT_FOUND
,
8555 _("The printer or class was not found."));
8563 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8565 send_http_error(con
, status
, printer
);
8570 * Hold pending/new jobs sent to the printer...
8573 printer
->holding_new_jobs
= 1;
8575 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8576 cupsdAddPrinterHistory(printer
);
8578 if (dtype
& CUPS_PRINTER_CLASS
)
8579 cupsdLogMessage(CUPSD_LOG_INFO
,
8580 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8581 printer
->name
, get_username(con
));
8583 cupsdLogMessage(CUPSD_LOG_INFO
,
8584 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8585 printer
->name
, get_username(con
));
8588 * Everything was ok, so return OK status...
8591 con
->response
->request
.status
.status_code
= IPP_OK
;
8596 * 'move_job()' - Move a job to a new destination.
8600 move_job(cupsd_client_t
*con
, /* I - Client connection */
8601 ipp_attribute_t
*uri
) /* I - Job URI */
8603 http_status_t status
; /* Policy status */
8604 ipp_attribute_t
*attr
; /* Current attribute */
8605 int jobid
; /* Job ID */
8606 cupsd_job_t
*job
; /* Current job */
8607 const char *src
; /* Source printer/class */
8608 cups_ptype_t stype
, /* Source type (printer or class) */
8609 dtype
; /* Destination type (printer/class) */
8610 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8611 username
[HTTP_MAX_URI
], /* Username portion of URI */
8612 host
[HTTP_MAX_URI
], /* Host portion of URI */
8613 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8614 int port
; /* Port portion of URI */
8615 cupsd_printer_t
*sprinter
, /* Source printer */
8616 *dprinter
; /* Destination printer */
8619 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8620 uri
->values
[0].string
.text
);
8623 * Get the new printer or class...
8626 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8627 IPP_TAG_URI
)) == NULL
)
8630 * Need job-printer-uri...
8633 send_ipp_status(con
, IPP_BAD_REQUEST
,
8634 _("job-printer-uri attribute missing"));
8638 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8644 send_ipp_status(con
, IPP_NOT_FOUND
,
8645 _("The printer or class was not found."));
8650 * See if we have a job URI or a printer URI...
8653 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8654 sizeof(scheme
), username
, sizeof(username
), host
,
8655 sizeof(host
), &port
, resource
, sizeof(resource
));
8657 if (!strcmp(uri
->name
, "printer-uri"))
8660 * Got a printer URI; see if we also have a job-id attribute...
8663 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8664 IPP_TAG_INTEGER
)) == NULL
)
8670 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8671 &sprinter
)) == NULL
)
8677 send_ipp_status(con
, IPP_NOT_FOUND
,
8678 _("The printer or class was not found."));
8687 * Otherwise, just move a single job...
8690 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8693 * Nope - return a "not found" error...
8696 send_ipp_status(con
, IPP_NOT_FOUND
,
8697 _("Job #%d does not exist"), attr
->values
[0].integer
);
8703 * Job found, initialize source pointers...
8714 * Got a job URI; parse it to get the job ID...
8717 if (strncmp(resource
, "/jobs/", 6))
8723 send_ipp_status(con
, IPP_BAD_REQUEST
,
8724 _("Bad job-uri attribute \"%s\""),
8725 uri
->values
[0].string
.text
);
8730 * See if the job exists...
8733 jobid
= atoi(resource
+ 6);
8735 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8738 * Nope - return a "not found" error...
8741 send_ipp_status(con
, IPP_NOT_FOUND
,
8742 _("Job #%d does not exist"), jobid
);
8748 * Job found, initialize source pointers...
8757 * Check the policy of the destination printer...
8760 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8761 job
? job
->username
: NULL
)) != HTTP_OK
)
8763 send_http_error(con
, status
, dprinter
);
8768 * Now move the job or jobs...
8774 * See if the job has been completed...
8777 if (job
->state_value
> IPP_JOB_STOPPED
)
8780 * Return a "not-possible" error...
8783 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8784 _("Job #%d is finished and cannot be altered"),
8790 * See if the job is owned by the requesting user...
8793 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8795 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8796 cupsdFindDest(job
->dest
));
8801 * Move the job to a different printer or class...
8804 cupsdMoveJob(job
, dprinter
);
8809 * Got the source printer, now look through the jobs...
8812 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8814 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8817 * See if the job is pointing at the source printer or has not been
8821 if (strcasecmp(job
->dest
, src
) ||
8822 job
->state_value
> IPP_JOB_STOPPED
)
8826 * See if the job can be moved by the requesting user...
8829 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8833 * Move the job to a different printer or class...
8836 cupsdMoveJob(job
, dprinter
);
8841 * Start jobs if possible...
8847 * Return with "everything is OK" status...
8850 con
->response
->request
.status
.status_code
= IPP_OK
;
8855 * 'ppd_parse_line()' - Parse a PPD default line.
8858 static int /* O - 0 on success, -1 on failure */
8859 ppd_parse_line(const char *line
, /* I - Line */
8860 char *option
, /* O - Option name */
8861 int olen
, /* I - Size of option name */
8862 char *choice
, /* O - Choice name */
8863 int clen
) /* I - Size of choice name */
8866 * Verify this is a default option line...
8869 if (strncmp(line
, "*Default", 8))
8873 * Read the option name...
8876 for (line
+= 8, olen
--;
8877 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8888 * Skip everything else up to the colon (:)...
8891 while (*line
&& *line
!= ':')
8900 * Now grab the option choice, skipping leading whitespace...
8903 while (isspace(*line
& 255))
8907 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8918 * Return with no errors...
8926 * 'print_job()' - Print a file to a printer or class.
8930 print_job(cupsd_client_t
*con
, /* I - Client connection */
8931 ipp_attribute_t
*uri
) /* I - Printer URI */
8933 ipp_attribute_t
*attr
; /* Current attribute */
8934 ipp_attribute_t
*format
; /* Document-format attribute */
8935 const char *default_format
; /* document-format-default value */
8936 cupsd_job_t
*job
; /* New job */
8937 char filename
[1024]; /* Job filename */
8938 mime_type_t
*filetype
; /* Type of file */
8939 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8940 type
[MIME_MAX_TYPE
], /* Subtype of file */
8941 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8942 /* Textual name of mime type */
8943 cupsd_printer_t
*printer
; /* Printer data */
8944 struct stat fileinfo
; /* File information */
8945 int kbytes
; /* Size of file */
8946 int compression
; /* Document compression */
8949 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8950 uri
->values
[0].string
.text
);
8953 * Validate print file attributes, for now just document-format and
8954 * compression (CUPS only supports "none" and "gzip")...
8957 compression
= CUPS_FILE_NONE
;
8959 if ((attr
= ippFindAttribute(con
->request
, "compression",
8960 IPP_TAG_KEYWORD
)) != NULL
)
8962 if (strcmp(attr
->values
[0].string
.text
, "none")
8964 && strcmp(attr
->values
[0].string
.text
, "gzip")
8965 #endif /* HAVE_LIBZ */
8968 send_ipp_status(con
, IPP_ATTRIBUTES
,
8969 _("Unsupported compression \"%s\""),
8970 attr
->values
[0].string
.text
);
8971 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8972 "compression", NULL
, attr
->values
[0].string
.text
);
8977 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8978 compression
= CUPS_FILE_GZIP
;
8979 #endif /* HAVE_LIBZ */
8983 * Do we have a file to print?
8988 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
8993 * Is the destination valid?
8996 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
9002 send_ipp_status(con
, IPP_NOT_FOUND
,
9003 _("The printer or class was not found."));
9008 * Is it a format we support?
9011 if ((format
= ippFindAttribute(con
->request
, "document-format",
9012 IPP_TAG_MIMETYPE
)) != NULL
)
9015 * Grab format from client...
9018 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9021 send_ipp_status(con
, IPP_BAD_REQUEST
,
9022 _("Could not scan type \"%s\""),
9023 format
->values
[0].string
.text
);
9027 else if ((default_format
= cupsGetOption("document-format",
9028 printer
->num_options
,
9029 printer
->options
)) != NULL
)
9032 * Use default document format...
9035 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9037 send_ipp_status(con
, IPP_BAD_REQUEST
,
9038 _("Could not scan type \"%s\""),
9049 strcpy(super
, "application");
9050 strcpy(type
, "octet-stream");
9053 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9056 * Auto-type the file...
9059 ipp_attribute_t
*doc_name
; /* document-name attribute */
9062 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9064 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9065 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9066 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9070 filetype
= mimeType(MimeDatabase
, super
, type
);
9072 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9073 filetype
->super
, filetype
->type
);
9076 filetype
= mimeType(MimeDatabase
, super
, type
);
9080 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9083 * Replace the document-format attribute value with the auto-typed or
9087 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9092 _cupsStrFree(format
->values
[0].string
.text
);
9094 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9097 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9098 "document-format", NULL
, mimetype
);
9102 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9103 _("Unsupported format \'%s/%s\'"), super
, type
);
9104 cupsdLogMessage(CUPSD_LOG_INFO
,
9105 "Hint: Do you have the raw file printing rules enabled?");
9108 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9109 "document-format", NULL
, format
->values
[0].string
.text
);
9115 * Read any embedded job ticket info from PS files...
9118 if (!strcasecmp(filetype
->super
, "application") &&
9119 (!strcasecmp(filetype
->type
, "postscript") ||
9120 !strcasecmp(filetype
->type
, "pdf")))
9121 read_job_ticket(con
);
9124 * Create the job object...
9127 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9131 * Update quota data...
9134 if (stat(con
->filename
, &fileinfo
))
9137 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9139 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9141 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9142 IPP_TAG_INTEGER
)) != NULL
)
9143 attr
->values
[0].integer
+= kbytes
;
9146 * Add the job file...
9149 if (add_file(con
, job
, filetype
, compression
))
9152 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9154 rename(con
->filename
, filename
);
9155 cupsdClearString(&con
->filename
);
9158 * See if we need to add the ending sheet...
9161 if (cupsdTimeoutJob(job
))
9165 * Log and save the job...
9168 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9169 "File of type %s/%s queued by \"%s\".",
9170 filetype
->super
, filetype
->type
, job
->username
);
9171 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9172 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9173 job
->dest
, job
->username
);
9176 * Start the job if possible...
9184 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9186 * This function only gets called when printing a single PDF or PostScript
9187 * file using the Print-Job operation. It doesn't work for Create-Job +
9188 * Send-File, since the job attributes need to be set at job creation
9189 * time for banners to work. The embedded job ticket stuff is here
9190 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9191 * options and IPP attributes which otherwise would be lost.
9193 * The format of a job ticket is simple:
9195 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9197 * %cupsJobTicket: attr1=value1
9198 * %cupsJobTicket: attr2=value2
9200 * %cupsJobTicket: attrN=valueN
9202 * Job ticket lines must appear immediately after the first line that
9203 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9204 * stops looking for job ticket info when it finds a line that does not begin
9205 * with "%cupsJobTicket:".
9207 * The maximum length of a job ticket line, including the prefix, is
9208 * 255 characters to conform with the Adobe DSC.
9210 * Read-only attributes are rejected with a notice to the error log in
9211 * case a malicious user tries anything. Since the job ticket is read
9212 * prior to attribute validation in print_job(), job ticket attributes
9213 * will go through the same validation as IPP attributes...
9217 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9219 cups_file_t
*fp
; /* File to read from */
9220 char line
[256]; /* Line data */
9221 int num_options
; /* Number of options */
9222 cups_option_t
*options
; /* Options */
9223 ipp_t
*ticket
; /* New attributes */
9224 ipp_attribute_t
*attr
, /* Current attribute */
9225 *attr2
, /* Job attribute */
9226 *prev2
; /* Previous job attribute */
9230 * First open the print file...
9233 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9235 cupsdLogMessage(CUPSD_LOG_ERROR
,
9236 "Unable to open print file for job ticket - %s",
9242 * Skip the first line...
9245 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9247 cupsdLogMessage(CUPSD_LOG_ERROR
,
9248 "Unable to read from print file for job ticket - %s",
9254 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9257 * Not a DSC-compliant file, so no job ticket info will be available...
9265 * Read job ticket info from the file...
9271 while (cupsFileGets(fp
, line
, sizeof(line
)))
9274 * Stop at the first non-ticket line...
9277 if (strncmp(line
, "%cupsJobTicket:", 15))
9281 * Add the options to the option array...
9284 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9288 * Done with the file; see if we have any options...
9293 if (num_options
== 0)
9297 * OK, convert the options to an attribute list, and apply them to
9302 cupsEncodeOptions(ticket
, num_options
, options
);
9305 * See what the user wants to change.
9308 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9310 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9313 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9314 !strcmp(attr
->name
, "job-originating-user-name") ||
9315 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9316 !strcmp(attr
->name
, "job-k-octets") ||
9317 !strcmp(attr
->name
, "job-id") ||
9318 !strncmp(attr
->name
, "job-state", 9) ||
9319 !strncmp(attr
->name
, "time-at-", 8))
9320 continue; /* Read-only attrs */
9322 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9323 IPP_TAG_ZERO
)) != NULL
)
9326 * Some other value; first free the old value...
9329 if (con
->request
->attrs
== attr2
)
9331 con
->request
->attrs
= attr2
->next
;
9336 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9337 if (prev2
->next
== attr2
)
9339 prev2
->next
= attr2
->next
;
9344 if (con
->request
->last
== attr2
)
9345 con
->request
->last
= prev2
;
9347 _ippFreeAttr(attr2
);
9351 * Add new option by copying it...
9354 copy_attribute(con
->request
, attr
, 0);
9358 * Then free the attribute list and option array...
9362 cupsFreeOptions(num_options
, options
);
9367 * 'reject_jobs()' - Reject print jobs to a printer.
9371 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9372 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9374 http_status_t status
; /* Policy status */
9375 cups_ptype_t dtype
; /* Destination type (printer/class) */
9376 cupsd_printer_t
*printer
; /* Printer data */
9377 ipp_attribute_t
*attr
; /* printer-state-message text */
9380 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9381 con
->http
.fd
, uri
->values
[0].string
.text
);
9384 * Is the destination valid?
9387 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9393 send_ipp_status(con
, IPP_NOT_FOUND
,
9394 _("The printer or class was not found."));
9402 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9404 send_http_error(con
, status
, printer
);
9409 * Reject jobs sent to the printer...
9412 printer
->accepting
= 0;
9414 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9415 IPP_TAG_TEXT
)) == NULL
)
9416 strcpy(printer
->state_message
, "Rejecting Jobs");
9418 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9419 sizeof(printer
->state_message
));
9421 cupsdAddPrinterHistory(printer
);
9423 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9424 "No longer accepting jobs.");
9426 if (dtype
& CUPS_PRINTER_CLASS
)
9428 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9430 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9431 printer
->name
, get_username(con
));
9435 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9437 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9438 printer
->name
, get_username(con
));
9442 * Everything was ok, so return OK status...
9445 con
->response
->request
.status
.status_code
= IPP_OK
;
9450 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9454 release_held_new_jobs(
9455 cupsd_client_t
*con
, /* I - Connection */
9456 ipp_attribute_t
*uri
) /* I - Printer URI */
9458 http_status_t status
; /* Policy status */
9459 cups_ptype_t dtype
; /* Destination type (printer/class) */
9460 cupsd_printer_t
*printer
; /* Printer data */
9463 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9464 con
->http
.fd
, uri
->values
[0].string
.text
);
9467 * Is the destination valid?
9470 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9476 send_ipp_status(con
, IPP_NOT_FOUND
,
9477 _("The printer or class was not found."));
9485 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9487 send_http_error(con
, status
, printer
);
9492 * Hold pending/new jobs sent to the printer...
9495 printer
->holding_new_jobs
= 0;
9497 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9498 cupsdAddPrinterHistory(printer
);
9500 if (dtype
& CUPS_PRINTER_CLASS
)
9501 cupsdLogMessage(CUPSD_LOG_INFO
,
9502 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9503 printer
->name
, get_username(con
));
9505 cupsdLogMessage(CUPSD_LOG_INFO
,
9506 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9507 printer
->name
, get_username(con
));
9510 * Everything was ok, so return OK status...
9513 con
->response
->request
.status
.status_code
= IPP_OK
;
9518 * 'release_job()' - Release a held print job.
9522 release_job(cupsd_client_t
*con
, /* I - Client connection */
9523 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9525 ipp_attribute_t
*attr
; /* Current attribute */
9526 int jobid
; /* Job ID */
9527 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9528 username
[HTTP_MAX_URI
], /* Username portion of URI */
9529 host
[HTTP_MAX_URI
], /* Host portion of URI */
9530 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9531 int port
; /* Port portion of URI */
9532 cupsd_job_t
*job
; /* Job information */
9535 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9536 con
->http
.fd
, uri
->values
[0].string
.text
);
9539 * See if we have a job URI or a printer URI...
9542 if (!strcmp(uri
->name
, "printer-uri"))
9545 * Got a printer URI; see if we also have a job-id attribute...
9548 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9549 IPP_TAG_INTEGER
)) == NULL
)
9551 send_ipp_status(con
, IPP_BAD_REQUEST
,
9552 _("Got a printer-uri attribute but no job-id"));
9556 jobid
= attr
->values
[0].integer
;
9561 * Got a job URI; parse it to get the job ID...
9564 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9565 sizeof(scheme
), username
, sizeof(username
), host
,
9566 sizeof(host
), &port
, resource
, sizeof(resource
));
9568 if (strncmp(resource
, "/jobs/", 6))
9574 send_ipp_status(con
, IPP_BAD_REQUEST
,
9575 _("Bad job-uri attribute \"%s\""),
9576 uri
->values
[0].string
.text
);
9580 jobid
= atoi(resource
+ 6);
9584 * See if the job exists...
9587 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9590 * Nope - return a "not found" error...
9593 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9598 * See if job is "held"...
9601 if (job
->state_value
!= IPP_JOB_HELD
)
9604 * Nope - return a "not possible" error...
9607 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held"), jobid
);
9612 * See if the job is owned by the requesting user...
9615 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9617 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9618 cupsdFindDest(job
->dest
));
9623 * Reset the job-hold-until value to "no-hold"...
9626 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9627 IPP_TAG_KEYWORD
)) == NULL
)
9628 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9632 _cupsStrFree(attr
->values
[0].string
.text
);
9634 attr
->value_tag
= IPP_TAG_KEYWORD
;
9635 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9637 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9638 "Job job-hold-until value changed by user.");
9642 * Release the job and return...
9645 cupsdReleaseJob(job
);
9647 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9648 "Job released by user.");
9650 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9652 con
->response
->request
.status
.status_code
= IPP_OK
;
9659 * 'renew_subscription()' - Renew an existing subscription...
9664 cupsd_client_t
*con
, /* I - Client connection */
9665 int sub_id
) /* I - Subscription ID */
9667 http_status_t status
; /* Policy status */
9668 cupsd_subscription_t
*sub
; /* Subscription */
9669 ipp_attribute_t
*lease
; /* notify-lease-duration */
9672 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9673 "renew_subscription(con=%p[%d], sub_id=%d)",
9674 con
, con
->http
.fd
, sub_id
);
9677 * Is the subscription ID valid?
9680 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9683 * Bad subscription ID...
9686 send_ipp_status(con
, IPP_NOT_FOUND
,
9687 _("notify-subscription-id %d no good"), sub_id
);
9694 * Job subscriptions cannot be renewed...
9697 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9698 _("Job subscriptions cannot be renewed"));
9706 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9708 con
, sub
->owner
)) != HTTP_OK
)
9710 send_http_error(con
, status
, sub
->dest
);
9715 * Renew the subscription...
9718 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9721 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9723 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9725 cupsdLogMessage(CUPSD_LOG_INFO
,
9726 "renew_subscription: Limiting notify-lease-duration to "
9729 sub
->lease
= MaxLeaseDuration
;
9732 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9734 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9736 con
->response
->request
.status
.status_code
= IPP_OK
;
9738 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9739 "notify-lease-duration", sub
->lease
);
9744 * 'restart_job()' - Restart an old print job.
9748 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9749 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9751 ipp_attribute_t
*attr
; /* Current attribute */
9752 int jobid
; /* Job ID */
9753 cupsd_job_t
*job
; /* Job information */
9754 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9755 username
[HTTP_MAX_URI
], /* Username portion of URI */
9756 host
[HTTP_MAX_URI
], /* Host portion of URI */
9757 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9758 int port
; /* Port portion of URI */
9761 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9762 con
->http
.fd
, uri
->values
[0].string
.text
);
9765 * See if we have a job URI or a printer URI...
9768 if (!strcmp(uri
->name
, "printer-uri"))
9771 * Got a printer URI; see if we also have a job-id attribute...
9774 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9775 IPP_TAG_INTEGER
)) == NULL
)
9777 send_ipp_status(con
, IPP_BAD_REQUEST
,
9778 _("Got a printer-uri attribute but no job-id"));
9782 jobid
= attr
->values
[0].integer
;
9787 * Got a job URI; parse it to get the job ID...
9790 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9791 sizeof(scheme
), username
, sizeof(username
), host
,
9792 sizeof(host
), &port
, resource
, sizeof(resource
));
9794 if (strncmp(resource
, "/jobs/", 6))
9800 send_ipp_status(con
, IPP_BAD_REQUEST
,
9801 _("Bad job-uri attribute \"%s\""),
9802 uri
->values
[0].string
.text
);
9806 jobid
= atoi(resource
+ 6);
9810 * See if the job exists...
9813 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9816 * Nope - return a "not found" error...
9819 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9824 * See if job is in any of the "completed" states...
9827 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9830 * Nope - return a "not possible" error...
9833 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete"),
9839 * See if we have retained the job files...
9844 if (!job
->attrs
|| job
->num_files
== 0)
9847 * Nope - return a "not possible" error...
9850 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9851 _("Job #%d cannot be restarted - no files"), jobid
);
9856 * See if the job is owned by the requesting user...
9859 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9861 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9862 cupsdFindDest(job
->dest
));
9867 * See if the job-hold-until attribute is specified...
9870 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9871 IPP_TAG_KEYWORD
)) == NULL
)
9872 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9874 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9877 * Return the job to a held state...
9880 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9881 "Restarted by \"%s\" with job-hold-until=%s.",
9882 username
, attr
->values
[0].string
.text
);
9883 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9885 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9886 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9887 attr
->values
[0].string
.text
);
9892 * Restart the job...
9895 cupsdRestartJob(job
);
9899 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9901 con
->response
->request
.status
.status_code
= IPP_OK
;
9906 * 'save_auth_info()' - Save authentication information for a job.
9911 cupsd_client_t
*con
, /* I - Client connection */
9912 cupsd_job_t
*job
, /* I - Job */
9913 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9915 int i
; /* Looping var */
9916 char filename
[1024]; /* Job authentication filename */
9917 cups_file_t
*fp
; /* Job authentication file */
9918 char line
[2048]; /* Line for file */
9919 cupsd_printer_t
*dest
; /* Destination printer/class */
9923 * This function saves the in-memory authentication information for
9924 * a job so that it can be used to authenticate with a remote host.
9925 * The information is stored in a file that is readable only by the
9926 * root user. The fields are Base-64 encoded, each on a separate line,
9927 * followed by random number (up to 1024) of newlines to limit the
9928 * amount of information that is exposed.
9930 * Because of the potential for exposing of authentication information,
9931 * this functionality is only enabled when running cupsd as root.
9933 * This caching only works for the Basic and BasicDigest authentication
9934 * types. Digest authentication cannot be cached this way, and in
9935 * the future Kerberos authentication may make all of this obsolete.
9937 * Authentication information is saved whenever an authenticated
9938 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9941 * This information is deleted after a job is completed or canceled,
9942 * so reprints may require subsequent re-authentication.
9948 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9952 * Create the authentication file and change permissions...
9955 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9956 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9958 cupsdLogMessage(CUPSD_LOG_ERROR
,
9959 "Unable to save authentication info to \"%s\" - %s",
9960 filename
, strerror(errno
));
9964 fchown(cupsFileNumber(fp
), 0, 0);
9965 fchmod(cupsFileNumber(fp
), 0400);
9967 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9970 * Write 1 to 3 auth values...
9973 cupsdClearString(&job
->auth_username
);
9974 cupsdClearString(&job
->auth_domain
);
9975 cupsdClearString(&job
->auth_password
);
9977 for (i
= 0; i
< auth_info
->num_values
; i
++)
9979 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9980 strlen(auth_info
->values
[i
].string
.text
));
9981 cupsFilePrintf(fp
, "%s\n", line
);
9983 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9984 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9985 auth_info
->values
[i
].string
.text
);
9986 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9987 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9988 auth_info
->values
[i
].string
.text
);
9989 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9990 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9991 auth_info
->values
[i
].string
.text
);
9994 else if (con
->username
[0])
9997 * Write the authenticated username...
10000 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
10001 cupsFilePrintf(fp
, "%s\n", line
);
10003 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
10004 cupsdClearString(&job
->auth_domain
);
10007 * Write the authenticated password...
10010 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10011 cupsFilePrintf(fp
, "%s\n", line
);
10013 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
10017 * Write a random number of newlines to the end of the file...
10020 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10021 cupsFilePutChar(fp
, '\n');
10024 * Close the file and return...
10029 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10030 # ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
10031 if (con
->have_gss
&&
10032 (con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
|| con
->gss_creds
))
10034 if (con
->have_gss
&& con
->gss_creds
)
10035 # endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
10036 save_krb5_creds(con
, job
);
10037 else if (job
->ccname
)
10038 cupsdClearString(&(job
->ccname
));
10039 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10043 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10045 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
10049 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
10050 cupsd_job_t
*job
) /* I - Job */
10053 * Get the credentials...
10056 job
->ccache
= cupsdCopyKrb5Creds(con
);
10059 * Add the KRB5CCNAME environment variable to the job so that the
10060 * backend can use the credentials when printing.
10065 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
10066 krb5_cc_get_name(KerberosContext
, job
->ccache
));
10068 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
10071 cupsdClearString(&(job
->ccname
));
10073 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10077 * 'send_document()' - Send a file to a printer or class.
10081 send_document(cupsd_client_t
*con
, /* I - Client connection */
10082 ipp_attribute_t
*uri
) /* I - Printer URI */
10084 ipp_attribute_t
*attr
; /* Current attribute */
10085 ipp_attribute_t
*format
; /* Request's document-format attribute */
10086 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10087 const char *default_format
;/* document-format-default value */
10088 int jobid
; /* Job ID number */
10089 cupsd_job_t
*job
; /* Current job */
10090 char job_uri
[HTTP_MAX_URI
],
10092 scheme
[HTTP_MAX_URI
],
10093 /* Method portion of URI */
10094 username
[HTTP_MAX_URI
],
10095 /* Username portion of URI */
10096 host
[HTTP_MAX_URI
],
10097 /* Host portion of URI */
10098 resource
[HTTP_MAX_URI
];
10099 /* Resource portion of URI */
10100 int port
; /* Port portion of URI */
10101 mime_type_t
*filetype
; /* Type of file */
10102 char super
[MIME_MAX_SUPER
],
10103 /* Supertype of file */
10104 type
[MIME_MAX_TYPE
],
10105 /* Subtype of file */
10106 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10107 /* Textual name of mime type */
10108 char filename
[1024]; /* Job filename */
10109 cupsd_printer_t
*printer
; /* Current printer */
10110 struct stat fileinfo
; /* File information */
10111 int kbytes
; /* Size of file */
10112 int compression
; /* Type of compression */
10113 int start_job
; /* Start the job? */
10116 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10117 con
->http
.fd
, uri
->values
[0].string
.text
);
10120 * See if we have a job URI or a printer URI...
10123 if (!strcmp(uri
->name
, "printer-uri"))
10126 * Got a printer URI; see if we also have a job-id attribute...
10129 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10130 IPP_TAG_INTEGER
)) == NULL
)
10132 send_ipp_status(con
, IPP_BAD_REQUEST
,
10133 _("Got a printer-uri attribute but no job-id"));
10137 jobid
= attr
->values
[0].integer
;
10142 * Got a job URI; parse it to get the job ID...
10145 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10146 sizeof(scheme
), username
, sizeof(username
), host
,
10147 sizeof(host
), &port
, resource
, sizeof(resource
));
10149 if (strncmp(resource
, "/jobs/", 6))
10155 send_ipp_status(con
, IPP_BAD_REQUEST
,
10156 _("Bad job-uri attribute \"%s\""),
10157 uri
->values
[0].string
.text
);
10161 jobid
= atoi(resource
+ 6);
10165 * See if the job exists...
10168 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10171 * Nope - return a "not found" error...
10174 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10178 printer
= cupsdFindDest(job
->dest
);
10181 * See if the job is owned by the requesting user...
10184 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10186 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10187 cupsdFindDest(job
->dest
));
10192 * OK, see if the client is sending the document compressed - CUPS
10193 * only supports "none" and "gzip".
10196 compression
= CUPS_FILE_NONE
;
10198 if ((attr
= ippFindAttribute(con
->request
, "compression",
10199 IPP_TAG_KEYWORD
)) != NULL
)
10201 if (strcmp(attr
->values
[0].string
.text
, "none")
10203 && strcmp(attr
->values
[0].string
.text
, "gzip")
10204 #endif /* HAVE_LIBZ */
10207 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\""),
10208 attr
->values
[0].string
.text
);
10209 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10210 "compression", NULL
, attr
->values
[0].string
.text
);
10215 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10216 compression
= CUPS_FILE_GZIP
;
10217 #endif /* HAVE_LIBZ */
10221 * Do we have a file to print?
10224 if (!con
->filename
)
10226 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
10231 * Is it a format we support?
10234 if ((format
= ippFindAttribute(con
->request
, "document-format",
10235 IPP_TAG_MIMETYPE
)) != NULL
)
10238 * Grab format from client...
10241 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10244 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
10245 format
->values
[0].string
.text
);
10249 else if ((default_format
= cupsGetOption("document-format",
10250 printer
->num_options
,
10251 printer
->options
)) != NULL
)
10254 * Use default document format...
10257 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10259 send_ipp_status(con
, IPP_BAD_REQUEST
,
10260 _("Could not scan type \"%s\""),
10268 * No document format attribute? Auto-type it!
10271 strcpy(super
, "application");
10272 strcpy(type
, "octet-stream");
10275 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10278 * Auto-type the file...
10281 ipp_attribute_t
*doc_name
; /* document-name attribute */
10284 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10286 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10287 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10288 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10292 filetype
= mimeType(MimeDatabase
, super
, type
);
10294 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10295 filetype
->super
, filetype
->type
);
10298 filetype
= mimeType(MimeDatabase
, super
, type
);
10303 * Replace the document-format attribute value with the auto-typed or
10307 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10310 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10311 IPP_TAG_MIMETYPE
)) != NULL
)
10313 _cupsStrFree(jformat
->values
[0].string
.text
);
10315 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10318 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10319 "document-format", NULL
, mimetype
);
10321 else if (!filetype
)
10323 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10324 _("Unsupported format \'%s/%s\'"), super
, type
);
10325 cupsdLogMessage(CUPSD_LOG_INFO
,
10326 "Hint: Do you have the raw file printing rules enabled?");
10329 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10330 "document-format", NULL
, format
->values
[0].string
.text
);
10335 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10337 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10340 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10341 _("Unsupported format \'%s\'"), mimetype
);
10343 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10344 "document-format", NULL
, mimetype
);
10350 * Add the file to the job...
10355 if (add_file(con
, job
, filetype
, compression
))
10358 if (stat(con
->filename
, &fileinfo
))
10361 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10363 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10365 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10366 IPP_TAG_INTEGER
)) != NULL
)
10367 attr
->values
[0].integer
+= kbytes
;
10369 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10371 rename(con
->filename
, filename
);
10373 cupsdClearString(&con
->filename
);
10375 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10376 filetype
->super
, filetype
->type
, job
->username
);
10379 * Start the job if this is the last document...
10382 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10383 IPP_TAG_BOOLEAN
)) != NULL
&&
10384 attr
->values
[0].boolean
)
10387 * See if we need to add the ending sheet...
10390 if (cupsdTimeoutJob(job
))
10393 if (job
->state_value
== IPP_JOB_STOPPED
)
10395 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10396 job
->state_value
= IPP_JOB_PENDING
;
10398 else if (job
->state_value
== IPP_JOB_HELD
)
10400 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10401 IPP_TAG_KEYWORD
)) == NULL
)
10402 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10404 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10406 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10407 job
->state_value
= IPP_JOB_PENDING
;
10412 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10418 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10419 IPP_TAG_KEYWORD
)) == NULL
)
10420 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10422 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10424 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10425 job
->state_value
= IPP_JOB_HELD
;
10426 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10429 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10436 * Fill in the response info...
10439 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10442 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10445 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10447 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10449 add_job_state_reasons(con
, job
);
10451 con
->response
->request
.status
.status_code
= IPP_OK
;
10454 * Start the job if necessary...
10463 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10468 cupsd_client_t
*con
, /* I - Client connection */
10469 http_status_t status
, /* I - HTTP status code */
10470 cupsd_printer_t
*printer
) /* I - Printer, if any */
10472 ipp_attribute_t
*uri
; /* Request URI, if any */
10475 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10476 IPP_TAG_URI
)) == NULL
)
10477 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10479 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10480 "Returning HTTP %s for %s (%s) from %s",
10481 httpStatus(status
),
10482 ippOpString(con
->request
->request
.op
.operation_id
),
10483 uri
? uri
->values
[0].string
.text
: "no URI",
10484 con
->http
.hostname
);
10488 int auth_type
; /* Type of authentication required */
10491 auth_type
= CUPSD_AUTH_NONE
;
10493 if (status
== HTTP_UNAUTHORIZED
&&
10494 printer
->num_auth_info_required
> 0 &&
10495 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10497 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10498 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10499 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10502 * Creating and authenticating jobs requires Kerberos...
10505 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10510 * Use policy/location-defined authentication requirements...
10513 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10514 cupsd_location_t
*auth
; /* Pointer to authentication element */
10517 if (printer
->type
& CUPS_PRINTER_CLASS
)
10518 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10520 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10522 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10523 auth
->type
== CUPSD_AUTH_NONE
)
10524 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10526 con
->request
->request
.op
.operation_id
:
10531 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10532 auth_type
= DefaultAuthType
;
10534 auth_type
= auth
->type
;
10538 cupsdSendError(con
, status
, auth_type
);
10541 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10543 ippDelete(con
->response
);
10544 con
->response
= NULL
;
10551 * 'send_ipp_status()' - Send a status back to the IPP client.
10555 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10556 ipp_status_t status
, /* I - IPP status code */
10557 const char *message
,/* I - Status message */
10558 ...) /* I - Additional args as needed */
10560 va_list ap
; /* Pointer to additional args */
10561 char formatted
[1024]; /* Formatted errror message */
10564 va_start(ap
, message
);
10565 vsnprintf(formatted
, sizeof(formatted
),
10566 _cupsLangString(con
->language
, message
), ap
);
10569 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10570 ippOpString(con
->request
->request
.op
.operation_id
),
10571 ippErrorString(status
), formatted
);
10573 con
->response
->request
.status
.status_code
= status
;
10575 if (ippFindAttribute(con
->response
, "attributes-charset",
10576 IPP_TAG_ZERO
) == NULL
)
10577 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10578 "attributes-charset", NULL
, "utf-8");
10580 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10581 IPP_TAG_ZERO
) == NULL
)
10582 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10583 "attributes-natural-language", NULL
, DefaultLanguage
);
10585 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10586 "status-message", NULL
, formatted
);
10591 * 'set_default()' - Set the default destination...
10595 set_default(cupsd_client_t
*con
, /* I - Client connection */
10596 ipp_attribute_t
*uri
) /* I - Printer URI */
10598 http_status_t status
; /* Policy status */
10599 cups_ptype_t dtype
; /* Destination type (printer/class) */
10600 cupsd_printer_t
*printer
, /* Printer */
10601 *oldprinter
; /* Old default printer */
10604 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10605 con
->http
.fd
, uri
->values
[0].string
.text
);
10608 * Is the destination valid?
10611 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10617 send_ipp_status(con
, IPP_NOT_FOUND
,
10618 _("The printer or class was not found."));
10626 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10628 send_http_error(con
, status
, NULL
);
10633 * Set it as the default...
10636 oldprinter
= DefaultPrinter
;
10637 DefaultPrinter
= printer
;
10640 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10641 "%s is no longer the default printer.", oldprinter
->name
);
10643 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10644 "%s is now the default printer.", printer
->name
);
10646 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10647 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10649 cupsdLogMessage(CUPSD_LOG_INFO
,
10650 "Default destination set to \"%s\" by \"%s\".",
10651 printer
->name
, get_username(con
));
10654 * Everything was ok, so return OK status...
10657 con
->response
->request
.status
.status_code
= IPP_OK
;
10662 * 'set_job_attrs()' - Set job attributes.
10666 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10667 ipp_attribute_t
*uri
) /* I - Job URI */
10669 ipp_attribute_t
*attr
, /* Current attribute */
10670 *attr2
; /* Job attribute */
10671 int jobid
; /* Job ID */
10672 cupsd_job_t
*job
; /* Current job */
10673 char scheme
[HTTP_MAX_URI
],
10674 /* Method portion of URI */
10675 username
[HTTP_MAX_URI
],
10676 /* Username portion of URI */
10677 host
[HTTP_MAX_URI
],
10678 /* Host portion of URI */
10679 resource
[HTTP_MAX_URI
];
10680 /* Resource portion of URI */
10681 int port
; /* Port portion of URI */
10682 int event
; /* Events? */
10683 int check_jobs
; /* Check jobs? */
10686 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10687 con
->http
.fd
, uri
->values
[0].string
.text
);
10690 * Start with "everything is OK" status...
10693 con
->response
->request
.status
.status_code
= IPP_OK
;
10696 * See if we have a job URI or a printer URI...
10699 if (!strcmp(uri
->name
, "printer-uri"))
10702 * Got a printer URI; see if we also have a job-id attribute...
10705 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10706 IPP_TAG_INTEGER
)) == NULL
)
10708 send_ipp_status(con
, IPP_BAD_REQUEST
,
10709 _("Got a printer-uri attribute but no job-id"));
10713 jobid
= attr
->values
[0].integer
;
10718 * Got a job URI; parse it to get the job ID...
10721 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10722 sizeof(scheme
), username
, sizeof(username
), host
,
10723 sizeof(host
), &port
, resource
, sizeof(resource
));
10725 if (strncmp(resource
, "/jobs/", 6))
10731 send_ipp_status(con
, IPP_BAD_REQUEST
,
10732 _("Bad job-uri attribute \"%s\""),
10733 uri
->values
[0].string
.text
);
10737 jobid
= atoi(resource
+ 6);
10741 * See if the job exists...
10744 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10747 * Nope - return a "not found" error...
10750 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10755 * See if the job has been completed...
10758 if (job
->state_value
> IPP_JOB_STOPPED
)
10761 * Return a "not-possible" error...
10764 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10765 _("Job #%d is finished and cannot be altered"), jobid
);
10770 * See if the job is owned by the requesting user...
10773 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10775 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10776 cupsdFindDest(job
->dest
));
10781 * See what the user wants to change.
10789 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10791 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10794 if (!strcmp(attr
->name
, "attributes-charset") ||
10795 !strcmp(attr
->name
, "attributes-natural-language") ||
10796 !strcmp(attr
->name
, "document-compression") ||
10797 !strcmp(attr
->name
, "document-format") ||
10798 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10799 !strcmp(attr
->name
, "job-document-access-errors") ||
10800 !strcmp(attr
->name
, "job-id") ||
10801 !strcmp(attr
->name
, "job-impressions-completed") ||
10802 !strcmp(attr
->name
, "job-k-octets") ||
10803 !strcmp(attr
->name
, "job-originating-host-name") ||
10804 !strcmp(attr
->name
, "job-originating-user-name") ||
10805 !strcmp(attr
->name
, "job-printer-up-time") ||
10806 !strcmp(attr
->name
, "job-printer-uri") ||
10807 !strcmp(attr
->name
, "job-sheets") ||
10808 !strcmp(attr
->name
, "job-state-message") ||
10809 !strcmp(attr
->name
, "job-state-reasons") ||
10810 !strcmp(attr
->name
, "job-uri") ||
10811 !strcmp(attr
->name
, "number-of-documents") ||
10812 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10813 !strcmp(attr
->name
, "output-device-assigned") ||
10814 !strncmp(attr
->name
, "date-time-at-", 13) ||
10815 !strncmp(attr
->name
, "job-k-octets", 12) ||
10816 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10817 !strncmp(attr
->name
, "time-at-", 8))
10823 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10824 _("%s cannot be changed."), attr
->name
);
10826 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10827 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10832 if (!strcmp(attr
->name
, "job-priority"))
10835 * Change the job priority...
10838 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10840 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value"));
10842 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10843 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10845 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10847 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10848 _("Job is completed and cannot be changed."));
10851 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10853 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10854 attr
->values
[0].integer
);
10855 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10858 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10859 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10862 else if (!strcmp(attr
->name
, "job-state"))
10865 * Change the job state...
10868 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10870 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value"));
10872 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10873 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10877 switch (attr
->values
[0].integer
)
10879 case IPP_JOB_PENDING
:
10880 case IPP_JOB_HELD
:
10881 if (job
->state_value
> IPP_JOB_HELD
)
10883 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10884 _("Job state cannot be changed."));
10887 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10889 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10890 attr
->values
[0].integer
);
10891 cupsdSetJobState(job
, attr
->values
[0].integer
,
10893 "Job state changed by \"%s\"", username
);
10898 case IPP_JOB_PROCESSING
:
10899 case IPP_JOB_STOPPED
:
10900 if (job
->state_value
!= attr
->values
[0].integer
)
10902 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10903 _("Job state cannot be changed."));
10908 case IPP_JOB_CANCELED
:
10909 case IPP_JOB_ABORTED
:
10910 case IPP_JOB_COMPLETED
:
10911 if (job
->state_value
> IPP_JOB_PROCESSING
)
10913 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10914 _("Job state cannot be changed."));
10917 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10919 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10920 attr
->values
[0].integer
);
10921 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10923 "Job state changed by \"%s\"", username
);
10930 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10932 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10933 IPP_TAG_ZERO
)) != NULL
)
10936 * Some other value; first free the old value...
10939 if (job
->attrs
->prev
)
10940 job
->attrs
->prev
->next
= attr2
->next
;
10942 job
->attrs
->attrs
= attr2
->next
;
10944 if (job
->attrs
->last
== attr2
)
10945 job
->attrs
->last
= job
->attrs
->prev
;
10947 _ippFreeAttr(attr2
);
10950 * Then copy the attribute...
10953 copy_attribute(job
->attrs
, attr
, 0);
10956 * See if the job-name or job-hold-until is being changed.
10959 if (!strcmp(attr
->name
, "job-hold-until"))
10961 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10962 attr
->values
[0].string
.text
);
10963 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10965 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10967 cupsdReleaseJob(job
);
10971 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10972 "Job held by \"%s\".", username
);
10974 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10977 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10980 * Delete the attribute...
10983 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10984 IPP_TAG_ZERO
)) != NULL
)
10986 if (job
->attrs
->prev
)
10987 job
->attrs
->prev
->next
= attr2
->next
;
10989 job
->attrs
->attrs
= attr2
->next
;
10991 if (attr2
== job
->attrs
->last
)
10992 job
->attrs
->last
= job
->attrs
->prev
;
10994 _ippFreeAttr(attr2
);
10996 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11002 * Add new option by copying it...
11005 copy_attribute(job
->attrs
, attr
, 0);
11007 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11016 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11019 * Send events as needed...
11022 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11023 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11024 cupsdFindDest(job
->dest
), job
,
11025 "Job priority changed by user.");
11027 if (event
& CUPSD_EVENT_JOB_STATE
)
11028 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11029 job
->state_value
== IPP_JOB_HELD
?
11030 "Job held by user." : "Job restarted by user.");
11032 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11033 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11034 "Job options changed by user.");
11037 * Start jobs if possible...
11046 * 'set_printer_attrs()' - Set printer attributes.
11050 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11051 ipp_attribute_t
*uri
) /* I - Printer */
11053 http_status_t status
; /* Policy status */
11054 cups_ptype_t dtype
; /* Destination type (printer/class) */
11055 cupsd_printer_t
*printer
; /* Printer/class */
11056 ipp_attribute_t
*attr
; /* Printer attribute */
11057 int changed
= 0; /* Was anything changed? */
11060 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11061 con
->http
.fd
, uri
->values
[0].string
.text
);
11064 * Is the destination valid?
11067 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11073 send_ipp_status(con
, IPP_NOT_FOUND
,
11074 _("The printer or class was not found."));
11082 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11084 send_http_error(con
, status
, printer
);
11089 * Return a list of attributes that can be set via Set-Printer-Attributes.
11092 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11093 IPP_TAG_TEXT
)) != NULL
)
11095 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11099 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11100 IPP_TAG_TEXT
)) != NULL
)
11102 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11107 * Update the printer attributes and return...
11112 cupsdSetPrinterAttrs(printer
);
11113 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11115 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11116 "Printer \"%s\" description or location changed by \"%s\".",
11117 printer
->name
, get_username(con
));
11119 cupsdLogMessage(CUPSD_LOG_INFO
,
11120 "Printer \"%s\" description or location changed by \"%s\".",
11121 printer
->name
, get_username(con
));
11124 con
->response
->request
.status
.status_code
= IPP_OK
;
11129 * 'set_printer_defaults()' - Set printer default options from a request.
11133 set_printer_defaults(
11134 cupsd_client_t
*con
, /* I - Client connection */
11135 cupsd_printer_t
*printer
) /* I - Printer */
11137 int i
; /* Looping var */
11138 ipp_attribute_t
*attr
; /* Current attribute */
11139 int namelen
; /* Length of attribute name */
11140 char name
[256], /* New attribute name */
11141 value
[256]; /* String version of integer attrs */
11144 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11147 * Skip non-printer attributes...
11150 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11153 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11155 if (!strcmp(attr
->name
, "job-sheets-default"))
11158 * Only allow keywords and names...
11161 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11165 * Only allow job-sheets-default to be set when running without a
11166 * system high classification level...
11169 if (Classification
)
11172 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11174 if (attr
->num_values
> 1)
11175 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11177 cupsdSetString(&printer
->job_sheets
[1], "none");
11179 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11181 cupsdFreePrinterUsers(printer
);
11183 printer
->deny_users
= 0;
11185 if (attr
->value_tag
== IPP_TAG_NAME
&&
11186 (attr
->num_values
> 1 ||
11187 strcmp(attr
->values
[0].string
.text
, "all")))
11189 for (i
= 0; i
< attr
->num_values
; i
++)
11190 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
11193 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11195 cupsdFreePrinterUsers(printer
);
11197 printer
->deny_users
= 1;
11199 if (attr
->value_tag
== IPP_TAG_NAME
&&
11200 (attr
->num_values
> 1 ||
11201 strcmp(attr
->values
[0].string
.text
, "none")))
11203 for (i
= 0; i
< attr
->num_values
; i
++)
11204 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
11207 else if (!strcmp(attr
->name
, "job-quota-period"))
11209 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11212 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11213 attr
->values
[0].integer
);
11214 cupsdFreeQuotas(printer
);
11216 printer
->quota_period
= attr
->values
[0].integer
;
11218 else if (!strcmp(attr
->name
, "job-k-limit"))
11220 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11223 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11224 attr
->values
[0].integer
);
11225 cupsdFreeQuotas(printer
);
11227 printer
->k_limit
= attr
->values
[0].integer
;
11229 else if (!strcmp(attr
->name
, "job-page-limit"))
11231 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11234 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11235 attr
->values
[0].integer
);
11236 cupsdFreeQuotas(printer
);
11238 printer
->page_limit
= attr
->values
[0].integer
;
11240 else if (!strcmp(attr
->name
, "printer-op-policy"))
11242 cupsd_policy_t
*p
; /* Policy */
11245 if (attr
->value_tag
!= IPP_TAG_NAME
)
11248 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11250 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11251 "Setting printer-op-policy to \"%s\"...",
11252 attr
->values
[0].string
.text
);
11253 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11254 printer
->op_policy_ptr
= p
;
11258 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11259 _("Unknown printer-op-policy \"%s\"."),
11260 attr
->values
[0].string
.text
);
11264 else if (!strcmp(attr
->name
, "printer-error-policy"))
11266 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11269 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11270 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
11271 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11272 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11273 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11275 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11276 _("Unknown printer-error-policy \"%s\"."),
11277 attr
->values
[0].string
.text
);
11281 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11282 "Setting printer-error-policy to \"%s\"...",
11283 attr
->values
[0].string
.text
);
11284 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11288 * Skip any other non-default attributes...
11291 namelen
= strlen(attr
->name
);
11292 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11293 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11297 * OK, anything else must be a user-defined default...
11300 strlcpy(name
, attr
->name
, sizeof(name
));
11301 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11303 switch (attr
->value_tag
)
11305 case IPP_TAG_DELETEATTR
:
11306 printer
->num_options
= cupsRemoveOption(name
,
11307 printer
->num_options
,
11308 &(printer
->options
));
11309 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11310 "Deleting %s", attr
->name
);
11313 case IPP_TAG_NAME
:
11314 case IPP_TAG_KEYWORD
:
11316 printer
->num_options
= cupsAddOption(name
,
11317 attr
->values
[0].string
.text
,
11318 printer
->num_options
,
11319 &(printer
->options
));
11320 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11321 "Setting %s to \"%s\"...", attr
->name
,
11322 attr
->values
[0].string
.text
);
11325 case IPP_TAG_BOOLEAN
:
11326 printer
->num_options
= cupsAddOption(name
,
11327 attr
->values
[0].boolean
?
11329 printer
->num_options
,
11330 &(printer
->options
));
11331 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11332 "Setting %s to %s...", attr
->name
,
11333 attr
->values
[0].boolean
? "true" : "false");
11336 case IPP_TAG_INTEGER
:
11337 case IPP_TAG_ENUM
:
11338 sprintf(value
, "%d", attr
->values
[0].integer
);
11339 printer
->num_options
= cupsAddOption(name
, value
,
11340 printer
->num_options
,
11341 &(printer
->options
));
11342 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11343 "Setting %s to %s...", attr
->name
, value
);
11346 case IPP_TAG_RANGE
:
11347 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11348 attr
->values
[0].range
.upper
);
11349 printer
->num_options
= cupsAddOption(name
, value
,
11350 printer
->num_options
,
11351 &(printer
->options
));
11352 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11353 "Setting %s to %s...", attr
->name
, value
);
11356 case IPP_TAG_RESOLUTION
:
11357 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11358 attr
->values
[0].resolution
.yres
,
11359 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11361 printer
->num_options
= cupsAddOption(name
, value
,
11362 printer
->num_options
,
11363 &(printer
->options
));
11364 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11365 "Setting %s to %s...", attr
->name
, value
);
11369 /* Do nothing for other values */
11377 * 'start_printer()' - Start a printer.
11381 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11382 ipp_attribute_t
*uri
) /* I - Printer URI */
11384 http_status_t status
; /* Policy status */
11385 cups_ptype_t dtype
; /* Destination type (printer/class) */
11386 cupsd_printer_t
*printer
; /* Printer data */
11389 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11390 con
->http
.fd
, uri
->values
[0].string
.text
);
11393 * Is the destination valid?
11396 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11402 send_ipp_status(con
, IPP_NOT_FOUND
,
11403 _("The printer or class was not found."));
11411 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11413 send_http_error(con
, status
, printer
);
11418 * Start the printer...
11421 printer
->state_message
[0] = '\0';
11423 cupsdStartPrinter(printer
, 1);
11425 if (dtype
& CUPS_PRINTER_CLASS
)
11426 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11427 printer
->name
, get_username(con
));
11429 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11430 printer
->name
, get_username(con
));
11435 * Everything was ok, so return OK status...
11438 con
->response
->request
.status
.status_code
= IPP_OK
;
11443 * 'stop_printer()' - Stop a printer.
11447 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11448 ipp_attribute_t
*uri
) /* I - Printer URI */
11450 http_status_t status
; /* Policy status */
11451 cups_ptype_t dtype
; /* Destination type (printer/class) */
11452 cupsd_printer_t
*printer
; /* Printer data */
11453 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11456 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11457 con
->http
.fd
, uri
->values
[0].string
.text
);
11460 * Is the destination valid?
11463 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11469 send_ipp_status(con
, IPP_NOT_FOUND
,
11470 _("The printer or class was not found."));
11478 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11480 send_http_error(con
, status
, printer
);
11485 * Stop the printer...
11488 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11489 IPP_TAG_TEXT
)) == NULL
)
11490 strcpy(printer
->state_message
, "Paused");
11493 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11494 sizeof(printer
->state_message
));
11497 cupsdStopPrinter(printer
, 1);
11499 if (dtype
& CUPS_PRINTER_CLASS
)
11500 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11501 printer
->name
, get_username(con
));
11503 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11504 printer
->name
, get_username(con
));
11507 * Everything was ok, so return OK status...
11510 con
->response
->request
.status
.status_code
= IPP_OK
;
11515 * 'url_encode_attr()' - URL-encode a string attribute.
11519 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11520 char *buffer
,/* I - String buffer */
11521 int bufsize
)/* I - Size of buffer */
11523 int i
; /* Looping var */
11524 char *bufptr
, /* Pointer into buffer */
11525 *bufend
; /* End of buffer */
11528 strlcpy(buffer
, attr
->name
, bufsize
);
11529 bufptr
= buffer
+ strlen(buffer
);
11530 bufend
= buffer
+ bufsize
- 1;
11532 for (i
= 0; i
< attr
->num_values
; i
++)
11534 if (bufptr
>= bufend
)
11542 if (bufptr
>= bufend
)
11547 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11548 bufptr
, bufend
- bufptr
+ 1);
11550 if (bufptr
>= bufend
)
11561 * 'url_encode_string()' - URL-encode a string.
11564 static char * /* O - End of string */
11565 url_encode_string(const char *s
, /* I - String */
11566 char *buffer
, /* I - String buffer */
11567 int bufsize
) /* I - Size of buffer */
11569 char *bufptr
, /* Pointer into buffer */
11570 *bufend
; /* End of buffer */
11571 static const char *hex
= "0123456789ABCDEF";
11576 bufend
= buffer
+ bufsize
- 1;
11578 while (*s
&& bufptr
< bufend
)
11580 if (*s
== ' ' || *s
== '%' || *s
== '+')
11582 if (bufptr
>= (bufend
- 2))
11586 *bufptr
++ = hex
[(*s
>> 4) & 15];
11587 *bufptr
++ = hex
[*s
& 15];
11591 else if (*s
== '\'' || *s
== '\\')
11593 if (bufptr
>= (bufend
- 1))
11610 * 'user_allowed()' - See if a user is allowed to print to a queue.
11613 static int /* O - 0 if not allowed, 1 if allowed */
11614 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11615 const char *username
) /* I - Username */
11617 int i
; /* Looping var */
11618 struct passwd
*pw
; /* User password data */
11619 char baseuser
[256], /* Base username */
11620 *baseptr
; /* Pointer to "@" in base username */
11623 if (p
->num_users
== 0)
11626 if (!strcmp(username
, "root"))
11629 if (strchr(username
, '@'))
11632 * Strip @REALM for username check...
11635 strlcpy(baseuser
, username
, sizeof(baseuser
));
11637 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11640 username
= baseuser
;
11643 pw
= getpwnam(username
);
11646 for (i
= 0; i
< p
->num_users
; i
++)
11648 if (p
->users
[i
][0] == '@')
11651 * Check group membership...
11654 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
11657 else if (p
->users
[i
][0] == '#')
11663 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
11666 else if (!strcasecmp(username
, p
->users
[i
]))
11670 return ((i
< p
->num_users
) != p
->deny_users
);
11675 * 'validate_job()' - Validate printer options and destination.
11679 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11680 ipp_attribute_t
*uri
) /* I - Printer URI */
11682 http_status_t status
; /* Policy status */
11683 ipp_attribute_t
*attr
; /* Current attribute */
11684 ipp_attribute_t
*format
; /* Document-format attribute */
11685 cups_ptype_t dtype
; /* Destination type (printer/class) */
11686 char super
[MIME_MAX_SUPER
],
11687 /* Supertype of file */
11688 type
[MIME_MAX_TYPE
];
11689 /* Subtype of file */
11690 cupsd_printer_t
*printer
; /* Printer */
11693 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11694 con
->http
.fd
, uri
->values
[0].string
.text
);
11697 * OK, see if the client is sending the document compressed - CUPS
11698 * doesn't support compression yet...
11701 if ((attr
= ippFindAttribute(con
->request
, "compression",
11702 IPP_TAG_KEYWORD
)) != NULL
&&
11703 !strcmp(attr
->values
[0].string
.text
, "none"))
11705 send_ipp_status(con
, IPP_ATTRIBUTES
,
11706 _("Unsupported compression attribute %s"),
11707 attr
->values
[0].string
.text
);
11708 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11709 "compression", NULL
, attr
->values
[0].string
.text
);
11714 * Is it a format we support?
11717 if ((format
= ippFindAttribute(con
->request
, "document-format",
11718 IPP_TAG_MIMETYPE
)) != NULL
)
11720 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11723 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
11724 format
->values
[0].string
.text
);
11728 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11729 !mimeType(MimeDatabase
, super
, type
))
11731 cupsdLogMessage(CUPSD_LOG_INFO
,
11732 "Hint: Do you have the raw file printing rules enabled?");
11733 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11734 _("Unsupported format \"%s\""),
11735 format
->values
[0].string
.text
);
11736 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11737 "document-format", NULL
, format
->values
[0].string
.text
);
11743 * Is the destination valid?
11746 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11752 send_ipp_status(con
, IPP_NOT_FOUND
,
11753 _("The printer or class was not found."));
11761 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11763 send_http_error(con
, status
, printer
);
11768 * Everything was ok, so return OK status...
11771 con
->response
->request
.status
.status_code
= IPP_OK
;
11776 * 'validate_name()' - Make sure the printer name only contains valid chars.
11779 static int /* O - 0 if name is no good, 1 if good */
11780 validate_name(const char *name
) /* I - Name to check */
11782 const char *ptr
; /* Pointer into name */
11786 * Scan the whole name...
11789 for (ptr
= name
; *ptr
; ptr
++)
11790 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11794 * All the characters are good; validate the length, too...
11797 return ((ptr
- name
) < 128);
11802 * 'validate_user()' - Validate the user for the request.
11805 static int /* O - 1 if permitted, 0 otherwise */
11806 validate_user(cupsd_job_t
*job
, /* I - Job */
11807 cupsd_client_t
*con
, /* I - Client connection */
11808 const char *owner
, /* I - Owner of job/resource */
11809 char *username
, /* O - Authenticated username */
11810 int userlen
) /* I - Length of username */
11812 cupsd_printer_t
*printer
; /* Printer for job */
11815 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11816 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11818 job
->id
, con
? con
->http
.fd
: 0,
11819 owner
? owner
: "(null)", username
, userlen
);
11822 * Validate input...
11825 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11829 * Get the best authenticated username that is available.
11832 strlcpy(username
, get_username(con
), userlen
);
11835 * Check the username against the owner...
11838 printer
= cupsdFindDest(job
->dest
);
11840 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11841 con
, owner
) == HTTP_OK
);
11846 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".