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.ipp4", CacheDir
,
2950 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.pwg3", 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 forbidden,
4395 -1 if limit reached */
4396 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4397 cupsd_printer_t
*p
) /* I - Printer or class */
4399 int i
; /* Looping var */
4400 char username
[33]; /* Username */
4401 cupsd_quota_t
*q
; /* Quota data */
4402 #ifdef HAVE_MBR_UID_TO_UUID
4404 * Use Apple membership APIs which require that all names represent
4405 * valid user account or group records accessible by the server.
4408 uuid_t usr_uuid
; /* UUID for job requesting user */
4409 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4410 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4411 int mbr_err
; /* Error from membership function */
4412 int is_member
; /* Is this user a member? */
4415 * Use standard POSIX APIs for checking users and groups...
4418 struct passwd
*pw
; /* User password data */
4419 #endif /* HAVE_MBR_UID_TO_UUID */
4422 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4423 con
, con
->http
.fd
, p
, p
->name
);
4426 * Figure out who is printing...
4429 strlcpy(username
, get_username(con
), sizeof(username
));
4432 * Check global active job limits for printers and users...
4435 if (MaxJobsPerPrinter
)
4438 * Check if there are too many pending jobs on this printer...
4441 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4443 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4452 * Check if there are too many pending jobs for this user...
4455 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4457 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4464 * Check against users...
4467 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4472 #ifdef HAVE_MBR_UID_TO_UUID
4474 * Get UUID for job requesting user...
4477 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4483 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4484 "check_quotas: UUID lookup failed for user \"%s\"",
4486 cupsdLogMessage(CUPSD_LOG_INFO
,
4487 "Denying user \"%s\" access to printer \"%s\" "
4488 "(unknown user)...",
4494 * Get UID and GID of requesting user...
4497 pw
= getpwnam(username
);
4499 #endif /* HAVE_MBR_UID_TO_UUID */
4501 for (i
= 0; i
< p
->num_users
; i
++)
4502 if (p
->users
[i
][0] == '@')
4505 * Check group membership...
4508 #ifdef HAVE_MBR_UID_TO_UUID
4509 if (p
->users
[i
][1] == '#')
4511 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4512 uuid_clear(grp_uuid
);
4514 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4518 * Invalid ACL entries are ignored for matching; just record a
4519 * warning in the log...
4522 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4523 "check_quotas: UUID lookup failed for ACL entry "
4524 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4525 cupsdLogMessage(CUPSD_LOG_WARN
,
4526 "Access control entry \"%s\" not a valid group name; "
4527 "entry ignored", p
->users
[i
]);
4530 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4534 * At this point, there should be no errors, but check anyways...
4537 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4538 "check_quotas: group \"%s\" membership check "
4539 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4544 * Stop if we found a match...
4551 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4553 #endif /* HAVE_MBR_UID_TO_UUID */
4555 #ifdef HAVE_MBR_UID_TO_UUID
4558 if (p
->users
[i
][0] == '#')
4560 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4561 uuid_clear(usr2_uuid
);
4563 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4567 * Invalid ACL entries are ignored for matching; just record a
4568 * warning in the log...
4571 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4572 "check_quotas: UUID lookup failed for ACL entry "
4573 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4574 cupsdLogMessage(CUPSD_LOG_WARN
,
4575 "Access control entry \"%s\" not a valid user name; "
4576 "entry ignored", p
->users
[i
]);
4579 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4583 else if (!strcasecmp(username
, p
->users
[i
]))
4585 #endif /* HAVE_MBR_UID_TO_UUID */
4587 if ((i
< p
->num_users
) == p
->deny_users
)
4589 cupsdLogMessage(CUPSD_LOG_INFO
,
4590 "Denying user \"%s\" access to printer \"%s\"...",
4600 if (p
->k_limit
|| p
->page_limit
)
4602 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4604 cupsdLogMessage(CUPSD_LOG_ERROR
,
4605 "Unable to allocate quota data for user \"%s\"",
4610 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4611 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4613 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4620 * If we have gotten this far, we're done!
4628 * 'close_job()' - Close a multi-file job.
4632 close_job(cupsd_client_t
*con
, /* I - Client connection */
4633 ipp_attribute_t
*uri
) /* I - Printer URI */
4635 cupsd_job_t
*job
; /* Job */
4636 ipp_attribute_t
*attr
; /* Attribute */
4637 char job_uri
[HTTP_MAX_URI
],
4639 username
[256]; /* User name */
4642 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4643 con
->http
.fd
, uri
->values
[0].string
.text
);
4646 * See if we have a job URI or a printer URI...
4649 if (strcmp(uri
->name
, "printer-uri"))
4652 * job-uri is not supported by Close-Job!
4655 send_ipp_status(con
, IPP_BAD_REQUEST
,
4656 _("Close-Job doesn't support the job-uri attribute."));
4661 * Got a printer URI; see if we also have a job-id attribute...
4664 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4665 IPP_TAG_INTEGER
)) == NULL
)
4667 send_ipp_status(con
, IPP_BAD_REQUEST
,
4668 _("Got a printer-uri attribute but no job-id"));
4672 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4675 * Nope - return a "not found" error...
4678 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
4679 attr
->values
[0].integer
);
4684 * See if the job is owned by the requesting user...
4687 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4689 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4690 cupsdFindDest(job
->dest
));
4695 * Add any ending sheet...
4698 if (cupsdTimeoutJob(job
))
4701 if (job
->state_value
== IPP_JOB_STOPPED
)
4703 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4704 job
->state_value
= IPP_JOB_PENDING
;
4706 else if (job
->state_value
== IPP_JOB_HELD
)
4708 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4709 IPP_TAG_KEYWORD
)) == NULL
)
4710 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4712 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
4714 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4715 job
->state_value
= IPP_JOB_PENDING
;
4720 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
4723 * Fill in the response info...
4726 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
4727 LocalPort
, job
->id
);
4728 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4731 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4733 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4736 add_job_state_reasons(con
, job
);
4738 con
->response
->request
.status
.status_code
= IPP_OK
;
4741 * Start the job if necessary...
4749 * 'copy_attribute()' - Copy a single attribute.
4752 static ipp_attribute_t
* /* O - New attribute */
4754 ipp_t
*to
, /* O - Destination request/response */
4755 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4756 int quickcopy
) /* I - Do a quick copy? */
4758 int i
; /* Looping var */
4759 ipp_attribute_t
*toattr
; /* Destination attribute */
4762 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4763 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4764 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4767 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4770 toattr
= ippAddSeparator(to
);
4773 case IPP_TAG_INTEGER
:
4775 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4776 attr
->name
, attr
->num_values
, NULL
);
4778 for (i
= 0; i
< attr
->num_values
; i
++)
4779 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4782 case IPP_TAG_BOOLEAN
:
4783 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4784 attr
->num_values
, NULL
);
4786 for (i
= 0; i
< attr
->num_values
; i
++)
4787 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4790 case IPP_TAG_STRING
:
4793 case IPP_TAG_KEYWORD
:
4795 case IPP_TAG_URISCHEME
:
4796 case IPP_TAG_CHARSET
:
4797 case IPP_TAG_LANGUAGE
:
4798 case IPP_TAG_MIMETYPE
:
4799 toattr
= ippAddStrings(to
, attr
->group_tag
,
4800 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4801 attr
->name
, attr
->num_values
, NULL
, NULL
);
4805 for (i
= 0; i
< attr
->num_values
; i
++)
4806 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4808 else if (attr
->value_tag
& IPP_TAG_COPY
)
4810 for (i
= 0; i
< attr
->num_values
; i
++)
4811 toattr
->values
[i
].string
.text
=
4812 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4816 for (i
= 0; i
< attr
->num_values
; i
++)
4817 toattr
->values
[i
].string
.text
=
4818 _cupsStrRetain(attr
->values
[i
].string
.text
);
4823 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4824 attr
->values
[0].date
);
4827 case IPP_TAG_RESOLUTION
:
4828 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4829 attr
->num_values
, IPP_RES_PER_INCH
,
4832 for (i
= 0; i
< attr
->num_values
; i
++)
4834 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4835 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4836 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4840 case IPP_TAG_RANGE
:
4841 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4842 attr
->num_values
, NULL
, NULL
);
4844 for (i
= 0; i
< attr
->num_values
; i
++)
4846 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4847 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4851 case IPP_TAG_TEXTLANG
:
4852 case IPP_TAG_NAMELANG
:
4853 toattr
= ippAddStrings(to
, attr
->group_tag
,
4854 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4855 attr
->name
, attr
->num_values
, NULL
, NULL
);
4859 for (i
= 0; i
< attr
->num_values
; i
++)
4861 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4862 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4865 else if (attr
->value_tag
& IPP_TAG_COPY
)
4867 for (i
= 0; i
< attr
->num_values
; i
++)
4870 toattr
->values
[i
].string
.charset
=
4871 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4873 toattr
->values
[i
].string
.charset
=
4874 toattr
->values
[0].string
.charset
;
4876 toattr
->values
[i
].string
.text
=
4877 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4882 for (i
= 0; i
< attr
->num_values
; i
++)
4885 toattr
->values
[i
].string
.charset
=
4886 _cupsStrRetain(attr
->values
[i
].string
.charset
);
4888 toattr
->values
[i
].string
.charset
=
4889 toattr
->values
[0].string
.charset
;
4891 toattr
->values
[i
].string
.text
=
4892 _cupsStrRetain(attr
->values
[i
].string
.text
);
4897 case IPP_TAG_BEGIN_COLLECTION
:
4898 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4899 attr
->num_values
, NULL
);
4901 for (i
= 0; i
< attr
->num_values
; i
++)
4903 toattr
->values
[i
].collection
= attr
->values
[i
].collection
;
4904 attr
->values
[i
].collection
->use
++;
4909 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4910 attr
->name
, attr
->num_values
, NULL
);
4912 for (i
= 0; i
< attr
->num_values
; i
++)
4914 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4916 if (toattr
->values
[i
].unknown
.length
> 0)
4918 if ((toattr
->values
[i
].unknown
.data
=
4919 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4920 toattr
->values
[i
].unknown
.length
= 0;
4922 memcpy(toattr
->values
[i
].unknown
.data
,
4923 attr
->values
[i
].unknown
.data
,
4924 toattr
->values
[i
].unknown
.length
);
4927 break; /* anti-compiler-warning-code */
4935 * 'copy_attrs()' - Copy attributes from one request to another.
4939 copy_attrs(ipp_t
*to
, /* I - Destination request */
4940 ipp_t
*from
, /* I - Source request */
4941 cups_array_t
*ra
, /* I - Requested attributes */
4942 ipp_tag_t group
, /* I - Group to copy */
4943 int quickcopy
) /* I - Do a quick copy? */
4945 ipp_attribute_t
*fromattr
; /* Source attribute */
4948 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4949 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4950 to
, from
, ra
, group
, quickcopy
);
4955 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4958 * Filter attributes as needed...
4961 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4962 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4965 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4968 * Don't send collection attributes by default to IPP/1.x clients
4969 * since many do not support collections. Also don't send
4970 * media-col-database unless specifically requested by the client.
4973 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4975 (to
->request
.status
.version
[0] == 1 ||
4976 !strcmp(fromattr
->name
, "media-col-database")))
4979 copy_attribute(to
, fromattr
, quickcopy
);
4986 * 'copy_banner()' - Copy a banner file to the requests directory for the
4990 static int /* O - Size of banner file in kbytes */
4991 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4992 cupsd_job_t
*job
, /* I - Job information */
4993 const char *name
) /* I - Name of banner */
4995 int i
; /* Looping var */
4996 int kbytes
; /* Size of banner file in kbytes */
4997 char filename
[1024]; /* Job filename */
4998 cupsd_banner_t
*banner
; /* Pointer to banner */
4999 cups_file_t
*in
; /* Input file */
5000 cups_file_t
*out
; /* Output file */
5001 int ch
; /* Character from file */
5002 char attrname
[255], /* Name of attribute */
5003 *s
; /* Pointer into name */
5004 ipp_attribute_t
*attr
; /* Attribute */
5007 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5008 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
5009 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
5010 name
? name
: "(null)");
5013 * Find the banner; return if not found or "none"...
5016 if (!name
|| !strcmp(name
, "none") ||
5017 (banner
= cupsdFindBanner(name
)) == NULL
)
5021 * Open the banner and job files...
5024 if (add_file(con
, job
, banner
->filetype
, 0))
5027 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
5029 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
5031 cupsdLogMessage(CUPSD_LOG_ERROR
,
5032 "Unable to create banner job file %s - %s",
5033 filename
, strerror(errno
));
5038 fchmod(cupsFileNumber(out
), 0640);
5039 fchown(cupsFileNumber(out
), RunUser
, Group
);
5042 * Try the localized banner file under the subdirectory...
5045 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5047 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5050 * Convert ll-cc to ll_CC...
5054 attrname
[3] = toupper(attrname
[3] & 255);
5055 attrname
[4] = toupper(attrname
[4] & 255);
5058 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5061 if (access(filename
, 0) && strlen(attrname
) > 2)
5064 * Wasn't able to find "ll_CC" locale file; try the non-national
5065 * localization banner directory.
5070 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5074 if (access(filename
, 0))
5077 * Use the non-localized banner file.
5080 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5083 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5087 cupsdLogMessage(CUPSD_LOG_ERROR
,
5088 "Unable to open banner template file %s - %s",
5089 filename
, strerror(errno
));
5095 * Parse the file to the end...
5098 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5102 * Get an attribute name...
5105 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5106 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5108 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5118 * Ignore { followed by stuff that is not an attribute name...
5121 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5126 * See if it is defined...
5129 if (attrname
[0] == '?')
5134 if (!strcmp(s
, "printer-name"))
5136 cupsFilePuts(out
, job
->dest
);
5139 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5142 * See if we have a leading question mark...
5145 if (attrname
[0] != '?')
5148 * Nope, write to file as-is; probably a PostScript procedure...
5151 cupsFilePrintf(out
, "{%s}", attrname
);
5158 * Output value(s)...
5161 for (i
= 0; i
< attr
->num_values
; i
++)
5164 cupsFilePutChar(out
, ',');
5166 switch (attr
->value_tag
)
5168 case IPP_TAG_INTEGER
:
5170 if (!strncmp(s
, "time-at-", 8))
5172 struct timeval tv
= { attr
->values
[i
].integer
, 0 };
5173 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5176 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5179 case IPP_TAG_BOOLEAN
:
5180 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5183 case IPP_TAG_NOVALUE
:
5184 cupsFilePuts(out
, "novalue");
5187 case IPP_TAG_RANGE
:
5188 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5189 attr
->values
[i
].range
.upper
);
5192 case IPP_TAG_RESOLUTION
:
5193 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5194 attr
->values
[i
].resolution
.yres
,
5195 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5200 case IPP_TAG_STRING
:
5203 case IPP_TAG_KEYWORD
:
5204 case IPP_TAG_CHARSET
:
5205 case IPP_TAG_LANGUAGE
:
5206 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
5209 * Need to quote strings for PS banners...
5214 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5216 if (*p
== '(' || *p
== ')' || *p
== '\\')
5218 cupsFilePutChar(out
, '\\');
5219 cupsFilePutChar(out
, *p
);
5221 else if (*p
< 32 || *p
> 126)
5222 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5224 cupsFilePutChar(out
, *p
);
5228 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5232 break; /* anti-compiler-warning-code */
5236 else if (ch
== '\\') /* Quoted char */
5238 ch
= cupsFileGetChar(in
);
5240 if (ch
!= '{') /* Only do special handling for \{ */
5241 cupsFilePutChar(out
, '\\');
5243 cupsFilePutChar(out
, ch
);
5246 cupsFilePutChar(out
, ch
);
5250 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5252 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5253 IPP_TAG_INTEGER
)) != NULL
)
5254 attr
->values
[0].integer
+= kbytes
;
5263 * 'copy_file()' - Copy a PPD file or interface script...
5266 static int /* O - 0 = success, -1 = error */
5267 copy_file(const char *from
, /* I - Source file */
5268 const char *to
) /* I - Destination file */
5270 cups_file_t
*src
, /* Source file */
5271 *dst
; /* Destination file */
5272 int bytes
; /* Bytes to read/write */
5273 char buffer
[2048]; /* Copy buffer */
5276 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5279 * Open the source and destination file for a copy...
5282 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5285 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5292 * Copy the source file to the destination...
5295 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5296 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5304 * Close both files and return...
5309 return (cupsFileClose(dst
));
5314 * 'copy_model()' - Copy a PPD model file, substituting default values
5318 static int /* O - 0 = success, -1 = error */
5319 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5320 const char *from
, /* I - Source file */
5321 const char *to
) /* I - Destination file */
5323 fd_set input
; /* select() input set */
5324 struct timeval timeout
; /* select() timeout */
5325 int maxfd
; /* Max file descriptor for select() */
5326 char tempfile
[1024]; /* Temporary PPD file */
5327 int tempfd
; /* Temporary PPD file descriptor */
5328 int temppid
; /* Process ID of cups-driverd */
5329 int temppipe
[2]; /* Temporary pipes */
5330 char *argv
[4], /* Command-line arguments */
5331 *envp
[MAX_ENV
]; /* Environment */
5332 cups_file_t
*src
, /* Source file */
5333 *dst
; /* Destination file */
5334 ppd_file_t
*ppd
; /* PPD file */
5335 int bytes
, /* Bytes from pipe */
5336 total
; /* Total bytes from pipe */
5337 char buffer
[2048]; /* Copy buffer */
5338 int i
; /* Looping var */
5339 char option
[PPD_MAX_NAME
], /* Option name */
5340 choice
[PPD_MAX_NAME
]; /* Choice name */
5341 ppd_size_t
*size
; /* Default size */
5342 int num_defaults
; /* Number of default options */
5343 cups_option_t
*defaults
; /* Default options */
5344 char cups_protocol
[PPD_MAX_LINE
];
5345 /* cupsProtocol attribute */
5348 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5349 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5353 * Run cups-driverd to get the PPD file...
5356 argv
[0] = "cups-driverd";
5358 argv
[2] = (char *)from
;
5361 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5363 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5364 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5365 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5369 cupsdOpenPipe(temppipe
);
5371 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5372 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5374 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5375 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5386 * Wait up to 30 seconds for the PPD file to be copied...
5391 if (temppipe
[0] > CGIPipes
[0])
5392 maxfd
= temppipe
[0] + 1;
5394 maxfd
= CGIPipes
[0] + 1;
5399 * See if we have data ready...
5403 FD_SET(temppipe
[0], &input
);
5404 FD_SET(CGIPipes
[0], &input
);
5406 timeout
.tv_sec
= 30;
5407 timeout
.tv_usec
= 0;
5409 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5419 * We have timed out...
5425 if (FD_ISSET(temppipe
[0], &input
))
5428 * Read the PPD file from the pipe, and write it to the PPD file.
5431 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5433 if (write(tempfd
, buffer
, bytes
) < bytes
)
5442 if (FD_ISSET(CGIPipes
[0], &input
))
5452 * No data from cups-deviced...
5455 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5461 * Read the source file and see what page sizes are supported...
5464 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5471 * Open the destination (if possible) and set the default options...
5476 cups_protocol
[0] = '\0';
5478 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5481 * Read all of the default lines from the old PPD...
5484 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5485 if (!strncmp(buffer
, "*Default", 8))
5488 * Add the default option...
5491 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5492 choice
, sizeof(choice
)))
5494 ppd_option_t
*ppdo
; /* PPD option */
5498 * Only add the default if the default hasn't already been
5499 * set and the choice exists in the new PPD...
5502 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5503 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5504 ppdFindChoice(ppdo
, choice
))
5505 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5509 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5510 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5514 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5517 * Add the default media sizes...
5520 num_defaults
= cupsAddOption("PageSize", size
->name
,
5521 num_defaults
, &defaults
);
5522 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5523 num_defaults
, &defaults
);
5524 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5525 num_defaults
, &defaults
);
5526 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5527 num_defaults
, &defaults
);
5533 * Open the source file for a copy...
5536 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5538 cupsFreeOptions(num_defaults
, defaults
);
5544 * Open the destination file for a copy...
5547 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5549 cupsFreeOptions(num_defaults
, defaults
);
5556 * Copy the source file to the destination...
5559 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5561 if (!strncmp(buffer
, "*Default", 8))
5564 * Check for an previous default option choice...
5567 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5568 choice
, sizeof(choice
)))
5570 const char *val
; /* Default option value */
5573 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5576 * Substitute the previous choice...
5579 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5584 cupsFilePrintf(dst
, "%s\n", buffer
);
5587 if (cups_protocol
[0])
5588 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5590 cupsFreeOptions(num_defaults
, defaults
);
5593 * Close both files and return...
5600 return (cupsFileClose(dst
));
5605 * 'copy_job_attrs()' - Copy job attributes.
5609 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5610 cupsd_job_t
*job
, /* I - Job */
5611 cups_array_t
*ra
) /* I - Requested attributes array */
5613 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5617 * Send the requested attributes for each job...
5620 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5621 con
->servername
, con
->serverport
, "/jobs/%d",
5624 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5625 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5626 "document-count", job
->num_files
);
5628 if (!ra
|| cupsArrayFind(ra
, "job-media-progress"))
5629 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5630 "job-media-progress", job
->progress
);
5632 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5633 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5634 "job-more-info", NULL
, job_uri
);
5636 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5637 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5638 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5639 job
->num_files
> 0);
5641 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5642 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5643 "job-printer-up-time", time(NULL
));
5645 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5646 add_job_state_reasons(con
, job
);
5648 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5649 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5650 "job-uri", NULL
, job_uri
);
5652 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5657 * 'copy_printer_attrs()' - Copy printer attributes.
5662 cupsd_client_t
*con
, /* I - Client connection */
5663 cupsd_printer_t
*printer
, /* I - Printer */
5664 cups_array_t
*ra
) /* I - Requested attributes array */
5666 char printer_uri
[HTTP_MAX_URI
];
5668 char printer_icons
[HTTP_MAX_URI
];
5670 time_t curtime
; /* Current time */
5671 int i
; /* Looping var */
5672 ipp_attribute_t
*history
; /* History collection */
5676 * Copy the printer attributes to the response using requested-attributes
5677 * and document-format attributes that may be provided by the client.
5680 curtime
= time(NULL
);
5682 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5683 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5684 "marker-change-time", printer
->marker_time
);
5686 if (printer
->num_printers
> 0 &&
5687 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5689 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5690 cupsd_printer_t
*p2
; /* Printer in class */
5691 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5694 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5695 IPP_TAG_URI
, "member-uris",
5696 printer
->num_printers
, NULL
,
5699 for (i
= 0; i
< printer
->num_printers
; i
++)
5701 p2
= printer
->printers
[i
];
5703 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5704 IPP_TAG_URI
)) != NULL
)
5705 member_uris
->values
[i
].string
.text
=
5706 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5709 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5710 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5712 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5713 "/classes/%s" : "/printers/%s", p2
->name
);
5714 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5720 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5721 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5722 "printer-alert", NULL
, printer
->alert
);
5724 if (printer
->alert_description
&&
5725 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5726 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5727 "printer-alert-description", NULL
,
5728 printer
->alert_description
);
5730 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5731 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5732 ippTimeToDate(curtime
));
5735 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5737 if (printer
->reg_name
)
5738 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5739 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5741 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5742 "printer-dns-sd-name", 0);
5744 #endif /* HAVE_DNSSD */
5746 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5747 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5748 "printer-error-policy", NULL
, printer
->error_policy
);
5750 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
5752 static const char * const errors
[] =/* printer-error-policy-supported values */
5755 "retry-current-job",
5760 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
5761 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5762 "printer-error-policy-supported", NULL
, "retry-current-job");
5764 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5765 "printer-error-policy-supported",
5766 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
5769 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
5771 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
5772 "http", NULL
, con
->servername
, con
->serverport
,
5773 "/icons/%s.png", printer
->name
);
5774 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
5775 NULL
, printer_icons
);
5776 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
5779 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5780 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5781 printer
->accepting
);
5783 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5784 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5787 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5788 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5790 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5791 "http", NULL
, con
->servername
, con
->serverport
,
5792 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5793 "/classes/%s" : "/printers/%s", printer
->name
);
5794 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5795 "printer-more-info", NULL
, printer_uri
);
5798 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5799 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5800 "printer-op-policy", NULL
, printer
->op_policy
);
5802 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5803 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5806 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5807 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5808 "printer-state-change-time", printer
->state_time
);
5810 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5811 cupsArrayFind(ra
, "printer-state-history"))
5814 * Printer history is only sent if specifically requested, so that
5815 * older CUPS/IPP clients won't barf on the collection attributes.
5818 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5819 "printer-state-history",
5820 printer
->num_history
, NULL
);
5822 for (i
= 0; i
< printer
->num_history
; i
++)
5823 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5824 NULL
, IPP_TAG_ZERO
, 0);
5827 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5828 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5829 "printer-state-message", NULL
, printer
->state_message
);
5831 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5832 add_printer_state_reasons(con
, printer
);
5834 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5836 int type
; /* printer-type value */
5840 * Add the CUPS-specific printer-type attribute...
5843 type
= printer
->type
;
5845 if (printer
== DefaultPrinter
)
5846 type
|= CUPS_PRINTER_DEFAULT
;
5848 if (!printer
->accepting
)
5849 type
|= CUPS_PRINTER_REJECTING
;
5851 if (!printer
->shared
)
5852 type
|= CUPS_PRINTER_NOT_SHARED
;
5854 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5858 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5859 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5860 "printer-up-time", curtime
);
5862 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5863 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5865 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5866 "ipp", NULL
, con
->servername
, con
->serverport
,
5867 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5868 "/classes/%s" : "/printers/%s", printer
->name
);
5869 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5870 "printer-uri-supported", NULL
, printer_uri
);
5871 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5875 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5876 add_queued_job_count(con
, printer
);
5878 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5879 if (printer
->ppd_attrs
)
5880 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0);
5881 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5886 * 'copy_subscription_attrs()' - Copy subscription attributes.
5890 copy_subscription_attrs(
5891 cupsd_client_t
*con
, /* I - Client connection */
5892 cupsd_subscription_t
*sub
, /* I - Subscription */
5893 cups_array_t
*ra
) /* I - Requested attributes array */
5895 ipp_attribute_t
*attr
; /* Current attribute */
5896 char printer_uri
[HTTP_MAX_URI
];
5898 int count
; /* Number of events */
5899 unsigned mask
; /* Current event mask */
5900 const char *name
; /* Current event name */
5904 * Copy the subscription attributes to the response using the
5905 * requested-attributes attribute that may be provided by the client.
5908 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5910 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5913 * Simple event list...
5916 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5917 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5918 "notify-events", NULL
, name
);
5923 * Complex event list...
5926 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5927 if (sub
->mask
& mask
)
5930 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5931 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5932 "notify-events", count
, NULL
, NULL
);
5934 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5935 if (sub
->mask
& mask
)
5937 attr
->values
[count
].string
.text
=
5938 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5945 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5946 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5947 "notify-job-id", sub
->job
->id
);
5949 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5950 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5951 "notify-lease-duration", sub
->lease
);
5953 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5955 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5956 "ipp", NULL
, con
->servername
, con
->serverport
,
5957 "/printers/%s", sub
->dest
->name
);
5958 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5959 "notify-printer-uri", NULL
, printer_uri
);
5962 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5963 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5964 "notify-recipient-uri", NULL
, sub
->recipient
);
5965 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5966 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5967 "notify-pull-method", NULL
, "ippget");
5969 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5970 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5971 "notify-subscriber-user-name", NULL
, sub
->owner
);
5973 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5974 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5975 "notify-subscription-id", sub
->id
);
5977 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5978 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5979 "notify-time-interval", sub
->interval
);
5981 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5982 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5983 sub
->user_data
, sub
->user_data_len
);
5988 * 'create_job()' - Print a file to a printer or class.
5992 create_job(cupsd_client_t
*con
, /* I - Client connection */
5993 ipp_attribute_t
*uri
) /* I - Printer URI */
5995 cupsd_printer_t
*printer
; /* Printer */
5996 cupsd_job_t
*job
; /* New job */
5999 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
6000 con
->http
.fd
, uri
->values
[0].string
.text
);
6003 * Is the destination valid?
6006 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6012 send_ipp_status(con
, IPP_NOT_FOUND
,
6013 _("The printer or class was not found."));
6018 * Create the job object...
6021 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6024 job
->pending_timeout
= 1;
6027 * Save and log the job...
6030 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6031 job
->dest
, job
->username
);
6036 * 'create_requested_array()' - Create an array for the requested-attributes.
6039 static cups_array_t
* /* O - Array of attributes or NULL */
6040 create_requested_array(ipp_t
*request
) /* I - IPP request */
6042 int i
; /* Looping var */
6043 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6044 cups_array_t
*ra
; /* Requested attributes array */
6045 char *value
; /* Current value */
6049 * Get the requested-attributes attribute, and return NULL if we don't
6053 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6054 IPP_TAG_KEYWORD
)) == NULL
)
6058 * If the attribute contains a single "all" keyword, return NULL...
6061 if (requested
->num_values
== 1 &&
6062 !strcmp(requested
->values
[0].string
.text
, "all"))
6066 * Create an array using "strcmp" as the comparison function...
6069 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6071 for (i
= 0; i
< requested
->num_values
; i
++)
6073 value
= requested
->values
[i
].string
.text
;
6075 if (!strcmp(value
, "job-template"))
6077 cupsArrayAdd(ra
, "copies");
6078 cupsArrayAdd(ra
, "copies-default");
6079 cupsArrayAdd(ra
, "copies-supported");
6080 cupsArrayAdd(ra
, "finishings");
6081 cupsArrayAdd(ra
, "finishings-default");
6082 cupsArrayAdd(ra
, "finishings-supported");
6083 cupsArrayAdd(ra
, "job-hold-until");
6084 cupsArrayAdd(ra
, "job-hold-until-default");
6085 cupsArrayAdd(ra
, "job-hold-until-supported");
6086 cupsArrayAdd(ra
, "job-priority");
6087 cupsArrayAdd(ra
, "job-priority-default");
6088 cupsArrayAdd(ra
, "job-priority-supported");
6089 cupsArrayAdd(ra
, "job-sheets");
6090 cupsArrayAdd(ra
, "job-sheets-default");
6091 cupsArrayAdd(ra
, "job-sheets-supported");
6092 cupsArrayAdd(ra
, "media");
6093 cupsArrayAdd(ra
, "media-default");
6094 cupsArrayAdd(ra
, "media-supported");
6095 cupsArrayAdd(ra
, "multiple-document-handling");
6096 cupsArrayAdd(ra
, "multiple-document-handling-default");
6097 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6098 cupsArrayAdd(ra
, "number-up");
6099 cupsArrayAdd(ra
, "number-up-default");
6100 cupsArrayAdd(ra
, "number-up-supported");
6101 cupsArrayAdd(ra
, "orientation-requested");
6102 cupsArrayAdd(ra
, "orientation-requested-default");
6103 cupsArrayAdd(ra
, "orientation-requested-supported");
6104 cupsArrayAdd(ra
, "page-ranges");
6105 cupsArrayAdd(ra
, "page-ranges-supported");
6106 cupsArrayAdd(ra
, "printer-resolution");
6107 cupsArrayAdd(ra
, "printer-resolution-default");
6108 cupsArrayAdd(ra
, "printer-resolution-supported");
6109 cupsArrayAdd(ra
, "print-quality");
6110 cupsArrayAdd(ra
, "print-quality-default");
6111 cupsArrayAdd(ra
, "print-quality-supported");
6112 cupsArrayAdd(ra
, "sides");
6113 cupsArrayAdd(ra
, "sides-default");
6114 cupsArrayAdd(ra
, "sides-supported");
6116 else if (!strcmp(value
, "job-description"))
6118 cupsArrayAdd(ra
, "date-time-at-completed");
6119 cupsArrayAdd(ra
, "date-time-at-creation");
6120 cupsArrayAdd(ra
, "date-time-at-processing");
6121 cupsArrayAdd(ra
, "job-detailed-status-message");
6122 cupsArrayAdd(ra
, "job-document-access-errors");
6123 cupsArrayAdd(ra
, "job-id");
6124 cupsArrayAdd(ra
, "job-impressions");
6125 cupsArrayAdd(ra
, "job-impressions-completed");
6126 cupsArrayAdd(ra
, "job-k-octets");
6127 cupsArrayAdd(ra
, "job-k-octets-processed");
6128 cupsArrayAdd(ra
, "job-media-progress");
6129 cupsArrayAdd(ra
, "job-media-sheets");
6130 cupsArrayAdd(ra
, "job-media-sheets-completed");
6131 cupsArrayAdd(ra
, "job-message-from-operator");
6132 cupsArrayAdd(ra
, "job-more-info");
6133 cupsArrayAdd(ra
, "job-name");
6134 cupsArrayAdd(ra
, "job-originating-user-name");
6135 cupsArrayAdd(ra
, "job-printer-up-time");
6136 cupsArrayAdd(ra
, "job-printer-uri");
6137 cupsArrayAdd(ra
, "job-state");
6138 cupsArrayAdd(ra
, "job-state-message");
6139 cupsArrayAdd(ra
, "job-state-reasons");
6140 cupsArrayAdd(ra
, "job-uri");
6141 cupsArrayAdd(ra
, "number-of-documents");
6142 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6143 cupsArrayAdd(ra
, "output-device-assigned");
6144 cupsArrayAdd(ra
, "time-at-completed");
6145 cupsArrayAdd(ra
, "time-at-creation");
6146 cupsArrayAdd(ra
, "time-at-processing");
6148 else if (!strcmp(value
, "printer-description"))
6150 cupsArrayAdd(ra
, "charset-configured");
6151 cupsArrayAdd(ra
, "charset-supported");
6152 cupsArrayAdd(ra
, "color-supported");
6153 cupsArrayAdd(ra
, "compression-supported");
6154 cupsArrayAdd(ra
, "document-format-default");
6155 cupsArrayAdd(ra
, "document-format-supported");
6156 cupsArrayAdd(ra
, "generated-natural-language-supported");
6157 cupsArrayAdd(ra
, "ipp-versions-supported");
6158 cupsArrayAdd(ra
, "job-impressions-supported");
6159 cupsArrayAdd(ra
, "job-k-octets-supported");
6160 cupsArrayAdd(ra
, "job-media-sheets-supported");
6161 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6162 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6163 cupsArrayAdd(ra
, "multiple-operation-time-out");
6164 cupsArrayAdd(ra
, "natural-language-configured");
6165 cupsArrayAdd(ra
, "notify-attributes-supported");
6166 cupsArrayAdd(ra
, "notify-lease-duration-default");
6167 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6168 cupsArrayAdd(ra
, "notify-max-events-supported");
6169 cupsArrayAdd(ra
, "notify-events-default");
6170 cupsArrayAdd(ra
, "notify-events-supported");
6171 cupsArrayAdd(ra
, "notify-pull-method-supported");
6172 cupsArrayAdd(ra
, "notify-schemes-supported");
6173 cupsArrayAdd(ra
, "operations-supported");
6174 cupsArrayAdd(ra
, "pages-per-minute");
6175 cupsArrayAdd(ra
, "pages-per-minute-color");
6176 cupsArrayAdd(ra
, "pdl-override-supported");
6177 cupsArrayAdd(ra
, "printer-alert");
6178 cupsArrayAdd(ra
, "printer-alert-description");
6179 cupsArrayAdd(ra
, "printer-commands");
6180 cupsArrayAdd(ra
, "printer-current-time");
6181 cupsArrayAdd(ra
, "printer-driver-installer");
6182 cupsArrayAdd(ra
, "printer-dns-sd-name");
6183 cupsArrayAdd(ra
, "printer-info");
6184 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6185 cupsArrayAdd(ra
, "printer-location");
6186 cupsArrayAdd(ra
, "printer-make-and-model");
6187 cupsArrayAdd(ra
, "printer-message-from-operator");
6188 cupsArrayAdd(ra
, "printer-more-info");
6189 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6190 cupsArrayAdd(ra
, "printer-name");
6191 cupsArrayAdd(ra
, "printer-state");
6192 cupsArrayAdd(ra
, "printer-state-message");
6193 cupsArrayAdd(ra
, "printer-state-reasons");
6194 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6195 cupsArrayAdd(ra
, "printer-type");
6196 cupsArrayAdd(ra
, "printer-up-time");
6197 cupsArrayAdd(ra
, "printer-uri-supported");
6198 cupsArrayAdd(ra
, "queued-job-count");
6199 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6200 cupsArrayAdd(ra
, "uri-authentication-supported");
6201 cupsArrayAdd(ra
, "uri-security-supported");
6203 else if (!strcmp(value
, "printer-defaults"))
6205 char *name
; /* Option name */
6208 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6210 name
= (char *)cupsArrayNext(CommonDefaults
))
6211 cupsArrayAdd(ra
, name
);
6213 else if (!strcmp(value
, "subscription-template"))
6215 cupsArrayAdd(ra
, "notify-attributes");
6216 cupsArrayAdd(ra
, "notify-charset");
6217 cupsArrayAdd(ra
, "notify-events");
6218 cupsArrayAdd(ra
, "notify-lease-duration");
6219 cupsArrayAdd(ra
, "notify-natural-language");
6220 cupsArrayAdd(ra
, "notify-pull-method");
6221 cupsArrayAdd(ra
, "notify-recipient-uri");
6222 cupsArrayAdd(ra
, "notify-time-interval");
6223 cupsArrayAdd(ra
, "notify-user-data");
6226 cupsArrayAdd(ra
, value
);
6234 * 'create_subscription()' - Create a notification subscription.
6238 create_subscription(
6239 cupsd_client_t
*con
, /* I - Client connection */
6240 ipp_attribute_t
*uri
) /* I - Printer URI */
6242 http_status_t status
; /* Policy status */
6243 int i
; /* Looping var */
6244 ipp_attribute_t
*attr
; /* Current attribute */
6245 cups_ptype_t dtype
; /* Destination type (printer/class) */
6246 char scheme
[HTTP_MAX_URI
],
6247 /* Scheme portion of URI */
6248 userpass
[HTTP_MAX_URI
],
6249 /* Username portion of URI */
6251 /* Host portion of URI */
6252 resource
[HTTP_MAX_URI
];
6253 /* Resource portion of URI */
6254 int port
; /* Port portion of URI */
6255 cupsd_printer_t
*printer
; /* Printer/class */
6256 cupsd_job_t
*job
; /* Job */
6257 int jobid
; /* Job ID */
6258 cupsd_subscription_t
*sub
; /* Subscription object */
6259 const char *username
, /* requesting-user-name or
6260 authenticated username */
6261 *recipient
, /* notify-recipient-uri */
6262 *pullmethod
; /* notify-pull-method */
6263 ipp_attribute_t
*user_data
; /* notify-user-data */
6264 int interval
, /* notify-time-interval */
6265 lease
; /* notify-lease-duration */
6266 unsigned mask
; /* notify-events */
6267 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6268 *notify_lease
; /* notify-lease-duration(-default) */
6272 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6274 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6275 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6276 attr
->value_tag
, attr
->name
);
6278 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6283 * Is the destination valid?
6286 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6287 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6288 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6290 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6291 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6292 sizeof(host
), &port
, resource
, sizeof(resource
));
6294 if (!strcmp(resource
, "/"))
6296 dtype
= (cups_ptype_t
)0;
6299 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6301 dtype
= (cups_ptype_t
)0;
6304 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6306 dtype
= CUPS_PRINTER_CLASS
;
6309 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6315 send_ipp_status(con
, IPP_NOT_FOUND
,
6316 _("The printer or class was not found."));
6326 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6329 send_http_error(con
, status
, printer
);
6333 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6335 send_http_error(con
, status
, NULL
);
6340 * Get the user that is requesting the subscription...
6343 username
= get_username(con
);
6346 * Find the first subscription group attribute; return if we have
6350 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6351 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6356 send_ipp_status(con
, IPP_BAD_REQUEST
,
6357 _("No subscription attributes in request"));
6362 * Process the subscription attributes in the request...
6365 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6373 lease
= DefaultLeaseDuration
;
6375 mask
= CUPSD_EVENT_NONE
;
6379 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6381 notify_lease
= ippFindAttribute(printer
->attrs
,
6382 "notify-lease-duration-default",
6386 lease
= notify_lease
->values
[0].integer
;
6390 notify_events
= NULL
;
6391 notify_lease
= NULL
;
6394 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6396 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6397 attr
->value_tag
== IPP_TAG_URI
)
6400 * Validate the recipient scheme against the ServerBin/notifier
6404 char notifier
[1024]; /* Notifier filename */
6407 recipient
= attr
->values
[0].string
.text
;
6409 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6410 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6411 host
, sizeof(host
), &port
,
6412 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6414 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6415 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
6416 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6417 "notify-status-code", IPP_URI_SCHEME
);
6421 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6423 if (access(notifier
, X_OK
))
6425 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6426 _("notify-recipient-uri URI \"%s\" uses unknown "
6427 "scheme"), recipient
);
6428 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6429 "notify-status-code", IPP_URI_SCHEME
);
6433 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6435 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6436 _("notify-recipient-uri URI \"%s\" is already used"),
6438 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6439 "notify-status-code", IPP_ATTRIBUTES
);
6443 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6444 attr
->value_tag
== IPP_TAG_KEYWORD
)
6446 pullmethod
= attr
->values
[0].string
.text
;
6448 if (strcmp(pullmethod
, "ippget"))
6450 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6451 _("Bad notify-pull-method \"%s\""), pullmethod
);
6452 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6453 "notify-status-code", IPP_ATTRIBUTES
);
6457 else if (!strcmp(attr
->name
, "notify-charset") &&
6458 attr
->value_tag
== IPP_TAG_CHARSET
&&
6459 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6460 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6462 send_ipp_status(con
, IPP_CHARSET
,
6463 _("Character set \"%s\" not supported"),
6464 attr
->values
[0].string
.text
);
6467 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6468 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6469 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6471 send_ipp_status(con
, IPP_CHARSET
,
6472 _("Language \"%s\" not supported"),
6473 attr
->values
[0].string
.text
);
6476 else if (!strcmp(attr
->name
, "notify-user-data") &&
6477 attr
->value_tag
== IPP_TAG_STRING
)
6479 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6481 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6482 _("The notify-user-data value is too large "
6483 "(%d > 63 octets)"),
6484 attr
->values
[0].unknown
.length
);
6490 else if (!strcmp(attr
->name
, "notify-events") &&
6491 attr
->value_tag
== IPP_TAG_KEYWORD
)
6492 notify_events
= attr
;
6493 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6494 attr
->value_tag
== IPP_TAG_INTEGER
)
6495 lease
= attr
->values
[0].integer
;
6496 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6497 attr
->value_tag
== IPP_TAG_INTEGER
)
6498 interval
= attr
->values
[0].integer
;
6499 else if (!strcmp(attr
->name
, "notify-job-id") &&
6500 attr
->value_tag
== IPP_TAG_INTEGER
)
6501 jobid
= attr
->values
[0].integer
;
6508 for (i
= 0; i
< notify_events
->num_values
; i
++)
6509 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6513 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6515 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6516 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6517 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6519 if (!recipient
&& !pullmethod
)
6522 if (mask
== CUPSD_EVENT_NONE
)
6525 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6527 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6530 send_ipp_status(con
, IPP_BAD_REQUEST
,
6531 _("notify-events not specified"));
6536 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6538 cupsdLogMessage(CUPSD_LOG_INFO
,
6539 "create_subscription: Limiting notify-lease-duration to "
6542 lease
= MaxLeaseDuration
;
6547 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6549 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found"), jobid
);
6556 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6558 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6559 _("There are too many subscriptions."));
6564 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6567 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6568 "Added subscription %d for printer \"%s\"",
6569 sub
->id
, printer
->name
);
6571 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6574 sub
->interval
= interval
;
6576 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6578 cupsdSetString(&sub
->owner
, username
);
6582 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6583 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6584 sub
->user_data_len
);
6587 ippAddSeparator(con
->response
);
6588 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6589 "notify-subscription-id", sub
->id
);
6591 con
->response
->request
.status
.status_code
= IPP_OK
;
6597 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6602 * 'delete_printer()' - Remove a printer or class from the system.
6606 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6607 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6609 http_status_t status
; /* Policy status */
6610 cups_ptype_t dtype
; /* Destination type (printer/class) */
6611 cupsd_printer_t
*printer
; /* Printer/class */
6612 char filename
[1024]; /* Script/PPD filename */
6615 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6616 con
->http
.fd
, uri
->values
[0].string
.text
);
6619 * Do we have a valid URI?
6622 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6628 send_ipp_status(con
, IPP_NOT_FOUND
,
6629 _("The printer or class was not found."));
6637 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6639 send_http_error(con
, status
, NULL
);
6644 * Remove old jobs...
6647 cupsdCancelJobs(printer
->name
, NULL
, 1);
6650 * Remove old subscriptions and send a "deleted printer" event...
6653 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6654 "%s \"%s\" deleted by \"%s\".",
6655 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6656 printer
->name
, get_username(con
));
6658 cupsdExpireSubscriptions(printer
, NULL
);
6661 * Remove any old PPD or script files...
6664 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6668 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6672 snprintf(filename
, sizeof(filename
), "%s/%s.ipp4", CacheDir
, printer
->name
);
6675 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
6678 snprintf(filename
, sizeof(filename
), "%s/%s.pwg3", CacheDir
, printer
->name
);
6683 * Unregister color profiles...
6686 apple_unregister_profiles(printer
);
6687 #endif /* __APPLE__ */
6689 if (dtype
& CUPS_PRINTER_CLASS
)
6691 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6692 printer
->name
, get_username(con
));
6694 cupsdDeletePrinter(printer
, 0);
6695 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6699 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6700 printer
->name
, get_username(con
));
6702 if (cupsdDeletePrinter(printer
, 0))
6703 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6705 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6708 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6711 * Return with no errors...
6714 con
->response
->request
.status
.status_code
= IPP_OK
;
6719 * 'get_default()' - Get the default destination.
6723 get_default(cupsd_client_t
*con
) /* I - Client connection */
6725 http_status_t status
; /* Policy status */
6726 cups_array_t
*ra
; /* Requested attributes array */
6729 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6735 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6737 send_http_error(con
, status
, NULL
);
6743 ra
= create_requested_array(con
->request
);
6745 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6747 cupsArrayDelete(ra
);
6749 con
->response
->request
.status
.status_code
= IPP_OK
;
6752 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6757 * 'get_devices()' - Get the list of available devices on the local system.
6761 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6763 http_status_t status
; /* Policy status */
6764 ipp_attribute_t
*limit
, /* limit attribute */
6765 *timeout
, /* timeout attribute */
6766 *requested
, /* requested-attributes attribute */
6767 *exclude
, /* exclude-schemes attribute */
6768 *include
; /* include-schemes attribute */
6769 char command
[1024], /* cups-deviced command */
6770 options
[2048], /* Options to pass to command */
6772 /* String for requested attributes */
6774 /* String for excluded schemes */
6776 /* String for included schemes */
6779 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6785 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6787 send_http_error(con
, status
, NULL
);
6792 * Run cups-deviced command with the given options...
6795 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6796 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6797 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6799 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6800 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6803 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6805 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6808 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6810 exclude_str
[0] = '\0';
6813 url_encode_attr(include
, include_str
, sizeof(include_str
));
6815 include_str
[0] = '\0';
6817 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6818 snprintf(options
, sizeof(options
),
6819 "%d+%d+%d+%d+%s%s%s%s%s",
6820 con
->request
->request
.op
.request_id
,
6821 limit
? limit
->values
[0].integer
: 0,
6822 timeout
? timeout
->values
[0].integer
: 15,
6825 exclude_str
[0] ? "%20" : "", exclude_str
,
6826 include_str
[0] ? "%20" : "", include_str
);
6828 if (cupsdSendCommand(con
, command
, options
, 1))
6831 * Command started successfully, don't send an IPP response here...
6834 ippDelete(con
->response
);
6835 con
->response
= NULL
;
6840 * Command failed, return "internal error" so the user knows something
6844 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6845 _("cups-deviced failed to execute."));
6851 * 'get_document()' - Get a copy of a job file.
6855 get_document(cupsd_client_t
*con
, /* I - Client connection */
6856 ipp_attribute_t
*uri
) /* I - Job URI */
6858 http_status_t status
; /* Policy status */
6859 ipp_attribute_t
*attr
; /* Current attribute */
6860 int jobid
; /* Job ID */
6861 int docnum
; /* Document number */
6862 cupsd_job_t
*job
; /* Current job */
6863 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6864 username
[HTTP_MAX_URI
], /* Username portion of URI */
6865 host
[HTTP_MAX_URI
], /* Host portion of URI */
6866 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6867 int port
; /* Port portion of URI */
6868 char filename
[1024], /* Filename for document */
6869 format
[1024]; /* Format for document */
6872 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6873 con
->http
.fd
, uri
->values
[0].string
.text
);
6876 * See if we have a job URI or a printer URI...
6879 if (!strcmp(uri
->name
, "printer-uri"))
6882 * Got a printer URI; see if we also have a job-id attribute...
6885 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6886 IPP_TAG_INTEGER
)) == NULL
)
6888 send_ipp_status(con
, IPP_BAD_REQUEST
,
6889 _("Got a printer-uri attribute but no job-id"));
6893 jobid
= attr
->values
[0].integer
;
6898 * Got a job URI; parse it to get the job ID...
6901 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6902 sizeof(scheme
), username
, sizeof(username
), host
,
6903 sizeof(host
), &port
, resource
, sizeof(resource
));
6905 if (strncmp(resource
, "/jobs/", 6))
6911 send_ipp_status(con
, IPP_BAD_REQUEST
,
6912 _("Bad job-uri attribute \"%s\""),
6913 uri
->values
[0].string
.text
);
6917 jobid
= atoi(resource
+ 6);
6921 * See if the job exists...
6924 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6927 * Nope - return a "not found" error...
6930 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
6938 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6940 send_http_error(con
, status
, NULL
);
6945 * Get the document number...
6948 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6949 IPP_TAG_INTEGER
)) == NULL
)
6951 send_ipp_status(con
, IPP_BAD_REQUEST
,
6952 _("Missing document-number attribute"));
6956 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6957 attr
->num_values
> 1)
6959 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6964 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6966 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6968 cupsdLogMessage(CUPSD_LOG_ERROR
,
6969 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6971 send_ipp_status(con
, IPP_NOT_FOUND
,
6972 _("Unable to open document %d in job %d"), docnum
, jobid
);
6976 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6980 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6981 job
->filetypes
[docnum
- 1]->type
);
6983 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6985 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6987 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6988 IPP_TAG_NAME
)) != NULL
)
6989 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6990 NULL
, attr
->values
[0].string
.text
);
6995 * 'get_job_attrs()' - Get job attributes.
6999 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
7000 ipp_attribute_t
*uri
) /* I - Job URI */
7002 http_status_t status
; /* Policy status */
7003 ipp_attribute_t
*attr
; /* Current attribute */
7004 int jobid
; /* Job ID */
7005 cupsd_job_t
*job
; /* Current job */
7006 cupsd_printer_t
*printer
; /* Current printer */
7007 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7008 username
[HTTP_MAX_URI
], /* Username portion of URI */
7009 host
[HTTP_MAX_URI
], /* Host portion of URI */
7010 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7011 int port
; /* Port portion of URI */
7012 cups_array_t
*ra
; /* Requested attributes array */
7015 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7016 con
->http
.fd
, uri
->values
[0].string
.text
);
7019 * See if we have a job URI or a printer URI...
7022 if (!strcmp(uri
->name
, "printer-uri"))
7025 * Got a printer URI; see if we also have a job-id attribute...
7028 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7029 IPP_TAG_INTEGER
)) == NULL
)
7031 send_ipp_status(con
, IPP_BAD_REQUEST
,
7032 _("Got a printer-uri attribute but no job-id"));
7036 jobid
= attr
->values
[0].integer
;
7041 * Got a job URI; parse it to get the job ID...
7044 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7045 sizeof(scheme
), username
, sizeof(username
), host
,
7046 sizeof(host
), &port
, resource
, sizeof(resource
));
7048 if (strncmp(resource
, "/jobs/", 6))
7054 send_ipp_status(con
, IPP_BAD_REQUEST
,
7055 _("Bad job-uri attribute \"%s\""),
7056 uri
->values
[0].string
.text
);
7060 jobid
= atoi(resource
+ 6);
7064 * See if the job exists...
7067 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7070 * Nope - return a "not found" error...
7073 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
7081 if ((printer
= job
->printer
) == NULL
)
7082 printer
= cupsdFindDest(job
->dest
);
7086 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
7089 send_http_error(con
, status
, printer
);
7093 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7095 send_http_error(con
, status
, NULL
);
7100 * Copy attributes...
7105 ra
= create_requested_array(con
->request
);
7106 copy_job_attrs(con
, job
, ra
);
7107 cupsArrayDelete(ra
);
7109 con
->response
->request
.status
.status_code
= IPP_OK
;
7114 * 'get_jobs()' - Get a list of jobs for the specified printer.
7118 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7119 ipp_attribute_t
*uri
) /* I - Printer URI */
7121 http_status_t status
; /* Policy status */
7122 ipp_attribute_t
*attr
; /* Current attribute */
7123 const char *dest
; /* Destination */
7124 cups_ptype_t dtype
; /* Destination type (printer/class) */
7125 cups_ptype_t dmask
; /* Destination type mask */
7126 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7127 username
[HTTP_MAX_URI
], /* Username portion of URI */
7128 host
[HTTP_MAX_URI
], /* Host portion of URI */
7129 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7130 int port
; /* Port portion of URI */
7131 int job_comparison
; /* Job comparison */
7132 ipp_jstate_t job_state
; /* job-state value */
7133 int first_job_id
; /* First job ID */
7134 int limit
; /* Maximum number of jobs to return */
7135 int count
; /* Number of jobs that match */
7136 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7137 cupsd_job_t
*job
; /* Current job pointer */
7138 cupsd_printer_t
*printer
; /* Printer */
7139 cups_array_t
*list
; /* Which job list... */
7140 cups_array_t
*ra
; /* Requested attributes array */
7143 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7144 uri
->values
[0].string
.text
);
7147 * Is the destination valid?
7150 if (strcmp(uri
->name
, "printer-uri"))
7152 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request"));
7156 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7157 sizeof(scheme
), username
, sizeof(username
), host
,
7158 sizeof(host
), &port
, resource
, sizeof(resource
));
7160 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7163 dtype
= (cups_ptype_t
)0;
7164 dmask
= (cups_ptype_t
)0;
7167 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7170 dtype
= (cups_ptype_t
)0;
7171 dmask
= CUPS_PRINTER_CLASS
;
7174 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7177 dtype
= CUPS_PRINTER_CLASS
;
7178 dmask
= CUPS_PRINTER_CLASS
;
7181 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7188 send_ipp_status(con
, IPP_NOT_FOUND
,
7189 _("The printer or class was not found."));
7194 dtype
&= CUPS_PRINTER_CLASS
;
7195 dmask
= CUPS_PRINTER_CLASS
;
7204 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
7207 send_http_error(con
, status
, printer
);
7211 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7213 send_http_error(con
, status
, NULL
);
7217 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7220 * See if the "which-jobs" attribute have been specified...
7223 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7224 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7226 send_ipp_status(con
, IPP_CONFLICT
,
7227 _("The %s attribute cannot be provided with job-ids."),
7231 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7233 job_comparison
= -1;
7234 job_state
= IPP_JOB_STOPPED
;
7237 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7240 job_state
= IPP_JOB_CANCELED
;
7243 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7246 job_state
= IPP_JOB_ABORTED
;
7249 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7252 job_state
= IPP_JOB_PENDING
;
7255 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7258 job_state
= IPP_JOB_CANCELED
;
7261 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7264 job_state
= IPP_JOB_PENDING
;
7267 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7270 job_state
= IPP_JOB_HELD
;
7273 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7276 job_state
= IPP_JOB_PROCESSING
;
7277 list
= PrintingJobs
;
7279 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7282 job_state
= IPP_JOB_STOPPED
;
7287 send_ipp_status(con
, IPP_ATTRIBUTES
,
7288 _("The which-jobs value \"%s\" is not supported."),
7289 attr
->values
[0].string
.text
);
7290 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7291 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7296 * See if they want to limit the number of jobs reported...
7299 if ((attr
= ippFindAttribute(con
->request
, "limit",
7300 IPP_TAG_INTEGER
)) != NULL
)
7304 send_ipp_status(con
, IPP_CONFLICT
,
7305 _("The %s attribute cannot be provided with job-ids."),
7310 limit
= attr
->values
[0].integer
;
7315 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7316 IPP_TAG_INTEGER
)) != NULL
)
7320 send_ipp_status(con
, IPP_CONFLICT
,
7321 _("The %s attribute cannot be provided with job-ids."),
7326 first_job_id
= attr
->values
[0].integer
;
7332 * See if we only want to see jobs for a specific user...
7335 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7336 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7338 send_ipp_status(con
, IPP_CONFLICT
,
7339 _("The %s attribute cannot be provided with job-ids."),
7343 else if (attr
&& attr
->values
[0].boolean
)
7344 strlcpy(username
, get_username(con
), sizeof(username
));
7348 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7349 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7352 * IPP conformance - Get-Jobs has a default requested-attributes value of
7353 * "job-id" and "job-uri".
7356 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7357 cupsArrayAdd(ra
, "job-id");
7358 cupsArrayAdd(ra
, "job-uri");
7362 * OK, build a list of jobs for this printer...
7367 int i
; /* Looping var */
7369 for (i
= 0; i
< job_ids
->num_values
; i
++)
7371 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
7375 if (i
< job_ids
->num_values
)
7377 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
7378 job_ids
->values
[i
].integer
);
7382 for (i
= 0; i
< job_ids
->num_values
; i
++)
7384 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7390 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7396 ippAddSeparator(con
->response
);
7398 copy_job_attrs(con
, job
, ra
);
7403 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7404 (limit
<= 0 || count
< limit
) && job
;
7405 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7408 * Filter out jobs that don't match...
7411 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7412 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7413 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7414 job
->username
, job
->state_value
, job
->attrs
);
7416 if (!job
->dest
|| !job
->username
)
7419 if (!job
->dest
|| !job
->username
)
7422 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7423 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7425 if ((job
->dtype
& dmask
) != dtype
&&
7426 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7429 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7430 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7431 (job_comparison
> 0 && job
->state_value
< job_state
))
7434 if (job
->id
< first_job_id
)
7441 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7446 if (username
[0] && strcasecmp(username
, job
->username
))
7450 ippAddSeparator(con
->response
);
7454 copy_job_attrs(con
, job
, ra
);
7457 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7460 cupsArrayDelete(ra
);
7462 con
->response
->request
.status
.status_code
= IPP_OK
;
7467 * 'get_notifications()' - Get events for a subscription.
7471 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7473 int i
, j
; /* Looping vars */
7474 http_status_t status
; /* Policy status */
7475 cupsd_subscription_t
*sub
; /* Subscription */
7476 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7477 *sequences
; /* notify-sequence-numbers */
7478 int min_seq
; /* Minimum sequence number */
7479 int interval
; /* Poll interval */
7482 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7486 * Get subscription attributes...
7489 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7491 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7496 send_ipp_status(con
, IPP_BAD_REQUEST
,
7497 _("Missing notify-subscription-ids attribute"));
7502 * Are the subscription IDs valid?
7505 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7507 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7510 * Bad subscription ID...
7513 send_ipp_status(con
, IPP_NOT_FOUND
,
7514 _("notify-subscription-id %d no good"),
7515 ids
->values
[i
].integer
);
7523 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7525 con
, sub
->owner
)) != HTTP_OK
)
7527 send_http_error(con
, status
, sub
->dest
);
7532 * Check the subscription type and update the interval accordingly.
7535 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7538 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7540 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7546 * Tell the client to poll again in N seconds...
7550 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7551 "notify-get-interval", interval
);
7553 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7554 "printer-up-time", time(NULL
));
7557 * Copy the subscription event attributes to the response.
7560 con
->response
->request
.status
.status_code
=
7561 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7563 for (i
= 0; i
< ids
->num_values
; i
++)
7566 * Get the subscription and sequence number...
7569 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7571 if (sequences
&& i
< sequences
->num_values
)
7572 min_seq
= sequences
->values
[i
].integer
;
7577 * If we don't have any new events, nothing to do here...
7580 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7584 * Otherwise copy all of the new events...
7587 if (sub
->first_event_id
> min_seq
)
7590 j
= min_seq
- sub
->first_event_id
;
7592 for (; j
< sub
->num_events
; j
++)
7594 ippAddSeparator(con
->response
);
7596 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7597 IPP_TAG_EVENT_NOTIFICATION
, 0);
7604 * 'get_ppd()' - Get a named PPD from the local system.
7608 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7609 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7611 http_status_t status
; /* Policy status */
7612 cupsd_printer_t
*dest
; /* Destination */
7613 cups_ptype_t dtype
; /* Destination type */
7616 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7617 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7619 if (!strcmp(uri
->name
, "ppd-name"))
7622 * Return a PPD file from cups-driverd...
7625 char command
[1024], /* cups-driverd command */
7626 options
[1024], /* Options to pass to command */
7627 ppd_name
[1024]; /* ppd-name */
7634 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7636 send_http_error(con
, status
, NULL
);
7641 * Run cups-driverd command with the given options...
7644 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7645 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7646 snprintf(options
, sizeof(options
), "get+%d+%s",
7647 con
->request
->request
.op
.request_id
, ppd_name
);
7649 if (cupsdSendCommand(con
, command
, options
, 0))
7652 * Command started successfully, don't send an IPP response here...
7655 ippDelete(con
->response
);
7656 con
->response
= NULL
;
7661 * Command failed, return "internal error" so the user knows something
7665 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7666 _("cups-driverd failed to execute."));
7669 else if (!strcmp(uri
->name
, "printer-uri") &&
7670 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7672 int i
; /* Looping var */
7673 char filename
[1024]; /* PPD filename */
7680 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7682 send_http_error(con
, status
, dest
);
7687 * See if we need the PPD for a class or remote printer...
7690 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7693 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7695 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7696 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7697 "printer-uri", NULL
, dest
->uri
);
7700 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7702 for (i
= 0; i
< dest
->num_printers
; i
++)
7703 if (!(dest
->printers
[i
]->type
&
7704 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7706 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7707 dest
->printers
[i
]->name
);
7709 if (!access(filename
, 0))
7713 if (i
< dest
->num_printers
)
7714 dest
= dest
->printers
[i
];
7717 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7718 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7719 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7725 * Found the printer with the PPD file, now see if there is one...
7728 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7730 send_ipp_status(con
, IPP_NOT_FOUND
,
7731 _("The PPD file \"%s\" could not be opened: %s"),
7732 uri
->values
[0].string
.text
, strerror(errno
));
7736 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7740 con
->response
->request
.status
.status_code
= IPP_OK
;
7743 send_ipp_status(con
, IPP_NOT_FOUND
,
7744 _("The PPD file \"%s\" could not be found."),
7745 uri
->values
[0].string
.text
);
7750 * 'get_ppds()' - Get the list of PPD files on the local system.
7754 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7756 http_status_t status
; /* Policy status */
7757 ipp_attribute_t
*limit
, /* Limit attribute */
7758 *device
, /* ppd-device-id attribute */
7759 *language
, /* ppd-natural-language attribute */
7760 *make
, /* ppd-make attribute */
7761 *model
, /* ppd-make-and-model attribute */
7762 *model_number
, /* ppd-model-number attribute */
7763 *product
, /* ppd-product attribute */
7764 *psversion
, /* ppd-psverion attribute */
7765 *type
, /* ppd-type attribute */
7766 *requested
, /* requested-attributes attribute */
7767 *exclude
, /* exclude-schemes attribute */
7768 *include
; /* include-schemes attribute */
7769 char command
[1024], /* cups-driverd command */
7770 options
[4096], /* Options to pass to command */
7771 device_str
[256],/* Escaped ppd-device-id string */
7773 /* Escaped ppd-natural-language */
7774 make_str
[256], /* Escaped ppd-make string */
7775 model_str
[256], /* Escaped ppd-make-and-model string */
7776 model_number_str
[256],
7777 /* ppd-model-number string */
7779 /* Escaped ppd-product string */
7781 /* Escaped ppd-psversion string */
7782 type_str
[256], /* Escaped ppd-type string */
7784 /* String for requested attributes */
7786 /* String for excluded schemes */
7788 /* String for included schemes */
7791 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7797 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7799 send_http_error(con
, status
, NULL
);
7804 * Run cups-driverd command with the given options...
7807 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7808 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7809 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7811 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7812 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7814 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7816 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7817 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7818 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7819 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7821 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7823 include
= ippFindAttribute(con
->request
, "include-schemes",
7827 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7829 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7832 url_encode_attr(device
, device_str
, sizeof(device_str
));
7834 device_str
[0] = '\0';
7837 url_encode_attr(language
, language_str
, sizeof(language_str
));
7839 language_str
[0] = '\0';
7842 url_encode_attr(make
, make_str
, sizeof(make_str
));
7847 url_encode_attr(model
, model_str
, sizeof(model_str
));
7849 model_str
[0] = '\0';
7852 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7853 model_number
->values
[0].integer
);
7855 model_number_str
[0] = '\0';
7858 url_encode_attr(product
, product_str
, sizeof(product_str
));
7860 product_str
[0] = '\0';
7863 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7865 psversion_str
[0] = '\0';
7868 url_encode_attr(type
, type_str
, sizeof(type_str
));
7873 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7875 exclude_str
[0] = '\0';
7878 url_encode_attr(include
, include_str
, sizeof(include_str
));
7880 include_str
[0] = '\0';
7882 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7883 snprintf(options
, sizeof(options
),
7884 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7885 con
->request
->request
.op
.request_id
,
7886 limit
? limit
->values
[0].integer
: 0,
7888 device
? "%20" : "", device_str
,
7889 language
? "%20" : "", language_str
,
7890 make
? "%20" : "", make_str
,
7891 model
? "%20" : "", model_str
,
7892 model_number
? "%20" : "", model_number_str
,
7893 product
? "%20" : "", product_str
,
7894 psversion
? "%20" : "", psversion_str
,
7895 type
? "%20" : "", type_str
,
7896 exclude_str
[0] ? "%20" : "", exclude_str
,
7897 include_str
[0] ? "%20" : "", include_str
);
7899 if (cupsdSendCommand(con
, command
, options
, 0))
7902 * Command started successfully, don't send an IPP response here...
7905 ippDelete(con
->response
);
7906 con
->response
= NULL
;
7911 * Command failed, return "internal error" so the user knows something
7915 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7916 _("cups-driverd failed to execute."));
7922 * 'get_printer_attrs()' - Get printer attributes.
7926 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7927 ipp_attribute_t
*uri
) /* I - Printer URI */
7929 http_status_t status
; /* Policy status */
7930 cups_ptype_t dtype
; /* Destination type (printer/class) */
7931 cupsd_printer_t
*printer
; /* Printer/class */
7932 cups_array_t
*ra
; /* Requested attributes array */
7935 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7936 con
->http
.fd
, uri
->values
[0].string
.text
);
7939 * Is the destination valid?
7942 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7948 send_ipp_status(con
, IPP_NOT_FOUND
,
7949 _("The printer or class was not found."));
7957 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7959 send_http_error(con
, status
, printer
);
7964 * Send the attributes...
7967 ra
= create_requested_array(con
->request
);
7969 copy_printer_attrs(con
, printer
, ra
);
7971 cupsArrayDelete(ra
);
7973 con
->response
->request
.status
.status_code
= IPP_OK
;
7978 * 'get_printer_supported()' - Get printer supported values.
7982 get_printer_supported(
7983 cupsd_client_t
*con
, /* I - Client connection */
7984 ipp_attribute_t
*uri
) /* I - Printer URI */
7986 http_status_t status
; /* Policy status */
7987 cups_ptype_t dtype
; /* Destination type (printer/class) */
7988 cupsd_printer_t
*printer
; /* Printer/class */
7991 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7992 con
->http
.fd
, uri
->values
[0].string
.text
);
7995 * Is the destination valid?
7998 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8004 send_ipp_status(con
, IPP_NOT_FOUND
,
8005 _("The printer or class was not found."));
8013 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8015 send_http_error(con
, status
, printer
);
8020 * Return a list of attributes that can be set via Set-Printer-Attributes.
8023 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8025 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8026 "printer-location", 0);
8028 con
->response
->request
.status
.status_code
= IPP_OK
;
8033 * 'get_printers()' - Get a list of printers or classes.
8037 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8038 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8040 http_status_t status
; /* Policy status */
8041 ipp_attribute_t
*attr
; /* Current attribute */
8042 int limit
; /* Max number of printers to return */
8043 int count
; /* Number of printers that match */
8044 cupsd_printer_t
*printer
; /* Current printer pointer */
8045 int printer_type
, /* printer-type attribute */
8046 printer_mask
; /* printer-type-mask attribute */
8047 char *location
; /* Location string */
8048 const char *username
; /* Current user */
8049 char *first_printer_name
; /* first-printer-name attribute */
8050 cups_array_t
*ra
; /* Requested attributes array */
8051 int local
; /* Local connection? */
8054 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8055 con
->http
.fd
, type
);
8061 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8063 send_http_error(con
, status
, NULL
);
8068 * Check for printers...
8071 if (!Printers
|| !cupsArrayCount(Printers
))
8073 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8078 * See if they want to limit the number of printers reported...
8081 if ((attr
= ippFindAttribute(con
->request
, "limit",
8082 IPP_TAG_INTEGER
)) != NULL
)
8083 limit
= attr
->values
[0].integer
;
8087 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8088 IPP_TAG_NAME
)) != NULL
)
8089 first_printer_name
= attr
->values
[0].string
.text
;
8091 first_printer_name
= NULL
;
8094 * Support filtering...
8097 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8098 IPP_TAG_ENUM
)) != NULL
)
8099 printer_type
= attr
->values
[0].integer
;
8103 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8104 IPP_TAG_ENUM
)) != NULL
)
8105 printer_mask
= attr
->values
[0].integer
;
8109 local
= httpAddrLocalhost(&(con
->clientaddr
));
8111 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8112 IPP_TAG_TEXT
)) != NULL
)
8113 location
= attr
->values
[0].string
.text
;
8117 if (con
->username
[0])
8118 username
= con
->username
;
8119 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8120 IPP_TAG_NAME
)) != NULL
)
8121 username
= attr
->values
[0].string
.text
;
8125 ra
= create_requested_array(con
->request
);
8128 * OK, build a list of printers for this printer...
8131 if (first_printer_name
)
8133 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8134 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8137 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8140 count
< limit
&& printer
;
8141 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8143 if (!local
&& !printer
->shared
)
8146 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8147 (printer
->type
& printer_mask
) == printer_type
&&
8149 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
8152 * If HideImplicitMembers is enabled, see if this printer or class
8153 * is a member of an implicit class...
8156 if (ImplicitClasses
&& HideImplicitMembers
&&
8157 printer
->in_implicit_class
)
8161 * If a username is specified, see if it is allowed or denied
8165 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
8169 * Add the group separator as needed...
8173 ippAddSeparator(con
->response
);
8178 * Send the attributes...
8181 copy_printer_attrs(con
, printer
, ra
);
8185 cupsArrayDelete(ra
);
8187 con
->response
->request
.status
.status_code
= IPP_OK
;
8192 * 'get_subscription_attrs()' - Get subscription attributes.
8196 get_subscription_attrs(
8197 cupsd_client_t
*con
, /* I - Client connection */
8198 int sub_id
) /* I - Subscription ID */
8200 http_status_t status
; /* Policy status */
8201 cupsd_subscription_t
*sub
; /* Subscription */
8202 cups_array_t
*ra
; /* Requested attributes array */
8205 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8206 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8207 con
, con
->http
.fd
, sub_id
);
8210 * Is the subscription ID valid?
8213 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8216 * Bad subscription ID...
8219 send_ipp_status(con
, IPP_NOT_FOUND
,
8220 _("notify-subscription-id %d no good"), sub_id
);
8228 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8230 con
, sub
->owner
)) != HTTP_OK
)
8232 send_http_error(con
, status
, sub
->dest
);
8237 * Copy the subscription attributes to the response using the
8238 * requested-attributes attribute that may be provided by the client.
8241 ra
= create_requested_array(con
->request
);
8243 copy_subscription_attrs(con
, sub
, ra
);
8245 cupsArrayDelete(ra
);
8247 con
->response
->request
.status
.status_code
= IPP_OK
;
8252 * 'get_subscriptions()' - Get subscriptions.
8256 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8257 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8259 http_status_t status
; /* Policy status */
8260 int count
; /* Number of subscriptions */
8261 int limit
; /* Limit */
8262 cupsd_subscription_t
*sub
; /* Subscription */
8263 cups_array_t
*ra
; /* Requested attributes array */
8264 ipp_attribute_t
*attr
; /* Attribute */
8265 cups_ptype_t dtype
; /* Destination type (printer/class) */
8266 char scheme
[HTTP_MAX_URI
],
8267 /* Scheme portion of URI */
8268 username
[HTTP_MAX_URI
],
8269 /* Username portion of URI */
8271 /* Host portion of URI */
8272 resource
[HTTP_MAX_URI
];
8273 /* Resource portion of URI */
8274 int port
; /* Port portion of URI */
8275 cupsd_job_t
*job
; /* Job pointer */
8276 cupsd_printer_t
*printer
; /* Printer */
8279 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8280 "get_subscriptions(con=%p[%d], uri=%s)",
8281 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8284 * Is the destination valid?
8287 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8288 sizeof(scheme
), username
, sizeof(username
), host
,
8289 sizeof(host
), &port
, resource
, sizeof(resource
));
8291 if (!strcmp(resource
, "/") ||
8292 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8293 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8294 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8299 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8302 job
= cupsdFindJob(atoi(resource
+ 6));
8306 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist"),
8311 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8317 send_ipp_status(con
, IPP_NOT_FOUND
,
8318 _("The printer or class was not found."));
8321 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8322 IPP_TAG_INTEGER
)) != NULL
)
8324 job
= cupsdFindJob(attr
->values
[0].integer
);
8328 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
8329 attr
->values
[0].integer
);
8340 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
8342 con
, NULL
)) != HTTP_OK
)
8344 send_http_error(con
, status
, printer
);
8349 * Copy the subscription attributes to the response using the
8350 * requested-attributes attribute that may be provided by the client.
8353 ra
= create_requested_array(con
->request
);
8355 if ((attr
= ippFindAttribute(con
->request
, "limit",
8356 IPP_TAG_INTEGER
)) != NULL
)
8357 limit
= attr
->values
[0].integer
;
8362 * See if we only want to see subscriptions for a specific user...
8365 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8366 IPP_TAG_BOOLEAN
)) != NULL
&&
8367 attr
->values
[0].boolean
)
8368 strlcpy(username
, get_username(con
), sizeof(username
));
8372 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8374 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8375 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8376 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
8378 ippAddSeparator(con
->response
);
8379 copy_subscription_attrs(con
, sub
, ra
);
8382 if (limit
&& count
>= limit
)
8386 cupsArrayDelete(ra
);
8389 con
->response
->request
.status
.status_code
= IPP_OK
;
8391 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8396 * 'get_username()' - Get the username associated with a request.
8399 static const char * /* O - Username */
8400 get_username(cupsd_client_t
*con
) /* I - Connection */
8402 ipp_attribute_t
*attr
; /* Attribute */
8405 if (con
->username
[0])
8406 return (con
->username
);
8407 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8408 IPP_TAG_NAME
)) != NULL
)
8409 return (attr
->values
[0].string
.text
);
8411 return ("anonymous");
8416 * 'hold_job()' - Hold a print job.
8420 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8421 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8423 ipp_attribute_t
*attr
; /* Current job-hold-until */
8424 const char *when
; /* New value */
8425 int jobid
; /* Job ID */
8426 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8427 username
[HTTP_MAX_URI
], /* Username portion of URI */
8428 host
[HTTP_MAX_URI
], /* Host portion of URI */
8429 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8430 int port
; /* Port portion of URI */
8431 cupsd_job_t
*job
; /* Job information */
8434 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8435 uri
->values
[0].string
.text
);
8438 * See if we have a job URI or a printer URI...
8441 if (!strcmp(uri
->name
, "printer-uri"))
8444 * Got a printer URI; see if we also have a job-id attribute...
8447 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8448 IPP_TAG_INTEGER
)) == NULL
)
8450 send_ipp_status(con
, IPP_BAD_REQUEST
,
8451 _("Got a printer-uri attribute but no job-id"));
8455 jobid
= attr
->values
[0].integer
;
8460 * Got a job URI; parse it to get the job ID...
8463 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8464 sizeof(scheme
), username
, sizeof(username
), host
,
8465 sizeof(host
), &port
, resource
, sizeof(resource
));
8467 if (strncmp(resource
, "/jobs/", 6))
8473 send_ipp_status(con
, IPP_BAD_REQUEST
,
8474 _("Bad job-uri attribute \"%s\""),
8475 uri
->values
[0].string
.text
);
8479 jobid
= atoi(resource
+ 6);
8483 * See if the job exists...
8486 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8489 * Nope - return a "not found" error...
8492 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
8497 * See if the job is owned by the requesting user...
8500 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8502 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8503 cupsdFindDest(job
->dest
));
8508 * Hold the job and return...
8511 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8512 IPP_TAG_KEYWORD
)) == NULL
)
8513 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8517 when
= attr
->values
[0].string
.text
;
8519 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8520 "Job job-hold-until value changed by user.");
8523 when
= "indefinite";
8525 cupsdSetJobHoldUntil(job
, when
, 1);
8526 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8529 con
->response
->request
.status
.status_code
= IPP_OK
;
8534 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8538 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8539 ipp_attribute_t
*uri
) /* I - Printer URI */
8541 http_status_t status
; /* Policy status */
8542 cups_ptype_t dtype
; /* Destination type (printer/class) */
8543 cupsd_printer_t
*printer
; /* Printer data */
8546 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8547 con
->http
.fd
, uri
->values
[0].string
.text
);
8550 * Is the destination valid?
8553 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8559 send_ipp_status(con
, IPP_NOT_FOUND
,
8560 _("The printer or class was not found."));
8568 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8570 send_http_error(con
, status
, printer
);
8575 * Hold pending/new jobs sent to the printer...
8578 printer
->holding_new_jobs
= 1;
8580 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8581 cupsdAddPrinterHistory(printer
);
8583 if (dtype
& CUPS_PRINTER_CLASS
)
8584 cupsdLogMessage(CUPSD_LOG_INFO
,
8585 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8586 printer
->name
, get_username(con
));
8588 cupsdLogMessage(CUPSD_LOG_INFO
,
8589 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8590 printer
->name
, get_username(con
));
8593 * Everything was ok, so return OK status...
8596 con
->response
->request
.status
.status_code
= IPP_OK
;
8601 * 'move_job()' - Move a job to a new destination.
8605 move_job(cupsd_client_t
*con
, /* I - Client connection */
8606 ipp_attribute_t
*uri
) /* I - Job URI */
8608 http_status_t status
; /* Policy status */
8609 ipp_attribute_t
*attr
; /* Current attribute */
8610 int jobid
; /* Job ID */
8611 cupsd_job_t
*job
; /* Current job */
8612 const char *src
; /* Source printer/class */
8613 cups_ptype_t stype
, /* Source type (printer or class) */
8614 dtype
; /* Destination type (printer/class) */
8615 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8616 username
[HTTP_MAX_URI
], /* Username portion of URI */
8617 host
[HTTP_MAX_URI
], /* Host portion of URI */
8618 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8619 int port
; /* Port portion of URI */
8620 cupsd_printer_t
*sprinter
, /* Source printer */
8621 *dprinter
; /* Destination printer */
8624 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8625 uri
->values
[0].string
.text
);
8628 * Get the new printer or class...
8631 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8632 IPP_TAG_URI
)) == NULL
)
8635 * Need job-printer-uri...
8638 send_ipp_status(con
, IPP_BAD_REQUEST
,
8639 _("job-printer-uri attribute missing"));
8643 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8649 send_ipp_status(con
, IPP_NOT_FOUND
,
8650 _("The printer or class was not found."));
8655 * See if we have a job URI or a printer URI...
8658 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8659 sizeof(scheme
), username
, sizeof(username
), host
,
8660 sizeof(host
), &port
, resource
, sizeof(resource
));
8662 if (!strcmp(uri
->name
, "printer-uri"))
8665 * Got a printer URI; see if we also have a job-id attribute...
8668 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8669 IPP_TAG_INTEGER
)) == NULL
)
8675 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8676 &sprinter
)) == NULL
)
8682 send_ipp_status(con
, IPP_NOT_FOUND
,
8683 _("The printer or class was not found."));
8692 * Otherwise, just move a single job...
8695 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8698 * Nope - return a "not found" error...
8701 send_ipp_status(con
, IPP_NOT_FOUND
,
8702 _("Job #%d does not exist"), attr
->values
[0].integer
);
8708 * Job found, initialize source pointers...
8719 * Got a job URI; parse it to get the job ID...
8722 if (strncmp(resource
, "/jobs/", 6))
8728 send_ipp_status(con
, IPP_BAD_REQUEST
,
8729 _("Bad job-uri attribute \"%s\""),
8730 uri
->values
[0].string
.text
);
8735 * See if the job exists...
8738 jobid
= atoi(resource
+ 6);
8740 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8743 * Nope - return a "not found" error...
8746 send_ipp_status(con
, IPP_NOT_FOUND
,
8747 _("Job #%d does not exist"), jobid
);
8753 * Job found, initialize source pointers...
8762 * Check the policy of the destination printer...
8765 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8766 job
? job
->username
: NULL
)) != HTTP_OK
)
8768 send_http_error(con
, status
, dprinter
);
8773 * Now move the job or jobs...
8779 * See if the job has been completed...
8782 if (job
->state_value
> IPP_JOB_STOPPED
)
8785 * Return a "not-possible" error...
8788 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8789 _("Job #%d is finished and cannot be altered"),
8795 * See if the job is owned by the requesting user...
8798 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8800 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8801 cupsdFindDest(job
->dest
));
8806 * Move the job to a different printer or class...
8809 cupsdMoveJob(job
, dprinter
);
8814 * Got the source printer, now look through the jobs...
8817 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8819 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8822 * See if the job is pointing at the source printer or has not been
8826 if (strcasecmp(job
->dest
, src
) ||
8827 job
->state_value
> IPP_JOB_STOPPED
)
8831 * See if the job can be moved by the requesting user...
8834 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8838 * Move the job to a different printer or class...
8841 cupsdMoveJob(job
, dprinter
);
8846 * Start jobs if possible...
8852 * Return with "everything is OK" status...
8855 con
->response
->request
.status
.status_code
= IPP_OK
;
8860 * 'ppd_parse_line()' - Parse a PPD default line.
8863 static int /* O - 0 on success, -1 on failure */
8864 ppd_parse_line(const char *line
, /* I - Line */
8865 char *option
, /* O - Option name */
8866 int olen
, /* I - Size of option name */
8867 char *choice
, /* O - Choice name */
8868 int clen
) /* I - Size of choice name */
8871 * Verify this is a default option line...
8874 if (strncmp(line
, "*Default", 8))
8878 * Read the option name...
8881 for (line
+= 8, olen
--;
8882 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8893 * Skip everything else up to the colon (:)...
8896 while (*line
&& *line
!= ':')
8905 * Now grab the option choice, skipping leading whitespace...
8908 while (isspace(*line
& 255))
8912 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8923 * Return with no errors...
8931 * 'print_job()' - Print a file to a printer or class.
8935 print_job(cupsd_client_t
*con
, /* I - Client connection */
8936 ipp_attribute_t
*uri
) /* I - Printer URI */
8938 ipp_attribute_t
*attr
; /* Current attribute */
8939 ipp_attribute_t
*format
; /* Document-format attribute */
8940 const char *default_format
; /* document-format-default value */
8941 cupsd_job_t
*job
; /* New job */
8942 char filename
[1024]; /* Job filename */
8943 mime_type_t
*filetype
; /* Type of file */
8944 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8945 type
[MIME_MAX_TYPE
], /* Subtype of file */
8946 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8947 /* Textual name of mime type */
8948 cupsd_printer_t
*printer
; /* Printer data */
8949 struct stat fileinfo
; /* File information */
8950 int kbytes
; /* Size of file */
8951 int compression
; /* Document compression */
8954 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8955 uri
->values
[0].string
.text
);
8958 * Validate print file attributes, for now just document-format and
8959 * compression (CUPS only supports "none" and "gzip")...
8962 compression
= CUPS_FILE_NONE
;
8964 if ((attr
= ippFindAttribute(con
->request
, "compression",
8965 IPP_TAG_KEYWORD
)) != NULL
)
8967 if (strcmp(attr
->values
[0].string
.text
, "none")
8969 && strcmp(attr
->values
[0].string
.text
, "gzip")
8970 #endif /* HAVE_LIBZ */
8973 send_ipp_status(con
, IPP_ATTRIBUTES
,
8974 _("Unsupported compression \"%s\""),
8975 attr
->values
[0].string
.text
);
8976 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8977 "compression", NULL
, attr
->values
[0].string
.text
);
8982 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8983 compression
= CUPS_FILE_GZIP
;
8984 #endif /* HAVE_LIBZ */
8988 * Do we have a file to print?
8993 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
8998 * Is the destination valid?
9001 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
9007 send_ipp_status(con
, IPP_NOT_FOUND
,
9008 _("The printer or class was not found."));
9013 * Is it a format we support?
9016 if ((format
= ippFindAttribute(con
->request
, "document-format",
9017 IPP_TAG_MIMETYPE
)) != NULL
)
9020 * Grab format from client...
9023 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9026 send_ipp_status(con
, IPP_BAD_REQUEST
,
9027 _("Bad document-format \"%s\""),
9028 format
->values
[0].string
.text
);
9032 else if ((default_format
= cupsGetOption("document-format",
9033 printer
->num_options
,
9034 printer
->options
)) != NULL
)
9037 * Use default document format...
9040 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9042 send_ipp_status(con
, IPP_BAD_REQUEST
,
9043 _("Bad document-format \"%s\""),
9054 strcpy(super
, "application");
9055 strcpy(type
, "octet-stream");
9058 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9061 * Auto-type the file...
9064 ipp_attribute_t
*doc_name
; /* document-name attribute */
9067 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9069 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9070 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9071 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9075 filetype
= mimeType(MimeDatabase
, super
, type
);
9077 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9078 filetype
->super
, filetype
->type
);
9081 filetype
= mimeType(MimeDatabase
, super
, type
);
9085 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9088 * Replace the document-format attribute value with the auto-typed or
9092 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9097 _cupsStrFree(format
->values
[0].string
.text
);
9099 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9102 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9103 "document-format", NULL
, mimetype
);
9107 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9108 _("Unsupported document-format \"%s\""),
9109 format
? format
->values
[0].string
.text
:
9110 "application/octet-stream");
9111 cupsdLogMessage(CUPSD_LOG_INFO
,
9112 "Hint: Do you have the raw file printing rules enabled?");
9115 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9116 "document-format", NULL
, format
->values
[0].string
.text
);
9122 * Read any embedded job ticket info from PS files...
9125 if (!strcasecmp(filetype
->super
, "application") &&
9126 (!strcasecmp(filetype
->type
, "postscript") ||
9127 !strcasecmp(filetype
->type
, "pdf")))
9128 read_job_ticket(con
);
9131 * Create the job object...
9134 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9138 * Update quota data...
9141 if (stat(con
->filename
, &fileinfo
))
9144 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9146 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9148 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9149 IPP_TAG_INTEGER
)) != NULL
)
9150 attr
->values
[0].integer
+= kbytes
;
9153 * Add the job file...
9156 if (add_file(con
, job
, filetype
, compression
))
9159 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9161 rename(con
->filename
, filename
);
9162 cupsdClearString(&con
->filename
);
9165 * See if we need to add the ending sheet...
9168 if (cupsdTimeoutJob(job
))
9172 * Log and save the job...
9175 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9176 "File of type %s/%s queued by \"%s\".",
9177 filetype
->super
, filetype
->type
, job
->username
);
9178 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9179 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9180 job
->dest
, job
->username
);
9183 * Start the job if possible...
9191 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9193 * This function only gets called when printing a single PDF or PostScript
9194 * file using the Print-Job operation. It doesn't work for Create-Job +
9195 * Send-File, since the job attributes need to be set at job creation
9196 * time for banners to work. The embedded job ticket stuff is here
9197 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9198 * options and IPP attributes which otherwise would be lost.
9200 * The format of a job ticket is simple:
9202 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9204 * %cupsJobTicket: attr1=value1
9205 * %cupsJobTicket: attr2=value2
9207 * %cupsJobTicket: attrN=valueN
9209 * Job ticket lines must appear immediately after the first line that
9210 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9211 * stops looking for job ticket info when it finds a line that does not begin
9212 * with "%cupsJobTicket:".
9214 * The maximum length of a job ticket line, including the prefix, is
9215 * 255 characters to conform with the Adobe DSC.
9217 * Read-only attributes are rejected with a notice to the error log in
9218 * case a malicious user tries anything. Since the job ticket is read
9219 * prior to attribute validation in print_job(), job ticket attributes
9220 * will go through the same validation as IPP attributes...
9224 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9226 cups_file_t
*fp
; /* File to read from */
9227 char line
[256]; /* Line data */
9228 int num_options
; /* Number of options */
9229 cups_option_t
*options
; /* Options */
9230 ipp_t
*ticket
; /* New attributes */
9231 ipp_attribute_t
*attr
, /* Current attribute */
9232 *attr2
, /* Job attribute */
9233 *prev2
; /* Previous job attribute */
9237 * First open the print file...
9240 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9242 cupsdLogMessage(CUPSD_LOG_ERROR
,
9243 "Unable to open print file for job ticket - %s",
9249 * Skip the first line...
9252 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9254 cupsdLogMessage(CUPSD_LOG_ERROR
,
9255 "Unable to read from print file for job ticket - %s",
9261 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9264 * Not a DSC-compliant file, so no job ticket info will be available...
9272 * Read job ticket info from the file...
9278 while (cupsFileGets(fp
, line
, sizeof(line
)))
9281 * Stop at the first non-ticket line...
9284 if (strncmp(line
, "%cupsJobTicket:", 15))
9288 * Add the options to the option array...
9291 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9295 * Done with the file; see if we have any options...
9300 if (num_options
== 0)
9304 * OK, convert the options to an attribute list, and apply them to
9309 cupsEncodeOptions(ticket
, num_options
, options
);
9312 * See what the user wants to change.
9315 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9317 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9320 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9321 !strcmp(attr
->name
, "job-originating-user-name") ||
9322 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9323 !strcmp(attr
->name
, "job-k-octets") ||
9324 !strcmp(attr
->name
, "job-id") ||
9325 !strncmp(attr
->name
, "job-state", 9) ||
9326 !strncmp(attr
->name
, "time-at-", 8))
9327 continue; /* Read-only attrs */
9329 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9330 IPP_TAG_ZERO
)) != NULL
)
9333 * Some other value; first free the old value...
9336 if (con
->request
->attrs
== attr2
)
9338 con
->request
->attrs
= attr2
->next
;
9343 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9344 if (prev2
->next
== attr2
)
9346 prev2
->next
= attr2
->next
;
9351 if (con
->request
->last
== attr2
)
9352 con
->request
->last
= prev2
;
9354 _ippFreeAttr(attr2
);
9358 * Add new option by copying it...
9361 copy_attribute(con
->request
, attr
, 0);
9365 * Then free the attribute list and option array...
9369 cupsFreeOptions(num_options
, options
);
9374 * 'reject_jobs()' - Reject print jobs to a printer.
9378 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9379 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9381 http_status_t status
; /* Policy status */
9382 cups_ptype_t dtype
; /* Destination type (printer/class) */
9383 cupsd_printer_t
*printer
; /* Printer data */
9384 ipp_attribute_t
*attr
; /* printer-state-message text */
9387 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9388 con
->http
.fd
, uri
->values
[0].string
.text
);
9391 * Is the destination valid?
9394 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9400 send_ipp_status(con
, IPP_NOT_FOUND
,
9401 _("The printer or class was not found."));
9409 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9411 send_http_error(con
, status
, printer
);
9416 * Reject jobs sent to the printer...
9419 printer
->accepting
= 0;
9421 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9422 IPP_TAG_TEXT
)) == NULL
)
9423 strcpy(printer
->state_message
, "Rejecting Jobs");
9425 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9426 sizeof(printer
->state_message
));
9428 cupsdAddPrinterHistory(printer
);
9430 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9431 "No longer accepting jobs.");
9433 if (dtype
& CUPS_PRINTER_CLASS
)
9435 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9437 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9438 printer
->name
, get_username(con
));
9442 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9444 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9445 printer
->name
, get_username(con
));
9449 * Everything was ok, so return OK status...
9452 con
->response
->request
.status
.status_code
= IPP_OK
;
9457 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9461 release_held_new_jobs(
9462 cupsd_client_t
*con
, /* I - Connection */
9463 ipp_attribute_t
*uri
) /* I - Printer URI */
9465 http_status_t status
; /* Policy status */
9466 cups_ptype_t dtype
; /* Destination type (printer/class) */
9467 cupsd_printer_t
*printer
; /* Printer data */
9470 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9471 con
->http
.fd
, uri
->values
[0].string
.text
);
9474 * Is the destination valid?
9477 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9483 send_ipp_status(con
, IPP_NOT_FOUND
,
9484 _("The printer or class was not found."));
9492 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9494 send_http_error(con
, status
, printer
);
9499 * Hold pending/new jobs sent to the printer...
9502 printer
->holding_new_jobs
= 0;
9504 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9505 cupsdAddPrinterHistory(printer
);
9507 if (dtype
& CUPS_PRINTER_CLASS
)
9508 cupsdLogMessage(CUPSD_LOG_INFO
,
9509 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9510 printer
->name
, get_username(con
));
9512 cupsdLogMessage(CUPSD_LOG_INFO
,
9513 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9514 printer
->name
, get_username(con
));
9517 * Everything was ok, so return OK status...
9520 con
->response
->request
.status
.status_code
= IPP_OK
;
9525 * 'release_job()' - Release a held print job.
9529 release_job(cupsd_client_t
*con
, /* I - Client connection */
9530 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9532 ipp_attribute_t
*attr
; /* Current attribute */
9533 int jobid
; /* Job ID */
9534 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9535 username
[HTTP_MAX_URI
], /* Username portion of URI */
9536 host
[HTTP_MAX_URI
], /* Host portion of URI */
9537 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9538 int port
; /* Port portion of URI */
9539 cupsd_job_t
*job
; /* Job information */
9542 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9543 con
->http
.fd
, uri
->values
[0].string
.text
);
9546 * See if we have a job URI or a printer URI...
9549 if (!strcmp(uri
->name
, "printer-uri"))
9552 * Got a printer URI; see if we also have a job-id attribute...
9555 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9556 IPP_TAG_INTEGER
)) == NULL
)
9558 send_ipp_status(con
, IPP_BAD_REQUEST
,
9559 _("Got a printer-uri attribute but no job-id"));
9563 jobid
= attr
->values
[0].integer
;
9568 * Got a job URI; parse it to get the job ID...
9571 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9572 sizeof(scheme
), username
, sizeof(username
), host
,
9573 sizeof(host
), &port
, resource
, sizeof(resource
));
9575 if (strncmp(resource
, "/jobs/", 6))
9581 send_ipp_status(con
, IPP_BAD_REQUEST
,
9582 _("Bad job-uri attribute \"%s\""),
9583 uri
->values
[0].string
.text
);
9587 jobid
= atoi(resource
+ 6);
9591 * See if the job exists...
9594 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9597 * Nope - return a "not found" error...
9600 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9605 * See if job is "held"...
9608 if (job
->state_value
!= IPP_JOB_HELD
)
9611 * Nope - return a "not possible" error...
9614 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held"), jobid
);
9619 * See if the job is owned by the requesting user...
9622 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9624 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9625 cupsdFindDest(job
->dest
));
9630 * Reset the job-hold-until value to "no-hold"...
9633 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9634 IPP_TAG_KEYWORD
)) == NULL
)
9635 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9639 _cupsStrFree(attr
->values
[0].string
.text
);
9641 attr
->value_tag
= IPP_TAG_KEYWORD
;
9642 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9644 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9645 "Job job-hold-until value changed by user.");
9649 * Release the job and return...
9652 cupsdReleaseJob(job
);
9654 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9655 "Job released by user.");
9657 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9659 con
->response
->request
.status
.status_code
= IPP_OK
;
9666 * 'renew_subscription()' - Renew an existing subscription...
9671 cupsd_client_t
*con
, /* I - Client connection */
9672 int sub_id
) /* I - Subscription ID */
9674 http_status_t status
; /* Policy status */
9675 cupsd_subscription_t
*sub
; /* Subscription */
9676 ipp_attribute_t
*lease
; /* notify-lease-duration */
9679 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9680 "renew_subscription(con=%p[%d], sub_id=%d)",
9681 con
, con
->http
.fd
, sub_id
);
9684 * Is the subscription ID valid?
9687 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9690 * Bad subscription ID...
9693 send_ipp_status(con
, IPP_NOT_FOUND
,
9694 _("notify-subscription-id %d no good"), sub_id
);
9701 * Job subscriptions cannot be renewed...
9704 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9705 _("Job subscriptions cannot be renewed"));
9713 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9715 con
, sub
->owner
)) != HTTP_OK
)
9717 send_http_error(con
, status
, sub
->dest
);
9722 * Renew the subscription...
9725 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9728 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9730 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9732 cupsdLogMessage(CUPSD_LOG_INFO
,
9733 "renew_subscription: Limiting notify-lease-duration to "
9736 sub
->lease
= MaxLeaseDuration
;
9739 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9741 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9743 con
->response
->request
.status
.status_code
= IPP_OK
;
9745 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9746 "notify-lease-duration", sub
->lease
);
9751 * 'restart_job()' - Restart an old print job.
9755 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9756 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9758 ipp_attribute_t
*attr
; /* Current attribute */
9759 int jobid
; /* Job ID */
9760 cupsd_job_t
*job
; /* Job information */
9761 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9762 username
[HTTP_MAX_URI
], /* Username portion of URI */
9763 host
[HTTP_MAX_URI
], /* Host portion of URI */
9764 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9765 int port
; /* Port portion of URI */
9768 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9769 con
->http
.fd
, uri
->values
[0].string
.text
);
9772 * See if we have a job URI or a printer URI...
9775 if (!strcmp(uri
->name
, "printer-uri"))
9778 * Got a printer URI; see if we also have a job-id attribute...
9781 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9782 IPP_TAG_INTEGER
)) == NULL
)
9784 send_ipp_status(con
, IPP_BAD_REQUEST
,
9785 _("Got a printer-uri attribute but no job-id"));
9789 jobid
= attr
->values
[0].integer
;
9794 * Got a job URI; parse it to get the job ID...
9797 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9798 sizeof(scheme
), username
, sizeof(username
), host
,
9799 sizeof(host
), &port
, resource
, sizeof(resource
));
9801 if (strncmp(resource
, "/jobs/", 6))
9807 send_ipp_status(con
, IPP_BAD_REQUEST
,
9808 _("Bad job-uri attribute \"%s\""),
9809 uri
->values
[0].string
.text
);
9813 jobid
= atoi(resource
+ 6);
9817 * See if the job exists...
9820 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9823 * Nope - return a "not found" error...
9826 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9831 * See if job is in any of the "completed" states...
9834 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9837 * Nope - return a "not possible" error...
9840 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete"),
9846 * See if we have retained the job files...
9851 if (!job
->attrs
|| job
->num_files
== 0)
9854 * Nope - return a "not possible" error...
9857 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9858 _("Job #%d cannot be restarted - no files"), jobid
);
9863 * See if the job is owned by the requesting user...
9866 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9868 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9869 cupsdFindDest(job
->dest
));
9874 * See if the job-hold-until attribute is specified...
9877 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9878 IPP_TAG_KEYWORD
)) == NULL
)
9879 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9881 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9884 * Return the job to a held state...
9887 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9888 "Restarted by \"%s\" with job-hold-until=%s.",
9889 username
, attr
->values
[0].string
.text
);
9890 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9892 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9893 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9894 attr
->values
[0].string
.text
);
9899 * Restart the job...
9902 cupsdRestartJob(job
);
9906 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9908 con
->response
->request
.status
.status_code
= IPP_OK
;
9913 * 'save_auth_info()' - Save authentication information for a job.
9918 cupsd_client_t
*con
, /* I - Client connection */
9919 cupsd_job_t
*job
, /* I - Job */
9920 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9922 int i
; /* Looping var */
9923 char filename
[1024]; /* Job authentication filename */
9924 cups_file_t
*fp
; /* Job authentication file */
9925 char line
[2048]; /* Line for file */
9926 cupsd_printer_t
*dest
; /* Destination printer/class */
9930 * This function saves the in-memory authentication information for
9931 * a job so that it can be used to authenticate with a remote host.
9932 * The information is stored in a file that is readable only by the
9933 * root user. The fields are Base-64 encoded, each on a separate line,
9934 * followed by random number (up to 1024) of newlines to limit the
9935 * amount of information that is exposed.
9937 * Because of the potential for exposing of authentication information,
9938 * this functionality is only enabled when running cupsd as root.
9940 * This caching only works for the Basic and BasicDigest authentication
9941 * types. Digest authentication cannot be cached this way, and in
9942 * the future Kerberos authentication may make all of this obsolete.
9944 * Authentication information is saved whenever an authenticated
9945 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9948 * This information is deleted after a job is completed or canceled,
9949 * so reprints may require subsequent re-authentication.
9955 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9959 * Create the authentication file and change permissions...
9962 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9963 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9965 cupsdLogMessage(CUPSD_LOG_ERROR
,
9966 "Unable to save authentication info to \"%s\" - %s",
9967 filename
, strerror(errno
));
9971 fchown(cupsFileNumber(fp
), 0, 0);
9972 fchmod(cupsFileNumber(fp
), 0400);
9974 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9977 * Write 1 to 3 auth values...
9980 cupsdClearString(&job
->auth_username
);
9981 cupsdClearString(&job
->auth_domain
);
9982 cupsdClearString(&job
->auth_password
);
9984 for (i
= 0; i
< auth_info
->num_values
; i
++)
9986 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9987 strlen(auth_info
->values
[i
].string
.text
));
9988 cupsFilePrintf(fp
, "%s\n", line
);
9990 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9991 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9992 auth_info
->values
[i
].string
.text
);
9993 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9994 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9995 auth_info
->values
[i
].string
.text
);
9996 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9997 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9998 auth_info
->values
[i
].string
.text
);
10001 else if (con
->username
[0])
10004 * Write the authenticated username...
10007 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
10008 cupsFilePrintf(fp
, "%s\n", line
);
10010 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
10011 cupsdClearString(&job
->auth_domain
);
10014 * Write the authenticated password...
10017 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10018 cupsFilePrintf(fp
, "%s\n", line
);
10020 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
10024 * Write a random number of newlines to the end of the file...
10027 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10028 cupsFilePutChar(fp
, '\n');
10031 * Close the file and return...
10036 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10037 # ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
10038 if (con
->have_gss
&&
10039 (con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
|| con
->gss_creds
))
10041 if (con
->have_gss
&& con
->gss_creds
)
10042 # endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
10043 save_krb5_creds(con
, job
);
10044 else if (job
->ccname
)
10045 cupsdClearString(&(job
->ccname
));
10046 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10050 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10052 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
10056 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
10057 cupsd_job_t
*job
) /* I - Job */
10060 * Get the credentials...
10063 job
->ccache
= cupsdCopyKrb5Creds(con
);
10066 * Add the KRB5CCNAME environment variable to the job so that the
10067 * backend can use the credentials when printing.
10072 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
10073 krb5_cc_get_name(KerberosContext
, job
->ccache
));
10075 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
10078 cupsdClearString(&(job
->ccname
));
10080 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10084 * 'send_document()' - Send a file to a printer or class.
10088 send_document(cupsd_client_t
*con
, /* I - Client connection */
10089 ipp_attribute_t
*uri
) /* I - Printer URI */
10091 ipp_attribute_t
*attr
; /* Current attribute */
10092 ipp_attribute_t
*format
; /* Request's document-format attribute */
10093 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10094 const char *default_format
;/* document-format-default value */
10095 int jobid
; /* Job ID number */
10096 cupsd_job_t
*job
; /* Current job */
10097 char job_uri
[HTTP_MAX_URI
],
10099 scheme
[HTTP_MAX_URI
],
10100 /* Method portion of URI */
10101 username
[HTTP_MAX_URI
],
10102 /* Username portion of URI */
10103 host
[HTTP_MAX_URI
],
10104 /* Host portion of URI */
10105 resource
[HTTP_MAX_URI
];
10106 /* Resource portion of URI */
10107 int port
; /* Port portion of URI */
10108 mime_type_t
*filetype
; /* Type of file */
10109 char super
[MIME_MAX_SUPER
],
10110 /* Supertype of file */
10111 type
[MIME_MAX_TYPE
],
10112 /* Subtype of file */
10113 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10114 /* Textual name of mime type */
10115 char filename
[1024]; /* Job filename */
10116 cupsd_printer_t
*printer
; /* Current printer */
10117 struct stat fileinfo
; /* File information */
10118 int kbytes
; /* Size of file */
10119 int compression
; /* Type of compression */
10120 int start_job
; /* Start the job? */
10123 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10124 con
->http
.fd
, uri
->values
[0].string
.text
);
10127 * See if we have a job URI or a printer URI...
10130 if (!strcmp(uri
->name
, "printer-uri"))
10133 * Got a printer URI; see if we also have a job-id attribute...
10136 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10137 IPP_TAG_INTEGER
)) == NULL
)
10139 send_ipp_status(con
, IPP_BAD_REQUEST
,
10140 _("Got a printer-uri attribute but no job-id"));
10144 jobid
= attr
->values
[0].integer
;
10149 * Got a job URI; parse it to get the job ID...
10152 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10153 sizeof(scheme
), username
, sizeof(username
), host
,
10154 sizeof(host
), &port
, resource
, sizeof(resource
));
10156 if (strncmp(resource
, "/jobs/", 6))
10162 send_ipp_status(con
, IPP_BAD_REQUEST
,
10163 _("Bad job-uri attribute \"%s\""),
10164 uri
->values
[0].string
.text
);
10168 jobid
= atoi(resource
+ 6);
10172 * See if the job exists...
10175 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10178 * Nope - return a "not found" error...
10181 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10185 printer
= cupsdFindDest(job
->dest
);
10188 * See if the job is owned by the requesting user...
10191 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10193 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10194 cupsdFindDest(job
->dest
));
10199 * OK, see if the client is sending the document compressed - CUPS
10200 * only supports "none" and "gzip".
10203 compression
= CUPS_FILE_NONE
;
10205 if ((attr
= ippFindAttribute(con
->request
, "compression",
10206 IPP_TAG_KEYWORD
)) != NULL
)
10208 if (strcmp(attr
->values
[0].string
.text
, "none")
10210 && strcmp(attr
->values
[0].string
.text
, "gzip")
10211 #endif /* HAVE_LIBZ */
10214 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\""),
10215 attr
->values
[0].string
.text
);
10216 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10217 "compression", NULL
, attr
->values
[0].string
.text
);
10222 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10223 compression
= CUPS_FILE_GZIP
;
10224 #endif /* HAVE_LIBZ */
10228 * Do we have a file to print?
10231 if (!con
->filename
)
10234 * Check for an empty request with "last-document" set to true, which is
10235 * used to close an "open" job by RFC 2911, section 3.3.2.
10238 if (job
->num_files
> 0 &&
10239 (attr
= ippFindAttribute(con
->request
, "last-document",
10240 IPP_TAG_BOOLEAN
)) != NULL
&&
10241 attr
->values
[0].boolean
)
10242 goto last_document
;
10244 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
10249 * Is it a format we support?
10252 if ((format
= ippFindAttribute(con
->request
, "document-format",
10253 IPP_TAG_MIMETYPE
)) != NULL
)
10256 * Grab format from client...
10259 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10262 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
10263 format
->values
[0].string
.text
);
10267 else if ((default_format
= cupsGetOption("document-format",
10268 printer
->num_options
,
10269 printer
->options
)) != NULL
)
10272 * Use default document format...
10275 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10277 send_ipp_status(con
, IPP_BAD_REQUEST
,
10278 _("Could not scan type \"%s\""),
10286 * No document format attribute? Auto-type it!
10289 strcpy(super
, "application");
10290 strcpy(type
, "octet-stream");
10293 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10296 * Auto-type the file...
10299 ipp_attribute_t
*doc_name
; /* document-name attribute */
10302 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10304 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10305 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10306 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10310 filetype
= mimeType(MimeDatabase
, super
, type
);
10312 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10313 filetype
->super
, filetype
->type
);
10316 filetype
= mimeType(MimeDatabase
, super
, type
);
10321 * Replace the document-format attribute value with the auto-typed or
10325 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10328 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10329 IPP_TAG_MIMETYPE
)) != NULL
)
10331 _cupsStrFree(jformat
->values
[0].string
.text
);
10333 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10336 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10337 "document-format", NULL
, mimetype
);
10339 else if (!filetype
)
10341 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10342 _("Unsupported format \'%s/%s\'"), super
, type
);
10343 cupsdLogMessage(CUPSD_LOG_INFO
,
10344 "Hint: Do you have the raw file printing rules enabled?");
10347 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10348 "document-format", NULL
, format
->values
[0].string
.text
);
10353 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10355 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10358 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10359 _("Unsupported format \'%s\'"), mimetype
);
10361 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10362 "document-format", NULL
, mimetype
);
10368 * Add the file to the job...
10373 if (add_file(con
, job
, filetype
, compression
))
10376 if (stat(con
->filename
, &fileinfo
))
10379 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10381 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10383 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10384 IPP_TAG_INTEGER
)) != NULL
)
10385 attr
->values
[0].integer
+= kbytes
;
10387 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10389 rename(con
->filename
, filename
);
10391 cupsdClearString(&con
->filename
);
10393 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10394 filetype
->super
, filetype
->type
, job
->username
);
10397 * Start the job if this is the last document...
10402 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10403 IPP_TAG_BOOLEAN
)) != NULL
&&
10404 attr
->values
[0].boolean
)
10407 * See if we need to add the ending sheet...
10410 if (cupsdTimeoutJob(job
))
10413 if (job
->state_value
== IPP_JOB_STOPPED
)
10415 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10416 job
->state_value
= IPP_JOB_PENDING
;
10418 else if (job
->state_value
== IPP_JOB_HELD
)
10420 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10421 IPP_TAG_KEYWORD
)) == NULL
)
10422 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10424 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10426 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10427 job
->state_value
= IPP_JOB_PENDING
;
10432 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10438 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10439 IPP_TAG_KEYWORD
)) == NULL
)
10440 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10442 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10444 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10445 job
->state_value
= IPP_JOB_HELD
;
10446 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10449 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10456 * Fill in the response info...
10459 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10462 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10465 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10467 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10469 add_job_state_reasons(con
, job
);
10471 con
->response
->request
.status
.status_code
= IPP_OK
;
10474 * Start the job if necessary...
10483 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10488 cupsd_client_t
*con
, /* I - Client connection */
10489 http_status_t status
, /* I - HTTP status code */
10490 cupsd_printer_t
*printer
) /* I - Printer, if any */
10492 ipp_attribute_t
*uri
; /* Request URI, if any */
10495 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10496 IPP_TAG_URI
)) == NULL
)
10497 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10499 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10500 "Returning HTTP %s for %s (%s) from %s",
10501 httpStatus(status
),
10502 ippOpString(con
->request
->request
.op
.operation_id
),
10503 uri
? uri
->values
[0].string
.text
: "no URI",
10504 con
->http
.hostname
);
10508 int auth_type
; /* Type of authentication required */
10511 auth_type
= CUPSD_AUTH_NONE
;
10513 if (status
== HTTP_UNAUTHORIZED
&&
10514 printer
->num_auth_info_required
> 0 &&
10515 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10517 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10518 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10519 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10522 * Creating and authenticating jobs requires Kerberos...
10525 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10530 * Use policy/location-defined authentication requirements...
10533 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10534 cupsd_location_t
*auth
; /* Pointer to authentication element */
10537 if (printer
->type
& CUPS_PRINTER_CLASS
)
10538 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10540 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10542 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10543 auth
->type
== CUPSD_AUTH_NONE
)
10544 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10546 con
->request
->request
.op
.operation_id
:
10551 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10552 auth_type
= DefaultAuthType
;
10554 auth_type
= auth
->type
;
10558 cupsdSendError(con
, status
, auth_type
);
10561 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10563 ippDelete(con
->response
);
10564 con
->response
= NULL
;
10571 * 'send_ipp_status()' - Send a status back to the IPP client.
10575 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10576 ipp_status_t status
, /* I - IPP status code */
10577 const char *message
,/* I - Status message */
10578 ...) /* I - Additional args as needed */
10580 va_list ap
; /* Pointer to additional args */
10581 char formatted
[1024]; /* Formatted errror message */
10584 va_start(ap
, message
);
10585 vsnprintf(formatted
, sizeof(formatted
),
10586 _cupsLangString(con
->language
, message
), ap
);
10589 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10590 ippOpString(con
->request
->request
.op
.operation_id
),
10591 ippErrorString(status
), formatted
);
10593 con
->response
->request
.status
.status_code
= status
;
10595 if (ippFindAttribute(con
->response
, "attributes-charset",
10596 IPP_TAG_ZERO
) == NULL
)
10597 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10598 "attributes-charset", NULL
, "utf-8");
10600 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10601 IPP_TAG_ZERO
) == NULL
)
10602 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10603 "attributes-natural-language", NULL
, DefaultLanguage
);
10605 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10606 "status-message", NULL
, formatted
);
10611 * 'set_default()' - Set the default destination...
10615 set_default(cupsd_client_t
*con
, /* I - Client connection */
10616 ipp_attribute_t
*uri
) /* I - Printer URI */
10618 http_status_t status
; /* Policy status */
10619 cups_ptype_t dtype
; /* Destination type (printer/class) */
10620 cupsd_printer_t
*printer
, /* Printer */
10621 *oldprinter
; /* Old default printer */
10624 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10625 con
->http
.fd
, uri
->values
[0].string
.text
);
10628 * Is the destination valid?
10631 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10637 send_ipp_status(con
, IPP_NOT_FOUND
,
10638 _("The printer or class was not found."));
10646 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10648 send_http_error(con
, status
, NULL
);
10653 * Set it as the default...
10656 oldprinter
= DefaultPrinter
;
10657 DefaultPrinter
= printer
;
10660 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10661 "%s is no longer the default printer.", oldprinter
->name
);
10663 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10664 "%s is now the default printer.", printer
->name
);
10666 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10667 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10669 cupsdLogMessage(CUPSD_LOG_INFO
,
10670 "Default destination set to \"%s\" by \"%s\".",
10671 printer
->name
, get_username(con
));
10674 * Everything was ok, so return OK status...
10677 con
->response
->request
.status
.status_code
= IPP_OK
;
10682 * 'set_job_attrs()' - Set job attributes.
10686 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10687 ipp_attribute_t
*uri
) /* I - Job URI */
10689 ipp_attribute_t
*attr
, /* Current attribute */
10690 *attr2
; /* Job attribute */
10691 int jobid
; /* Job ID */
10692 cupsd_job_t
*job
; /* Current job */
10693 char scheme
[HTTP_MAX_URI
],
10694 /* Method portion of URI */
10695 username
[HTTP_MAX_URI
],
10696 /* Username portion of URI */
10697 host
[HTTP_MAX_URI
],
10698 /* Host portion of URI */
10699 resource
[HTTP_MAX_URI
];
10700 /* Resource portion of URI */
10701 int port
; /* Port portion of URI */
10702 int event
; /* Events? */
10703 int check_jobs
; /* Check jobs? */
10706 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10707 con
->http
.fd
, uri
->values
[0].string
.text
);
10710 * Start with "everything is OK" status...
10713 con
->response
->request
.status
.status_code
= IPP_OK
;
10716 * See if we have a job URI or a printer URI...
10719 if (!strcmp(uri
->name
, "printer-uri"))
10722 * Got a printer URI; see if we also have a job-id attribute...
10725 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10726 IPP_TAG_INTEGER
)) == NULL
)
10728 send_ipp_status(con
, IPP_BAD_REQUEST
,
10729 _("Got a printer-uri attribute but no job-id"));
10733 jobid
= attr
->values
[0].integer
;
10738 * Got a job URI; parse it to get the job ID...
10741 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10742 sizeof(scheme
), username
, sizeof(username
), host
,
10743 sizeof(host
), &port
, resource
, sizeof(resource
));
10745 if (strncmp(resource
, "/jobs/", 6))
10751 send_ipp_status(con
, IPP_BAD_REQUEST
,
10752 _("Bad job-uri attribute \"%s\""),
10753 uri
->values
[0].string
.text
);
10757 jobid
= atoi(resource
+ 6);
10761 * See if the job exists...
10764 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10767 * Nope - return a "not found" error...
10770 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10775 * See if the job has been completed...
10778 if (job
->state_value
> IPP_JOB_STOPPED
)
10781 * Return a "not-possible" error...
10784 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10785 _("Job #%d is finished and cannot be altered"), jobid
);
10790 * See if the job is owned by the requesting user...
10793 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10795 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10796 cupsdFindDest(job
->dest
));
10801 * See what the user wants to change.
10809 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10811 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10814 if (!strcmp(attr
->name
, "attributes-charset") ||
10815 !strcmp(attr
->name
, "attributes-natural-language") ||
10816 !strcmp(attr
->name
, "document-compression") ||
10817 !strcmp(attr
->name
, "document-format") ||
10818 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10819 !strcmp(attr
->name
, "job-document-access-errors") ||
10820 !strcmp(attr
->name
, "job-id") ||
10821 !strcmp(attr
->name
, "job-impressions-completed") ||
10822 !strcmp(attr
->name
, "job-k-octets") ||
10823 !strcmp(attr
->name
, "job-originating-host-name") ||
10824 !strcmp(attr
->name
, "job-originating-user-name") ||
10825 !strcmp(attr
->name
, "job-printer-up-time") ||
10826 !strcmp(attr
->name
, "job-printer-uri") ||
10827 !strcmp(attr
->name
, "job-sheets") ||
10828 !strcmp(attr
->name
, "job-state-message") ||
10829 !strcmp(attr
->name
, "job-state-reasons") ||
10830 !strcmp(attr
->name
, "job-uri") ||
10831 !strcmp(attr
->name
, "number-of-documents") ||
10832 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10833 !strcmp(attr
->name
, "output-device-assigned") ||
10834 !strncmp(attr
->name
, "date-time-at-", 13) ||
10835 !strncmp(attr
->name
, "job-k-octets", 12) ||
10836 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10837 !strncmp(attr
->name
, "time-at-", 8))
10843 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10844 _("%s cannot be changed."), attr
->name
);
10846 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10847 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10852 if (!strcmp(attr
->name
, "job-priority"))
10855 * Change the job priority...
10858 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10860 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value"));
10862 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10863 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10865 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10867 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10868 _("Job is completed and cannot be changed."));
10871 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10873 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10874 attr
->values
[0].integer
);
10875 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10878 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10879 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10882 else if (!strcmp(attr
->name
, "job-state"))
10885 * Change the job state...
10888 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10890 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value"));
10892 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10893 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10897 switch (attr
->values
[0].integer
)
10899 case IPP_JOB_PENDING
:
10900 case IPP_JOB_HELD
:
10901 if (job
->state_value
> IPP_JOB_HELD
)
10903 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10904 _("Job state cannot be changed."));
10907 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10909 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10910 attr
->values
[0].integer
);
10911 cupsdSetJobState(job
, attr
->values
[0].integer
,
10913 "Job state changed by \"%s\"", username
);
10918 case IPP_JOB_PROCESSING
:
10919 case IPP_JOB_STOPPED
:
10920 if (job
->state_value
!= attr
->values
[0].integer
)
10922 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10923 _("Job state cannot be changed."));
10928 case IPP_JOB_CANCELED
:
10929 case IPP_JOB_ABORTED
:
10930 case IPP_JOB_COMPLETED
:
10931 if (job
->state_value
> IPP_JOB_PROCESSING
)
10933 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10934 _("Job state cannot be changed."));
10937 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10939 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10940 attr
->values
[0].integer
);
10941 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10943 "Job state changed by \"%s\"", username
);
10950 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10952 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10953 IPP_TAG_ZERO
)) != NULL
)
10956 * Some other value; first free the old value...
10959 if (job
->attrs
->prev
)
10960 job
->attrs
->prev
->next
= attr2
->next
;
10962 job
->attrs
->attrs
= attr2
->next
;
10964 if (job
->attrs
->last
== attr2
)
10965 job
->attrs
->last
= job
->attrs
->prev
;
10967 _ippFreeAttr(attr2
);
10970 * Then copy the attribute...
10973 copy_attribute(job
->attrs
, attr
, 0);
10976 * See if the job-name or job-hold-until is being changed.
10979 if (!strcmp(attr
->name
, "job-hold-until"))
10981 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10982 attr
->values
[0].string
.text
);
10983 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10985 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10987 cupsdReleaseJob(job
);
10991 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10992 "Job held by \"%s\".", username
);
10994 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10997 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
11000 * Delete the attribute...
11003 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11004 IPP_TAG_ZERO
)) != NULL
)
11006 if (job
->attrs
->prev
)
11007 job
->attrs
->prev
->next
= attr2
->next
;
11009 job
->attrs
->attrs
= attr2
->next
;
11011 if (attr2
== job
->attrs
->last
)
11012 job
->attrs
->last
= job
->attrs
->prev
;
11014 _ippFreeAttr(attr2
);
11016 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11022 * Add new option by copying it...
11025 copy_attribute(job
->attrs
, attr
, 0);
11027 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11036 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11039 * Send events as needed...
11042 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11043 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11044 cupsdFindDest(job
->dest
), job
,
11045 "Job priority changed by user.");
11047 if (event
& CUPSD_EVENT_JOB_STATE
)
11048 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11049 job
->state_value
== IPP_JOB_HELD
?
11050 "Job held by user." : "Job restarted by user.");
11052 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11053 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11054 "Job options changed by user.");
11057 * Start jobs if possible...
11066 * 'set_printer_attrs()' - Set printer attributes.
11070 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11071 ipp_attribute_t
*uri
) /* I - Printer */
11073 http_status_t status
; /* Policy status */
11074 cups_ptype_t dtype
; /* Destination type (printer/class) */
11075 cupsd_printer_t
*printer
; /* Printer/class */
11076 ipp_attribute_t
*attr
; /* Printer attribute */
11077 int changed
= 0; /* Was anything changed? */
11080 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11081 con
->http
.fd
, uri
->values
[0].string
.text
);
11084 * Is the destination valid?
11087 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11093 send_ipp_status(con
, IPP_NOT_FOUND
,
11094 _("The printer or class was not found."));
11102 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11104 send_http_error(con
, status
, printer
);
11109 * Return a list of attributes that can be set via Set-Printer-Attributes.
11112 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11113 IPP_TAG_TEXT
)) != NULL
)
11115 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11119 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11120 IPP_TAG_TEXT
)) != NULL
)
11122 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11127 * Update the printer attributes and return...
11132 cupsdSetPrinterAttrs(printer
);
11133 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11135 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11136 "Printer \"%s\" description or location changed by \"%s\".",
11137 printer
->name
, get_username(con
));
11139 cupsdLogMessage(CUPSD_LOG_INFO
,
11140 "Printer \"%s\" description or location changed by \"%s\".",
11141 printer
->name
, get_username(con
));
11144 con
->response
->request
.status
.status_code
= IPP_OK
;
11149 * 'set_printer_defaults()' - Set printer default options from a request.
11153 set_printer_defaults(
11154 cupsd_client_t
*con
, /* I - Client connection */
11155 cupsd_printer_t
*printer
) /* I - Printer */
11157 int i
; /* Looping var */
11158 ipp_attribute_t
*attr
; /* Current attribute */
11159 int namelen
; /* Length of attribute name */
11160 char name
[256], /* New attribute name */
11161 value
[256]; /* String version of integer attrs */
11164 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11167 * Skip non-printer attributes...
11170 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11173 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11175 if (!strcmp(attr
->name
, "job-sheets-default"))
11178 * Only allow keywords and names...
11181 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11185 * Only allow job-sheets-default to be set when running without a
11186 * system high classification level...
11189 if (Classification
)
11192 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11194 if (attr
->num_values
> 1)
11195 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11197 cupsdSetString(&printer
->job_sheets
[1], "none");
11199 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11201 cupsdFreePrinterUsers(printer
);
11203 printer
->deny_users
= 0;
11205 if (attr
->value_tag
== IPP_TAG_NAME
&&
11206 (attr
->num_values
> 1 ||
11207 strcmp(attr
->values
[0].string
.text
, "all")))
11209 for (i
= 0; i
< attr
->num_values
; i
++)
11210 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
11213 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11215 cupsdFreePrinterUsers(printer
);
11217 printer
->deny_users
= 1;
11219 if (attr
->value_tag
== IPP_TAG_NAME
&&
11220 (attr
->num_values
> 1 ||
11221 strcmp(attr
->values
[0].string
.text
, "none")))
11223 for (i
= 0; i
< attr
->num_values
; i
++)
11224 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
11227 else if (!strcmp(attr
->name
, "job-quota-period"))
11229 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11232 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11233 attr
->values
[0].integer
);
11234 cupsdFreeQuotas(printer
);
11236 printer
->quota_period
= attr
->values
[0].integer
;
11238 else if (!strcmp(attr
->name
, "job-k-limit"))
11240 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11243 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11244 attr
->values
[0].integer
);
11245 cupsdFreeQuotas(printer
);
11247 printer
->k_limit
= attr
->values
[0].integer
;
11249 else if (!strcmp(attr
->name
, "job-page-limit"))
11251 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11254 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11255 attr
->values
[0].integer
);
11256 cupsdFreeQuotas(printer
);
11258 printer
->page_limit
= attr
->values
[0].integer
;
11260 else if (!strcmp(attr
->name
, "printer-op-policy"))
11262 cupsd_policy_t
*p
; /* Policy */
11265 if (attr
->value_tag
!= IPP_TAG_NAME
)
11268 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11270 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11271 "Setting printer-op-policy to \"%s\"...",
11272 attr
->values
[0].string
.text
);
11273 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11274 printer
->op_policy_ptr
= p
;
11278 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11279 _("Unknown printer-op-policy \"%s\"."),
11280 attr
->values
[0].string
.text
);
11284 else if (!strcmp(attr
->name
, "printer-error-policy"))
11286 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11289 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11290 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
11291 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11292 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11293 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11295 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11296 _("Unknown printer-error-policy \"%s\"."),
11297 attr
->values
[0].string
.text
);
11301 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11302 "Setting printer-error-policy to \"%s\"...",
11303 attr
->values
[0].string
.text
);
11304 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11308 * Skip any other non-default attributes...
11311 namelen
= strlen(attr
->name
);
11312 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11313 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11317 * OK, anything else must be a user-defined default...
11320 strlcpy(name
, attr
->name
, sizeof(name
));
11321 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11323 switch (attr
->value_tag
)
11325 case IPP_TAG_DELETEATTR
:
11326 printer
->num_options
= cupsRemoveOption(name
,
11327 printer
->num_options
,
11328 &(printer
->options
));
11329 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11330 "Deleting %s", attr
->name
);
11333 case IPP_TAG_NAME
:
11334 case IPP_TAG_KEYWORD
:
11336 printer
->num_options
= cupsAddOption(name
,
11337 attr
->values
[0].string
.text
,
11338 printer
->num_options
,
11339 &(printer
->options
));
11340 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11341 "Setting %s to \"%s\"...", attr
->name
,
11342 attr
->values
[0].string
.text
);
11345 case IPP_TAG_BOOLEAN
:
11346 printer
->num_options
= cupsAddOption(name
,
11347 attr
->values
[0].boolean
?
11349 printer
->num_options
,
11350 &(printer
->options
));
11351 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11352 "Setting %s to %s...", attr
->name
,
11353 attr
->values
[0].boolean
? "true" : "false");
11356 case IPP_TAG_INTEGER
:
11357 case IPP_TAG_ENUM
:
11358 sprintf(value
, "%d", attr
->values
[0].integer
);
11359 printer
->num_options
= cupsAddOption(name
, value
,
11360 printer
->num_options
,
11361 &(printer
->options
));
11362 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11363 "Setting %s to %s...", attr
->name
, value
);
11366 case IPP_TAG_RANGE
:
11367 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11368 attr
->values
[0].range
.upper
);
11369 printer
->num_options
= cupsAddOption(name
, value
,
11370 printer
->num_options
,
11371 &(printer
->options
));
11372 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11373 "Setting %s to %s...", attr
->name
, value
);
11376 case IPP_TAG_RESOLUTION
:
11377 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11378 attr
->values
[0].resolution
.yres
,
11379 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11381 printer
->num_options
= cupsAddOption(name
, value
,
11382 printer
->num_options
,
11383 &(printer
->options
));
11384 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11385 "Setting %s to %s...", attr
->name
, value
);
11389 /* Do nothing for other values */
11397 * 'start_printer()' - Start a printer.
11401 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11402 ipp_attribute_t
*uri
) /* I - Printer URI */
11404 http_status_t status
; /* Policy status */
11405 cups_ptype_t dtype
; /* Destination type (printer/class) */
11406 cupsd_printer_t
*printer
; /* Printer data */
11409 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11410 con
->http
.fd
, uri
->values
[0].string
.text
);
11413 * Is the destination valid?
11416 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11422 send_ipp_status(con
, IPP_NOT_FOUND
,
11423 _("The printer or class was not found."));
11431 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11433 send_http_error(con
, status
, printer
);
11438 * Start the printer...
11441 printer
->state_message
[0] = '\0';
11443 cupsdStartPrinter(printer
, 1);
11445 if (dtype
& CUPS_PRINTER_CLASS
)
11446 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11447 printer
->name
, get_username(con
));
11449 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11450 printer
->name
, get_username(con
));
11455 * Everything was ok, so return OK status...
11458 con
->response
->request
.status
.status_code
= IPP_OK
;
11463 * 'stop_printer()' - Stop a printer.
11467 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11468 ipp_attribute_t
*uri
) /* I - Printer URI */
11470 http_status_t status
; /* Policy status */
11471 cups_ptype_t dtype
; /* Destination type (printer/class) */
11472 cupsd_printer_t
*printer
; /* Printer data */
11473 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11476 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11477 con
->http
.fd
, uri
->values
[0].string
.text
);
11480 * Is the destination valid?
11483 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11489 send_ipp_status(con
, IPP_NOT_FOUND
,
11490 _("The printer or class was not found."));
11498 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11500 send_http_error(con
, status
, printer
);
11505 * Stop the printer...
11508 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11509 IPP_TAG_TEXT
)) == NULL
)
11510 strcpy(printer
->state_message
, "Paused");
11513 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11514 sizeof(printer
->state_message
));
11517 cupsdStopPrinter(printer
, 1);
11519 if (dtype
& CUPS_PRINTER_CLASS
)
11520 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11521 printer
->name
, get_username(con
));
11523 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11524 printer
->name
, get_username(con
));
11527 * Everything was ok, so return OK status...
11530 con
->response
->request
.status
.status_code
= IPP_OK
;
11535 * 'url_encode_attr()' - URL-encode a string attribute.
11539 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11540 char *buffer
,/* I - String buffer */
11541 int bufsize
)/* I - Size of buffer */
11543 int i
; /* Looping var */
11544 char *bufptr
, /* Pointer into buffer */
11545 *bufend
; /* End of buffer */
11548 strlcpy(buffer
, attr
->name
, bufsize
);
11549 bufptr
= buffer
+ strlen(buffer
);
11550 bufend
= buffer
+ bufsize
- 1;
11552 for (i
= 0; i
< attr
->num_values
; i
++)
11554 if (bufptr
>= bufend
)
11562 if (bufptr
>= bufend
)
11567 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11568 bufptr
, bufend
- bufptr
+ 1);
11570 if (bufptr
>= bufend
)
11581 * 'url_encode_string()' - URL-encode a string.
11584 static char * /* O - End of string */
11585 url_encode_string(const char *s
, /* I - String */
11586 char *buffer
, /* I - String buffer */
11587 int bufsize
) /* I - Size of buffer */
11589 char *bufptr
, /* Pointer into buffer */
11590 *bufend
; /* End of buffer */
11591 static const char *hex
= "0123456789ABCDEF";
11596 bufend
= buffer
+ bufsize
- 1;
11598 while (*s
&& bufptr
< bufend
)
11600 if (*s
== ' ' || *s
== '%' || *s
== '+')
11602 if (bufptr
>= (bufend
- 2))
11606 *bufptr
++ = hex
[(*s
>> 4) & 15];
11607 *bufptr
++ = hex
[*s
& 15];
11611 else if (*s
== '\'' || *s
== '\\')
11613 if (bufptr
>= (bufend
- 1))
11630 * 'user_allowed()' - See if a user is allowed to print to a queue.
11633 static int /* O - 0 if not allowed, 1 if allowed */
11634 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11635 const char *username
) /* I - Username */
11637 int i
; /* Looping var */
11638 struct passwd
*pw
; /* User password data */
11639 char baseuser
[256], /* Base username */
11640 *baseptr
; /* Pointer to "@" in base username */
11643 if (p
->num_users
== 0)
11646 if (!strcmp(username
, "root"))
11649 if (strchr(username
, '@'))
11652 * Strip @REALM for username check...
11655 strlcpy(baseuser
, username
, sizeof(baseuser
));
11657 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11660 username
= baseuser
;
11663 pw
= getpwnam(username
);
11666 for (i
= 0; i
< p
->num_users
; i
++)
11668 if (p
->users
[i
][0] == '@')
11671 * Check group membership...
11674 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
11677 else if (p
->users
[i
][0] == '#')
11683 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
11686 else if (!strcasecmp(username
, p
->users
[i
]))
11690 return ((i
< p
->num_users
) != p
->deny_users
);
11695 * 'validate_job()' - Validate printer options and destination.
11699 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11700 ipp_attribute_t
*uri
) /* I - Printer URI */
11702 http_status_t status
; /* Policy status */
11703 ipp_attribute_t
*attr
, /* Current attribute */
11704 *auth_info
; /* auth-info attribute */
11705 ipp_attribute_t
*format
; /* Document-format attribute */
11706 cups_ptype_t dtype
; /* Destination type (printer/class) */
11707 char super
[MIME_MAX_SUPER
],
11708 /* Supertype of file */
11709 type
[MIME_MAX_TYPE
];
11710 /* Subtype of file */
11711 cupsd_printer_t
*printer
; /* Printer */
11714 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11715 con
->http
.fd
, uri
->values
[0].string
.text
);
11718 * OK, see if the client is sending the document compressed - CUPS
11719 * doesn't support compression yet...
11722 if ((attr
= ippFindAttribute(con
->request
, "compression",
11723 IPP_TAG_KEYWORD
)) != NULL
)
11725 if (strcmp(attr
->values
[0].string
.text
, "none")
11727 && strcmp(attr
->values
[0].string
.text
, "gzip")
11728 #endif /* HAVE_LIBZ */
11731 send_ipp_status(con
, IPP_ATTRIBUTES
,
11732 _("Unsupported compression \"%s\""),
11733 attr
->values
[0].string
.text
);
11734 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11735 "compression", NULL
, attr
->values
[0].string
.text
);
11741 * Is it a format we support?
11744 if ((format
= ippFindAttribute(con
->request
, "document-format",
11745 IPP_TAG_MIMETYPE
)) != NULL
)
11747 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11750 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
11751 format
->values
[0].string
.text
);
11755 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11756 !mimeType(MimeDatabase
, super
, type
))
11758 cupsdLogMessage(CUPSD_LOG_INFO
,
11759 "Hint: Do you have the raw file printing rules enabled?");
11760 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11761 _("Unsupported document-format \"%s\""),
11762 format
->values
[0].string
.text
);
11763 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11764 "document-format", NULL
, format
->values
[0].string
.text
);
11770 * Is the destination valid?
11773 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11779 send_ipp_status(con
, IPP_NOT_FOUND
,
11780 _("The printer or class was not found."));
11788 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11790 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11792 send_http_error(con
, status
, printer
);
11795 else if (printer
->num_auth_info_required
== 1 &&
11796 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11799 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11803 else if (auth_info
&& !con
->http
.tls
&&
11804 !httpAddrLocalhost(con
->http
.hostaddr
))
11807 * Require encryption of auth-info over non-local connections...
11810 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11813 #endif /* HAVE_SSL */
11816 * Everything was ok, so return OK status...
11819 con
->response
->request
.status
.status_code
= IPP_OK
;
11824 * 'validate_name()' - Make sure the printer name only contains valid chars.
11827 static int /* O - 0 if name is no good, 1 if good */
11828 validate_name(const char *name
) /* I - Name to check */
11830 const char *ptr
; /* Pointer into name */
11834 * Scan the whole name...
11837 for (ptr
= name
; *ptr
; ptr
++)
11838 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11842 * All the characters are good; validate the length, too...
11845 return ((ptr
- name
) < 128);
11850 * 'validate_user()' - Validate the user for the request.
11853 static int /* O - 1 if permitted, 0 otherwise */
11854 validate_user(cupsd_job_t
*job
, /* I - Job */
11855 cupsd_client_t
*con
, /* I - Client connection */
11856 const char *owner
, /* I - Owner of job/resource */
11857 char *username
, /* O - Authenticated username */
11858 int userlen
) /* I - Length of username */
11860 cupsd_printer_t
*printer
; /* Printer for job */
11863 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11864 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11866 job
->id
, con
? con
->http
.fd
: 0,
11867 owner
? owner
: "(null)", username
, userlen
);
11870 * Validate input...
11873 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11877 * Get the best authenticated username that is available.
11880 strlcpy(username
, get_username(con
), userlen
);
11883 * Check the username against the owner...
11886 printer
= cupsdFindDest(job
->dest
);
11888 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11889 con
, owner
) == HTTP_OK
);
11894 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".