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 if (!cupsdLoadJob(job
))
848 printer
= cupsdFindDest(job
->dest
);
849 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
852 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
853 attr
&& attr
->num_values
> 1)
859 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
860 attr
->values
[1].string
.text
);
862 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
865 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
873 * 'accept_jobs()' - Accept print jobs to a printer.
877 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
878 ipp_attribute_t
*uri
) /* I - Printer or class URI */
880 http_status_t status
; /* Policy status */
881 cups_ptype_t dtype
; /* Destination type (printer/class) */
882 cupsd_printer_t
*printer
; /* Printer data */
885 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
886 con
->http
.fd
, uri
->values
[0].string
.text
);
889 * Is the destination valid?
892 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
898 send_ipp_status(con
, IPP_NOT_FOUND
,
899 _("The printer or class was not found."));
907 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
909 send_http_error(con
, status
, printer
);
914 * Accept jobs sent to the printer...
917 printer
->accepting
= 1;
918 printer
->state_message
[0] = '\0';
920 cupsdAddPrinterHistory(printer
);
922 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
923 "Now accepting jobs.");
925 if (dtype
& CUPS_PRINTER_CLASS
)
927 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
929 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
930 printer
->name
, get_username(con
));
934 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
936 cupsdLogMessage(CUPSD_LOG_INFO
,
937 "Printer \"%s\" now accepting jobs (\"%s\").",
938 printer
->name
, get_username(con
));
942 * Everything was ok, so return OK status...
945 con
->response
->request
.status
.status_code
= IPP_OK
;
950 * 'add_class()' - Add a class to the system.
954 add_class(cupsd_client_t
*con
, /* I - Client connection */
955 ipp_attribute_t
*uri
) /* I - URI of class */
957 http_status_t status
; /* Policy status */
958 int i
; /* Looping var */
959 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
960 username
[HTTP_MAX_URI
], /* Username portion of URI */
961 host
[HTTP_MAX_URI
], /* Host portion of URI */
962 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
963 int port
; /* Port portion of URI */
964 cupsd_printer_t
*pclass
, /* Class */
965 *member
; /* Member printer/class */
966 cups_ptype_t dtype
; /* Destination type */
967 ipp_attribute_t
*attr
; /* Printer attribute */
968 int modify
; /* Non-zero if we just modified */
969 char newname
[IPP_MAX_NAME
]; /* New class name */
970 int need_restart_job
; /* Need to restart job? */
973 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
974 con
->http
.fd
, uri
->values
[0].string
.text
);
977 * Do we have a valid URI?
980 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
981 sizeof(scheme
), username
, sizeof(username
), host
,
982 sizeof(host
), &port
, resource
, sizeof(resource
));
985 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
988 * No, return an error...
991 send_ipp_status(con
, IPP_BAD_REQUEST
,
992 _("The printer-uri must be of the form "
993 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
998 * Do we have a valid printer name?
1001 if (!validate_name(resource
+ 9))
1004 * No, return an error...
1007 send_ipp_status(con
, IPP_BAD_REQUEST
,
1008 _("The printer-uri \"%s\" contains invalid characters."),
1009 uri
->values
[0].string
.text
);
1014 * See if the class already exists; if not, create a new class...
1017 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
1020 * Class doesn't exist; see if we have a printer of the same name...
1023 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
1024 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
1027 * Yes, return an error...
1030 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1031 _("A printer named \"%s\" already exists"),
1037 * No, check the default policy and then add the class...
1040 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1042 send_http_error(con
, status
, NULL
);
1046 pclass
= cupsdAddClass(resource
+ 9);
1049 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1052 * Check the default policy, then rename the implicit class to "AnyClass"
1056 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1058 send_http_error(con
, status
, NULL
);
1062 if (ImplicitAnyClasses
)
1064 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1065 cupsdRenamePrinter(pclass
, newname
);
1068 cupsdDeletePrinter(pclass
, 1);
1071 * Add the class as a new local class...
1074 pclass
= cupsdAddClass(resource
+ 9);
1077 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1080 * Check the default policy, then rename the remote class to "Class"...
1083 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1085 send_http_error(con
, status
, NULL
);
1089 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1090 cupsdRenamePrinter(pclass
, newname
);
1093 * Add the class as a new local class...
1096 pclass
= cupsdAddClass(resource
+ 9);
1099 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1102 send_http_error(con
, status
, pclass
);
1109 * Look for attributes and copy them over as needed...
1112 need_restart_job
= 0;
1114 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1115 IPP_TAG_TEXT
)) != NULL
)
1116 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1118 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1119 IPP_TAG_TEXT
)) != NULL
)
1120 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1122 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1123 IPP_TAG_BOOLEAN
)) != NULL
&&
1124 attr
->values
[0].boolean
!= pclass
->accepting
)
1126 cupsdLogMessage(CUPSD_LOG_INFO
,
1127 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1128 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1130 pclass
->accepting
= attr
->values
[0].boolean
;
1131 cupsdAddPrinterHistory(pclass
);
1133 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1134 pclass
->accepting
? "Now" : "No longer");
1137 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1138 IPP_TAG_BOOLEAN
)) != NULL
)
1140 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1141 cupsdDeregisterPrinter(pclass
, 1);
1143 cupsdLogMessage(CUPSD_LOG_INFO
,
1144 "Setting %s printer-is-shared to %d (was %d.)",
1145 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1147 pclass
->shared
= attr
->values
[0].boolean
;
1150 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1151 IPP_TAG_ENUM
)) != NULL
)
1153 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1154 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1156 send_ipp_status(con
, IPP_BAD_REQUEST
,
1157 _("Attempt to set %s printer-state to bad value %d"),
1158 pclass
->name
, attr
->values
[0].integer
);
1162 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1163 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1165 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1166 cupsdStopPrinter(pclass
, 0);
1169 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1170 need_restart_job
= 1;
1173 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1174 IPP_TAG_TEXT
)) != NULL
)
1176 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1177 sizeof(pclass
->state_message
));
1178 cupsdAddPrinterHistory(pclass
);
1180 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1181 pclass
->state_message
);
1183 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1184 IPP_TAG_URI
)) != NULL
)
1187 * Clear the printer array as needed...
1190 need_restart_job
= 1;
1192 if (pclass
->num_printers
> 0)
1194 free(pclass
->printers
);
1195 pclass
->num_printers
= 0;
1199 * Add each printer or class that is listed...
1202 for (i
= 0; i
< attr
->num_values
; i
++)
1205 * Search for the printer or class URI...
1208 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1214 send_ipp_status(con
, IPP_NOT_FOUND
,
1215 _("The printer or class was not found."));
1218 else if (dtype
& CUPS_PRINTER_CLASS
)
1220 send_ipp_status(con
, IPP_BAD_REQUEST
,
1221 _("Nested classes are not allowed"));
1226 * Add it to the class...
1229 cupsdAddPrinterToClass(pclass
, member
);
1233 set_printer_defaults(con
, pclass
);
1235 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1236 IPP_TAG_KEYWORD
)) != NULL
)
1237 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1240 * Update the printer class attributes and return...
1243 cupsdSetPrinterAttrs(pclass
);
1244 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1246 if (need_restart_job
&& pclass
->job
)
1249 * Reset the current job to a "pending" status...
1252 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1253 "Job restarted because the class was modified.");
1256 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1260 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1261 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1262 pclass
->name
, get_username(con
));
1264 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1265 pclass
->name
, get_username(con
));
1269 cupsdAddPrinterHistory(pclass
);
1271 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1272 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1273 pclass
->name
, get_username(con
));
1275 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1276 pclass
->name
, get_username(con
));
1279 con
->response
->request
.status
.status_code
= IPP_OK
;
1284 * 'add_file()' - Add a file to a job.
1287 static int /* O - 0 on success, -1 on error */
1288 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1289 cupsd_job_t
*job
, /* I - Job to add to */
1290 mime_type_t
*filetype
, /* I - Type of file */
1291 int compression
) /* I - Compression */
1293 mime_type_t
**filetypes
; /* New filetypes array... */
1294 int *compressions
; /* New compressions array... */
1297 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1298 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1299 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1300 filetype
->super
, filetype
->type
, compression
);
1303 * Add the file to the job...
1306 if (job
->num_files
== 0)
1308 compressions
= (int *)malloc(sizeof(int));
1309 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1313 compressions
= (int *)realloc(job
->compressions
,
1314 (job
->num_files
+ 1) * sizeof(int));
1315 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1316 (job
->num_files
+ 1) *
1317 sizeof(mime_type_t
*));
1320 if (!compressions
|| !filetypes
)
1322 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1323 "Job aborted because the scheduler ran out of memory.");
1326 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1327 _("Unable to allocate memory for file types"));
1332 job
->compressions
= compressions
;
1333 job
->compressions
[job
->num_files
] = compression
;
1334 job
->filetypes
= filetypes
;
1335 job
->filetypes
[job
->num_files
] = filetype
;
1340 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1347 * 'add_job()' - Add a job to a print queue.
1350 static cupsd_job_t
* /* O - Job object */
1351 add_job(cupsd_client_t
*con
, /* I - Client connection */
1352 cupsd_printer_t
*printer
, /* I - Destination printer */
1353 mime_type_t
*filetype
) /* I - First print file type, if any */
1355 http_status_t status
; /* Policy status */
1356 ipp_attribute_t
*attr
, /* Current attribute */
1357 *auth_info
; /* auth-info attribute */
1358 const char *val
; /* Default option value */
1359 int priority
; /* Job priority */
1360 cupsd_job_t
*job
; /* Current job */
1361 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1362 int kbytes
; /* Size of print file */
1363 int i
; /* Looping var */
1364 int lowerpagerange
; /* Page range bound */
1365 int exact
; /* Did we have an exact match? */
1366 ipp_attribute_t
*media_col
, /* media-col attribute */
1367 *media_margin
; /* media-*-margin attribute */
1368 ipp_t
*unsup_col
; /* media-col in unsupported response */
1371 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1372 con
, con
->http
.fd
, printer
, printer
->name
,
1373 filetype
, filetype
? filetype
->super
: "none",
1374 filetype
? filetype
->type
: "none");
1377 * Check remote printing to non-shared printer...
1380 if (!printer
->shared
&&
1381 strcasecmp(con
->http
.hostname
, "localhost") &&
1382 strcasecmp(con
->http
.hostname
, ServerName
))
1384 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1385 _("The printer or class is not shared"));
1393 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1395 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1397 send_http_error(con
, status
, printer
);
1400 else if (printer
->num_auth_info_required
== 1 &&
1401 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1404 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1408 else if (auth_info
&& !con
->http
.tls
&&
1409 !httpAddrLocalhost(con
->http
.hostaddr
))
1412 * Require encryption of auth-info over non-local connections...
1415 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1418 #endif /* HAVE_SSL */
1421 * See if the printer is accepting jobs...
1424 if (!printer
->accepting
)
1426 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1427 _("Destination \"%s\" is not accepting jobs."),
1433 * Validate job template attributes; for now just document-format,
1434 * copies, number-up, and page-ranges...
1437 if (filetype
&& printer
->filetypes
&&
1438 !cupsArrayFind(printer
->filetypes
, filetype
))
1440 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1441 /* MIME media type string */
1444 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1447 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1448 _("Unsupported format \'%s\'"), mimetype
);
1450 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1451 "document-format", NULL
, mimetype
);
1456 if ((attr
= ippFindAttribute(con
->request
, "copies",
1457 IPP_TAG_INTEGER
)) != NULL
)
1459 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1461 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1462 attr
->values
[0].integer
);
1463 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1464 "copies", attr
->values
[0].integer
);
1469 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1470 IPP_TAG_ZERO
)) != NULL
)
1472 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1473 attr
->value_tag
!= IPP_TAG_NAME
)
1475 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type"));
1479 if (attr
->num_values
> 2)
1481 send_ipp_status(con
, IPP_BAD_REQUEST
,
1482 _("Too many job-sheets values (%d > 2)"),
1487 for (i
= 0; i
< attr
->num_values
; i
++)
1488 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1489 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1491 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\""),
1492 attr
->values
[i
].string
.text
);
1497 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1498 IPP_TAG_INTEGER
)) != NULL
)
1500 if (attr
->values
[0].integer
!= 1 &&
1501 attr
->values
[0].integer
!= 2 &&
1502 attr
->values
[0].integer
!= 4 &&
1503 attr
->values
[0].integer
!= 6 &&
1504 attr
->values
[0].integer
!= 9 &&
1505 attr
->values
[0].integer
!= 16)
1507 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1508 attr
->values
[0].integer
);
1509 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1510 "number-up", attr
->values
[0].integer
);
1515 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1516 IPP_TAG_RANGE
)) != NULL
)
1518 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1520 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1521 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1523 send_ipp_status(con
, IPP_BAD_REQUEST
,
1524 _("Bad page-ranges values %d-%d."),
1525 attr
->values
[i
].range
.lower
,
1526 attr
->values
[i
].range
.upper
);
1530 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1535 * Do media selection as needed...
1538 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1539 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1540 _pwgGetPageSize(printer
->pwg
, con
->request
, NULL
, &exact
))
1543 (media_col
= ippFindAttribute(con
->request
, "media-col",
1544 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1546 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1548 unsup_col
= ippNew();
1549 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1550 "media-bottom-margin",
1551 IPP_TAG_INTEGER
)) != NULL
)
1552 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1553 "media-bottom-margin", media_margin
->values
[0].integer
);
1555 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1556 "media-left-margin",
1557 IPP_TAG_INTEGER
)) != NULL
)
1558 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1559 "media-left-margin", media_margin
->values
[0].integer
);
1561 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1562 "media-right-margin",
1563 IPP_TAG_INTEGER
)) != NULL
)
1564 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1565 "media-right-margin", media_margin
->values
[0].integer
);
1567 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1569 IPP_TAG_INTEGER
)) != NULL
)
1570 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1571 "media-top-margin", media_margin
->values
[0].integer
);
1573 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1575 ippDelete(unsup_col
);
1580 * Make sure we aren't over our limit...
1583 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1586 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1588 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1589 _("Too many active jobs."));
1593 if ((i
= check_quotas(con
, printer
)) < 0)
1595 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1600 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1605 * Create the job and set things up...
1608 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1609 IPP_TAG_INTEGER
)) != NULL
)
1610 priority
= attr
->values
[0].integer
;
1613 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1614 printer
->options
)) != NULL
)
1615 priority
= atoi(val
);
1619 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1623 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1624 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1627 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1629 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1630 _("Unable to add job for destination \"%s\""),
1635 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1636 CUPS_PRINTER_REMOTE
);
1637 job
->attrs
= con
->request
;
1639 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1641 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1643 add_job_uuid(con
, job
);
1644 apply_printer_defaults(printer
, job
);
1646 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1648 if (con
->username
[0])
1650 cupsdSetString(&job
->username
, con
->username
);
1653 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1657 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1658 "add_job: requesting-user-name=\"%s\"",
1659 attr
->values
[0].string
.text
);
1661 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1664 cupsdSetString(&job
->username
, "anonymous");
1667 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1668 "job-originating-user-name", NULL
, job
->username
);
1671 attr
->group_tag
= IPP_TAG_JOB
;
1672 _cupsStrFree(attr
->name
);
1673 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1676 if (con
->username
[0] || auth_info
)
1678 save_auth_info(con
, job
, auth_info
);
1681 * Remove the auth-info attribute from the attribute data...
1685 ippDeleteAttribute(job
->attrs
, auth_info
);
1688 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1689 IPP_TAG_ZERO
)) != NULL
)
1692 * Request contains a job-originating-host-name attribute; validate it...
1695 if (attr
->value_tag
!= IPP_TAG_NAME
||
1696 attr
->num_values
!= 1 ||
1697 strcmp(con
->http
.hostname
, "localhost"))
1700 * Can't override the value if we aren't connected via localhost.
1701 * Also, we can only have 1 value and it must be a name value.
1704 switch (attr
->value_tag
)
1706 case IPP_TAG_STRING
:
1707 case IPP_TAG_TEXTLANG
:
1708 case IPP_TAG_NAMELANG
:
1711 case IPP_TAG_KEYWORD
:
1713 case IPP_TAG_URISCHEME
:
1714 case IPP_TAG_CHARSET
:
1715 case IPP_TAG_LANGUAGE
:
1716 case IPP_TAG_MIMETYPE
:
1718 * Free old strings...
1721 for (i
= 0; i
< attr
->num_values
; i
++)
1723 _cupsStrFree(attr
->values
[i
].string
.text
);
1724 attr
->values
[i
].string
.text
= NULL
;
1725 if (attr
->values
[i
].string
.charset
)
1727 _cupsStrFree(attr
->values
[i
].string
.charset
);
1728 attr
->values
[i
].string
.charset
= NULL
;
1737 * Use the default connection hostname instead...
1740 attr
->value_tag
= IPP_TAG_NAME
;
1741 attr
->num_values
= 1;
1742 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1745 attr
->group_tag
= IPP_TAG_JOB
;
1750 * No job-originating-host-name attribute, so use the hostname from
1754 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1755 "job-originating-host-name", NULL
, con
->http
.hostname
);
1758 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1760 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1761 "time-at-processing", 0);
1762 attr
->value_tag
= IPP_TAG_NOVALUE
;
1763 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1764 "time-at-completed", 0);
1765 attr
->value_tag
= IPP_TAG_NOVALUE
;
1768 * Add remaining job attributes...
1771 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1772 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1773 "job-state", IPP_JOB_STOPPED
);
1774 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1775 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1776 "job-media-sheets-completed", 0);
1777 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1780 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1781 IPP_TAG_INTEGER
)) != NULL
)
1782 attr
->values
[0].integer
= 0;
1784 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1786 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1787 IPP_TAG_KEYWORD
)) == NULL
)
1788 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1791 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1792 printer
->options
)) == NULL
)
1795 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1796 "job-hold-until", NULL
, val
);
1798 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1801 * Hold job until specified time...
1804 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1806 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1807 job
->state_value
= IPP_JOB_HELD
;
1809 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1811 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1812 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1813 job
->state_value
= IPP_JOB_HELD
;
1817 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1818 job
->state_value
= IPP_JOB_PENDING
;
1821 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1825 * Add job sheets options...
1828 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1829 IPP_TAG_ZERO
)) == NULL
)
1831 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1832 "Adding default job-sheets values \"%s,%s\"...",
1833 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1835 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1837 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1838 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1841 job
->job_sheets
= attr
;
1844 * Enforce classification level if set...
1849 cupsdLogMessage(CUPSD_LOG_INFO
,
1850 "Classification=\"%s\", ClassifyOverride=%d",
1851 Classification
? Classification
: "(null)",
1854 if (ClassifyOverride
)
1856 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1857 (attr
->num_values
== 1 ||
1858 !strcmp(attr
->values
[1].string
.text
, "none")))
1861 * Force the leading banner to have the classification on it...
1864 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1866 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1867 "job-sheets=\"%s,none\", "
1868 "job-originating-user-name=\"%s\"",
1869 Classification
, job
->username
);
1871 else if (attr
->num_values
== 2 &&
1872 strcmp(attr
->values
[0].string
.text
,
1873 attr
->values
[1].string
.text
) &&
1874 strcmp(attr
->values
[0].string
.text
, "none") &&
1875 strcmp(attr
->values
[1].string
.text
, "none"))
1878 * Can't put two different security markings on the same document!
1881 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1883 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1884 "job-sheets=\"%s,%s\", "
1885 "job-originating-user-name=\"%s\"",
1886 attr
->values
[0].string
.text
,
1887 attr
->values
[1].string
.text
, job
->username
);
1889 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1890 strcmp(attr
->values
[0].string
.text
, "none") &&
1891 (attr
->num_values
== 1 ||
1892 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1893 strcmp(attr
->values
[1].string
.text
, "none"))))
1895 if (attr
->num_values
== 1)
1896 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1897 "CLASSIFICATION OVERRIDDEN "
1898 "job-sheets=\"%s\", "
1899 "job-originating-user-name=\"%s\"",
1900 attr
->values
[0].string
.text
, job
->username
);
1902 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1903 "CLASSIFICATION OVERRIDDEN "
1904 "job-sheets=\"%s,%s\",fffff "
1905 "job-originating-user-name=\"%s\"",
1906 attr
->values
[0].string
.text
,
1907 attr
->values
[1].string
.text
, job
->username
);
1910 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1911 (attr
->num_values
== 1 ||
1912 strcmp(attr
->values
[1].string
.text
, Classification
)))
1915 * Force the banner to have the classification on it...
1918 if (attr
->num_values
> 1 &&
1919 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1921 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1922 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1926 if (attr
->num_values
== 1 ||
1927 strcmp(attr
->values
[0].string
.text
, "none"))
1928 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1930 if (attr
->num_values
> 1 &&
1931 strcmp(attr
->values
[1].string
.text
, "none"))
1932 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1935 if (attr
->num_values
> 1)
1936 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1937 "CLASSIFICATION FORCED "
1938 "job-sheets=\"%s,%s\", "
1939 "job-originating-user-name=\"%s\"",
1940 attr
->values
[0].string
.text
,
1941 attr
->values
[1].string
.text
, job
->username
);
1943 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1944 "CLASSIFICATION FORCED "
1945 "job-sheets=\"%s\", "
1946 "job-originating-user-name=\"%s\"",
1947 Classification
, job
->username
);
1952 * See if we need to add the starting sheet...
1955 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1957 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1958 attr
->values
[0].string
.text
);
1960 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1962 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1963 "Aborting job because the start banner could not be "
1968 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1971 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1972 IPP_TAG_ZERO
)) != NULL
)
1976 * Fill in the response info...
1979 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1980 LocalPort
, job
->id
);
1982 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1985 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1987 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1989 add_job_state_reasons(con
, job
);
1991 con
->response
->request
.status
.status_code
= IPP_OK
;
1994 * Add any job subscriptions...
1997 add_job_subscriptions(con
, job
);
2000 * Set all but the first two attributes to the job attributes group...
2003 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
2004 attr
->group_tag
= IPP_TAG_JOB
;
2007 * Fire the "job created" event...
2010 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
2013 * Return the new job...
2021 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
2022 * upon the job and printer state...
2026 add_job_state_reasons(
2027 cupsd_client_t
*con
, /* I - Client connection */
2028 cupsd_job_t
*job
) /* I - Job info */
2030 cupsd_printer_t
*dest
; /* Destination printer */
2033 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
2034 con
, con
->http
.fd
, job
? job
->id
: 0);
2036 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
2038 case IPP_JOB_PENDING
:
2039 dest
= cupsdFindDest(job
->dest
);
2041 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
2042 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2043 "job-state-reasons", NULL
, "printer-stopped");
2045 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2046 "job-state-reasons", NULL
, "none");
2050 if (ippFindAttribute(job
->attrs
, "job-hold-until",
2051 IPP_TAG_KEYWORD
) != NULL
||
2052 ippFindAttribute(job
->attrs
, "job-hold-until",
2053 IPP_TAG_NAME
) != NULL
)
2054 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2055 "job-state-reasons", NULL
, "job-hold-until-specified");
2057 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2058 "job-state-reasons", NULL
, "job-incoming");
2061 case IPP_JOB_PROCESSING
:
2062 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2063 "job-state-reasons", NULL
, "job-printing");
2066 case IPP_JOB_STOPPED
:
2067 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2068 "job-state-reasons", NULL
, "job-stopped");
2071 case IPP_JOB_CANCELED
:
2072 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2073 "job-state-reasons", NULL
, "job-canceled-by-user");
2076 case IPP_JOB_ABORTED
:
2077 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2078 "job-state-reasons", NULL
, "aborted-by-system");
2081 case IPP_JOB_COMPLETED
:
2082 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2083 "job-state-reasons", NULL
, "job-completed-successfully");
2090 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2094 add_job_subscriptions(
2095 cupsd_client_t
*con
, /* I - Client connection */
2096 cupsd_job_t
*job
) /* I - Newly created job */
2098 int i
; /* Looping var */
2099 ipp_attribute_t
*prev
, /* Previous attribute */
2100 *next
, /* Next attribute */
2101 *attr
; /* Current attribute */
2102 cupsd_subscription_t
*sub
; /* Subscription object */
2103 const char *recipient
, /* notify-recipient-uri */
2104 *pullmethod
; /* notify-pull-method */
2105 ipp_attribute_t
*user_data
; /* notify-user-data */
2106 int interval
; /* notify-time-interval */
2107 unsigned mask
; /* notify-events */
2111 * Find the first subscription group attribute; return if we have
2115 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2116 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2123 * Process the subscription attributes in the request...
2132 mask
= CUPSD_EVENT_NONE
;
2134 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2136 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2137 attr
->value_tag
== IPP_TAG_URI
)
2140 * Validate the recipient scheme against the ServerBin/notifier
2144 char notifier
[1024], /* Notifier filename */
2145 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2146 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2147 host
[HTTP_MAX_URI
], /* Host portion of URI */
2148 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2149 int port
; /* Port portion of URI */
2152 recipient
= attr
->values
[0].string
.text
;
2154 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2155 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2156 host
, sizeof(host
), &port
,
2157 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2159 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2160 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
2161 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2162 "notify-status-code", IPP_URI_SCHEME
);
2166 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2168 if (access(notifier
, X_OK
))
2170 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2171 _("notify-recipient-uri URI \"%s\" uses unknown "
2172 "scheme"), recipient
);
2173 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2174 "notify-status-code", IPP_URI_SCHEME
);
2178 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2180 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2181 _("notify-recipient-uri URI \"%s\" is already used"),
2183 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2184 "notify-status-code", IPP_ATTRIBUTES
);
2188 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2189 attr
->value_tag
== IPP_TAG_KEYWORD
)
2191 pullmethod
= attr
->values
[0].string
.text
;
2193 if (strcmp(pullmethod
, "ippget"))
2195 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2196 _("Bad notify-pull-method \"%s\""), pullmethod
);
2197 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2198 "notify-status-code", IPP_ATTRIBUTES
);
2202 else if (!strcmp(attr
->name
, "notify-charset") &&
2203 attr
->value_tag
== IPP_TAG_CHARSET
&&
2204 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2205 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2207 send_ipp_status(con
, IPP_CHARSET
,
2208 _("Character set \"%s\" not supported"),
2209 attr
->values
[0].string
.text
);
2212 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2213 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2214 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2216 send_ipp_status(con
, IPP_CHARSET
,
2217 _("Language \"%s\" not supported"),
2218 attr
->values
[0].string
.text
);
2221 else if (!strcmp(attr
->name
, "notify-user-data") &&
2222 attr
->value_tag
== IPP_TAG_STRING
)
2224 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2226 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2227 _("The notify-user-data value is too large "
2228 "(%d > 63 octets)"),
2229 attr
->values
[0].unknown
.length
);
2235 else if (!strcmp(attr
->name
, "notify-events") &&
2236 attr
->value_tag
== IPP_TAG_KEYWORD
)
2238 for (i
= 0; i
< attr
->num_values
; i
++)
2239 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2241 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2243 send_ipp_status(con
, IPP_BAD_REQUEST
,
2244 _("The notify-lease-duration attribute cannot be "
2245 "used with job subscriptions."));
2248 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2249 attr
->value_tag
== IPP_TAG_INTEGER
)
2250 interval
= attr
->values
[0].integer
;
2255 if (!recipient
&& !pullmethod
)
2258 if (mask
== CUPSD_EVENT_NONE
)
2259 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2261 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2262 recipient
, 0)) != NULL
)
2264 sub
->interval
= interval
;
2266 cupsdSetString(&sub
->owner
, job
->username
);
2270 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2271 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2272 sub
->user_data_len
);
2275 ippAddSeparator(con
->response
);
2276 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2277 "notify-subscription-id", sub
->id
);
2279 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2287 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2290 * Remove all of the subscription attributes from the job request...
2292 * TODO: Optimize this since subscription groups have to come at the
2293 * end of the request...
2296 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2300 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2301 attr
->group_tag
== IPP_TAG_ZERO
)
2304 * Free and remove this attribute...
2312 job
->attrs
->attrs
= next
;
2318 job
->attrs
->last
= prev
;
2319 job
->attrs
->current
= prev
;
2324 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2326 * See RFC 4122 for the definition of UUIDs and the format.
2330 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2331 cupsd_job_t
*job
) /* I - Job */
2333 char uuid
[1024]; /* job-uuid string */
2334 _cups_md5_state_t md5state
; /* MD5 state */
2335 unsigned char md5sum
[16]; /* MD5 digest/sum */
2339 * First see if the job already has a job-uuid attribute; if so, return...
2342 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2346 * No job-uuid attribute, so build a version 3 UUID with the local job
2347 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2348 * the ServerName, server name and port that the client connected to,
2349 * and local job ID...
2352 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2353 con
->serverport
, job
->id
);
2355 _cupsMD5Init(&md5state
);
2356 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2357 _cupsMD5Finish(&md5state
, md5sum
);
2360 * Format the UUID URI using the MD5 sum and job ID.
2363 snprintf(uuid
, sizeof(uuid
),
2364 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2365 "%02x%02x%02x%02x%02x%02x",
2366 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2367 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2368 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2369 md5sum
[14], md5sum
[15]);
2371 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2376 * 'add_printer()' - Add a printer to the system.
2380 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2381 ipp_attribute_t
*uri
) /* I - URI of printer */
2383 http_status_t status
; /* Policy status */
2384 int i
; /* Looping var */
2385 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2386 username
[HTTP_MAX_URI
], /* Username portion of URI */
2387 host
[HTTP_MAX_URI
], /* Host portion of URI */
2388 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2389 int port
; /* Port portion of URI */
2390 cupsd_printer_t
*printer
; /* Printer/class */
2391 ipp_attribute_t
*attr
; /* Printer attribute */
2392 cups_file_t
*fp
; /* Script/PPD file */
2393 char line
[1024]; /* Line from file... */
2394 char srcfile
[1024], /* Source Script/PPD file */
2395 dstfile
[1024]; /* Destination Script/PPD file */
2396 int modify
; /* Non-zero if we are modifying */
2397 char newname
[IPP_MAX_NAME
]; /* New printer name */
2398 int changed_driver
, /* Changed the PPD/interface script? */
2399 need_restart_job
, /* Need to restart job? */
2400 set_device_uri
, /* Did we set the device URI? */
2401 set_port_monitor
; /* Did we set the port monitor? */
2404 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2405 con
->http
.fd
, uri
->values
[0].string
.text
);
2408 * Do we have a valid URI?
2411 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2412 sizeof(scheme
), username
, sizeof(username
), host
,
2413 sizeof(host
), &port
, resource
, sizeof(resource
));
2415 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2418 * No, return an error...
2421 send_ipp_status(con
, IPP_BAD_REQUEST
,
2422 _("The printer-uri must be of the form "
2423 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2428 * Do we have a valid printer name?
2431 if (!validate_name(resource
+ 10))
2434 * No, return an error...
2437 send_ipp_status(con
, IPP_BAD_REQUEST
,
2438 _("The printer-uri \"%s\" contains invalid characters."),
2439 uri
->values
[0].string
.text
);
2444 * See if the printer already exists; if not, create a new printer...
2447 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2450 * Printer doesn't exist; see if we have a class of the same name...
2453 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2454 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2457 * Yes, return an error...
2460 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2461 _("A class named \"%s\" already exists"),
2467 * No, check the default policy then add the printer...
2470 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2472 send_http_error(con
, status
, NULL
);
2476 printer
= cupsdAddPrinter(resource
+ 10);
2479 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2482 * Check the default policy, then rename the implicit printer to
2483 * "AnyPrinter" or delete it...
2486 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2488 send_http_error(con
, status
, NULL
);
2492 if (ImplicitAnyClasses
)
2494 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2495 cupsdRenamePrinter(printer
, newname
);
2498 cupsdDeletePrinter(printer
, 1);
2501 * Add the printer as a new local printer...
2504 printer
= cupsdAddPrinter(resource
+ 10);
2507 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2510 * Check the default policy, then rename the remote printer to
2511 * "Printer@server"...
2514 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2516 send_http_error(con
, status
, NULL
);
2520 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2522 cupsdRenamePrinter(printer
, newname
);
2525 * Add the printer as a new local printer...
2528 printer
= cupsdAddPrinter(resource
+ 10);
2531 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2534 send_http_error(con
, status
, printer
);
2541 * Look for attributes and copy them over as needed...
2545 need_restart_job
= 0;
2547 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2548 IPP_TAG_TEXT
)) != NULL
)
2549 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2551 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2552 IPP_TAG_TEXT
)) != NULL
)
2553 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2557 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2558 IPP_TAG_URI
)) != NULL
)
2561 * Do we have a valid device URI?
2564 http_uri_status_t uri_status
; /* URI separation status */
2565 char old_device_uri
[1024];
2566 /* Old device URI */
2569 need_restart_job
= 1;
2571 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2572 attr
->values
[0].string
.text
,
2573 scheme
, sizeof(scheme
),
2574 username
, sizeof(username
),
2575 host
, sizeof(host
), &port
,
2576 resource
, sizeof(resource
));
2578 if (uri_status
< HTTP_URI_OK
)
2580 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\""),
2581 attr
->values
[0].string
.text
);
2582 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2583 "add_printer: httpSeparateURI returned %d", uri_status
);
2587 if (!strcmp(scheme
, "file"))
2590 * See if the administrator has enabled file devices...
2593 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2596 * File devices are disabled and the URL is not file:/dev/null...
2599 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2600 _("File device URIs have been disabled! "
2601 "To enable, see the FileDevice directive in "
2602 "\"%s/cupsd.conf\"."),
2610 * See if the backend exists and is executable...
2613 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2614 if (access(srcfile
, X_OK
))
2617 * Could not find device in list!
2620 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\""),
2626 if (printer
->sanitized_device_uri
)
2627 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2628 sizeof(old_device_uri
));
2630 old_device_uri
[0] = '\0';
2632 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2634 cupsdLogMessage(CUPSD_LOG_INFO
,
2635 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2636 printer
->name
, printer
->sanitized_device_uri
,
2642 set_port_monitor
= 0;
2644 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2645 IPP_TAG_NAME
)) != NULL
)
2647 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2650 need_restart_job
= 1;
2652 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2656 for (i
= 0; i
< supported
->num_values
; i
++)
2657 if (!strcmp(supported
->values
[i
].string
.text
,
2658 attr
->values
[0].string
.text
))
2662 if (!supported
|| i
>= supported
->num_values
)
2664 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\""),
2665 attr
->values
[0].string
.text
);
2669 cupsdLogMessage(CUPSD_LOG_INFO
,
2670 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2671 printer
->name
, attr
->values
[0].string
.text
,
2672 printer
->port_monitor
? printer
->port_monitor
: "none");
2674 if (strcmp(attr
->values
[0].string
.text
, "none"))
2675 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2677 cupsdClearString(&printer
->port_monitor
);
2679 set_port_monitor
= 1;
2682 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2683 IPP_TAG_BOOLEAN
)) != NULL
&&
2684 attr
->values
[0].boolean
!= printer
->accepting
)
2686 cupsdLogMessage(CUPSD_LOG_INFO
,
2687 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2688 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2690 printer
->accepting
= attr
->values
[0].boolean
;
2691 cupsdAddPrinterHistory(printer
);
2693 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2694 "%s accepting jobs.",
2695 printer
->accepting
? "Now" : "No longer");
2698 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2699 IPP_TAG_BOOLEAN
)) != NULL
)
2701 if (printer
->shared
&& !attr
->values
[0].boolean
)
2702 cupsdDeregisterPrinter(printer
, 1);
2704 cupsdLogMessage(CUPSD_LOG_INFO
,
2705 "Setting %s printer-is-shared to %d (was %d.)",
2706 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2708 printer
->shared
= attr
->values
[0].boolean
;
2711 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2712 IPP_TAG_ENUM
)) != NULL
)
2714 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2715 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2717 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d"),
2718 attr
->values
[0].integer
);
2722 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2723 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2725 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2726 cupsdStopPrinter(printer
, 0);
2729 need_restart_job
= 1;
2730 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2734 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2735 IPP_TAG_TEXT
)) != NULL
)
2737 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2738 sizeof(printer
->state_message
));
2739 cupsdAddPrinterHistory(printer
);
2741 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2742 printer
->state_message
);
2745 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2746 IPP_TAG_KEYWORD
)) != NULL
)
2748 if (attr
->num_values
>
2749 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2751 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2752 _("Too many printer-state-reasons values (%d > %d)"),
2754 (int)(sizeof(printer
->reasons
) /
2755 sizeof(printer
->reasons
[0])));
2759 for (i
= 0; i
< printer
->num_reasons
; i
++)
2760 _cupsStrFree(printer
->reasons
[i
]);
2762 printer
->num_reasons
= 0;
2763 for (i
= 0; i
< attr
->num_values
; i
++)
2765 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2768 printer
->reasons
[printer
->num_reasons
] =
2769 _cupsStrRetain(attr
->values
[i
].string
.text
);
2770 printer
->num_reasons
++;
2772 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2773 printer
->state
!= IPP_PRINTER_STOPPED
)
2775 cupsdLogMessage(CUPSD_LOG_INFO
,
2776 "Setting %s printer-state to %d (was %d.)",
2777 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2778 cupsdStopPrinter(printer
, 0);
2782 if (PrintcapFormat
== PRINTCAP_PLIST
)
2783 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2785 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2786 "Printer \"%s\" state changed.", printer
->name
);
2789 set_printer_defaults(con
, printer
);
2791 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2792 IPP_TAG_KEYWORD
)) != NULL
)
2793 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2796 * See if we have all required attributes...
2799 if (!printer
->device_uri
)
2800 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2803 * See if we have an interface script or PPD file attached to the request...
2808 need_restart_job
= 1;
2811 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2813 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2816 * Yes; get the first line from it...
2820 cupsFileGets(fp
, line
, sizeof(line
));
2824 * Then see what kind of file it is...
2827 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2830 if (!strncmp(line
, "*PPD-Adobe", 10))
2833 * The new file is a PPD file, so remove any old interface script
2834 * that might be lying around...
2842 * This must be an interface script, so move the file over to the
2843 * interfaces directory and make it executable...
2846 if (copy_file(srcfile
, dstfile
))
2848 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2849 _("Unable to copy interface script - %s"),
2854 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2855 "Copied interface script successfully");
2856 chmod(dstfile
, 0755);
2859 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2862 if (!strncmp(line
, "*PPD-Adobe", 10))
2865 * The new file is a PPD file, so move the file over to the
2866 * ppd directory and make it readable by all...
2869 if (copy_file(srcfile
, dstfile
))
2871 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2872 _("Unable to copy PPD file - %s"),
2877 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2878 "Copied PPD file successfully");
2879 chmod(dstfile
, 0644);
2884 * This must be an interface script, so remove any old PPD file that
2885 * may be lying around...
2892 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2893 IPP_TAG_NAME
)) != NULL
)
2895 need_restart_job
= 1;
2898 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2901 * Raw driver, remove any existing PPD or interface script files.
2904 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2908 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2918 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2922 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2925 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2927 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file"));
2931 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2932 "Copied PPD file successfully");
2933 chmod(dstfile
, 0644);
2940 * If we changed the PPD/interface script, then remove the printer's cache
2941 * file and clear the printer-state-reasons...
2944 char cache_name
[1024]; /* Cache filename for printer attrs */
2946 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp3", CacheDir
,
2950 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.pwg2", CacheDir
,
2954 cupsdSetPrinterReasons(printer
, "none");
2958 * (Re)register color profiles...
2963 apple_unregister_profiles(printer
);
2964 apple_register_profiles(printer
);
2966 #endif /* __APPLE__ */
2970 * If we set the device URI but not the port monitor, check which port
2971 * monitor to use by default...
2974 if (set_device_uri
&& !set_port_monitor
)
2976 ppd_file_t
*ppd
; /* PPD file */
2977 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2980 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2981 sizeof(scheme
), username
, sizeof(username
), host
,
2982 sizeof(host
), &port
, resource
, sizeof(resource
));
2984 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2986 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2988 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2990 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2991 if (!strcmp(scheme
, ppdattr
->spec
))
2993 cupsdLogMessage(CUPSD_LOG_INFO
,
2994 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2995 printer
->name
, ppdattr
->value
,
2996 printer
->port_monitor
? printer
->port_monitor
2999 if (strcmp(ppdattr
->value
, "none"))
3000 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
3002 cupsdClearString(&printer
->port_monitor
);
3012 * Update the printer attributes and return...
3015 cupsdSetPrinterAttrs(printer
);
3016 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3018 if (need_restart_job
&& printer
->job
)
3021 * Restart the current job...
3024 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
3025 "Job restarted because the printer was modified.");
3028 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3032 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
3033 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
3034 printer
->name
, get_username(con
));
3036 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
3037 printer
->name
, get_username(con
));
3041 cupsdAddPrinterHistory(printer
);
3043 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
3044 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
3045 printer
->name
, get_username(con
));
3047 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
3048 printer
->name
, get_username(con
));
3051 con
->response
->request
.status
.status_code
= IPP_OK
;
3056 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
3057 * based upon the printer state...
3061 add_printer_state_reasons(
3062 cupsd_client_t
*con
, /* I - Client connection */
3063 cupsd_printer_t
*p
) /* I - Printer info */
3065 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3066 "add_printer_state_reasons(%p[%d], %p[%s])",
3067 con
, con
->http
.fd
, p
, p
->name
);
3069 if (p
->num_reasons
== 0)
3070 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3071 "printer-state-reasons", NULL
, "none");
3073 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3074 "printer-state-reasons", p
->num_reasons
, NULL
,
3075 (const char * const *)p
->reasons
);
3080 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
3081 * the specified printer or class.
3085 add_queued_job_count(
3086 cupsd_client_t
*con
, /* I - Client connection */
3087 cupsd_printer_t
*p
) /* I - Printer or class */
3089 int count
; /* Number of jobs on destination */
3092 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3093 con
, con
->http
.fd
, p
, p
->name
);
3095 count
= cupsdGetPrinterJobCount(p
->name
);
3097 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3098 "queued-job-count", count
);
3104 * 'apple_init_profile()' - Initialize a color profile.
3109 ppd_file_t
*ppd
, /* I - PPD file */
3110 cups_array_t
*languages
, /* I - Languages in the PPD file */
3111 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3112 unsigned id
, /* I - Profile ID */
3113 const char *name
, /* I - Profile name */
3114 const char *text
, /* I - Profile UI text */
3115 const char *iccfile
) /* I - ICC filename */
3117 char url
[1024]; /* URL for profile filename */
3118 CFMutableDictionaryRef dict
; /* Dictionary for name */
3119 char *language
; /* Current language */
3120 ppd_attr_t
*attr
; /* Profile attribute */
3121 CFStringRef cflang
, /* Language string */
3122 cftext
; /* Localized text */
3126 * Build the profile name dictionary...
3129 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3130 &kCFTypeDictionaryKeyCallBacks
,
3131 &kCFTypeDictionaryValueCallBacks
);
3133 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3134 kCFStringEncodingUTF8
);
3138 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
3145 * Find localized names for the color profiles...
3148 cupsArraySave(ppd
->sorted_attrs
);
3150 for (language
= (char *)cupsArrayFirst(languages
);
3152 language
= (char *)cupsArrayNext(languages
))
3156 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3158 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3161 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3163 if (attr
&& attr
->text
[0])
3165 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3166 kCFStringEncodingUTF8
);
3167 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3168 kCFStringEncodingUTF8
);
3170 if (cflang
&& cftext
)
3171 CFDictionarySetValue(dict
, cflang
, cftext
);
3181 cupsArrayRestore(ppd
->sorted_attrs
);
3185 * Fill in the profile data...
3189 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3192 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3193 profile
->profileID
= id
;
3194 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3195 profile
->profileName
= dict
;
3198 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3199 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3204 * 'apple_register_profiles()' - Register color profiles for a printer.
3208 apple_register_profiles(
3209 cupsd_printer_t
*p
) /* I - Printer */
3211 int i
; /* Looping var */
3212 char ppdfile
[1024], /* PPD filename */
3213 iccfile
[1024], /* ICC filename */
3214 selector
[PPD_MAX_NAME
];
3215 /* Profile selection string */
3216 ppd_file_t
*ppd
; /* PPD file */
3217 ppd_attr_t
*attr
, /* Profile attributes */
3218 *profileid_attr
,/* cupsProfileID attribute */
3219 *q1_attr
, /* ColorModel (or other) qualifier */
3220 *q2_attr
, /* MediaType (or other) qualifier */
3221 *q3_attr
; /* Resolution (or other) qualifier */
3222 char q_keyword
[PPD_MAX_NAME
];
3223 /* Qualifier keyword */
3224 const char *q1_choice
, /* ColorModel (or other) choice */
3225 *q2_choice
, /* MediaType (or other) choice */
3226 *q3_choice
; /* Resolution (or other) choice */
3227 const char *profile_key
; /* Profile keyword */
3228 ppd_option_t
*cm_option
; /* Color model option */
3229 ppd_choice_t
*cm_choice
; /* Color model choice */
3230 int num_profiles
; /* Number of profiles */
3231 CMError error
; /* Last error */
3232 unsigned device_id
, /* Printer device ID */
3233 profile_id
, /* Profile ID */
3234 default_profile_id
= 0;
3235 /* Default profile ID */
3236 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3237 CFStringRef printer_name
; /* Printer name string */
3238 CMDeviceScope scope
= /* Scope of the registration */
3240 kCFPreferencesAnyUser
,
3241 kCFPreferencesCurrentHost
3243 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3244 CMDeviceProfileInfo
*profile
; /* Current profile */
3245 cups_array_t
*languages
; /* Languages array */
3249 * Make sure ColorSync is available...
3252 if (CMRegisterColorDevice
== NULL
)
3256 * Try opening the PPD file for this printer...
3259 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3260 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3264 * See if we have any profiles...
3267 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3268 profile_key
= "APTiogaProfile";
3271 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3272 profile_key
= "cupsICCProfile";
3275 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3276 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3278 if (attr
->value
[0] != '/')
3279 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3282 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3284 if (access(iccfile
, 0))
3292 * If we have profiles, add them...
3295 if (num_profiles
> 0)
3297 if (profile_key
[0] == 'A')
3300 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3304 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3306 default_profile_id
= atoi(attr
->value
);
3308 q1_choice
= q2_choice
= q3_choice
= NULL
;
3313 * For CUPS PPDs, figure out the default profile selector values...
3316 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3317 attr
->value
&& attr
->value
[0])
3319 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3320 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3322 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3323 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3325 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3326 q1_choice
= q1_attr
->value
;
3330 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3331 attr
->value
&& attr
->value
[0])
3333 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3334 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3337 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3339 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3340 q2_choice
= q2_attr
->value
;
3344 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3345 attr
->value
&& attr
->value
[0])
3347 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3348 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3351 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3353 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3354 q3_choice
= q3_attr
->value
;
3360 * Build the array of profiles...
3362 * Note: This calloc actually requests slightly more memory than needed.
3365 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3367 cupsdLogMessage(CUPSD_LOG_ERROR
,
3368 "Unable to allocate memory for %d profiles",
3374 profiles
->profileCount
= num_profiles
;
3375 languages
= _ppdGetLanguages(ppd
);
3377 for (profile
= profiles
->profiles
,
3378 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3380 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3381 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3384 * Add this profile...
3387 if (attr
->value
[0] != '/')
3388 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3391 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3393 if (access(iccfile
, 0))
3396 if (profile_key
[0] == 'c')
3398 cupsArraySave(ppd
->sorted_attrs
);
3400 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3401 attr
->spec
)) != NULL
&&
3402 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3403 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3405 profile_id
= _ppdHashName(attr
->spec
);
3407 cupsArrayRestore(ppd
->sorted_attrs
);
3410 profile_id
= atoi(attr
->spec
);
3412 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3413 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3418 * See if this is the default profile...
3421 if (!default_profile_id
)
3427 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3428 q1_choice
, q2_choice
, q3_choice
);
3429 if (!strcmp(selector
, attr
->spec
))
3430 default_profile_id
= profile_id
;
3433 if (!default_profile_id
)
3435 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3437 if (!strcmp(selector
, attr
->spec
))
3438 default_profile_id
= profile_id
;
3442 if (!default_profile_id
&& q3_choice
)
3444 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3446 if (!strcmp(selector
, attr
->spec
))
3447 default_profile_id
= profile_id
;
3450 if (!default_profile_id
)
3452 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3453 if (!strcmp(selector
, attr
->spec
))
3454 default_profile_id
= profile_id
;
3459 _ppdFreeLanguages(languages
);
3461 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3464 * Extract profiles from ColorModel option...
3467 const char *profile_name
; /* Name of generic profile */
3470 num_profiles
= cm_option
->num_choices
;
3472 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3474 cupsdLogMessage(CUPSD_LOG_ERROR
,
3475 "Unable to allocate memory for %d profiles",
3481 profiles
->profileCount
= num_profiles
;
3483 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3484 cm_choice
= cm_option
->choices
;
3486 i
--, cm_choice
++, profile
++)
3488 if (!strcmp(cm_choice
->choice
, "Gray") ||
3489 !strcmp(cm_choice
->choice
, "Black"))
3490 profile_name
= "Gray";
3491 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3492 !strcmp(cm_choice
->choice
, "CMY"))
3493 profile_name
= "RGB";
3494 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3495 !strcmp(cm_choice
->choice
, "KCMY"))
3496 profile_name
= "CMYK";
3498 profile_name
= "DeviceN";
3500 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3501 profile_id
= _ppdHashName(selector
);
3503 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3504 cm_choice
->text
, NULL
);
3506 if (cm_choice
->marked
)
3507 default_profile_id
= profile_id
;
3513 * Use the default colorspace...
3516 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3518 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3520 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3522 cupsdLogMessage(CUPSD_LOG_ERROR
,
3523 "Unable to allocate memory for %d profiles",
3529 profiles
->profileCount
= num_profiles
;
3531 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3532 "Gray", "Gray", NULL
);
3534 switch (ppd
->colorspace
)
3538 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3539 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3543 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3544 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3552 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3553 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3559 if (num_profiles
> 0)
3562 * Make sure we have a default profile ID...
3565 if (!default_profile_id
)
3566 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3569 * Get the device ID hash and pathelogical name dictionary.
3572 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3575 device_id
= _ppdHashName(p
->name
);
3576 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3577 &kCFTypeDictionaryKeyCallBacks
,
3578 &kCFTypeDictionaryValueCallBacks
);
3579 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3580 p
->name
, kCFStringEncodingUTF8
);
3582 if (device_name
&& printer_name
)
3584 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3587 * Register the device with ColorSync...
3590 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3591 device_name
, &scope
);
3594 * Register the profiles...
3598 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3599 default_profile_id
, profiles
);
3609 cupsdLogMessage(CUPSD_LOG_ERROR
,
3610 "Unable to register ICC color profiles for \"%s\" - %d",
3611 p
->name
, (int)error
);
3613 for (profile
= profiles
->profiles
;
3615 profile
++, num_profiles
--)
3616 CFRelease(profile
->profileName
);
3621 CFRelease(printer_name
);
3624 CFRelease(device_name
);
3632 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3637 apple_unregister_profiles(
3638 cupsd_printer_t
*p
) /* I - Printer */
3641 * Make sure ColorSync is available...
3644 if (CMUnregisterColorDevice
!= NULL
)
3645 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3647 #endif /* __APPLE__ */
3650 * 'apply_printer_defaults()' - Apply printer default options to a job.
3654 apply_printer_defaults(
3655 cupsd_printer_t
*printer
, /* I - Printer */
3656 cupsd_job_t
*job
) /* I - Job */
3658 int i
, /* Looping var */
3659 num_options
; /* Number of default options */
3660 cups_option_t
*options
, /* Default options */
3661 *option
; /* Current option */
3665 * Collect all of the default options and add the missing ones to the
3669 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3670 option
= printer
->options
;
3673 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3675 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3680 * Encode these options as attributes in the job object...
3683 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3684 cupsFreeOptions(num_options
, options
);
3689 * 'authenticate_job()' - Set job authentication info.
3693 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3694 ipp_attribute_t
*uri
) /* I - Job URI */
3696 ipp_attribute_t
*attr
, /* job-id attribute */
3697 *auth_info
; /* auth-info attribute */
3698 int jobid
; /* Job ID */
3699 cupsd_job_t
*job
; /* Current job */
3700 char scheme
[HTTP_MAX_URI
],
3701 /* Method portion of URI */
3702 username
[HTTP_MAX_URI
],
3703 /* Username portion of URI */
3705 /* Host portion of URI */
3706 resource
[HTTP_MAX_URI
];
3707 /* Resource portion of URI */
3708 int port
; /* Port portion of URI */
3711 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3712 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3715 * Start with "everything is OK" status...
3718 con
->response
->request
.status
.status_code
= IPP_OK
;
3721 * See if we have a job URI or a printer URI...
3724 if (!strcmp(uri
->name
, "printer-uri"))
3727 * Got a printer URI; see if we also have a job-id attribute...
3730 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3731 IPP_TAG_INTEGER
)) == NULL
)
3733 send_ipp_status(con
, IPP_BAD_REQUEST
,
3734 _("Got a printer-uri attribute but no job-id"));
3738 jobid
= attr
->values
[0].integer
;
3743 * Got a job URI; parse it to get the job ID...
3746 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3747 sizeof(scheme
), username
, sizeof(username
), host
,
3748 sizeof(host
), &port
, resource
, sizeof(resource
));
3750 if (strncmp(resource
, "/jobs/", 6))
3756 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\""),
3757 uri
->values
[0].string
.text
);
3761 jobid
= atoi(resource
+ 6);
3765 * See if the job exists...
3768 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3771 * Nope - return a "not found" error...
3774 send_ipp_status(con
, IPP_NOT_FOUND
,
3775 _("Job #%d does not exist"), jobid
);
3780 * See if the job has been completed...
3783 if (job
->state_value
!= IPP_JOB_HELD
)
3786 * Return a "not-possible" error...
3789 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3790 _("Job #%d is not held for authentication"),
3796 * See if we have already authenticated...
3799 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3801 if (!con
->username
[0] && !auth_info
)
3803 cupsd_printer_t
*printer
; /* Job destination */
3807 * No auth data. If we need to authenticate via Kerberos, send a
3808 * HTTP auth challenge, otherwise just return an IPP error...
3811 printer
= cupsdFindDest(job
->dest
);
3813 if (printer
&& printer
->num_auth_info_required
> 0 &&
3814 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3815 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3817 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3818 _("No authentication information provided"));
3823 * See if the job is owned by the requesting user...
3826 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3828 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3829 cupsdFindDest(job
->dest
));
3834 * Save the authentication information for this job...
3837 save_auth_info(con
, job
, auth_info
);
3840 * Reset the job-hold-until value to "no-hold"...
3843 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3844 IPP_TAG_KEYWORD
)) == NULL
)
3845 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3849 attr
->value_tag
= IPP_TAG_KEYWORD
;
3850 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3854 * Release the job and return...
3857 cupsdReleaseJob(job
);
3859 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3864 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3868 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3869 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3871 int i
; /* Looping var */
3872 http_status_t status
; /* Policy status */
3873 cups_ptype_t dtype
; /* Destination type */
3874 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3875 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3876 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3877 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3878 int port
; /* Port portion of URI */
3879 ipp_attribute_t
*attr
; /* Attribute in request */
3880 const char *username
= NULL
; /* Username */
3881 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3883 cupsd_printer_t
*printer
; /* Printer */
3884 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3885 cupsd_job_t
*job
; /* Job */
3888 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3889 con
->http
.fd
, uri
->values
[0].string
.text
);
3892 * Get the jobs to cancel/purge...
3895 switch (con
->request
->request
.op
.operation_id
)
3897 case IPP_PURGE_JOBS
:
3899 * Get the username (if any) for the jobs we want to cancel (only if
3900 * "my-jobs" is specified...
3903 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3904 IPP_TAG_BOOLEAN
)) != NULL
&&
3905 attr
->values
[0].boolean
)
3907 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3908 IPP_TAG_NAME
)) != NULL
)
3909 username
= attr
->values
[0].string
.text
;
3912 send_ipp_status(con
, IPP_BAD_REQUEST
,
3913 _("Missing requesting-user-name attribute"));
3919 * Look for the "purge-jobs" attribute...
3922 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3923 IPP_TAG_BOOLEAN
)) != NULL
)
3924 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3926 purge
= CUPSD_JOB_PURGE
;
3929 case IPP_CANCEL_MY_JOBS
:
3930 if (con
->username
[0])
3931 username
= con
->username
;
3932 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3933 IPP_TAG_NAME
)) != NULL
)
3934 username
= attr
->values
[0].string
.text
;
3937 send_ipp_status(con
, IPP_BAD_REQUEST
,
3938 _("Missing requesting-user-name attribute"));
3946 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3949 * See if we have a printer URI...
3952 if (strcmp(uri
->name
, "printer-uri"))
3954 send_ipp_status(con
, IPP_BAD_REQUEST
,
3955 _("The printer-uri attribute is required"));
3960 * And if the destination is valid...
3963 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3969 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3970 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3971 hostname
, sizeof(hostname
), &port
,
3972 resource
, sizeof(resource
));
3974 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3975 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3977 send_ipp_status(con
, IPP_NOT_FOUND
,
3978 _("The printer or class was not found."));
3986 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3988 send_http_error(con
, status
, NULL
);
3994 for (i
= 0; i
< job_ids
->num_values
; i
++)
3996 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
4000 if (i
< job_ids
->num_values
)
4002 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
4003 job_ids
->values
[i
].integer
);
4007 for (i
= 0; i
< job_ids
->num_values
; i
++)
4009 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4011 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4012 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4013 "Job canceled by user.");
4016 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4017 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4023 * Cancel all jobs on all printers...
4026 cupsdCancelJobs(NULL
, username
, purge
);
4028 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
4029 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4039 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4042 send_http_error(con
, status
, printer
);
4048 for (i
= 0; i
< job_ids
->num_values
; i
++)
4050 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
4051 strcasecmp(job
->dest
, printer
->name
))
4055 if (i
< job_ids
->num_values
)
4057 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
4058 job_ids
->values
[i
].integer
);
4062 for (i
= 0; i
< job_ids
->num_values
; i
++)
4064 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4066 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4067 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4068 "Job canceled by user.");
4071 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4072 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4078 * Cancel all of the jobs on the named printer...
4081 cupsdCancelJobs(printer
->name
, username
, purge
);
4083 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
4085 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4090 con
->response
->request
.status
.status_code
= IPP_OK
;
4095 * 'cancel_job()' - Cancel a print job.
4099 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
4100 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4102 ipp_attribute_t
*attr
; /* Current attribute */
4103 int jobid
; /* Job ID */
4104 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4105 username
[HTTP_MAX_URI
], /* Username portion of URI */
4106 host
[HTTP_MAX_URI
], /* Host portion of URI */
4107 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4108 int port
; /* Port portion of URI */
4109 cupsd_job_t
*job
; /* Job information */
4110 cups_ptype_t dtype
; /* Destination type (printer/class) */
4111 cupsd_printer_t
*printer
; /* Printer data */
4112 cupsd_jobaction_t purge
; /* Purge the job? */
4115 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
4116 con
->http
.fd
, uri
->values
[0].string
.text
);
4119 * See if we have a job URI or a printer URI...
4122 if (!strcmp(uri
->name
, "printer-uri"))
4125 * Got a printer URI; see if we also have a job-id attribute...
4128 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4129 IPP_TAG_INTEGER
)) == NULL
)
4131 send_ipp_status(con
, IPP_BAD_REQUEST
,
4132 _("Got a printer-uri attribute but no job-id"));
4136 if ((jobid
= attr
->values
[0].integer
) == 0)
4139 * Find the current job on the specified printer...
4142 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4148 send_ipp_status(con
, IPP_NOT_FOUND
,
4149 _("The printer or class was not found."));
4154 * See if there are any pending jobs...
4157 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4159 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4160 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
4161 !strcasecmp(job
->dest
, printer
->name
))
4169 * No, try stopped jobs...
4172 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4174 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4175 if (job
->state_value
== IPP_JOB_STOPPED
&&
4176 !strcasecmp(job
->dest
, printer
->name
))
4183 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s"),
4193 * Got a job URI; parse it to get the job ID...
4196 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4197 sizeof(scheme
), username
, sizeof(username
), host
,
4198 sizeof(host
), &port
, resource
, sizeof(resource
));
4200 if (strncmp(resource
, "/jobs/", 6))
4206 send_ipp_status(con
, IPP_BAD_REQUEST
,
4207 _("Bad job-uri attribute \"%s\""),
4208 uri
->values
[0].string
.text
);
4212 jobid
= atoi(resource
+ 6);
4216 * Look for the "purge-job" attribute...
4219 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4220 IPP_TAG_BOOLEAN
)) != NULL
)
4221 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4223 purge
= CUPSD_JOB_DEFAULT
;
4226 * See if the job exists...
4229 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4232 * Nope - return a "not found" error...
4235 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
4240 * See if the job is owned by the requesting user...
4243 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4245 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4246 cupsdFindDest(job
->dest
));
4251 * See if the job is already completed, canceled, or aborted; if so,
4252 * we can't cancel...
4255 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4257 switch (job
->state_value
)
4259 case IPP_JOB_CANCELED
:
4260 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4261 _("Job #%d is already canceled - can\'t cancel."),
4265 case IPP_JOB_ABORTED
:
4266 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4267 _("Job #%d is already aborted - can\'t cancel."),
4272 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4273 _("Job #%d is already completed - can\'t cancel."),
4282 * Cancel the job and return...
4285 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4286 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4287 "Job canceled by \"%s\"",
4291 if (purge
== CUPSD_JOB_PURGE
)
4292 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4295 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4298 con
->response
->request
.status
.status_code
= IPP_OK
;
4303 * 'cancel_subscription()' - Cancel a subscription.
4307 cancel_subscription(
4308 cupsd_client_t
*con
, /* I - Client connection */
4309 int sub_id
) /* I - Subscription ID */
4311 http_status_t status
; /* Policy status */
4312 cupsd_subscription_t
*sub
; /* Subscription */
4315 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4316 "cancel_subscription(con=%p[%d], sub_id=%d)",
4317 con
, con
->http
.fd
, sub_id
);
4320 * Is the subscription ID valid?
4323 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4326 * Bad subscription ID...
4329 send_ipp_status(con
, IPP_NOT_FOUND
,
4330 _("notify-subscription-id %d no good"), sub_id
);
4338 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4340 con
, sub
->owner
)) != HTTP_OK
)
4342 send_http_error(con
, status
, sub
->dest
);
4347 * Cancel the subscription...
4350 cupsdDeleteSubscription(sub
, 1);
4352 con
->response
->request
.status
.status_code
= IPP_OK
;
4357 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4360 static int /* O - 1 if OK, 0 if not */
4361 check_rss_recipient(
4362 const char *recipient
) /* I - Recipient URI */
4364 cupsd_subscription_t
*sub
; /* Current subscription */
4367 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4369 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4373 * Compare the URIs up to the first ?...
4376 const char *r1
, *r2
;
4378 for (r1
= recipient
, r2
= sub
->recipient
;
4379 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4391 * 'check_quotas()' - Check quotas for a printer and user.
4394 static int /* O - 1 if OK, 0 if not */
4395 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4396 cupsd_printer_t
*p
) /* I - Printer or class */
4398 int i
; /* Looping var */
4399 char username
[33]; /* Username */
4400 cupsd_quota_t
*q
; /* Quota data */
4401 #ifdef HAVE_MBR_UID_TO_UUID
4403 * Use Apple membership APIs which require that all names represent
4404 * valid user account or group records accessible by the server.
4407 uuid_t usr_uuid
; /* UUID for job requesting user */
4408 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4409 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4410 int mbr_err
; /* Error from membership function */
4411 int is_member
; /* Is this user a member? */
4414 * Use standard POSIX APIs for checking users and groups...
4417 struct passwd
*pw
; /* User password data */
4418 #endif /* HAVE_MBR_UID_TO_UUID */
4421 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4422 con
, con
->http
.fd
, p
, p
->name
);
4425 * Figure out who is printing...
4428 strlcpy(username
, get_username(con
), sizeof(username
));
4431 * Check global active job limits for printers and users...
4434 if (MaxJobsPerPrinter
)
4437 * Check if there are too many pending jobs on this printer...
4440 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4442 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4451 * Check if there are too many pending jobs for this user...
4454 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4456 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4463 * Check against users...
4466 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4471 #ifdef HAVE_MBR_UID_TO_UUID
4473 * Get UUID for job requesting user...
4476 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4482 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4483 "check_quotas: UUID lookup failed for user \"%s\"",
4485 cupsdLogMessage(CUPSD_LOG_INFO
,
4486 "Denying user \"%s\" access to printer \"%s\" "
4487 "(unknown user)...",
4493 * Get UID and GID of requesting user...
4496 pw
= getpwnam(username
);
4498 #endif /* HAVE_MBR_UID_TO_UUID */
4500 for (i
= 0; i
< p
->num_users
; i
++)
4501 if (p
->users
[i
][0] == '@')
4504 * Check group membership...
4507 #ifdef HAVE_MBR_UID_TO_UUID
4508 if (p
->users
[i
][1] == '#')
4510 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4511 uuid_clear(grp_uuid
);
4513 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4517 * Invalid ACL entries are ignored for matching; just record a
4518 * warning in the log...
4521 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4522 "check_quotas: UUID lookup failed for ACL entry "
4523 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4524 cupsdLogMessage(CUPSD_LOG_WARN
,
4525 "Access control entry \"%s\" not a valid group name; "
4526 "entry ignored", p
->users
[i
]);
4529 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4533 * At this point, there should be no errors, but check anyways...
4536 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4537 "check_quotas: group \"%s\" membership check "
4538 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4543 * Stop if we found a match...
4550 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4552 #endif /* HAVE_MBR_UID_TO_UUID */
4554 #ifdef HAVE_MBR_UID_TO_UUID
4557 if (p
->users
[i
][0] == '#')
4559 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4560 uuid_clear(usr2_uuid
);
4562 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4566 * Invalid ACL entries are ignored for matching; just record a
4567 * warning in the log...
4570 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4571 "check_quotas: UUID lookup failed for ACL entry "
4572 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4573 cupsdLogMessage(CUPSD_LOG_WARN
,
4574 "Access control entry \"%s\" not a valid user name; "
4575 "entry ignored", p
->users
[i
]);
4578 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4582 else if (!strcasecmp(username
, p
->users
[i
]))
4584 #endif /* HAVE_MBR_UID_TO_UUID */
4586 if ((i
< p
->num_users
) == p
->deny_users
)
4588 cupsdLogMessage(CUPSD_LOG_INFO
,
4589 "Denying user \"%s\" access to printer \"%s\"...",
4599 if (p
->k_limit
|| p
->page_limit
)
4601 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4603 cupsdLogMessage(CUPSD_LOG_ERROR
,
4604 "Unable to allocate quota data for user \"%s\"",
4609 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4610 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4612 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4619 * If we have gotten this far, we're done!
4627 * 'close_job()' - Close a multi-file job.
4631 close_job(cupsd_client_t
*con
, /* I - Client connection */
4632 ipp_attribute_t
*uri
) /* I - Printer URI */
4634 cupsd_job_t
*job
; /* Job */
4635 ipp_attribute_t
*attr
; /* Attribute */
4636 char job_uri
[HTTP_MAX_URI
],
4638 username
[256]; /* User name */
4641 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4642 con
->http
.fd
, uri
->values
[0].string
.text
);
4645 * See if we have a job URI or a printer URI...
4648 if (strcmp(uri
->name
, "printer-uri"))
4651 * job-uri is not supported by Close-Job!
4654 send_ipp_status(con
, IPP_BAD_REQUEST
,
4655 _("Close-Job doesn't support the job-uri attribute."));
4660 * Got a printer URI; see if we also have a job-id attribute...
4663 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4664 IPP_TAG_INTEGER
)) == NULL
)
4666 send_ipp_status(con
, IPP_BAD_REQUEST
,
4667 _("Got a printer-uri attribute but no job-id"));
4671 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4674 * Nope - return a "not found" error...
4677 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
4678 attr
->values
[0].integer
);
4683 * See if the job is owned by the requesting user...
4686 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4688 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4689 cupsdFindDest(job
->dest
));
4694 * Add any ending sheet...
4697 if (cupsdTimeoutJob(job
))
4700 if (job
->state_value
== IPP_JOB_STOPPED
)
4702 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4703 job
->state_value
= IPP_JOB_PENDING
;
4705 else if (job
->state_value
== IPP_JOB_HELD
)
4707 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4708 IPP_TAG_KEYWORD
)) == NULL
)
4709 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4711 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
4713 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4714 job
->state_value
= IPP_JOB_PENDING
;
4719 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
4722 * Fill in the response info...
4725 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
4726 LocalPort
, job
->id
);
4727 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4730 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4732 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4735 add_job_state_reasons(con
, job
);
4737 con
->response
->request
.status
.status_code
= IPP_OK
;
4740 * Start the job if necessary...
4748 * 'copy_attribute()' - Copy a single attribute.
4751 static ipp_attribute_t
* /* O - New attribute */
4753 ipp_t
*to
, /* O - Destination request/response */
4754 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4755 int quickcopy
) /* I - Do a quick copy? */
4757 int i
; /* Looping var */
4758 ipp_attribute_t
*toattr
; /* Destination attribute */
4761 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4762 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4763 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4766 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4769 toattr
= ippAddSeparator(to
);
4772 case IPP_TAG_INTEGER
:
4774 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4775 attr
->name
, attr
->num_values
, NULL
);
4777 for (i
= 0; i
< attr
->num_values
; i
++)
4778 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4781 case IPP_TAG_BOOLEAN
:
4782 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4783 attr
->num_values
, NULL
);
4785 for (i
= 0; i
< attr
->num_values
; i
++)
4786 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4789 case IPP_TAG_STRING
:
4792 case IPP_TAG_KEYWORD
:
4794 case IPP_TAG_URISCHEME
:
4795 case IPP_TAG_CHARSET
:
4796 case IPP_TAG_LANGUAGE
:
4797 case IPP_TAG_MIMETYPE
:
4798 toattr
= ippAddStrings(to
, attr
->group_tag
,
4799 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4800 attr
->name
, attr
->num_values
, NULL
, NULL
);
4804 for (i
= 0; i
< attr
->num_values
; i
++)
4805 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4807 else if (attr
->value_tag
& IPP_TAG_COPY
)
4809 for (i
= 0; i
< attr
->num_values
; i
++)
4810 toattr
->values
[i
].string
.text
=
4811 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4815 for (i
= 0; i
< attr
->num_values
; i
++)
4816 toattr
->values
[i
].string
.text
=
4817 _cupsStrRetain(attr
->values
[i
].string
.text
);
4822 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4823 attr
->values
[0].date
);
4826 case IPP_TAG_RESOLUTION
:
4827 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4828 attr
->num_values
, IPP_RES_PER_INCH
,
4831 for (i
= 0; i
< attr
->num_values
; i
++)
4833 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4834 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4835 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4839 case IPP_TAG_RANGE
:
4840 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4841 attr
->num_values
, NULL
, NULL
);
4843 for (i
= 0; i
< attr
->num_values
; i
++)
4845 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4846 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4850 case IPP_TAG_TEXTLANG
:
4851 case IPP_TAG_NAMELANG
:
4852 toattr
= ippAddStrings(to
, attr
->group_tag
,
4853 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4854 attr
->name
, attr
->num_values
, NULL
, NULL
);
4858 for (i
= 0; i
< attr
->num_values
; i
++)
4860 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4861 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4864 else if (attr
->value_tag
& IPP_TAG_COPY
)
4866 for (i
= 0; i
< attr
->num_values
; i
++)
4869 toattr
->values
[i
].string
.charset
=
4870 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4872 toattr
->values
[i
].string
.charset
=
4873 toattr
->values
[0].string
.charset
;
4875 toattr
->values
[i
].string
.text
=
4876 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4881 for (i
= 0; i
< attr
->num_values
; i
++)
4884 toattr
->values
[i
].string
.charset
=
4885 _cupsStrRetain(attr
->values
[i
].string
.charset
);
4887 toattr
->values
[i
].string
.charset
=
4888 toattr
->values
[0].string
.charset
;
4890 toattr
->values
[i
].string
.text
=
4891 _cupsStrRetain(attr
->values
[i
].string
.text
);
4896 case IPP_TAG_BEGIN_COLLECTION
:
4897 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4898 attr
->num_values
, NULL
);
4900 for (i
= 0; i
< attr
->num_values
; i
++)
4902 toattr
->values
[i
].collection
= attr
->values
[i
].collection
;
4903 attr
->values
[i
].collection
->use
++;
4908 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4909 attr
->name
, attr
->num_values
, NULL
);
4911 for (i
= 0; i
< attr
->num_values
; i
++)
4913 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4915 if (toattr
->values
[i
].unknown
.length
> 0)
4917 if ((toattr
->values
[i
].unknown
.data
=
4918 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4919 toattr
->values
[i
].unknown
.length
= 0;
4921 memcpy(toattr
->values
[i
].unknown
.data
,
4922 attr
->values
[i
].unknown
.data
,
4923 toattr
->values
[i
].unknown
.length
);
4926 break; /* anti-compiler-warning-code */
4934 * 'copy_attrs()' - Copy attributes from one request to another.
4938 copy_attrs(ipp_t
*to
, /* I - Destination request */
4939 ipp_t
*from
, /* I - Source request */
4940 cups_array_t
*ra
, /* I - Requested attributes */
4941 ipp_tag_t group
, /* I - Group to copy */
4942 int quickcopy
) /* I - Do a quick copy? */
4944 ipp_attribute_t
*fromattr
; /* Source attribute */
4947 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4948 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4949 to
, from
, ra
, group
, quickcopy
);
4954 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4957 * Filter attributes as needed...
4960 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4961 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4964 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4967 * Don't send collection attributes by default to IPP/1.x clients
4968 * since many do not support collections. Also don't send
4969 * media-col-database unless specifically requested by the client.
4972 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4974 (to
->request
.status
.version
[0] == 1 ||
4975 !strcmp(fromattr
->name
, "media-col-database")))
4978 copy_attribute(to
, fromattr
, quickcopy
);
4985 * 'copy_banner()' - Copy a banner file to the requests directory for the
4989 static int /* O - Size of banner file in kbytes */
4990 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4991 cupsd_job_t
*job
, /* I - Job information */
4992 const char *name
) /* I - Name of banner */
4994 int i
; /* Looping var */
4995 int kbytes
; /* Size of banner file in kbytes */
4996 char filename
[1024]; /* Job filename */
4997 cupsd_banner_t
*banner
; /* Pointer to banner */
4998 cups_file_t
*in
; /* Input file */
4999 cups_file_t
*out
; /* Output file */
5000 int ch
; /* Character from file */
5001 char attrname
[255], /* Name of attribute */
5002 *s
; /* Pointer into name */
5003 ipp_attribute_t
*attr
; /* Attribute */
5006 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5007 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
5008 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
5009 name
? name
: "(null)");
5012 * Find the banner; return if not found or "none"...
5015 if (!name
|| !strcmp(name
, "none") ||
5016 (banner
= cupsdFindBanner(name
)) == NULL
)
5020 * Open the banner and job files...
5023 if (add_file(con
, job
, banner
->filetype
, 0))
5026 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
5028 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
5030 cupsdLogMessage(CUPSD_LOG_ERROR
,
5031 "Unable to create banner job file %s - %s",
5032 filename
, strerror(errno
));
5037 fchmod(cupsFileNumber(out
), 0640);
5038 fchown(cupsFileNumber(out
), RunUser
, Group
);
5041 * Try the localized banner file under the subdirectory...
5044 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5046 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5049 * Convert ll-cc to ll_CC...
5053 attrname
[3] = toupper(attrname
[3] & 255);
5054 attrname
[4] = toupper(attrname
[4] & 255);
5057 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5060 if (access(filename
, 0) && strlen(attrname
) > 2)
5063 * Wasn't able to find "ll_CC" locale file; try the non-national
5064 * localization banner directory.
5069 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5073 if (access(filename
, 0))
5076 * Use the non-localized banner file.
5079 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5082 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5086 cupsdLogMessage(CUPSD_LOG_ERROR
,
5087 "Unable to open banner template file %s - %s",
5088 filename
, strerror(errno
));
5094 * Parse the file to the end...
5097 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5101 * Get an attribute name...
5104 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5105 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5107 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5117 * Ignore { followed by stuff that is not an attribute name...
5120 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5125 * See if it is defined...
5128 if (attrname
[0] == '?')
5133 if (!strcmp(s
, "printer-name"))
5135 cupsFilePuts(out
, job
->dest
);
5138 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5141 * See if we have a leading question mark...
5144 if (attrname
[0] != '?')
5147 * Nope, write to file as-is; probably a PostScript procedure...
5150 cupsFilePrintf(out
, "{%s}", attrname
);
5157 * Output value(s)...
5160 for (i
= 0; i
< attr
->num_values
; i
++)
5163 cupsFilePutChar(out
, ',');
5165 switch (attr
->value_tag
)
5167 case IPP_TAG_INTEGER
:
5169 if (!strncmp(s
, "time-at-", 8))
5171 struct timeval tv
= { attr
->values
[i
].integer
, 0 };
5172 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5175 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5178 case IPP_TAG_BOOLEAN
:
5179 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5182 case IPP_TAG_NOVALUE
:
5183 cupsFilePuts(out
, "novalue");
5186 case IPP_TAG_RANGE
:
5187 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5188 attr
->values
[i
].range
.upper
);
5191 case IPP_TAG_RESOLUTION
:
5192 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5193 attr
->values
[i
].resolution
.yres
,
5194 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5199 case IPP_TAG_STRING
:
5202 case IPP_TAG_KEYWORD
:
5203 case IPP_TAG_CHARSET
:
5204 case IPP_TAG_LANGUAGE
:
5205 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
5208 * Need to quote strings for PS banners...
5213 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5215 if (*p
== '(' || *p
== ')' || *p
== '\\')
5217 cupsFilePutChar(out
, '\\');
5218 cupsFilePutChar(out
, *p
);
5220 else if (*p
< 32 || *p
> 126)
5221 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5223 cupsFilePutChar(out
, *p
);
5227 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5231 break; /* anti-compiler-warning-code */
5235 else if (ch
== '\\') /* Quoted char */
5237 ch
= cupsFileGetChar(in
);
5239 if (ch
!= '{') /* Only do special handling for \{ */
5240 cupsFilePutChar(out
, '\\');
5242 cupsFilePutChar(out
, ch
);
5245 cupsFilePutChar(out
, ch
);
5249 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5251 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5252 IPP_TAG_INTEGER
)) != NULL
)
5253 attr
->values
[0].integer
+= kbytes
;
5262 * 'copy_file()' - Copy a PPD file or interface script...
5265 static int /* O - 0 = success, -1 = error */
5266 copy_file(const char *from
, /* I - Source file */
5267 const char *to
) /* I - Destination file */
5269 cups_file_t
*src
, /* Source file */
5270 *dst
; /* Destination file */
5271 int bytes
; /* Bytes to read/write */
5272 char buffer
[2048]; /* Copy buffer */
5275 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5278 * Open the source and destination file for a copy...
5281 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5284 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5291 * Copy the source file to the destination...
5294 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5295 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5303 * Close both files and return...
5308 return (cupsFileClose(dst
));
5313 * 'copy_model()' - Copy a PPD model file, substituting default values
5317 static int /* O - 0 = success, -1 = error */
5318 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5319 const char *from
, /* I - Source file */
5320 const char *to
) /* I - Destination file */
5322 fd_set input
; /* select() input set */
5323 struct timeval timeout
; /* select() timeout */
5324 int maxfd
; /* Max file descriptor for select() */
5325 char tempfile
[1024]; /* Temporary PPD file */
5326 int tempfd
; /* Temporary PPD file descriptor */
5327 int temppid
; /* Process ID of cups-driverd */
5328 int temppipe
[2]; /* Temporary pipes */
5329 char *argv
[4], /* Command-line arguments */
5330 *envp
[MAX_ENV
]; /* Environment */
5331 cups_file_t
*src
, /* Source file */
5332 *dst
; /* Destination file */
5333 ppd_file_t
*ppd
; /* PPD file */
5334 int bytes
, /* Bytes from pipe */
5335 total
; /* Total bytes from pipe */
5336 char buffer
[2048]; /* Copy buffer */
5337 int i
; /* Looping var */
5338 char option
[PPD_MAX_NAME
], /* Option name */
5339 choice
[PPD_MAX_NAME
]; /* Choice name */
5340 ppd_size_t
*size
; /* Default size */
5341 int num_defaults
; /* Number of default options */
5342 cups_option_t
*defaults
; /* Default options */
5343 char cups_protocol
[PPD_MAX_LINE
];
5344 /* cupsProtocol attribute */
5347 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5348 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5352 * Run cups-driverd to get the PPD file...
5355 argv
[0] = "cups-driverd";
5357 argv
[2] = (char *)from
;
5360 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5362 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5363 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5364 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5368 cupsdOpenPipe(temppipe
);
5370 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5371 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5373 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5374 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5385 * Wait up to 30 seconds for the PPD file to be copied...
5390 if (temppipe
[0] > CGIPipes
[0])
5391 maxfd
= temppipe
[0] + 1;
5393 maxfd
= CGIPipes
[0] + 1;
5398 * See if we have data ready...
5402 FD_SET(temppipe
[0], &input
);
5403 FD_SET(CGIPipes
[0], &input
);
5405 timeout
.tv_sec
= 30;
5406 timeout
.tv_usec
= 0;
5408 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5418 * We have timed out...
5424 if (FD_ISSET(temppipe
[0], &input
))
5427 * Read the PPD file from the pipe, and write it to the PPD file.
5430 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5432 if (write(tempfd
, buffer
, bytes
) < bytes
)
5441 if (FD_ISSET(CGIPipes
[0], &input
))
5451 * No data from cups-deviced...
5454 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5460 * Read the source file and see what page sizes are supported...
5463 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5470 * Open the destination (if possible) and set the default options...
5475 cups_protocol
[0] = '\0';
5477 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5480 * Read all of the default lines from the old PPD...
5483 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5484 if (!strncmp(buffer
, "*Default", 8))
5487 * Add the default option...
5490 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5491 choice
, sizeof(choice
)))
5493 ppd_option_t
*ppdo
; /* PPD option */
5497 * Only add the default if the default hasn't already been
5498 * set and the choice exists in the new PPD...
5501 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5502 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5503 ppdFindChoice(ppdo
, choice
))
5504 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5508 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5509 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5513 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5516 * Add the default media sizes...
5519 num_defaults
= cupsAddOption("PageSize", size
->name
,
5520 num_defaults
, &defaults
);
5521 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5522 num_defaults
, &defaults
);
5523 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5524 num_defaults
, &defaults
);
5525 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5526 num_defaults
, &defaults
);
5532 * Open the source file for a copy...
5535 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5537 cupsFreeOptions(num_defaults
, defaults
);
5543 * Open the destination file for a copy...
5546 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5548 cupsFreeOptions(num_defaults
, defaults
);
5555 * Copy the source file to the destination...
5558 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5560 if (!strncmp(buffer
, "*Default", 8))
5563 * Check for an previous default option choice...
5566 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5567 choice
, sizeof(choice
)))
5569 const char *val
; /* Default option value */
5572 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5575 * Substitute the previous choice...
5578 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5583 cupsFilePrintf(dst
, "%s\n", buffer
);
5586 if (cups_protocol
[0])
5587 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5589 cupsFreeOptions(num_defaults
, defaults
);
5592 * Close both files and return...
5599 return (cupsFileClose(dst
));
5604 * 'copy_job_attrs()' - Copy job attributes.
5608 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5609 cupsd_job_t
*job
, /* I - Job */
5610 cups_array_t
*ra
) /* I - Requested attributes array */
5612 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5616 * Send the requested attributes for each job...
5619 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5620 con
->servername
, con
->serverport
, "/jobs/%d",
5623 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5624 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5625 "document-count", job
->num_files
);
5627 if (!ra
|| cupsArrayFind(ra
, "job-media-progress"))
5628 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5629 "job-media-progress", job
->progress
);
5631 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5632 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5633 "job-more-info", NULL
, job_uri
);
5635 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5636 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5637 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5638 job
->num_files
> 0);
5640 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5641 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5642 "job-printer-up-time", time(NULL
));
5644 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5645 add_job_state_reasons(con
, job
);
5647 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5648 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5649 "job-uri", NULL
, job_uri
);
5651 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5656 * 'copy_printer_attrs()' - Copy printer attributes.
5661 cupsd_client_t
*con
, /* I - Client connection */
5662 cupsd_printer_t
*printer
, /* I - Printer */
5663 cups_array_t
*ra
) /* I - Requested attributes array */
5665 char printer_uri
[HTTP_MAX_URI
];
5667 time_t curtime
; /* Current time */
5668 int i
; /* Looping var */
5669 ipp_attribute_t
*history
; /* History collection */
5673 * Copy the printer attributes to the response using requested-attributes
5674 * and document-format attributes that may be provided by the client.
5677 curtime
= time(NULL
);
5679 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5680 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5681 "marker-change-time", printer
->marker_time
);
5683 if (printer
->num_printers
> 0 &&
5684 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5686 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5687 cupsd_printer_t
*p2
; /* Printer in class */
5688 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5691 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5692 IPP_TAG_URI
, "member-uris",
5693 printer
->num_printers
, NULL
,
5696 for (i
= 0; i
< printer
->num_printers
; i
++)
5698 p2
= printer
->printers
[i
];
5700 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5701 IPP_TAG_URI
)) != NULL
)
5702 member_uris
->values
[i
].string
.text
=
5703 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5706 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5707 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5709 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5710 "/classes/%s" : "/printers/%s", p2
->name
);
5711 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5717 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5718 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5719 "printer-alert", NULL
, printer
->alert
);
5721 if (printer
->alert_description
&&
5722 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5723 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5724 "printer-alert-description", NULL
,
5725 printer
->alert_description
);
5727 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5728 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5729 ippTimeToDate(curtime
));
5732 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5734 if (printer
->reg_name
)
5735 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5736 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5738 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5739 "printer-dns-sd-name", 0);
5741 #endif /* HAVE_DNSSD */
5743 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5744 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5745 "printer-error-policy", NULL
, printer
->error_policy
);
5747 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
5749 static const char * const errors
[] =/* printer-error-policy-supported values */
5752 "retry-current-job",
5757 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
5758 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5759 "printer-error-policy-supported", NULL
, "retry-current-job");
5761 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5762 "printer-error-policy-supported",
5763 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
5766 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5767 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5768 printer
->accepting
);
5770 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5771 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5774 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5775 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5777 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5778 "http", NULL
, con
->servername
, con
->serverport
,
5779 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5780 "/classes/%s" : "/printers/%s", printer
->name
);
5781 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5782 "printer-more-info", NULL
, printer_uri
);
5785 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5786 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5787 "printer-op-policy", NULL
, printer
->op_policy
);
5789 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5790 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5793 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5794 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5795 "printer-state-change-time", printer
->state_time
);
5797 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5798 cupsArrayFind(ra
, "printer-state-history"))
5801 * Printer history is only sent if specifically requested, so that
5802 * older CUPS/IPP clients won't barf on the collection attributes.
5805 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5806 "printer-state-history",
5807 printer
->num_history
, NULL
);
5809 for (i
= 0; i
< printer
->num_history
; i
++)
5810 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5811 NULL
, IPP_TAG_ZERO
, 0);
5814 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5815 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5816 "printer-state-message", NULL
, printer
->state_message
);
5818 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5819 add_printer_state_reasons(con
, printer
);
5821 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5823 int type
; /* printer-type value */
5827 * Add the CUPS-specific printer-type attribute...
5830 type
= printer
->type
;
5832 if (printer
== DefaultPrinter
)
5833 type
|= CUPS_PRINTER_DEFAULT
;
5835 if (!printer
->accepting
)
5836 type
|= CUPS_PRINTER_REJECTING
;
5838 if (!printer
->shared
)
5839 type
|= CUPS_PRINTER_NOT_SHARED
;
5841 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5845 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5846 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5847 "printer-up-time", curtime
);
5849 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5850 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5852 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5853 "ipp", NULL
, con
->servername
, con
->serverport
,
5854 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5855 "/classes/%s" : "/printers/%s", printer
->name
);
5856 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5857 "printer-uri-supported", NULL
, printer_uri
);
5858 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5862 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5863 add_queued_job_count(con
, printer
);
5865 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5866 if (printer
->ppd_attrs
)
5867 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0);
5868 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5873 * 'copy_subscription_attrs()' - Copy subscription attributes.
5877 copy_subscription_attrs(
5878 cupsd_client_t
*con
, /* I - Client connection */
5879 cupsd_subscription_t
*sub
, /* I - Subscription */
5880 cups_array_t
*ra
) /* I - Requested attributes array */
5882 ipp_attribute_t
*attr
; /* Current attribute */
5883 char printer_uri
[HTTP_MAX_URI
];
5885 int count
; /* Number of events */
5886 unsigned mask
; /* Current event mask */
5887 const char *name
; /* Current event name */
5891 * Copy the subscription attributes to the response using the
5892 * requested-attributes attribute that may be provided by the client.
5895 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5897 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5900 * Simple event list...
5903 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5904 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5905 "notify-events", NULL
, name
);
5910 * Complex event list...
5913 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5914 if (sub
->mask
& mask
)
5917 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5918 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5919 "notify-events", count
, NULL
, NULL
);
5921 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5922 if (sub
->mask
& mask
)
5924 attr
->values
[count
].string
.text
=
5925 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5932 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5933 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5934 "notify-job-id", sub
->job
->id
);
5936 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5937 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5938 "notify-lease-duration", sub
->lease
);
5940 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5942 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5943 "ipp", NULL
, con
->servername
, con
->serverport
,
5944 "/printers/%s", sub
->dest
->name
);
5945 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5946 "notify-printer-uri", NULL
, printer_uri
);
5949 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5950 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5951 "notify-recipient-uri", NULL
, sub
->recipient
);
5952 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5953 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5954 "notify-pull-method", NULL
, "ippget");
5956 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5957 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5958 "notify-subscriber-user-name", NULL
, sub
->owner
);
5960 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5961 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5962 "notify-subscription-id", sub
->id
);
5964 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5965 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5966 "notify-time-interval", sub
->interval
);
5968 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5969 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5970 sub
->user_data
, sub
->user_data_len
);
5975 * 'create_job()' - Print a file to a printer or class.
5979 create_job(cupsd_client_t
*con
, /* I - Client connection */
5980 ipp_attribute_t
*uri
) /* I - Printer URI */
5982 cupsd_printer_t
*printer
; /* Printer */
5983 cupsd_job_t
*job
; /* New job */
5986 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5987 con
->http
.fd
, uri
->values
[0].string
.text
);
5990 * Is the destination valid?
5993 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5999 send_ipp_status(con
, IPP_NOT_FOUND
,
6000 _("The printer or class was not found."));
6005 * Create the job object...
6008 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6011 job
->pending_timeout
= 1;
6014 * Save and log the job...
6017 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6018 job
->dest
, job
->username
);
6023 * 'create_requested_array()' - Create an array for the requested-attributes.
6026 static cups_array_t
* /* O - Array of attributes or NULL */
6027 create_requested_array(ipp_t
*request
) /* I - IPP request */
6029 int i
; /* Looping var */
6030 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6031 cups_array_t
*ra
; /* Requested attributes array */
6032 char *value
; /* Current value */
6036 * Get the requested-attributes attribute, and return NULL if we don't
6040 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6041 IPP_TAG_KEYWORD
)) == NULL
)
6045 * If the attribute contains a single "all" keyword, return NULL...
6048 if (requested
->num_values
== 1 &&
6049 !strcmp(requested
->values
[0].string
.text
, "all"))
6053 * Create an array using "strcmp" as the comparison function...
6056 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6058 for (i
= 0; i
< requested
->num_values
; i
++)
6060 value
= requested
->values
[i
].string
.text
;
6062 if (!strcmp(value
, "job-template"))
6064 cupsArrayAdd(ra
, "copies");
6065 cupsArrayAdd(ra
, "copies-default");
6066 cupsArrayAdd(ra
, "copies-supported");
6067 cupsArrayAdd(ra
, "finishings");
6068 cupsArrayAdd(ra
, "finishings-default");
6069 cupsArrayAdd(ra
, "finishings-supported");
6070 cupsArrayAdd(ra
, "job-hold-until");
6071 cupsArrayAdd(ra
, "job-hold-until-default");
6072 cupsArrayAdd(ra
, "job-hold-until-supported");
6073 cupsArrayAdd(ra
, "job-priority");
6074 cupsArrayAdd(ra
, "job-priority-default");
6075 cupsArrayAdd(ra
, "job-priority-supported");
6076 cupsArrayAdd(ra
, "job-sheets");
6077 cupsArrayAdd(ra
, "job-sheets-default");
6078 cupsArrayAdd(ra
, "job-sheets-supported");
6079 cupsArrayAdd(ra
, "media");
6080 cupsArrayAdd(ra
, "media-default");
6081 cupsArrayAdd(ra
, "media-supported");
6082 cupsArrayAdd(ra
, "multiple-document-handling");
6083 cupsArrayAdd(ra
, "multiple-document-handling-default");
6084 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6085 cupsArrayAdd(ra
, "number-up");
6086 cupsArrayAdd(ra
, "number-up-default");
6087 cupsArrayAdd(ra
, "number-up-supported");
6088 cupsArrayAdd(ra
, "orientation-requested");
6089 cupsArrayAdd(ra
, "orientation-requested-default");
6090 cupsArrayAdd(ra
, "orientation-requested-supported");
6091 cupsArrayAdd(ra
, "page-ranges");
6092 cupsArrayAdd(ra
, "page-ranges-supported");
6093 cupsArrayAdd(ra
, "printer-resolution");
6094 cupsArrayAdd(ra
, "printer-resolution-default");
6095 cupsArrayAdd(ra
, "printer-resolution-supported");
6096 cupsArrayAdd(ra
, "print-quality");
6097 cupsArrayAdd(ra
, "print-quality-default");
6098 cupsArrayAdd(ra
, "print-quality-supported");
6099 cupsArrayAdd(ra
, "sides");
6100 cupsArrayAdd(ra
, "sides-default");
6101 cupsArrayAdd(ra
, "sides-supported");
6103 else if (!strcmp(value
, "job-description"))
6105 cupsArrayAdd(ra
, "date-time-at-completed");
6106 cupsArrayAdd(ra
, "date-time-at-creation");
6107 cupsArrayAdd(ra
, "date-time-at-processing");
6108 cupsArrayAdd(ra
, "job-detailed-status-message");
6109 cupsArrayAdd(ra
, "job-document-access-errors");
6110 cupsArrayAdd(ra
, "job-id");
6111 cupsArrayAdd(ra
, "job-impressions");
6112 cupsArrayAdd(ra
, "job-impressions-completed");
6113 cupsArrayAdd(ra
, "job-k-octets");
6114 cupsArrayAdd(ra
, "job-k-octets-processed");
6115 cupsArrayAdd(ra
, "job-media-progress");
6116 cupsArrayAdd(ra
, "job-media-sheets");
6117 cupsArrayAdd(ra
, "job-media-sheets-completed");
6118 cupsArrayAdd(ra
, "job-message-from-operator");
6119 cupsArrayAdd(ra
, "job-more-info");
6120 cupsArrayAdd(ra
, "job-name");
6121 cupsArrayAdd(ra
, "job-originating-user-name");
6122 cupsArrayAdd(ra
, "job-printer-up-time");
6123 cupsArrayAdd(ra
, "job-printer-uri");
6124 cupsArrayAdd(ra
, "job-state");
6125 cupsArrayAdd(ra
, "job-state-message");
6126 cupsArrayAdd(ra
, "job-state-reasons");
6127 cupsArrayAdd(ra
, "job-uri");
6128 cupsArrayAdd(ra
, "number-of-documents");
6129 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6130 cupsArrayAdd(ra
, "output-device-assigned");
6131 cupsArrayAdd(ra
, "time-at-completed");
6132 cupsArrayAdd(ra
, "time-at-creation");
6133 cupsArrayAdd(ra
, "time-at-processing");
6135 else if (!strcmp(value
, "printer-description"))
6137 cupsArrayAdd(ra
, "charset-configured");
6138 cupsArrayAdd(ra
, "charset-supported");
6139 cupsArrayAdd(ra
, "color-supported");
6140 cupsArrayAdd(ra
, "compression-supported");
6141 cupsArrayAdd(ra
, "document-format-default");
6142 cupsArrayAdd(ra
, "document-format-supported");
6143 cupsArrayAdd(ra
, "generated-natural-language-supported");
6144 cupsArrayAdd(ra
, "ipp-versions-supported");
6145 cupsArrayAdd(ra
, "job-impressions-supported");
6146 cupsArrayAdd(ra
, "job-k-octets-supported");
6147 cupsArrayAdd(ra
, "job-media-sheets-supported");
6148 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6149 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6150 cupsArrayAdd(ra
, "multiple-operation-time-out");
6151 cupsArrayAdd(ra
, "natural-language-configured");
6152 cupsArrayAdd(ra
, "notify-attributes-supported");
6153 cupsArrayAdd(ra
, "notify-lease-duration-default");
6154 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6155 cupsArrayAdd(ra
, "notify-max-events-supported");
6156 cupsArrayAdd(ra
, "notify-events-default");
6157 cupsArrayAdd(ra
, "notify-events-supported");
6158 cupsArrayAdd(ra
, "notify-pull-method-supported");
6159 cupsArrayAdd(ra
, "notify-schemes-supported");
6160 cupsArrayAdd(ra
, "operations-supported");
6161 cupsArrayAdd(ra
, "pages-per-minute");
6162 cupsArrayAdd(ra
, "pages-per-minute-color");
6163 cupsArrayAdd(ra
, "pdl-override-supported");
6164 cupsArrayAdd(ra
, "printer-alert");
6165 cupsArrayAdd(ra
, "printer-alert-description");
6166 cupsArrayAdd(ra
, "printer-commands");
6167 cupsArrayAdd(ra
, "printer-current-time");
6168 cupsArrayAdd(ra
, "printer-driver-installer");
6169 cupsArrayAdd(ra
, "printer-dns-sd-name");
6170 cupsArrayAdd(ra
, "printer-info");
6171 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6172 cupsArrayAdd(ra
, "printer-location");
6173 cupsArrayAdd(ra
, "printer-make-and-model");
6174 cupsArrayAdd(ra
, "printer-message-from-operator");
6175 cupsArrayAdd(ra
, "printer-more-info");
6176 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6177 cupsArrayAdd(ra
, "printer-name");
6178 cupsArrayAdd(ra
, "printer-state");
6179 cupsArrayAdd(ra
, "printer-state-message");
6180 cupsArrayAdd(ra
, "printer-state-reasons");
6181 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6182 cupsArrayAdd(ra
, "printer-type");
6183 cupsArrayAdd(ra
, "printer-up-time");
6184 cupsArrayAdd(ra
, "printer-uri-supported");
6185 cupsArrayAdd(ra
, "queued-job-count");
6186 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6187 cupsArrayAdd(ra
, "uri-authentication-supported");
6188 cupsArrayAdd(ra
, "uri-security-supported");
6190 else if (!strcmp(value
, "printer-defaults"))
6192 char *name
; /* Option name */
6195 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6197 name
= (char *)cupsArrayNext(CommonDefaults
))
6198 cupsArrayAdd(ra
, name
);
6200 else if (!strcmp(value
, "subscription-template"))
6202 cupsArrayAdd(ra
, "notify-attributes");
6203 cupsArrayAdd(ra
, "notify-charset");
6204 cupsArrayAdd(ra
, "notify-events");
6205 cupsArrayAdd(ra
, "notify-lease-duration");
6206 cupsArrayAdd(ra
, "notify-natural-language");
6207 cupsArrayAdd(ra
, "notify-pull-method");
6208 cupsArrayAdd(ra
, "notify-recipient-uri");
6209 cupsArrayAdd(ra
, "notify-time-interval");
6210 cupsArrayAdd(ra
, "notify-user-data");
6213 cupsArrayAdd(ra
, value
);
6221 * 'create_subscription()' - Create a notification subscription.
6225 create_subscription(
6226 cupsd_client_t
*con
, /* I - Client connection */
6227 ipp_attribute_t
*uri
) /* I - Printer URI */
6229 http_status_t status
; /* Policy status */
6230 int i
; /* Looping var */
6231 ipp_attribute_t
*attr
; /* Current attribute */
6232 cups_ptype_t dtype
; /* Destination type (printer/class) */
6233 char scheme
[HTTP_MAX_URI
],
6234 /* Scheme portion of URI */
6235 userpass
[HTTP_MAX_URI
],
6236 /* Username portion of URI */
6238 /* Host portion of URI */
6239 resource
[HTTP_MAX_URI
];
6240 /* Resource portion of URI */
6241 int port
; /* Port portion of URI */
6242 cupsd_printer_t
*printer
; /* Printer/class */
6243 cupsd_job_t
*job
; /* Job */
6244 int jobid
; /* Job ID */
6245 cupsd_subscription_t
*sub
; /* Subscription object */
6246 const char *username
, /* requesting-user-name or
6247 authenticated username */
6248 *recipient
, /* notify-recipient-uri */
6249 *pullmethod
; /* notify-pull-method */
6250 ipp_attribute_t
*user_data
; /* notify-user-data */
6251 int interval
, /* notify-time-interval */
6252 lease
; /* notify-lease-duration */
6253 unsigned mask
; /* notify-events */
6254 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6255 *notify_lease
; /* notify-lease-duration(-default) */
6259 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6261 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6262 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6263 attr
->value_tag
, attr
->name
);
6265 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6270 * Is the destination valid?
6273 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6274 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6275 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6277 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6278 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6279 sizeof(host
), &port
, resource
, sizeof(resource
));
6281 if (!strcmp(resource
, "/"))
6283 dtype
= (cups_ptype_t
)0;
6286 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6288 dtype
= (cups_ptype_t
)0;
6291 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6293 dtype
= CUPS_PRINTER_CLASS
;
6296 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6302 send_ipp_status(con
, IPP_NOT_FOUND
,
6303 _("The printer or class was not found."));
6313 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6316 send_http_error(con
, status
, printer
);
6320 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6322 send_http_error(con
, status
, NULL
);
6327 * Get the user that is requesting the subscription...
6330 username
= get_username(con
);
6333 * Find the first subscription group attribute; return if we have
6337 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6338 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6343 send_ipp_status(con
, IPP_BAD_REQUEST
,
6344 _("No subscription attributes in request"));
6349 * Process the subscription attributes in the request...
6352 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6360 lease
= DefaultLeaseDuration
;
6362 mask
= CUPSD_EVENT_NONE
;
6366 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6368 notify_lease
= ippFindAttribute(printer
->attrs
,
6369 "notify-lease-duration-default",
6373 lease
= notify_lease
->values
[0].integer
;
6377 notify_events
= NULL
;
6378 notify_lease
= NULL
;
6381 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6383 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6384 attr
->value_tag
== IPP_TAG_URI
)
6387 * Validate the recipient scheme against the ServerBin/notifier
6391 char notifier
[1024]; /* Notifier filename */
6394 recipient
= attr
->values
[0].string
.text
;
6396 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6397 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6398 host
, sizeof(host
), &port
,
6399 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6401 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6402 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
6403 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6404 "notify-status-code", IPP_URI_SCHEME
);
6408 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6410 if (access(notifier
, X_OK
))
6412 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6413 _("notify-recipient-uri URI \"%s\" uses unknown "
6414 "scheme"), recipient
);
6415 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6416 "notify-status-code", IPP_URI_SCHEME
);
6420 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6422 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6423 _("notify-recipient-uri URI \"%s\" is already used"),
6425 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6426 "notify-status-code", IPP_ATTRIBUTES
);
6430 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6431 attr
->value_tag
== IPP_TAG_KEYWORD
)
6433 pullmethod
= attr
->values
[0].string
.text
;
6435 if (strcmp(pullmethod
, "ippget"))
6437 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6438 _("Bad notify-pull-method \"%s\""), pullmethod
);
6439 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6440 "notify-status-code", IPP_ATTRIBUTES
);
6444 else if (!strcmp(attr
->name
, "notify-charset") &&
6445 attr
->value_tag
== IPP_TAG_CHARSET
&&
6446 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6447 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6449 send_ipp_status(con
, IPP_CHARSET
,
6450 _("Character set \"%s\" not supported"),
6451 attr
->values
[0].string
.text
);
6454 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6455 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6456 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6458 send_ipp_status(con
, IPP_CHARSET
,
6459 _("Language \"%s\" not supported"),
6460 attr
->values
[0].string
.text
);
6463 else if (!strcmp(attr
->name
, "notify-user-data") &&
6464 attr
->value_tag
== IPP_TAG_STRING
)
6466 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6468 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6469 _("The notify-user-data value is too large "
6470 "(%d > 63 octets)"),
6471 attr
->values
[0].unknown
.length
);
6477 else if (!strcmp(attr
->name
, "notify-events") &&
6478 attr
->value_tag
== IPP_TAG_KEYWORD
)
6479 notify_events
= attr
;
6480 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6481 attr
->value_tag
== IPP_TAG_INTEGER
)
6482 lease
= attr
->values
[0].integer
;
6483 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6484 attr
->value_tag
== IPP_TAG_INTEGER
)
6485 interval
= attr
->values
[0].integer
;
6486 else if (!strcmp(attr
->name
, "notify-job-id") &&
6487 attr
->value_tag
== IPP_TAG_INTEGER
)
6488 jobid
= attr
->values
[0].integer
;
6495 for (i
= 0; i
< notify_events
->num_values
; i
++)
6496 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6500 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6502 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6503 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6504 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6506 if (!recipient
&& !pullmethod
)
6509 if (mask
== CUPSD_EVENT_NONE
)
6512 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6514 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6517 send_ipp_status(con
, IPP_BAD_REQUEST
,
6518 _("notify-events not specified"));
6523 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6525 cupsdLogMessage(CUPSD_LOG_INFO
,
6526 "create_subscription: Limiting notify-lease-duration to "
6529 lease
= MaxLeaseDuration
;
6534 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6536 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found"), jobid
);
6543 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6545 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6546 _("There are too many subscriptions."));
6551 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6554 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6555 "Added subscription %d for printer \"%s\"",
6556 sub
->id
, printer
->name
);
6558 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6561 sub
->interval
= interval
;
6563 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6565 cupsdSetString(&sub
->owner
, username
);
6569 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6570 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6571 sub
->user_data_len
);
6574 ippAddSeparator(con
->response
);
6575 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6576 "notify-subscription-id", sub
->id
);
6578 con
->response
->request
.status
.status_code
= IPP_OK
;
6584 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6589 * 'delete_printer()' - Remove a printer or class from the system.
6593 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6594 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6596 http_status_t status
; /* Policy status */
6597 cups_ptype_t dtype
; /* Destination type (printer/class) */
6598 cupsd_printer_t
*printer
; /* Printer/class */
6599 char filename
[1024]; /* Script/PPD filename */
6602 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6603 con
->http
.fd
, uri
->values
[0].string
.text
);
6606 * Do we have a valid URI?
6609 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6615 send_ipp_status(con
, IPP_NOT_FOUND
,
6616 _("The printer or class was not found."));
6624 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6626 send_http_error(con
, status
, NULL
);
6631 * Remove old jobs...
6634 cupsdCancelJobs(printer
->name
, NULL
, 1);
6637 * Remove old subscriptions and send a "deleted printer" event...
6640 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6641 "%s \"%s\" deleted by \"%s\".",
6642 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6643 printer
->name
, get_username(con
));
6645 cupsdExpireSubscriptions(printer
, NULL
);
6648 * Remove any old PPD or script files...
6651 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6655 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6659 snprintf(filename
, sizeof(filename
), "%s/%s.ipp3", CacheDir
, printer
->name
);
6662 snprintf(filename
, sizeof(filename
), "%s/%s.pwg2", CacheDir
, printer
->name
);
6667 * Unregister color profiles...
6670 apple_unregister_profiles(printer
);
6671 #endif /* __APPLE__ */
6673 if (dtype
& CUPS_PRINTER_CLASS
)
6675 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6676 printer
->name
, get_username(con
));
6678 cupsdDeletePrinter(printer
, 0);
6679 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6683 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6684 printer
->name
, get_username(con
));
6686 if (cupsdDeletePrinter(printer
, 0))
6687 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6689 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6692 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6695 * Return with no errors...
6698 con
->response
->request
.status
.status_code
= IPP_OK
;
6703 * 'get_default()' - Get the default destination.
6707 get_default(cupsd_client_t
*con
) /* I - Client connection */
6709 http_status_t status
; /* Policy status */
6710 cups_array_t
*ra
; /* Requested attributes array */
6713 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6719 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6721 send_http_error(con
, status
, NULL
);
6727 ra
= create_requested_array(con
->request
);
6729 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6731 cupsArrayDelete(ra
);
6733 con
->response
->request
.status
.status_code
= IPP_OK
;
6736 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6741 * 'get_devices()' - Get the list of available devices on the local system.
6745 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6747 http_status_t status
; /* Policy status */
6748 ipp_attribute_t
*limit
, /* limit attribute */
6749 *timeout
, /* timeout attribute */
6750 *requested
, /* requested-attributes attribute */
6751 *exclude
, /* exclude-schemes attribute */
6752 *include
; /* include-schemes attribute */
6753 char command
[1024], /* cups-deviced command */
6754 options
[2048], /* Options to pass to command */
6756 /* String for requested attributes */
6758 /* String for excluded schemes */
6760 /* String for included schemes */
6763 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6769 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6771 send_http_error(con
, status
, NULL
);
6776 * Run cups-deviced command with the given options...
6779 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6780 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6781 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6783 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6784 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6787 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6789 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6792 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6794 exclude_str
[0] = '\0';
6797 url_encode_attr(include
, include_str
, sizeof(include_str
));
6799 include_str
[0] = '\0';
6801 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6802 snprintf(options
, sizeof(options
),
6803 "%d+%d+%d+%d+%s%s%s%s%s",
6804 con
->request
->request
.op
.request_id
,
6805 limit
? limit
->values
[0].integer
: 0,
6806 timeout
? timeout
->values
[0].integer
: 15,
6809 exclude_str
[0] ? "%20" : "", exclude_str
,
6810 include_str
[0] ? "%20" : "", include_str
);
6812 if (cupsdSendCommand(con
, command
, options
, 1))
6815 * Command started successfully, don't send an IPP response here...
6818 ippDelete(con
->response
);
6819 con
->response
= NULL
;
6824 * Command failed, return "internal error" so the user knows something
6828 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6829 _("cups-deviced failed to execute."));
6835 * 'get_document()' - Get a copy of a job file.
6839 get_document(cupsd_client_t
*con
, /* I - Client connection */
6840 ipp_attribute_t
*uri
) /* I - Job URI */
6842 http_status_t status
; /* Policy status */
6843 ipp_attribute_t
*attr
; /* Current attribute */
6844 int jobid
; /* Job ID */
6845 int docnum
; /* Document number */
6846 cupsd_job_t
*job
; /* Current job */
6847 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6848 username
[HTTP_MAX_URI
], /* Username portion of URI */
6849 host
[HTTP_MAX_URI
], /* Host portion of URI */
6850 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6851 int port
; /* Port portion of URI */
6852 char filename
[1024], /* Filename for document */
6853 format
[1024]; /* Format for document */
6856 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6857 con
->http
.fd
, uri
->values
[0].string
.text
);
6860 * See if we have a job URI or a printer URI...
6863 if (!strcmp(uri
->name
, "printer-uri"))
6866 * Got a printer URI; see if we also have a job-id attribute...
6869 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6870 IPP_TAG_INTEGER
)) == NULL
)
6872 send_ipp_status(con
, IPP_BAD_REQUEST
,
6873 _("Got a printer-uri attribute but no job-id"));
6877 jobid
= attr
->values
[0].integer
;
6882 * Got a job URI; parse it to get the job ID...
6885 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6886 sizeof(scheme
), username
, sizeof(username
), host
,
6887 sizeof(host
), &port
, resource
, sizeof(resource
));
6889 if (strncmp(resource
, "/jobs/", 6))
6895 send_ipp_status(con
, IPP_BAD_REQUEST
,
6896 _("Bad job-uri attribute \"%s\""),
6897 uri
->values
[0].string
.text
);
6901 jobid
= atoi(resource
+ 6);
6905 * See if the job exists...
6908 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6911 * Nope - return a "not found" error...
6914 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
6922 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6924 send_http_error(con
, status
, NULL
);
6929 * Get the document number...
6932 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6933 IPP_TAG_INTEGER
)) == NULL
)
6935 send_ipp_status(con
, IPP_BAD_REQUEST
,
6936 _("Missing document-number attribute"));
6940 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6941 attr
->num_values
> 1)
6943 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6948 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6950 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6952 cupsdLogMessage(CUPSD_LOG_ERROR
,
6953 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6955 send_ipp_status(con
, IPP_NOT_FOUND
,
6956 _("Unable to open document %d in job %d"), docnum
, jobid
);
6960 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6964 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6965 job
->filetypes
[docnum
- 1]->type
);
6967 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6969 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6971 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6972 IPP_TAG_NAME
)) != NULL
)
6973 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6974 NULL
, attr
->values
[0].string
.text
);
6979 * 'get_job_attrs()' - Get job attributes.
6983 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6984 ipp_attribute_t
*uri
) /* I - Job URI */
6986 http_status_t status
; /* Policy status */
6987 ipp_attribute_t
*attr
; /* Current attribute */
6988 int jobid
; /* Job ID */
6989 cupsd_job_t
*job
; /* Current job */
6990 cupsd_printer_t
*printer
; /* Current printer */
6991 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6992 username
[HTTP_MAX_URI
], /* Username portion of URI */
6993 host
[HTTP_MAX_URI
], /* Host portion of URI */
6994 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6995 int port
; /* Port portion of URI */
6996 cups_array_t
*ra
; /* Requested attributes array */
6999 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7000 con
->http
.fd
, uri
->values
[0].string
.text
);
7003 * See if we have a job URI or a printer URI...
7006 if (!strcmp(uri
->name
, "printer-uri"))
7009 * Got a printer URI; see if we also have a job-id attribute...
7012 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7013 IPP_TAG_INTEGER
)) == NULL
)
7015 send_ipp_status(con
, IPP_BAD_REQUEST
,
7016 _("Got a printer-uri attribute but no job-id"));
7020 jobid
= attr
->values
[0].integer
;
7025 * Got a job URI; parse it to get the job ID...
7028 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7029 sizeof(scheme
), username
, sizeof(username
), host
,
7030 sizeof(host
), &port
, resource
, sizeof(resource
));
7032 if (strncmp(resource
, "/jobs/", 6))
7038 send_ipp_status(con
, IPP_BAD_REQUEST
,
7039 _("Bad job-uri attribute \"%s\""),
7040 uri
->values
[0].string
.text
);
7044 jobid
= atoi(resource
+ 6);
7048 * See if the job exists...
7051 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7054 * Nope - return a "not found" error...
7057 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
7065 if ((printer
= job
->printer
) == NULL
)
7066 printer
= cupsdFindDest(job
->dest
);
7070 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
7073 send_http_error(con
, status
, printer
);
7077 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7079 send_http_error(con
, status
, NULL
);
7084 * Copy attributes...
7089 ra
= create_requested_array(con
->request
);
7090 copy_job_attrs(con
, job
, ra
);
7091 cupsArrayDelete(ra
);
7093 con
->response
->request
.status
.status_code
= IPP_OK
;
7098 * 'get_jobs()' - Get a list of jobs for the specified printer.
7102 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7103 ipp_attribute_t
*uri
) /* I - Printer URI */
7105 http_status_t status
; /* Policy status */
7106 ipp_attribute_t
*attr
; /* Current attribute */
7107 const char *dest
; /* Destination */
7108 cups_ptype_t dtype
; /* Destination type (printer/class) */
7109 cups_ptype_t dmask
; /* Destination type mask */
7110 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7111 username
[HTTP_MAX_URI
], /* Username portion of URI */
7112 host
[HTTP_MAX_URI
], /* Host portion of URI */
7113 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7114 int port
; /* Port portion of URI */
7115 int job_comparison
; /* Job comparison */
7116 ipp_jstate_t job_state
; /* job-state value */
7117 int first_job_id
; /* First job ID */
7118 int limit
; /* Maximum number of jobs to return */
7119 int count
; /* Number of jobs that match */
7120 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7121 cupsd_job_t
*job
; /* Current job pointer */
7122 cupsd_printer_t
*printer
; /* Printer */
7123 cups_array_t
*list
; /* Which job list... */
7124 cups_array_t
*ra
; /* Requested attributes array */
7127 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7128 uri
->values
[0].string
.text
);
7131 * Is the destination valid?
7134 if (strcmp(uri
->name
, "printer-uri"))
7136 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request"));
7140 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7141 sizeof(scheme
), username
, sizeof(username
), host
,
7142 sizeof(host
), &port
, resource
, sizeof(resource
));
7144 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7147 dtype
= (cups_ptype_t
)0;
7148 dmask
= (cups_ptype_t
)0;
7151 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7154 dtype
= (cups_ptype_t
)0;
7155 dmask
= CUPS_PRINTER_CLASS
;
7158 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7161 dtype
= CUPS_PRINTER_CLASS
;
7162 dmask
= CUPS_PRINTER_CLASS
;
7165 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7172 send_ipp_status(con
, IPP_NOT_FOUND
,
7173 _("The printer or class was not found."));
7178 dtype
&= CUPS_PRINTER_CLASS
;
7179 dmask
= CUPS_PRINTER_CLASS
;
7188 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
7191 send_http_error(con
, status
, printer
);
7195 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7197 send_http_error(con
, status
, NULL
);
7201 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7204 * See if the "which-jobs" attribute have been specified...
7207 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7208 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7210 send_ipp_status(con
, IPP_CONFLICT
,
7211 _("The %s attribute cannot be provided with job-ids."),
7215 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7217 job_comparison
= -1;
7218 job_state
= IPP_JOB_STOPPED
;
7221 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7224 job_state
= IPP_JOB_CANCELED
;
7227 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7230 job_state
= IPP_JOB_ABORTED
;
7233 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7236 job_state
= IPP_JOB_PENDING
;
7239 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7242 job_state
= IPP_JOB_CANCELED
;
7245 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7248 job_state
= IPP_JOB_PENDING
;
7251 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7254 job_state
= IPP_JOB_HELD
;
7257 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7260 job_state
= IPP_JOB_PROCESSING
;
7261 list
= PrintingJobs
;
7263 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7266 job_state
= IPP_JOB_STOPPED
;
7271 send_ipp_status(con
, IPP_ATTRIBUTES
,
7272 _("The which-jobs value \"%s\" is not supported."),
7273 attr
->values
[0].string
.text
);
7274 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7275 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7280 * See if they want to limit the number of jobs reported...
7283 if ((attr
= ippFindAttribute(con
->request
, "limit",
7284 IPP_TAG_INTEGER
)) != NULL
)
7288 send_ipp_status(con
, IPP_CONFLICT
,
7289 _("The %s attribute cannot be provided with job-ids."),
7294 limit
= attr
->values
[0].integer
;
7299 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7300 IPP_TAG_INTEGER
)) != NULL
)
7304 send_ipp_status(con
, IPP_CONFLICT
,
7305 _("The %s attribute cannot be provided with job-ids."),
7310 first_job_id
= attr
->values
[0].integer
;
7316 * See if we only want to see jobs for a specific user...
7319 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7320 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7322 send_ipp_status(con
, IPP_CONFLICT
,
7323 _("The %s attribute cannot be provided with job-ids."),
7327 else if (attr
&& attr
->values
[0].boolean
)
7328 strlcpy(username
, get_username(con
), sizeof(username
));
7332 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7333 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7336 * IPP conformance - Get-Jobs has a default requested-attributes value of
7337 * "job-id" and "job-uri".
7340 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7341 cupsArrayAdd(ra
, "job-id");
7342 cupsArrayAdd(ra
, "job-uri");
7346 * OK, build a list of jobs for this printer...
7351 int i
; /* Looping var */
7353 for (i
= 0; i
< job_ids
->num_values
; i
++)
7355 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
7359 if (i
< job_ids
->num_values
)
7361 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
7362 job_ids
->values
[i
].integer
);
7366 for (i
= 0; i
< job_ids
->num_values
; i
++)
7368 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7374 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7380 ippAddSeparator(con
->response
);
7382 copy_job_attrs(con
, job
, ra
);
7387 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7388 (limit
<= 0 || count
< limit
) && job
;
7389 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7392 * Filter out jobs that don't match...
7395 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7396 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7397 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7398 job
->username
, job
->state_value
, job
->attrs
);
7400 if (!job
->dest
|| !job
->username
)
7403 if (!job
->dest
|| !job
->username
)
7406 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7407 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7409 if ((job
->dtype
& dmask
) != dtype
&&
7410 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7413 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7414 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7415 (job_comparison
> 0 && job
->state_value
< job_state
))
7418 if (job
->id
< first_job_id
)
7425 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7430 if (username
[0] && strcasecmp(username
, job
->username
))
7434 ippAddSeparator(con
->response
);
7438 copy_job_attrs(con
, job
, ra
);
7441 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7444 cupsArrayDelete(ra
);
7446 con
->response
->request
.status
.status_code
= IPP_OK
;
7451 * 'get_notifications()' - Get events for a subscription.
7455 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7457 int i
, j
; /* Looping vars */
7458 http_status_t status
; /* Policy status */
7459 cupsd_subscription_t
*sub
; /* Subscription */
7460 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7461 *sequences
; /* notify-sequence-numbers */
7462 int min_seq
; /* Minimum sequence number */
7463 int interval
; /* Poll interval */
7466 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7470 * Get subscription attributes...
7473 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7475 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7480 send_ipp_status(con
, IPP_BAD_REQUEST
,
7481 _("Missing notify-subscription-ids attribute"));
7486 * Are the subscription IDs valid?
7489 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7491 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7494 * Bad subscription ID...
7497 send_ipp_status(con
, IPP_NOT_FOUND
,
7498 _("notify-subscription-id %d no good"),
7499 ids
->values
[i
].integer
);
7507 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7509 con
, sub
->owner
)) != HTTP_OK
)
7511 send_http_error(con
, status
, sub
->dest
);
7516 * Check the subscription type and update the interval accordingly.
7519 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7522 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7524 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7530 * Tell the client to poll again in N seconds...
7534 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7535 "notify-get-interval", interval
);
7537 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7538 "printer-up-time", time(NULL
));
7541 * Copy the subscription event attributes to the response.
7544 con
->response
->request
.status
.status_code
=
7545 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7547 for (i
= 0; i
< ids
->num_values
; i
++)
7550 * Get the subscription and sequence number...
7553 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7555 if (sequences
&& i
< sequences
->num_values
)
7556 min_seq
= sequences
->values
[i
].integer
;
7561 * If we don't have any new events, nothing to do here...
7564 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7568 * Otherwise copy all of the new events...
7571 if (sub
->first_event_id
> min_seq
)
7574 j
= min_seq
- sub
->first_event_id
;
7576 for (; j
< sub
->num_events
; j
++)
7578 ippAddSeparator(con
->response
);
7580 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7581 IPP_TAG_EVENT_NOTIFICATION
, 0);
7588 * 'get_ppd()' - Get a named PPD from the local system.
7592 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7593 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7595 http_status_t status
; /* Policy status */
7596 cupsd_printer_t
*dest
; /* Destination */
7597 cups_ptype_t dtype
; /* Destination type */
7600 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7601 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7603 if (!strcmp(uri
->name
, "ppd-name"))
7606 * Return a PPD file from cups-driverd...
7609 char command
[1024], /* cups-driverd command */
7610 options
[1024], /* Options to pass to command */
7611 ppd_name
[1024]; /* ppd-name */
7618 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7620 send_http_error(con
, status
, NULL
);
7625 * Run cups-driverd command with the given options...
7628 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7629 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7630 snprintf(options
, sizeof(options
), "get+%d+%s",
7631 con
->request
->request
.op
.request_id
, ppd_name
);
7633 if (cupsdSendCommand(con
, command
, options
, 0))
7636 * Command started successfully, don't send an IPP response here...
7639 ippDelete(con
->response
);
7640 con
->response
= NULL
;
7645 * Command failed, return "internal error" so the user knows something
7649 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7650 _("cups-driverd failed to execute."));
7653 else if (!strcmp(uri
->name
, "printer-uri") &&
7654 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7656 int i
; /* Looping var */
7657 char filename
[1024]; /* PPD filename */
7664 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7666 send_http_error(con
, status
, dest
);
7671 * See if we need the PPD for a class or remote printer...
7674 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7677 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7679 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7680 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7681 "printer-uri", NULL
, dest
->uri
);
7684 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7686 for (i
= 0; i
< dest
->num_printers
; i
++)
7687 if (!(dest
->printers
[i
]->type
&
7688 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7690 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7691 dest
->printers
[i
]->name
);
7693 if (!access(filename
, 0))
7697 if (i
< dest
->num_printers
)
7698 dest
= dest
->printers
[i
];
7701 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7702 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7703 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7709 * Found the printer with the PPD file, now see if there is one...
7712 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7714 send_ipp_status(con
, IPP_NOT_FOUND
,
7715 _("The PPD file \"%s\" could not be opened: %s"),
7716 uri
->values
[0].string
.text
, strerror(errno
));
7720 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7724 con
->response
->request
.status
.status_code
= IPP_OK
;
7727 send_ipp_status(con
, IPP_NOT_FOUND
,
7728 _("The PPD file \"%s\" could not be found."),
7729 uri
->values
[0].string
.text
);
7734 * 'get_ppds()' - Get the list of PPD files on the local system.
7738 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7740 http_status_t status
; /* Policy status */
7741 ipp_attribute_t
*limit
, /* Limit attribute */
7742 *device
, /* ppd-device-id attribute */
7743 *language
, /* ppd-natural-language attribute */
7744 *make
, /* ppd-make attribute */
7745 *model
, /* ppd-make-and-model attribute */
7746 *model_number
, /* ppd-model-number attribute */
7747 *product
, /* ppd-product attribute */
7748 *psversion
, /* ppd-psverion attribute */
7749 *type
, /* ppd-type attribute */
7750 *requested
, /* requested-attributes attribute */
7751 *exclude
, /* exclude-schemes attribute */
7752 *include
; /* include-schemes attribute */
7753 char command
[1024], /* cups-driverd command */
7754 options
[4096], /* Options to pass to command */
7755 device_str
[256],/* Escaped ppd-device-id string */
7757 /* Escaped ppd-natural-language */
7758 make_str
[256], /* Escaped ppd-make string */
7759 model_str
[256], /* Escaped ppd-make-and-model string */
7760 model_number_str
[256],
7761 /* ppd-model-number string */
7763 /* Escaped ppd-product string */
7765 /* Escaped ppd-psversion string */
7766 type_str
[256], /* Escaped ppd-type string */
7768 /* String for requested attributes */
7770 /* String for excluded schemes */
7772 /* String for included schemes */
7775 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7781 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7783 send_http_error(con
, status
, NULL
);
7788 * Run cups-driverd command with the given options...
7791 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7792 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7793 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7795 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7796 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7798 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7800 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7801 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7802 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7803 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7805 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7807 include
= ippFindAttribute(con
->request
, "include-schemes",
7811 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7813 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7816 url_encode_attr(device
, device_str
, sizeof(device_str
));
7818 device_str
[0] = '\0';
7821 url_encode_attr(language
, language_str
, sizeof(language_str
));
7823 language_str
[0] = '\0';
7826 url_encode_attr(make
, make_str
, sizeof(make_str
));
7831 url_encode_attr(model
, model_str
, sizeof(model_str
));
7833 model_str
[0] = '\0';
7836 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7837 model_number
->values
[0].integer
);
7839 model_number_str
[0] = '\0';
7842 url_encode_attr(product
, product_str
, sizeof(product_str
));
7844 product_str
[0] = '\0';
7847 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7849 psversion_str
[0] = '\0';
7852 url_encode_attr(type
, type_str
, sizeof(type_str
));
7857 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7859 exclude_str
[0] = '\0';
7862 url_encode_attr(include
, include_str
, sizeof(include_str
));
7864 include_str
[0] = '\0';
7866 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7867 snprintf(options
, sizeof(options
),
7868 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7869 con
->request
->request
.op
.request_id
,
7870 limit
? limit
->values
[0].integer
: 0,
7872 device
? "%20" : "", device_str
,
7873 language
? "%20" : "", language_str
,
7874 make
? "%20" : "", make_str
,
7875 model
? "%20" : "", model_str
,
7876 model_number
? "%20" : "", model_number_str
,
7877 product
? "%20" : "", product_str
,
7878 psversion
? "%20" : "", psversion_str
,
7879 type
? "%20" : "", type_str
,
7880 exclude_str
[0] ? "%20" : "", exclude_str
,
7881 include_str
[0] ? "%20" : "", include_str
);
7883 if (cupsdSendCommand(con
, command
, options
, 0))
7886 * Command started successfully, don't send an IPP response here...
7889 ippDelete(con
->response
);
7890 con
->response
= NULL
;
7895 * Command failed, return "internal error" so the user knows something
7899 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7900 _("cups-driverd failed to execute."));
7906 * 'get_printer_attrs()' - Get printer attributes.
7910 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7911 ipp_attribute_t
*uri
) /* I - Printer URI */
7913 http_status_t status
; /* Policy status */
7914 cups_ptype_t dtype
; /* Destination type (printer/class) */
7915 cupsd_printer_t
*printer
; /* Printer/class */
7916 cups_array_t
*ra
; /* Requested attributes array */
7919 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7920 con
->http
.fd
, uri
->values
[0].string
.text
);
7923 * Is the destination valid?
7926 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7932 send_ipp_status(con
, IPP_NOT_FOUND
,
7933 _("The printer or class was not found."));
7941 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7943 send_http_error(con
, status
, printer
);
7948 * Send the attributes...
7951 ra
= create_requested_array(con
->request
);
7953 copy_printer_attrs(con
, printer
, ra
);
7955 cupsArrayDelete(ra
);
7957 con
->response
->request
.status
.status_code
= IPP_OK
;
7962 * 'get_printer_supported()' - Get printer supported values.
7966 get_printer_supported(
7967 cupsd_client_t
*con
, /* I - Client connection */
7968 ipp_attribute_t
*uri
) /* I - Printer URI */
7970 http_status_t status
; /* Policy status */
7971 cups_ptype_t dtype
; /* Destination type (printer/class) */
7972 cupsd_printer_t
*printer
; /* Printer/class */
7975 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7976 con
->http
.fd
, uri
->values
[0].string
.text
);
7979 * Is the destination valid?
7982 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7988 send_ipp_status(con
, IPP_NOT_FOUND
,
7989 _("The printer or class was not found."));
7997 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7999 send_http_error(con
, status
, printer
);
8004 * Return a list of attributes that can be set via Set-Printer-Attributes.
8007 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8009 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8010 "printer-location", 0);
8012 con
->response
->request
.status
.status_code
= IPP_OK
;
8017 * 'get_printers()' - Get a list of printers or classes.
8021 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8022 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8024 http_status_t status
; /* Policy status */
8025 ipp_attribute_t
*attr
; /* Current attribute */
8026 int limit
; /* Max number of printers to return */
8027 int count
; /* Number of printers that match */
8028 cupsd_printer_t
*printer
; /* Current printer pointer */
8029 int printer_type
, /* printer-type attribute */
8030 printer_mask
; /* printer-type-mask attribute */
8031 char *location
; /* Location string */
8032 const char *username
; /* Current user */
8033 char *first_printer_name
; /* first-printer-name attribute */
8034 cups_array_t
*ra
; /* Requested attributes array */
8035 int local
; /* Local connection? */
8038 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8039 con
->http
.fd
, type
);
8045 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8047 send_http_error(con
, status
, NULL
);
8052 * Check for printers...
8055 if (!Printers
|| !cupsArrayCount(Printers
))
8057 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8062 * See if they want to limit the number of printers reported...
8065 if ((attr
= ippFindAttribute(con
->request
, "limit",
8066 IPP_TAG_INTEGER
)) != NULL
)
8067 limit
= attr
->values
[0].integer
;
8071 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8072 IPP_TAG_NAME
)) != NULL
)
8073 first_printer_name
= attr
->values
[0].string
.text
;
8075 first_printer_name
= NULL
;
8078 * Support filtering...
8081 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8082 IPP_TAG_ENUM
)) != NULL
)
8083 printer_type
= attr
->values
[0].integer
;
8087 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8088 IPP_TAG_ENUM
)) != NULL
)
8089 printer_mask
= attr
->values
[0].integer
;
8093 local
= httpAddrLocalhost(&(con
->clientaddr
));
8095 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8096 IPP_TAG_TEXT
)) != NULL
)
8097 location
= attr
->values
[0].string
.text
;
8101 if (con
->username
[0])
8102 username
= con
->username
;
8103 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8104 IPP_TAG_NAME
)) != NULL
)
8105 username
= attr
->values
[0].string
.text
;
8109 ra
= create_requested_array(con
->request
);
8112 * OK, build a list of printers for this printer...
8115 if (first_printer_name
)
8117 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8118 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8121 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8124 count
< limit
&& printer
;
8125 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8127 if (!local
&& !printer
->shared
)
8130 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8131 (printer
->type
& printer_mask
) == printer_type
&&
8133 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
8136 * If HideImplicitMembers is enabled, see if this printer or class
8137 * is a member of an implicit class...
8140 if (ImplicitClasses
&& HideImplicitMembers
&&
8141 printer
->in_implicit_class
)
8145 * If a username is specified, see if it is allowed or denied
8149 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
8153 * Add the group separator as needed...
8157 ippAddSeparator(con
->response
);
8162 * Send the attributes...
8165 copy_printer_attrs(con
, printer
, ra
);
8169 cupsArrayDelete(ra
);
8171 con
->response
->request
.status
.status_code
= IPP_OK
;
8176 * 'get_subscription_attrs()' - Get subscription attributes.
8180 get_subscription_attrs(
8181 cupsd_client_t
*con
, /* I - Client connection */
8182 int sub_id
) /* I - Subscription ID */
8184 http_status_t status
; /* Policy status */
8185 cupsd_subscription_t
*sub
; /* Subscription */
8186 cups_array_t
*ra
; /* Requested attributes array */
8189 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8190 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8191 con
, con
->http
.fd
, sub_id
);
8194 * Is the subscription ID valid?
8197 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8200 * Bad subscription ID...
8203 send_ipp_status(con
, IPP_NOT_FOUND
,
8204 _("notify-subscription-id %d no good"), sub_id
);
8212 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8214 con
, sub
->owner
)) != HTTP_OK
)
8216 send_http_error(con
, status
, sub
->dest
);
8221 * Copy the subscription attributes to the response using the
8222 * requested-attributes attribute that may be provided by the client.
8225 ra
= create_requested_array(con
->request
);
8227 copy_subscription_attrs(con
, sub
, ra
);
8229 cupsArrayDelete(ra
);
8231 con
->response
->request
.status
.status_code
= IPP_OK
;
8236 * 'get_subscriptions()' - Get subscriptions.
8240 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8241 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8243 http_status_t status
; /* Policy status */
8244 int count
; /* Number of subscriptions */
8245 int limit
; /* Limit */
8246 cupsd_subscription_t
*sub
; /* Subscription */
8247 cups_array_t
*ra
; /* Requested attributes array */
8248 ipp_attribute_t
*attr
; /* Attribute */
8249 cups_ptype_t dtype
; /* Destination type (printer/class) */
8250 char scheme
[HTTP_MAX_URI
],
8251 /* Scheme portion of URI */
8252 username
[HTTP_MAX_URI
],
8253 /* Username portion of URI */
8255 /* Host portion of URI */
8256 resource
[HTTP_MAX_URI
];
8257 /* Resource portion of URI */
8258 int port
; /* Port portion of URI */
8259 cupsd_job_t
*job
; /* Job pointer */
8260 cupsd_printer_t
*printer
; /* Printer */
8263 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8264 "get_subscriptions(con=%p[%d], uri=%s)",
8265 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8268 * Is the destination valid?
8271 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8272 sizeof(scheme
), username
, sizeof(username
), host
,
8273 sizeof(host
), &port
, resource
, sizeof(resource
));
8275 if (!strcmp(resource
, "/") ||
8276 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8277 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8278 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8283 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8286 job
= cupsdFindJob(atoi(resource
+ 6));
8290 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist"),
8295 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8301 send_ipp_status(con
, IPP_NOT_FOUND
,
8302 _("The printer or class was not found."));
8305 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8306 IPP_TAG_INTEGER
)) != NULL
)
8308 job
= cupsdFindJob(attr
->values
[0].integer
);
8312 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
8313 attr
->values
[0].integer
);
8324 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
8326 con
, NULL
)) != HTTP_OK
)
8328 send_http_error(con
, status
, printer
);
8333 * Copy the subscription attributes to the response using the
8334 * requested-attributes attribute that may be provided by the client.
8337 ra
= create_requested_array(con
->request
);
8339 if ((attr
= ippFindAttribute(con
->request
, "limit",
8340 IPP_TAG_INTEGER
)) != NULL
)
8341 limit
= attr
->values
[0].integer
;
8346 * See if we only want to see subscriptions for a specific user...
8349 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8350 IPP_TAG_BOOLEAN
)) != NULL
&&
8351 attr
->values
[0].boolean
)
8352 strlcpy(username
, get_username(con
), sizeof(username
));
8356 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8358 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8359 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8360 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
8362 ippAddSeparator(con
->response
);
8363 copy_subscription_attrs(con
, sub
, ra
);
8366 if (limit
&& count
>= limit
)
8370 cupsArrayDelete(ra
);
8373 con
->response
->request
.status
.status_code
= IPP_OK
;
8375 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8380 * 'get_username()' - Get the username associated with a request.
8383 static const char * /* O - Username */
8384 get_username(cupsd_client_t
*con
) /* I - Connection */
8386 ipp_attribute_t
*attr
; /* Attribute */
8389 if (con
->username
[0])
8390 return (con
->username
);
8391 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8392 IPP_TAG_NAME
)) != NULL
)
8393 return (attr
->values
[0].string
.text
);
8395 return ("anonymous");
8400 * 'hold_job()' - Hold a print job.
8404 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8405 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8407 ipp_attribute_t
*attr
; /* Current job-hold-until */
8408 const char *when
; /* New value */
8409 int jobid
; /* Job ID */
8410 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8411 username
[HTTP_MAX_URI
], /* Username portion of URI */
8412 host
[HTTP_MAX_URI
], /* Host portion of URI */
8413 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8414 int port
; /* Port portion of URI */
8415 cupsd_job_t
*job
; /* Job information */
8418 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8419 uri
->values
[0].string
.text
);
8422 * See if we have a job URI or a printer URI...
8425 if (!strcmp(uri
->name
, "printer-uri"))
8428 * Got a printer URI; see if we also have a job-id attribute...
8431 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8432 IPP_TAG_INTEGER
)) == NULL
)
8434 send_ipp_status(con
, IPP_BAD_REQUEST
,
8435 _("Got a printer-uri attribute but no job-id"));
8439 jobid
= attr
->values
[0].integer
;
8444 * Got a job URI; parse it to get the job ID...
8447 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8448 sizeof(scheme
), username
, sizeof(username
), host
,
8449 sizeof(host
), &port
, resource
, sizeof(resource
));
8451 if (strncmp(resource
, "/jobs/", 6))
8457 send_ipp_status(con
, IPP_BAD_REQUEST
,
8458 _("Bad job-uri attribute \"%s\""),
8459 uri
->values
[0].string
.text
);
8463 jobid
= atoi(resource
+ 6);
8467 * See if the job exists...
8470 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8473 * Nope - return a "not found" error...
8476 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
8481 * See if the job is owned by the requesting user...
8484 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8486 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8487 cupsdFindDest(job
->dest
));
8492 * Hold the job and return...
8495 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8496 IPP_TAG_KEYWORD
)) == NULL
)
8497 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8501 when
= attr
->values
[0].string
.text
;
8503 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8504 "Job job-hold-until value changed by user.");
8507 when
= "indefinite";
8509 cupsdSetJobHoldUntil(job
, when
, 1);
8510 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8513 con
->response
->request
.status
.status_code
= IPP_OK
;
8518 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8522 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8523 ipp_attribute_t
*uri
) /* I - Printer URI */
8525 http_status_t status
; /* Policy status */
8526 cups_ptype_t dtype
; /* Destination type (printer/class) */
8527 cupsd_printer_t
*printer
; /* Printer data */
8530 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8531 con
->http
.fd
, uri
->values
[0].string
.text
);
8534 * Is the destination valid?
8537 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8543 send_ipp_status(con
, IPP_NOT_FOUND
,
8544 _("The printer or class was not found."));
8552 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8554 send_http_error(con
, status
, printer
);
8559 * Hold pending/new jobs sent to the printer...
8562 printer
->holding_new_jobs
= 1;
8564 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8565 cupsdAddPrinterHistory(printer
);
8567 if (dtype
& CUPS_PRINTER_CLASS
)
8568 cupsdLogMessage(CUPSD_LOG_INFO
,
8569 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8570 printer
->name
, get_username(con
));
8572 cupsdLogMessage(CUPSD_LOG_INFO
,
8573 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8574 printer
->name
, get_username(con
));
8577 * Everything was ok, so return OK status...
8580 con
->response
->request
.status
.status_code
= IPP_OK
;
8585 * 'move_job()' - Move a job to a new destination.
8589 move_job(cupsd_client_t
*con
, /* I - Client connection */
8590 ipp_attribute_t
*uri
) /* I - Job URI */
8592 http_status_t status
; /* Policy status */
8593 ipp_attribute_t
*attr
; /* Current attribute */
8594 int jobid
; /* Job ID */
8595 cupsd_job_t
*job
; /* Current job */
8596 const char *src
; /* Source printer/class */
8597 cups_ptype_t stype
, /* Source type (printer or class) */
8598 dtype
; /* Destination type (printer/class) */
8599 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8600 username
[HTTP_MAX_URI
], /* Username portion of URI */
8601 host
[HTTP_MAX_URI
], /* Host portion of URI */
8602 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8603 int port
; /* Port portion of URI */
8604 cupsd_printer_t
*sprinter
, /* Source printer */
8605 *dprinter
; /* Destination printer */
8608 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8609 uri
->values
[0].string
.text
);
8612 * Get the new printer or class...
8615 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8616 IPP_TAG_URI
)) == NULL
)
8619 * Need job-printer-uri...
8622 send_ipp_status(con
, IPP_BAD_REQUEST
,
8623 _("job-printer-uri attribute missing"));
8627 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8633 send_ipp_status(con
, IPP_NOT_FOUND
,
8634 _("The printer or class was not found."));
8639 * See if we have a job URI or a printer URI...
8642 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8643 sizeof(scheme
), username
, sizeof(username
), host
,
8644 sizeof(host
), &port
, resource
, sizeof(resource
));
8646 if (!strcmp(uri
->name
, "printer-uri"))
8649 * Got a printer URI; see if we also have a job-id attribute...
8652 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8653 IPP_TAG_INTEGER
)) == NULL
)
8659 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8660 &sprinter
)) == NULL
)
8666 send_ipp_status(con
, IPP_NOT_FOUND
,
8667 _("The printer or class was not found."));
8676 * Otherwise, just move a single job...
8679 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8682 * Nope - return a "not found" error...
8685 send_ipp_status(con
, IPP_NOT_FOUND
,
8686 _("Job #%d does not exist"), attr
->values
[0].integer
);
8692 * Job found, initialize source pointers...
8703 * Got a job URI; parse it to get the job ID...
8706 if (strncmp(resource
, "/jobs/", 6))
8712 send_ipp_status(con
, IPP_BAD_REQUEST
,
8713 _("Bad job-uri attribute \"%s\""),
8714 uri
->values
[0].string
.text
);
8719 * See if the job exists...
8722 jobid
= atoi(resource
+ 6);
8724 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8727 * Nope - return a "not found" error...
8730 send_ipp_status(con
, IPP_NOT_FOUND
,
8731 _("Job #%d does not exist"), jobid
);
8737 * Job found, initialize source pointers...
8746 * Check the policy of the destination printer...
8749 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8750 job
? job
->username
: NULL
)) != HTTP_OK
)
8752 send_http_error(con
, status
, dprinter
);
8757 * Now move the job or jobs...
8763 * See if the job has been completed...
8766 if (job
->state_value
> IPP_JOB_STOPPED
)
8769 * Return a "not-possible" error...
8772 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8773 _("Job #%d is finished and cannot be altered"),
8779 * See if the job is owned by the requesting user...
8782 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8784 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8785 cupsdFindDest(job
->dest
));
8790 * Move the job to a different printer or class...
8793 cupsdMoveJob(job
, dprinter
);
8798 * Got the source printer, now look through the jobs...
8801 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8803 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8806 * See if the job is pointing at the source printer or has not been
8810 if (strcasecmp(job
->dest
, src
) ||
8811 job
->state_value
> IPP_JOB_STOPPED
)
8815 * See if the job can be moved by the requesting user...
8818 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8822 * Move the job to a different printer or class...
8825 cupsdMoveJob(job
, dprinter
);
8830 * Start jobs if possible...
8836 * Return with "everything is OK" status...
8839 con
->response
->request
.status
.status_code
= IPP_OK
;
8844 * 'ppd_parse_line()' - Parse a PPD default line.
8847 static int /* O - 0 on success, -1 on failure */
8848 ppd_parse_line(const char *line
, /* I - Line */
8849 char *option
, /* O - Option name */
8850 int olen
, /* I - Size of option name */
8851 char *choice
, /* O - Choice name */
8852 int clen
) /* I - Size of choice name */
8855 * Verify this is a default option line...
8858 if (strncmp(line
, "*Default", 8))
8862 * Read the option name...
8865 for (line
+= 8, olen
--;
8866 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8877 * Skip everything else up to the colon (:)...
8880 while (*line
&& *line
!= ':')
8889 * Now grab the option choice, skipping leading whitespace...
8892 while (isspace(*line
& 255))
8896 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8907 * Return with no errors...
8915 * 'print_job()' - Print a file to a printer or class.
8919 print_job(cupsd_client_t
*con
, /* I - Client connection */
8920 ipp_attribute_t
*uri
) /* I - Printer URI */
8922 ipp_attribute_t
*attr
; /* Current attribute */
8923 ipp_attribute_t
*format
; /* Document-format attribute */
8924 const char *default_format
; /* document-format-default value */
8925 cupsd_job_t
*job
; /* New job */
8926 char filename
[1024]; /* Job filename */
8927 mime_type_t
*filetype
; /* Type of file */
8928 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8929 type
[MIME_MAX_TYPE
], /* Subtype of file */
8930 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8931 /* Textual name of mime type */
8932 cupsd_printer_t
*printer
; /* Printer data */
8933 struct stat fileinfo
; /* File information */
8934 int kbytes
; /* Size of file */
8935 int compression
; /* Document compression */
8938 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8939 uri
->values
[0].string
.text
);
8942 * Validate print file attributes, for now just document-format and
8943 * compression (CUPS only supports "none" and "gzip")...
8946 compression
= CUPS_FILE_NONE
;
8948 if ((attr
= ippFindAttribute(con
->request
, "compression",
8949 IPP_TAG_KEYWORD
)) != NULL
)
8951 if (strcmp(attr
->values
[0].string
.text
, "none")
8953 && strcmp(attr
->values
[0].string
.text
, "gzip")
8954 #endif /* HAVE_LIBZ */
8957 send_ipp_status(con
, IPP_ATTRIBUTES
,
8958 _("Unsupported compression \"%s\""),
8959 attr
->values
[0].string
.text
);
8960 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8961 "compression", NULL
, attr
->values
[0].string
.text
);
8966 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8967 compression
= CUPS_FILE_GZIP
;
8968 #endif /* HAVE_LIBZ */
8972 * Do we have a file to print?
8977 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
8982 * Is the destination valid?
8985 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8991 send_ipp_status(con
, IPP_NOT_FOUND
,
8992 _("The printer or class was not found."));
8997 * Is it a format we support?
9000 if ((format
= ippFindAttribute(con
->request
, "document-format",
9001 IPP_TAG_MIMETYPE
)) != NULL
)
9004 * Grab format from client...
9007 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9010 send_ipp_status(con
, IPP_BAD_REQUEST
,
9011 _("Bad document-format \"%s\""),
9012 format
->values
[0].string
.text
);
9016 else if ((default_format
= cupsGetOption("document-format",
9017 printer
->num_options
,
9018 printer
->options
)) != NULL
)
9021 * Use default document format...
9024 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9026 send_ipp_status(con
, IPP_BAD_REQUEST
,
9027 _("Bad document-format \"%s\""),
9038 strcpy(super
, "application");
9039 strcpy(type
, "octet-stream");
9042 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9045 * Auto-type the file...
9048 ipp_attribute_t
*doc_name
; /* document-name attribute */
9051 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9053 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9054 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9055 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9059 filetype
= mimeType(MimeDatabase
, super
, type
);
9061 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9062 filetype
->super
, filetype
->type
);
9065 filetype
= mimeType(MimeDatabase
, super
, type
);
9069 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9072 * Replace the document-format attribute value with the auto-typed or
9076 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9081 _cupsStrFree(format
->values
[0].string
.text
);
9083 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9086 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9087 "document-format", NULL
, mimetype
);
9091 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9092 _("Unsupported document-format \"%s\""),
9093 format
? format
->values
[0].string
.text
:
9094 "application/octet-stream");
9095 cupsdLogMessage(CUPSD_LOG_INFO
,
9096 "Hint: Do you have the raw file printing rules enabled?");
9099 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9100 "document-format", NULL
, format
->values
[0].string
.text
);
9106 * Read any embedded job ticket info from PS files...
9109 if (!strcasecmp(filetype
->super
, "application") &&
9110 (!strcasecmp(filetype
->type
, "postscript") ||
9111 !strcasecmp(filetype
->type
, "pdf")))
9112 read_job_ticket(con
);
9115 * Create the job object...
9118 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9122 * Update quota data...
9125 if (stat(con
->filename
, &fileinfo
))
9128 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9130 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9132 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9133 IPP_TAG_INTEGER
)) != NULL
)
9134 attr
->values
[0].integer
+= kbytes
;
9137 * Add the job file...
9140 if (add_file(con
, job
, filetype
, compression
))
9143 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9145 rename(con
->filename
, filename
);
9146 cupsdClearString(&con
->filename
);
9149 * See if we need to add the ending sheet...
9152 if (cupsdTimeoutJob(job
))
9156 * Log and save the job...
9159 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9160 "File of type %s/%s queued by \"%s\".",
9161 filetype
->super
, filetype
->type
, job
->username
);
9162 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9163 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9164 job
->dest
, job
->username
);
9167 * Start the job if possible...
9175 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9177 * This function only gets called when printing a single PDF or PostScript
9178 * file using the Print-Job operation. It doesn't work for Create-Job +
9179 * Send-File, since the job attributes need to be set at job creation
9180 * time for banners to work. The embedded job ticket stuff is here
9181 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9182 * options and IPP attributes which otherwise would be lost.
9184 * The format of a job ticket is simple:
9186 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9188 * %cupsJobTicket: attr1=value1
9189 * %cupsJobTicket: attr2=value2
9191 * %cupsJobTicket: attrN=valueN
9193 * Job ticket lines must appear immediately after the first line that
9194 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9195 * stops looking for job ticket info when it finds a line that does not begin
9196 * with "%cupsJobTicket:".
9198 * The maximum length of a job ticket line, including the prefix, is
9199 * 255 characters to conform with the Adobe DSC.
9201 * Read-only attributes are rejected with a notice to the error log in
9202 * case a malicious user tries anything. Since the job ticket is read
9203 * prior to attribute validation in print_job(), job ticket attributes
9204 * will go through the same validation as IPP attributes...
9208 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9210 cups_file_t
*fp
; /* File to read from */
9211 char line
[256]; /* Line data */
9212 int num_options
; /* Number of options */
9213 cups_option_t
*options
; /* Options */
9214 ipp_t
*ticket
; /* New attributes */
9215 ipp_attribute_t
*attr
, /* Current attribute */
9216 *attr2
, /* Job attribute */
9217 *prev2
; /* Previous job attribute */
9221 * First open the print file...
9224 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9226 cupsdLogMessage(CUPSD_LOG_ERROR
,
9227 "Unable to open print file for job ticket - %s",
9233 * Skip the first line...
9236 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9238 cupsdLogMessage(CUPSD_LOG_ERROR
,
9239 "Unable to read from print file for job ticket - %s",
9245 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9248 * Not a DSC-compliant file, so no job ticket info will be available...
9256 * Read job ticket info from the file...
9262 while (cupsFileGets(fp
, line
, sizeof(line
)))
9265 * Stop at the first non-ticket line...
9268 if (strncmp(line
, "%cupsJobTicket:", 15))
9272 * Add the options to the option array...
9275 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9279 * Done with the file; see if we have any options...
9284 if (num_options
== 0)
9288 * OK, convert the options to an attribute list, and apply them to
9293 cupsEncodeOptions(ticket
, num_options
, options
);
9296 * See what the user wants to change.
9299 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9301 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9304 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9305 !strcmp(attr
->name
, "job-originating-user-name") ||
9306 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9307 !strcmp(attr
->name
, "job-k-octets") ||
9308 !strcmp(attr
->name
, "job-id") ||
9309 !strncmp(attr
->name
, "job-state", 9) ||
9310 !strncmp(attr
->name
, "time-at-", 8))
9311 continue; /* Read-only attrs */
9313 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9314 IPP_TAG_ZERO
)) != NULL
)
9317 * Some other value; first free the old value...
9320 if (con
->request
->attrs
== attr2
)
9322 con
->request
->attrs
= attr2
->next
;
9327 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9328 if (prev2
->next
== attr2
)
9330 prev2
->next
= attr2
->next
;
9335 if (con
->request
->last
== attr2
)
9336 con
->request
->last
= prev2
;
9338 _ippFreeAttr(attr2
);
9342 * Add new option by copying it...
9345 copy_attribute(con
->request
, attr
, 0);
9349 * Then free the attribute list and option array...
9353 cupsFreeOptions(num_options
, options
);
9358 * 'reject_jobs()' - Reject print jobs to a printer.
9362 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9363 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9365 http_status_t status
; /* Policy status */
9366 cups_ptype_t dtype
; /* Destination type (printer/class) */
9367 cupsd_printer_t
*printer
; /* Printer data */
9368 ipp_attribute_t
*attr
; /* printer-state-message text */
9371 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9372 con
->http
.fd
, uri
->values
[0].string
.text
);
9375 * Is the destination valid?
9378 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9384 send_ipp_status(con
, IPP_NOT_FOUND
,
9385 _("The printer or class was not found."));
9393 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9395 send_http_error(con
, status
, printer
);
9400 * Reject jobs sent to the printer...
9403 printer
->accepting
= 0;
9405 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9406 IPP_TAG_TEXT
)) == NULL
)
9407 strcpy(printer
->state_message
, "Rejecting Jobs");
9409 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9410 sizeof(printer
->state_message
));
9412 cupsdAddPrinterHistory(printer
);
9414 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9415 "No longer accepting jobs.");
9417 if (dtype
& CUPS_PRINTER_CLASS
)
9419 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9421 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9422 printer
->name
, get_username(con
));
9426 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9428 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9429 printer
->name
, get_username(con
));
9433 * Everything was ok, so return OK status...
9436 con
->response
->request
.status
.status_code
= IPP_OK
;
9441 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9445 release_held_new_jobs(
9446 cupsd_client_t
*con
, /* I - Connection */
9447 ipp_attribute_t
*uri
) /* I - Printer URI */
9449 http_status_t status
; /* Policy status */
9450 cups_ptype_t dtype
; /* Destination type (printer/class) */
9451 cupsd_printer_t
*printer
; /* Printer data */
9454 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9455 con
->http
.fd
, uri
->values
[0].string
.text
);
9458 * Is the destination valid?
9461 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9467 send_ipp_status(con
, IPP_NOT_FOUND
,
9468 _("The printer or class was not found."));
9476 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9478 send_http_error(con
, status
, printer
);
9483 * Hold pending/new jobs sent to the printer...
9486 printer
->holding_new_jobs
= 0;
9488 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9489 cupsdAddPrinterHistory(printer
);
9491 if (dtype
& CUPS_PRINTER_CLASS
)
9492 cupsdLogMessage(CUPSD_LOG_INFO
,
9493 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9494 printer
->name
, get_username(con
));
9496 cupsdLogMessage(CUPSD_LOG_INFO
,
9497 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9498 printer
->name
, get_username(con
));
9501 * Everything was ok, so return OK status...
9504 con
->response
->request
.status
.status_code
= IPP_OK
;
9509 * 'release_job()' - Release a held print job.
9513 release_job(cupsd_client_t
*con
, /* I - Client connection */
9514 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9516 ipp_attribute_t
*attr
; /* Current attribute */
9517 int jobid
; /* Job ID */
9518 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9519 username
[HTTP_MAX_URI
], /* Username portion of URI */
9520 host
[HTTP_MAX_URI
], /* Host portion of URI */
9521 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9522 int port
; /* Port portion of URI */
9523 cupsd_job_t
*job
; /* Job information */
9526 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9527 con
->http
.fd
, uri
->values
[0].string
.text
);
9530 * See if we have a job URI or a printer URI...
9533 if (!strcmp(uri
->name
, "printer-uri"))
9536 * Got a printer URI; see if we also have a job-id attribute...
9539 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9540 IPP_TAG_INTEGER
)) == NULL
)
9542 send_ipp_status(con
, IPP_BAD_REQUEST
,
9543 _("Got a printer-uri attribute but no job-id"));
9547 jobid
= attr
->values
[0].integer
;
9552 * Got a job URI; parse it to get the job ID...
9555 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9556 sizeof(scheme
), username
, sizeof(username
), host
,
9557 sizeof(host
), &port
, resource
, sizeof(resource
));
9559 if (strncmp(resource
, "/jobs/", 6))
9565 send_ipp_status(con
, IPP_BAD_REQUEST
,
9566 _("Bad job-uri attribute \"%s\""),
9567 uri
->values
[0].string
.text
);
9571 jobid
= atoi(resource
+ 6);
9575 * See if the job exists...
9578 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9581 * Nope - return a "not found" error...
9584 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9589 * See if job is "held"...
9592 if (job
->state_value
!= IPP_JOB_HELD
)
9595 * Nope - return a "not possible" error...
9598 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held"), jobid
);
9603 * See if the job is owned by the requesting user...
9606 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9608 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9609 cupsdFindDest(job
->dest
));
9614 * Reset the job-hold-until value to "no-hold"...
9617 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9618 IPP_TAG_KEYWORD
)) == NULL
)
9619 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9623 _cupsStrFree(attr
->values
[0].string
.text
);
9625 attr
->value_tag
= IPP_TAG_KEYWORD
;
9626 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9628 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9629 "Job job-hold-until value changed by user.");
9633 * Release the job and return...
9636 cupsdReleaseJob(job
);
9638 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9639 "Job released by user.");
9641 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9643 con
->response
->request
.status
.status_code
= IPP_OK
;
9650 * 'renew_subscription()' - Renew an existing subscription...
9655 cupsd_client_t
*con
, /* I - Client connection */
9656 int sub_id
) /* I - Subscription ID */
9658 http_status_t status
; /* Policy status */
9659 cupsd_subscription_t
*sub
; /* Subscription */
9660 ipp_attribute_t
*lease
; /* notify-lease-duration */
9663 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9664 "renew_subscription(con=%p[%d], sub_id=%d)",
9665 con
, con
->http
.fd
, sub_id
);
9668 * Is the subscription ID valid?
9671 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9674 * Bad subscription ID...
9677 send_ipp_status(con
, IPP_NOT_FOUND
,
9678 _("notify-subscription-id %d no good"), sub_id
);
9685 * Job subscriptions cannot be renewed...
9688 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9689 _("Job subscriptions cannot be renewed"));
9697 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9699 con
, sub
->owner
)) != HTTP_OK
)
9701 send_http_error(con
, status
, sub
->dest
);
9706 * Renew the subscription...
9709 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9712 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9714 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9716 cupsdLogMessage(CUPSD_LOG_INFO
,
9717 "renew_subscription: Limiting notify-lease-duration to "
9720 sub
->lease
= MaxLeaseDuration
;
9723 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9725 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9727 con
->response
->request
.status
.status_code
= IPP_OK
;
9729 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9730 "notify-lease-duration", sub
->lease
);
9735 * 'restart_job()' - Restart an old print job.
9739 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9740 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9742 ipp_attribute_t
*attr
; /* Current attribute */
9743 int jobid
; /* Job ID */
9744 cupsd_job_t
*job
; /* Job information */
9745 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9746 username
[HTTP_MAX_URI
], /* Username portion of URI */
9747 host
[HTTP_MAX_URI
], /* Host portion of URI */
9748 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9749 int port
; /* Port portion of URI */
9752 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9753 con
->http
.fd
, uri
->values
[0].string
.text
);
9756 * See if we have a job URI or a printer URI...
9759 if (!strcmp(uri
->name
, "printer-uri"))
9762 * Got a printer URI; see if we also have a job-id attribute...
9765 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9766 IPP_TAG_INTEGER
)) == NULL
)
9768 send_ipp_status(con
, IPP_BAD_REQUEST
,
9769 _("Got a printer-uri attribute but no job-id"));
9773 jobid
= attr
->values
[0].integer
;
9778 * Got a job URI; parse it to get the job ID...
9781 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9782 sizeof(scheme
), username
, sizeof(username
), host
,
9783 sizeof(host
), &port
, resource
, sizeof(resource
));
9785 if (strncmp(resource
, "/jobs/", 6))
9791 send_ipp_status(con
, IPP_BAD_REQUEST
,
9792 _("Bad job-uri attribute \"%s\""),
9793 uri
->values
[0].string
.text
);
9797 jobid
= atoi(resource
+ 6);
9801 * See if the job exists...
9804 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9807 * Nope - return a "not found" error...
9810 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9815 * See if job is in any of the "completed" states...
9818 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9821 * Nope - return a "not possible" error...
9824 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete"),
9830 * See if we have retained the job files...
9835 if (!job
->attrs
|| job
->num_files
== 0)
9838 * Nope - return a "not possible" error...
9841 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9842 _("Job #%d cannot be restarted - no files"), jobid
);
9847 * See if the job is owned by the requesting user...
9850 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9852 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9853 cupsdFindDest(job
->dest
));
9858 * See if the job-hold-until attribute is specified...
9861 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9862 IPP_TAG_KEYWORD
)) == NULL
)
9863 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9865 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9868 * Return the job to a held state...
9871 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9872 "Restarted by \"%s\" with job-hold-until=%s.",
9873 username
, attr
->values
[0].string
.text
);
9874 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9876 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9877 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9878 attr
->values
[0].string
.text
);
9883 * Restart the job...
9886 cupsdRestartJob(job
);
9890 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9892 con
->response
->request
.status
.status_code
= IPP_OK
;
9897 * 'save_auth_info()' - Save authentication information for a job.
9902 cupsd_client_t
*con
, /* I - Client connection */
9903 cupsd_job_t
*job
, /* I - Job */
9904 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9906 int i
; /* Looping var */
9907 char filename
[1024]; /* Job authentication filename */
9908 cups_file_t
*fp
; /* Job authentication file */
9909 char line
[2048]; /* Line for file */
9910 cupsd_printer_t
*dest
; /* Destination printer/class */
9914 * This function saves the in-memory authentication information for
9915 * a job so that it can be used to authenticate with a remote host.
9916 * The information is stored in a file that is readable only by the
9917 * root user. The fields are Base-64 encoded, each on a separate line,
9918 * followed by random number (up to 1024) of newlines to limit the
9919 * amount of information that is exposed.
9921 * Because of the potential for exposing of authentication information,
9922 * this functionality is only enabled when running cupsd as root.
9924 * This caching only works for the Basic and BasicDigest authentication
9925 * types. Digest authentication cannot be cached this way, and in
9926 * the future Kerberos authentication may make all of this obsolete.
9928 * Authentication information is saved whenever an authenticated
9929 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9932 * This information is deleted after a job is completed or canceled,
9933 * so reprints may require subsequent re-authentication.
9939 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9943 * Create the authentication file and change permissions...
9946 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9947 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9949 cupsdLogMessage(CUPSD_LOG_ERROR
,
9950 "Unable to save authentication info to \"%s\" - %s",
9951 filename
, strerror(errno
));
9955 fchown(cupsFileNumber(fp
), 0, 0);
9956 fchmod(cupsFileNumber(fp
), 0400);
9958 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9961 * Write 1 to 3 auth values...
9964 cupsdClearString(&job
->auth_username
);
9965 cupsdClearString(&job
->auth_domain
);
9966 cupsdClearString(&job
->auth_password
);
9968 for (i
= 0; i
< auth_info
->num_values
; i
++)
9970 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9971 strlen(auth_info
->values
[i
].string
.text
));
9972 cupsFilePrintf(fp
, "%s\n", line
);
9974 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9975 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9976 auth_info
->values
[i
].string
.text
);
9977 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9978 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9979 auth_info
->values
[i
].string
.text
);
9980 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9981 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9982 auth_info
->values
[i
].string
.text
);
9985 else if (con
->username
[0])
9988 * Write the authenticated username...
9991 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9992 cupsFilePrintf(fp
, "%s\n", line
);
9994 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9995 cupsdClearString(&job
->auth_domain
);
9998 * Write the authenticated password...
10001 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10002 cupsFilePrintf(fp
, "%s\n", line
);
10004 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
10008 * Write a random number of newlines to the end of the file...
10011 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10012 cupsFilePutChar(fp
, '\n');
10015 * Close the file and return...
10020 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10021 # ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
10022 if (con
->have_gss
&&
10023 (con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
|| con
->gss_creds
))
10025 if (con
->have_gss
&& con
->gss_creds
)
10026 # endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
10027 save_krb5_creds(con
, job
);
10028 else if (job
->ccname
)
10029 cupsdClearString(&(job
->ccname
));
10030 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10034 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10036 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
10040 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
10041 cupsd_job_t
*job
) /* I - Job */
10044 * Get the credentials...
10047 job
->ccache
= cupsdCopyKrb5Creds(con
);
10050 * Add the KRB5CCNAME environment variable to the job so that the
10051 * backend can use the credentials when printing.
10056 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
10057 krb5_cc_get_name(KerberosContext
, job
->ccache
));
10059 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
10062 cupsdClearString(&(job
->ccname
));
10064 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10068 * 'send_document()' - Send a file to a printer or class.
10072 send_document(cupsd_client_t
*con
, /* I - Client connection */
10073 ipp_attribute_t
*uri
) /* I - Printer URI */
10075 ipp_attribute_t
*attr
; /* Current attribute */
10076 ipp_attribute_t
*format
; /* Request's document-format attribute */
10077 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10078 const char *default_format
;/* document-format-default value */
10079 int jobid
; /* Job ID number */
10080 cupsd_job_t
*job
; /* Current job */
10081 char job_uri
[HTTP_MAX_URI
],
10083 scheme
[HTTP_MAX_URI
],
10084 /* Method portion of URI */
10085 username
[HTTP_MAX_URI
],
10086 /* Username portion of URI */
10087 host
[HTTP_MAX_URI
],
10088 /* Host portion of URI */
10089 resource
[HTTP_MAX_URI
];
10090 /* Resource portion of URI */
10091 int port
; /* Port portion of URI */
10092 mime_type_t
*filetype
; /* Type of file */
10093 char super
[MIME_MAX_SUPER
],
10094 /* Supertype of file */
10095 type
[MIME_MAX_TYPE
],
10096 /* Subtype of file */
10097 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10098 /* Textual name of mime type */
10099 char filename
[1024]; /* Job filename */
10100 cupsd_printer_t
*printer
; /* Current printer */
10101 struct stat fileinfo
; /* File information */
10102 int kbytes
; /* Size of file */
10103 int compression
; /* Type of compression */
10104 int start_job
; /* Start the job? */
10107 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10108 con
->http
.fd
, uri
->values
[0].string
.text
);
10111 * See if we have a job URI or a printer URI...
10114 if (!strcmp(uri
->name
, "printer-uri"))
10117 * Got a printer URI; see if we also have a job-id attribute...
10120 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10121 IPP_TAG_INTEGER
)) == NULL
)
10123 send_ipp_status(con
, IPP_BAD_REQUEST
,
10124 _("Got a printer-uri attribute but no job-id"));
10128 jobid
= attr
->values
[0].integer
;
10133 * Got a job URI; parse it to get the job ID...
10136 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10137 sizeof(scheme
), username
, sizeof(username
), host
,
10138 sizeof(host
), &port
, resource
, sizeof(resource
));
10140 if (strncmp(resource
, "/jobs/", 6))
10146 send_ipp_status(con
, IPP_BAD_REQUEST
,
10147 _("Bad job-uri attribute \"%s\""),
10148 uri
->values
[0].string
.text
);
10152 jobid
= atoi(resource
+ 6);
10156 * See if the job exists...
10159 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10162 * Nope - return a "not found" error...
10165 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10169 printer
= cupsdFindDest(job
->dest
);
10172 * See if the job is owned by the requesting user...
10175 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10177 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10178 cupsdFindDest(job
->dest
));
10183 * OK, see if the client is sending the document compressed - CUPS
10184 * only supports "none" and "gzip".
10187 compression
= CUPS_FILE_NONE
;
10189 if ((attr
= ippFindAttribute(con
->request
, "compression",
10190 IPP_TAG_KEYWORD
)) != NULL
)
10192 if (strcmp(attr
->values
[0].string
.text
, "none")
10194 && strcmp(attr
->values
[0].string
.text
, "gzip")
10195 #endif /* HAVE_LIBZ */
10198 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\""),
10199 attr
->values
[0].string
.text
);
10200 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10201 "compression", NULL
, attr
->values
[0].string
.text
);
10206 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10207 compression
= CUPS_FILE_GZIP
;
10208 #endif /* HAVE_LIBZ */
10212 * Do we have a file to print?
10215 if (!con
->filename
)
10218 * Check for an empty request with "last-document" set to true, which is
10219 * used to close an "open" job by RFC 2911, section 3.3.2.
10222 if (job
->num_files
> 0 &&
10223 (attr
= ippFindAttribute(con
->request
, "last-document",
10224 IPP_TAG_BOOLEAN
)) != NULL
&&
10225 attr
->values
[0].boolean
)
10226 goto last_document
;
10228 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
10233 * Is it a format we support?
10236 if ((format
= ippFindAttribute(con
->request
, "document-format",
10237 IPP_TAG_MIMETYPE
)) != NULL
)
10240 * Grab format from client...
10243 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10246 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
10247 format
->values
[0].string
.text
);
10251 else if ((default_format
= cupsGetOption("document-format",
10252 printer
->num_options
,
10253 printer
->options
)) != NULL
)
10256 * Use default document format...
10259 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10261 send_ipp_status(con
, IPP_BAD_REQUEST
,
10262 _("Could not scan type \"%s\""),
10270 * No document format attribute? Auto-type it!
10273 strcpy(super
, "application");
10274 strcpy(type
, "octet-stream");
10277 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10280 * Auto-type the file...
10283 ipp_attribute_t
*doc_name
; /* document-name attribute */
10286 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10288 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10289 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10290 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10294 filetype
= mimeType(MimeDatabase
, super
, type
);
10296 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10297 filetype
->super
, filetype
->type
);
10300 filetype
= mimeType(MimeDatabase
, super
, type
);
10305 * Replace the document-format attribute value with the auto-typed or
10309 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10312 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10313 IPP_TAG_MIMETYPE
)) != NULL
)
10315 _cupsStrFree(jformat
->values
[0].string
.text
);
10317 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10320 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10321 "document-format", NULL
, mimetype
);
10323 else if (!filetype
)
10325 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10326 _("Unsupported format \'%s/%s\'"), super
, type
);
10327 cupsdLogMessage(CUPSD_LOG_INFO
,
10328 "Hint: Do you have the raw file printing rules enabled?");
10331 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10332 "document-format", NULL
, format
->values
[0].string
.text
);
10337 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10339 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10342 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10343 _("Unsupported format \'%s\'"), mimetype
);
10345 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10346 "document-format", NULL
, mimetype
);
10352 * Add the file to the job...
10357 if (add_file(con
, job
, filetype
, compression
))
10360 if (stat(con
->filename
, &fileinfo
))
10363 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10365 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10367 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10368 IPP_TAG_INTEGER
)) != NULL
)
10369 attr
->values
[0].integer
+= kbytes
;
10371 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10373 rename(con
->filename
, filename
);
10375 cupsdClearString(&con
->filename
);
10377 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10378 filetype
->super
, filetype
->type
, job
->username
);
10381 * Start the job if this is the last document...
10386 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10387 IPP_TAG_BOOLEAN
)) != NULL
&&
10388 attr
->values
[0].boolean
)
10391 * See if we need to add the ending sheet...
10394 if (cupsdTimeoutJob(job
))
10397 if (job
->state_value
== IPP_JOB_STOPPED
)
10399 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10400 job
->state_value
= IPP_JOB_PENDING
;
10402 else if (job
->state_value
== IPP_JOB_HELD
)
10404 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10405 IPP_TAG_KEYWORD
)) == NULL
)
10406 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10408 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10410 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10411 job
->state_value
= IPP_JOB_PENDING
;
10416 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10422 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10423 IPP_TAG_KEYWORD
)) == NULL
)
10424 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10426 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10428 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10429 job
->state_value
= IPP_JOB_HELD
;
10430 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10433 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10440 * Fill in the response info...
10443 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10446 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10449 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10451 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10453 add_job_state_reasons(con
, job
);
10455 con
->response
->request
.status
.status_code
= IPP_OK
;
10458 * Start the job if necessary...
10467 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10472 cupsd_client_t
*con
, /* I - Client connection */
10473 http_status_t status
, /* I - HTTP status code */
10474 cupsd_printer_t
*printer
) /* I - Printer, if any */
10476 ipp_attribute_t
*uri
; /* Request URI, if any */
10479 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10480 IPP_TAG_URI
)) == NULL
)
10481 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10483 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10484 "Returning HTTP %s for %s (%s) from %s",
10485 httpStatus(status
),
10486 ippOpString(con
->request
->request
.op
.operation_id
),
10487 uri
? uri
->values
[0].string
.text
: "no URI",
10488 con
->http
.hostname
);
10492 int auth_type
; /* Type of authentication required */
10495 auth_type
= CUPSD_AUTH_NONE
;
10497 if (status
== HTTP_UNAUTHORIZED
&&
10498 printer
->num_auth_info_required
> 0 &&
10499 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10501 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10502 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10503 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10506 * Creating and authenticating jobs requires Kerberos...
10509 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10514 * Use policy/location-defined authentication requirements...
10517 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10518 cupsd_location_t
*auth
; /* Pointer to authentication element */
10521 if (printer
->type
& CUPS_PRINTER_CLASS
)
10522 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10524 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10526 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10527 auth
->type
== CUPSD_AUTH_NONE
)
10528 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10530 con
->request
->request
.op
.operation_id
:
10535 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10536 auth_type
= DefaultAuthType
;
10538 auth_type
= auth
->type
;
10542 cupsdSendError(con
, status
, auth_type
);
10545 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10547 ippDelete(con
->response
);
10548 con
->response
= NULL
;
10555 * 'send_ipp_status()' - Send a status back to the IPP client.
10559 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10560 ipp_status_t status
, /* I - IPP status code */
10561 const char *message
,/* I - Status message */
10562 ...) /* I - Additional args as needed */
10564 va_list ap
; /* Pointer to additional args */
10565 char formatted
[1024]; /* Formatted errror message */
10568 va_start(ap
, message
);
10569 vsnprintf(formatted
, sizeof(formatted
),
10570 _cupsLangString(con
->language
, message
), ap
);
10573 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10574 ippOpString(con
->request
->request
.op
.operation_id
),
10575 ippErrorString(status
), formatted
);
10577 con
->response
->request
.status
.status_code
= status
;
10579 if (ippFindAttribute(con
->response
, "attributes-charset",
10580 IPP_TAG_ZERO
) == NULL
)
10581 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10582 "attributes-charset", NULL
, "utf-8");
10584 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10585 IPP_TAG_ZERO
) == NULL
)
10586 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10587 "attributes-natural-language", NULL
, DefaultLanguage
);
10589 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10590 "status-message", NULL
, formatted
);
10595 * 'set_default()' - Set the default destination...
10599 set_default(cupsd_client_t
*con
, /* I - Client connection */
10600 ipp_attribute_t
*uri
) /* I - Printer URI */
10602 http_status_t status
; /* Policy status */
10603 cups_ptype_t dtype
; /* Destination type (printer/class) */
10604 cupsd_printer_t
*printer
, /* Printer */
10605 *oldprinter
; /* Old default printer */
10608 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10609 con
->http
.fd
, uri
->values
[0].string
.text
);
10612 * Is the destination valid?
10615 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10621 send_ipp_status(con
, IPP_NOT_FOUND
,
10622 _("The printer or class was not found."));
10630 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10632 send_http_error(con
, status
, NULL
);
10637 * Set it as the default...
10640 oldprinter
= DefaultPrinter
;
10641 DefaultPrinter
= printer
;
10644 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10645 "%s is no longer the default printer.", oldprinter
->name
);
10647 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10648 "%s is now the default printer.", printer
->name
);
10650 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10651 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10653 cupsdLogMessage(CUPSD_LOG_INFO
,
10654 "Default destination set to \"%s\" by \"%s\".",
10655 printer
->name
, get_username(con
));
10658 * Everything was ok, so return OK status...
10661 con
->response
->request
.status
.status_code
= IPP_OK
;
10666 * 'set_job_attrs()' - Set job attributes.
10670 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10671 ipp_attribute_t
*uri
) /* I - Job URI */
10673 ipp_attribute_t
*attr
, /* Current attribute */
10674 *attr2
; /* Job attribute */
10675 int jobid
; /* Job ID */
10676 cupsd_job_t
*job
; /* Current job */
10677 char scheme
[HTTP_MAX_URI
],
10678 /* Method portion of URI */
10679 username
[HTTP_MAX_URI
],
10680 /* Username portion of URI */
10681 host
[HTTP_MAX_URI
],
10682 /* Host portion of URI */
10683 resource
[HTTP_MAX_URI
];
10684 /* Resource portion of URI */
10685 int port
; /* Port portion of URI */
10686 int event
; /* Events? */
10687 int check_jobs
; /* Check jobs? */
10690 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10691 con
->http
.fd
, uri
->values
[0].string
.text
);
10694 * Start with "everything is OK" status...
10697 con
->response
->request
.status
.status_code
= IPP_OK
;
10700 * See if we have a job URI or a printer URI...
10703 if (!strcmp(uri
->name
, "printer-uri"))
10706 * Got a printer URI; see if we also have a job-id attribute...
10709 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10710 IPP_TAG_INTEGER
)) == NULL
)
10712 send_ipp_status(con
, IPP_BAD_REQUEST
,
10713 _("Got a printer-uri attribute but no job-id"));
10717 jobid
= attr
->values
[0].integer
;
10722 * Got a job URI; parse it to get the job ID...
10725 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10726 sizeof(scheme
), username
, sizeof(username
), host
,
10727 sizeof(host
), &port
, resource
, sizeof(resource
));
10729 if (strncmp(resource
, "/jobs/", 6))
10735 send_ipp_status(con
, IPP_BAD_REQUEST
,
10736 _("Bad job-uri attribute \"%s\""),
10737 uri
->values
[0].string
.text
);
10741 jobid
= atoi(resource
+ 6);
10745 * See if the job exists...
10748 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10751 * Nope - return a "not found" error...
10754 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10759 * See if the job has been completed...
10762 if (job
->state_value
> IPP_JOB_STOPPED
)
10765 * Return a "not-possible" error...
10768 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10769 _("Job #%d is finished and cannot be altered"), jobid
);
10774 * See if the job is owned by the requesting user...
10777 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10779 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10780 cupsdFindDest(job
->dest
));
10785 * See what the user wants to change.
10793 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10795 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10798 if (!strcmp(attr
->name
, "attributes-charset") ||
10799 !strcmp(attr
->name
, "attributes-natural-language") ||
10800 !strcmp(attr
->name
, "document-compression") ||
10801 !strcmp(attr
->name
, "document-format") ||
10802 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10803 !strcmp(attr
->name
, "job-document-access-errors") ||
10804 !strcmp(attr
->name
, "job-id") ||
10805 !strcmp(attr
->name
, "job-impressions-completed") ||
10806 !strcmp(attr
->name
, "job-k-octets") ||
10807 !strcmp(attr
->name
, "job-originating-host-name") ||
10808 !strcmp(attr
->name
, "job-originating-user-name") ||
10809 !strcmp(attr
->name
, "job-printer-up-time") ||
10810 !strcmp(attr
->name
, "job-printer-uri") ||
10811 !strcmp(attr
->name
, "job-sheets") ||
10812 !strcmp(attr
->name
, "job-state-message") ||
10813 !strcmp(attr
->name
, "job-state-reasons") ||
10814 !strcmp(attr
->name
, "job-uri") ||
10815 !strcmp(attr
->name
, "number-of-documents") ||
10816 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10817 !strcmp(attr
->name
, "output-device-assigned") ||
10818 !strncmp(attr
->name
, "date-time-at-", 13) ||
10819 !strncmp(attr
->name
, "job-k-octets", 12) ||
10820 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10821 !strncmp(attr
->name
, "time-at-", 8))
10827 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10828 _("%s cannot be changed."), attr
->name
);
10830 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10831 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10836 if (!strcmp(attr
->name
, "job-priority"))
10839 * Change the job priority...
10842 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10844 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value"));
10846 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10847 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10849 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10851 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10852 _("Job is completed and cannot be changed."));
10855 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10857 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10858 attr
->values
[0].integer
);
10859 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10862 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10863 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10866 else if (!strcmp(attr
->name
, "job-state"))
10869 * Change the job state...
10872 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10874 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value"));
10876 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10877 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10881 switch (attr
->values
[0].integer
)
10883 case IPP_JOB_PENDING
:
10884 case IPP_JOB_HELD
:
10885 if (job
->state_value
> IPP_JOB_HELD
)
10887 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10888 _("Job state cannot be changed."));
10891 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10893 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10894 attr
->values
[0].integer
);
10895 cupsdSetJobState(job
, attr
->values
[0].integer
,
10897 "Job state changed by \"%s\"", username
);
10902 case IPP_JOB_PROCESSING
:
10903 case IPP_JOB_STOPPED
:
10904 if (job
->state_value
!= attr
->values
[0].integer
)
10906 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10907 _("Job state cannot be changed."));
10912 case IPP_JOB_CANCELED
:
10913 case IPP_JOB_ABORTED
:
10914 case IPP_JOB_COMPLETED
:
10915 if (job
->state_value
> IPP_JOB_PROCESSING
)
10917 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10918 _("Job state cannot be changed."));
10921 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10923 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10924 attr
->values
[0].integer
);
10925 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10927 "Job state changed by \"%s\"", username
);
10934 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10936 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10937 IPP_TAG_ZERO
)) != NULL
)
10940 * Some other value; first free the old value...
10943 if (job
->attrs
->prev
)
10944 job
->attrs
->prev
->next
= attr2
->next
;
10946 job
->attrs
->attrs
= attr2
->next
;
10948 if (job
->attrs
->last
== attr2
)
10949 job
->attrs
->last
= job
->attrs
->prev
;
10951 _ippFreeAttr(attr2
);
10954 * Then copy the attribute...
10957 copy_attribute(job
->attrs
, attr
, 0);
10960 * See if the job-name or job-hold-until is being changed.
10963 if (!strcmp(attr
->name
, "job-hold-until"))
10965 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10966 attr
->values
[0].string
.text
);
10967 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10969 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10971 cupsdReleaseJob(job
);
10975 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10976 "Job held by \"%s\".", username
);
10978 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10981 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10984 * Delete the attribute...
10987 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10988 IPP_TAG_ZERO
)) != NULL
)
10990 if (job
->attrs
->prev
)
10991 job
->attrs
->prev
->next
= attr2
->next
;
10993 job
->attrs
->attrs
= attr2
->next
;
10995 if (attr2
== job
->attrs
->last
)
10996 job
->attrs
->last
= job
->attrs
->prev
;
10998 _ippFreeAttr(attr2
);
11000 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11006 * Add new option by copying it...
11009 copy_attribute(job
->attrs
, attr
, 0);
11011 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11020 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11023 * Send events as needed...
11026 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11027 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11028 cupsdFindDest(job
->dest
), job
,
11029 "Job priority changed by user.");
11031 if (event
& CUPSD_EVENT_JOB_STATE
)
11032 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11033 job
->state_value
== IPP_JOB_HELD
?
11034 "Job held by user." : "Job restarted by user.");
11036 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11037 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11038 "Job options changed by user.");
11041 * Start jobs if possible...
11050 * 'set_printer_attrs()' - Set printer attributes.
11054 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11055 ipp_attribute_t
*uri
) /* I - Printer */
11057 http_status_t status
; /* Policy status */
11058 cups_ptype_t dtype
; /* Destination type (printer/class) */
11059 cupsd_printer_t
*printer
; /* Printer/class */
11060 ipp_attribute_t
*attr
; /* Printer attribute */
11061 int changed
= 0; /* Was anything changed? */
11064 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11065 con
->http
.fd
, uri
->values
[0].string
.text
);
11068 * Is the destination valid?
11071 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11077 send_ipp_status(con
, IPP_NOT_FOUND
,
11078 _("The printer or class was not found."));
11086 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11088 send_http_error(con
, status
, printer
);
11093 * Return a list of attributes that can be set via Set-Printer-Attributes.
11096 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11097 IPP_TAG_TEXT
)) != NULL
)
11099 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11103 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11104 IPP_TAG_TEXT
)) != NULL
)
11106 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11111 * Update the printer attributes and return...
11116 cupsdSetPrinterAttrs(printer
);
11117 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11119 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11120 "Printer \"%s\" description or location changed by \"%s\".",
11121 printer
->name
, get_username(con
));
11123 cupsdLogMessage(CUPSD_LOG_INFO
,
11124 "Printer \"%s\" description or location changed by \"%s\".",
11125 printer
->name
, get_username(con
));
11128 con
->response
->request
.status
.status_code
= IPP_OK
;
11133 * 'set_printer_defaults()' - Set printer default options from a request.
11137 set_printer_defaults(
11138 cupsd_client_t
*con
, /* I - Client connection */
11139 cupsd_printer_t
*printer
) /* I - Printer */
11141 int i
; /* Looping var */
11142 ipp_attribute_t
*attr
; /* Current attribute */
11143 int namelen
; /* Length of attribute name */
11144 char name
[256], /* New attribute name */
11145 value
[256]; /* String version of integer attrs */
11148 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11151 * Skip non-printer attributes...
11154 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11157 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11159 if (!strcmp(attr
->name
, "job-sheets-default"))
11162 * Only allow keywords and names...
11165 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11169 * Only allow job-sheets-default to be set when running without a
11170 * system high classification level...
11173 if (Classification
)
11176 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11178 if (attr
->num_values
> 1)
11179 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11181 cupsdSetString(&printer
->job_sheets
[1], "none");
11183 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11185 cupsdFreePrinterUsers(printer
);
11187 printer
->deny_users
= 0;
11189 if (attr
->value_tag
== IPP_TAG_NAME
&&
11190 (attr
->num_values
> 1 ||
11191 strcmp(attr
->values
[0].string
.text
, "all")))
11193 for (i
= 0; i
< attr
->num_values
; i
++)
11194 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
11197 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11199 cupsdFreePrinterUsers(printer
);
11201 printer
->deny_users
= 1;
11203 if (attr
->value_tag
== IPP_TAG_NAME
&&
11204 (attr
->num_values
> 1 ||
11205 strcmp(attr
->values
[0].string
.text
, "none")))
11207 for (i
= 0; i
< attr
->num_values
; i
++)
11208 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
11211 else if (!strcmp(attr
->name
, "job-quota-period"))
11213 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11216 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11217 attr
->values
[0].integer
);
11218 cupsdFreeQuotas(printer
);
11220 printer
->quota_period
= attr
->values
[0].integer
;
11222 else if (!strcmp(attr
->name
, "job-k-limit"))
11224 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11227 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11228 attr
->values
[0].integer
);
11229 cupsdFreeQuotas(printer
);
11231 printer
->k_limit
= attr
->values
[0].integer
;
11233 else if (!strcmp(attr
->name
, "job-page-limit"))
11235 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11238 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11239 attr
->values
[0].integer
);
11240 cupsdFreeQuotas(printer
);
11242 printer
->page_limit
= attr
->values
[0].integer
;
11244 else if (!strcmp(attr
->name
, "printer-op-policy"))
11246 cupsd_policy_t
*p
; /* Policy */
11249 if (attr
->value_tag
!= IPP_TAG_NAME
)
11252 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11254 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11255 "Setting printer-op-policy to \"%s\"...",
11256 attr
->values
[0].string
.text
);
11257 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11258 printer
->op_policy_ptr
= p
;
11262 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11263 _("Unknown printer-op-policy \"%s\"."),
11264 attr
->values
[0].string
.text
);
11268 else if (!strcmp(attr
->name
, "printer-error-policy"))
11270 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11273 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11274 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
11275 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11276 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11277 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11279 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11280 _("Unknown printer-error-policy \"%s\"."),
11281 attr
->values
[0].string
.text
);
11285 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11286 "Setting printer-error-policy to \"%s\"...",
11287 attr
->values
[0].string
.text
);
11288 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11292 * Skip any other non-default attributes...
11295 namelen
= strlen(attr
->name
);
11296 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11297 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11301 * OK, anything else must be a user-defined default...
11304 strlcpy(name
, attr
->name
, sizeof(name
));
11305 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11307 switch (attr
->value_tag
)
11309 case IPP_TAG_DELETEATTR
:
11310 printer
->num_options
= cupsRemoveOption(name
,
11311 printer
->num_options
,
11312 &(printer
->options
));
11313 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11314 "Deleting %s", attr
->name
);
11317 case IPP_TAG_NAME
:
11318 case IPP_TAG_KEYWORD
:
11320 printer
->num_options
= cupsAddOption(name
,
11321 attr
->values
[0].string
.text
,
11322 printer
->num_options
,
11323 &(printer
->options
));
11324 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11325 "Setting %s to \"%s\"...", attr
->name
,
11326 attr
->values
[0].string
.text
);
11329 case IPP_TAG_BOOLEAN
:
11330 printer
->num_options
= cupsAddOption(name
,
11331 attr
->values
[0].boolean
?
11333 printer
->num_options
,
11334 &(printer
->options
));
11335 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11336 "Setting %s to %s...", attr
->name
,
11337 attr
->values
[0].boolean
? "true" : "false");
11340 case IPP_TAG_INTEGER
:
11341 case IPP_TAG_ENUM
:
11342 sprintf(value
, "%d", attr
->values
[0].integer
);
11343 printer
->num_options
= cupsAddOption(name
, value
,
11344 printer
->num_options
,
11345 &(printer
->options
));
11346 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11347 "Setting %s to %s...", attr
->name
, value
);
11350 case IPP_TAG_RANGE
:
11351 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11352 attr
->values
[0].range
.upper
);
11353 printer
->num_options
= cupsAddOption(name
, value
,
11354 printer
->num_options
,
11355 &(printer
->options
));
11356 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11357 "Setting %s to %s...", attr
->name
, value
);
11360 case IPP_TAG_RESOLUTION
:
11361 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11362 attr
->values
[0].resolution
.yres
,
11363 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11365 printer
->num_options
= cupsAddOption(name
, value
,
11366 printer
->num_options
,
11367 &(printer
->options
));
11368 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11369 "Setting %s to %s...", attr
->name
, value
);
11373 /* Do nothing for other values */
11381 * 'start_printer()' - Start a printer.
11385 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11386 ipp_attribute_t
*uri
) /* I - Printer URI */
11388 http_status_t status
; /* Policy status */
11389 cups_ptype_t dtype
; /* Destination type (printer/class) */
11390 cupsd_printer_t
*printer
; /* Printer data */
11393 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11394 con
->http
.fd
, uri
->values
[0].string
.text
);
11397 * Is the destination valid?
11400 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11406 send_ipp_status(con
, IPP_NOT_FOUND
,
11407 _("The printer or class was not found."));
11415 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11417 send_http_error(con
, status
, printer
);
11422 * Start the printer...
11425 printer
->state_message
[0] = '\0';
11427 cupsdStartPrinter(printer
, 1);
11429 if (dtype
& CUPS_PRINTER_CLASS
)
11430 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11431 printer
->name
, get_username(con
));
11433 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11434 printer
->name
, get_username(con
));
11439 * Everything was ok, so return OK status...
11442 con
->response
->request
.status
.status_code
= IPP_OK
;
11447 * 'stop_printer()' - Stop a printer.
11451 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11452 ipp_attribute_t
*uri
) /* I - Printer URI */
11454 http_status_t status
; /* Policy status */
11455 cups_ptype_t dtype
; /* Destination type (printer/class) */
11456 cupsd_printer_t
*printer
; /* Printer data */
11457 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11460 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11461 con
->http
.fd
, uri
->values
[0].string
.text
);
11464 * Is the destination valid?
11467 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11473 send_ipp_status(con
, IPP_NOT_FOUND
,
11474 _("The printer or class was not found."));
11482 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11484 send_http_error(con
, status
, printer
);
11489 * Stop the printer...
11492 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11493 IPP_TAG_TEXT
)) == NULL
)
11494 strcpy(printer
->state_message
, "Paused");
11497 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11498 sizeof(printer
->state_message
));
11501 cupsdStopPrinter(printer
, 1);
11503 if (dtype
& CUPS_PRINTER_CLASS
)
11504 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11505 printer
->name
, get_username(con
));
11507 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11508 printer
->name
, get_username(con
));
11511 * Everything was ok, so return OK status...
11514 con
->response
->request
.status
.status_code
= IPP_OK
;
11519 * 'url_encode_attr()' - URL-encode a string attribute.
11523 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11524 char *buffer
,/* I - String buffer */
11525 int bufsize
)/* I - Size of buffer */
11527 int i
; /* Looping var */
11528 char *bufptr
, /* Pointer into buffer */
11529 *bufend
; /* End of buffer */
11532 strlcpy(buffer
, attr
->name
, bufsize
);
11533 bufptr
= buffer
+ strlen(buffer
);
11534 bufend
= buffer
+ bufsize
- 1;
11536 for (i
= 0; i
< attr
->num_values
; i
++)
11538 if (bufptr
>= bufend
)
11546 if (bufptr
>= bufend
)
11551 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11552 bufptr
, bufend
- bufptr
+ 1);
11554 if (bufptr
>= bufend
)
11565 * 'url_encode_string()' - URL-encode a string.
11568 static char * /* O - End of string */
11569 url_encode_string(const char *s
, /* I - String */
11570 char *buffer
, /* I - String buffer */
11571 int bufsize
) /* I - Size of buffer */
11573 char *bufptr
, /* Pointer into buffer */
11574 *bufend
; /* End of buffer */
11575 static const char *hex
= "0123456789ABCDEF";
11580 bufend
= buffer
+ bufsize
- 1;
11582 while (*s
&& bufptr
< bufend
)
11584 if (*s
== ' ' || *s
== '%' || *s
== '+')
11586 if (bufptr
>= (bufend
- 2))
11590 *bufptr
++ = hex
[(*s
>> 4) & 15];
11591 *bufptr
++ = hex
[*s
& 15];
11595 else if (*s
== '\'' || *s
== '\\')
11597 if (bufptr
>= (bufend
- 1))
11614 * 'user_allowed()' - See if a user is allowed to print to a queue.
11617 static int /* O - 0 if not allowed, 1 if allowed */
11618 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11619 const char *username
) /* I - Username */
11621 int i
; /* Looping var */
11622 struct passwd
*pw
; /* User password data */
11623 char baseuser
[256], /* Base username */
11624 *baseptr
; /* Pointer to "@" in base username */
11627 if (p
->num_users
== 0)
11630 if (!strcmp(username
, "root"))
11633 if (strchr(username
, '@'))
11636 * Strip @REALM for username check...
11639 strlcpy(baseuser
, username
, sizeof(baseuser
));
11641 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11644 username
= baseuser
;
11647 pw
= getpwnam(username
);
11650 for (i
= 0; i
< p
->num_users
; i
++)
11652 if (p
->users
[i
][0] == '@')
11655 * Check group membership...
11658 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
11661 else if (p
->users
[i
][0] == '#')
11667 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
11670 else if (!strcasecmp(username
, p
->users
[i
]))
11674 return ((i
< p
->num_users
) != p
->deny_users
);
11679 * 'validate_job()' - Validate printer options and destination.
11683 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11684 ipp_attribute_t
*uri
) /* I - Printer URI */
11686 http_status_t status
; /* Policy status */
11687 ipp_attribute_t
*attr
, /* Current attribute */
11688 *auth_info
; /* auth-info attribute */
11689 ipp_attribute_t
*format
; /* Document-format attribute */
11690 cups_ptype_t dtype
; /* Destination type (printer/class) */
11691 char super
[MIME_MAX_SUPER
],
11692 /* Supertype of file */
11693 type
[MIME_MAX_TYPE
];
11694 /* Subtype of file */
11695 cupsd_printer_t
*printer
; /* Printer */
11698 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11699 con
->http
.fd
, uri
->values
[0].string
.text
);
11702 * OK, see if the client is sending the document compressed - CUPS
11703 * doesn't support compression yet...
11706 if ((attr
= ippFindAttribute(con
->request
, "compression",
11707 IPP_TAG_KEYWORD
)) != NULL
)
11709 if (strcmp(attr
->values
[0].string
.text
, "none")
11711 && strcmp(attr
->values
[0].string
.text
, "gzip")
11712 #endif /* HAVE_LIBZ */
11715 send_ipp_status(con
, IPP_ATTRIBUTES
,
11716 _("Unsupported compression \"%s\""),
11717 attr
->values
[0].string
.text
);
11718 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11719 "compression", NULL
, attr
->values
[0].string
.text
);
11725 * Is it a format we support?
11728 if ((format
= ippFindAttribute(con
->request
, "document-format",
11729 IPP_TAG_MIMETYPE
)) != NULL
)
11731 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11734 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
11735 format
->values
[0].string
.text
);
11739 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11740 !mimeType(MimeDatabase
, super
, type
))
11742 cupsdLogMessage(CUPSD_LOG_INFO
,
11743 "Hint: Do you have the raw file printing rules enabled?");
11744 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11745 _("Unsupported document-format \"%s\""),
11746 format
->values
[0].string
.text
);
11747 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11748 "document-format", NULL
, format
->values
[0].string
.text
);
11754 * Is the destination valid?
11757 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11763 send_ipp_status(con
, IPP_NOT_FOUND
,
11764 _("The printer or class was not found."));
11772 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11774 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11776 send_http_error(con
, status
, printer
);
11779 else if (printer
->num_auth_info_required
== 1 &&
11780 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11783 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11787 else if (auth_info
&& !con
->http
.tls
&&
11788 !httpAddrLocalhost(con
->http
.hostaddr
))
11791 * Require encryption of auth-info over non-local connections...
11794 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11797 #endif /* HAVE_SSL */
11800 * Everything was ok, so return OK status...
11803 con
->response
->request
.status
.status_code
= IPP_OK
;
11808 * 'validate_name()' - Make sure the printer name only contains valid chars.
11811 static int /* O - 0 if name is no good, 1 if good */
11812 validate_name(const char *name
) /* I - Name to check */
11814 const char *ptr
; /* Pointer into name */
11818 * Scan the whole name...
11821 for (ptr
= name
; *ptr
; ptr
++)
11822 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11826 * All the characters are good; validate the length, too...
11829 return ((ptr
- name
) < 128);
11834 * 'validate_user()' - Validate the user for the request.
11837 static int /* O - 1 if permitted, 0 otherwise */
11838 validate_user(cupsd_job_t
*job
, /* I - Job */
11839 cupsd_client_t
*con
, /* I - Client connection */
11840 const char *owner
, /* I - Owner of job/resource */
11841 char *username
, /* O - Authenticated username */
11842 int userlen
) /* I - Length of username */
11844 cupsd_printer_t
*printer
; /* Printer for job */
11847 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11848 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11850 job
->id
, con
? con
->http
.fd
: 0,
11851 owner
? owner
: "(null)", username
, userlen
);
11854 * Validate input...
11857 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11861 * Get the best authenticated username that is available.
11864 strlcpy(username
, get_username(con
), userlen
);
11867 * Check the username against the owner...
11870 printer
= cupsdFindDest(job
->dest
);
11872 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11873 con
, owner
) == HTTP_OK
);
11878 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".