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 const char *ppd
; /* PPD keyword for media selection */
1366 int exact
; /* Did we have an exact match? */
1367 ipp_attribute_t
*media_col
, /* media-col attribute */
1368 *media_margin
; /* media-*-margin attribute */
1369 ipp_t
*unsup_col
; /* media-col in unsupported response */
1372 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1373 con
, con
->http
.fd
, printer
, printer
->name
,
1374 filetype
, filetype
? filetype
->super
: "none",
1375 filetype
? filetype
->type
: "none");
1378 * Check remote printing to non-shared printer...
1381 if (!printer
->shared
&&
1382 strcasecmp(con
->http
.hostname
, "localhost") &&
1383 strcasecmp(con
->http
.hostname
, ServerName
))
1385 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1386 _("The printer or class is not shared"));
1394 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1396 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1398 send_http_error(con
, status
, printer
);
1401 else if (printer
->num_auth_info_required
== 1 &&
1402 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1405 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1409 else if (auth_info
&& !con
->http
.tls
&&
1410 !httpAddrLocalhost(con
->http
.hostaddr
))
1413 * Require encryption of auth-info over non-local connections...
1416 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1419 #endif /* HAVE_SSL */
1422 * See if the printer is accepting jobs...
1425 if (!printer
->accepting
)
1427 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1428 _("Destination \"%s\" is not accepting jobs."),
1434 * Validate job template attributes; for now just document-format,
1435 * copies, number-up, and page-ranges...
1438 if (filetype
&& printer
->filetypes
&&
1439 !cupsArrayFind(printer
->filetypes
, filetype
))
1441 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1442 /* MIME media type string */
1445 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1448 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1449 _("Unsupported format \'%s\'"), mimetype
);
1451 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1452 "document-format", NULL
, mimetype
);
1457 if ((attr
= ippFindAttribute(con
->request
, "copies",
1458 IPP_TAG_INTEGER
)) != NULL
)
1460 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1462 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1463 attr
->values
[0].integer
);
1464 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1465 "copies", attr
->values
[0].integer
);
1470 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1471 IPP_TAG_ZERO
)) != NULL
)
1473 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1474 attr
->value_tag
!= IPP_TAG_NAME
)
1476 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type"));
1480 if (attr
->num_values
> 2)
1482 send_ipp_status(con
, IPP_BAD_REQUEST
,
1483 _("Too many job-sheets values (%d > 2)"),
1488 for (i
= 0; i
< attr
->num_values
; i
++)
1489 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1490 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1492 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\""),
1493 attr
->values
[i
].string
.text
);
1498 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1499 IPP_TAG_INTEGER
)) != NULL
)
1501 if (attr
->values
[0].integer
!= 1 &&
1502 attr
->values
[0].integer
!= 2 &&
1503 attr
->values
[0].integer
!= 4 &&
1504 attr
->values
[0].integer
!= 6 &&
1505 attr
->values
[0].integer
!= 9 &&
1506 attr
->values
[0].integer
!= 16)
1508 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1509 attr
->values
[0].integer
);
1510 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1511 "number-up", attr
->values
[0].integer
);
1516 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1517 IPP_TAG_RANGE
)) != NULL
)
1519 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1521 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1522 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1524 send_ipp_status(con
, IPP_BAD_REQUEST
,
1525 _("Bad page-ranges values %d-%d."),
1526 attr
->values
[i
].range
.lower
,
1527 attr
->values
[i
].range
.upper
);
1531 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1536 * Do media selection as needed...
1539 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1540 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1541 (ppd
= _pwgGetPageSize(printer
->pwg
, con
->request
, NULL
, &exact
)) != NULL
)
1544 (media_col
= ippFindAttribute(con
->request
, "media-col",
1545 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1547 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1549 unsup_col
= ippNew();
1550 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1551 "media-bottom-margin",
1552 IPP_TAG_INTEGER
)) != NULL
)
1553 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1554 "media-bottom-margin", media_margin
->values
[0].integer
);
1556 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1557 "media-left-margin",
1558 IPP_TAG_INTEGER
)) != NULL
)
1559 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1560 "media-left-margin", media_margin
->values
[0].integer
);
1562 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1563 "media-right-margin",
1564 IPP_TAG_INTEGER
)) != NULL
)
1565 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1566 "media-right-margin", media_margin
->values
[0].integer
);
1568 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1570 IPP_TAG_INTEGER
)) != NULL
)
1571 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1572 "media-top-margin", media_margin
->values
[0].integer
);
1574 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1576 ippDelete(unsup_col
);
1581 * Make sure we aren't over our limit...
1584 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1587 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1589 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1590 _("Too many active jobs."));
1594 if ((i
= check_quotas(con
, printer
)) < 0)
1596 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1601 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1606 * Create the job and set things up...
1609 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1610 IPP_TAG_INTEGER
)) != NULL
)
1611 priority
= attr
->values
[0].integer
;
1614 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1615 printer
->options
)) != NULL
)
1616 priority
= atoi(val
);
1620 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1624 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1625 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1628 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1630 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1631 _("Unable to add job for destination \"%s\""),
1636 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1637 CUPS_PRINTER_REMOTE
);
1638 job
->attrs
= con
->request
;
1640 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1642 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1644 add_job_uuid(con
, job
);
1645 apply_printer_defaults(printer
, job
);
1647 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1649 if (con
->username
[0])
1651 cupsdSetString(&job
->username
, con
->username
);
1654 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1658 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1659 "add_job: requesting-user-name=\"%s\"",
1660 attr
->values
[0].string
.text
);
1662 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1665 cupsdSetString(&job
->username
, "anonymous");
1668 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1669 "job-originating-user-name", NULL
, job
->username
);
1672 attr
->group_tag
= IPP_TAG_JOB
;
1673 _cupsStrFree(attr
->name
);
1674 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1677 if (con
->username
[0] || auth_info
)
1679 save_auth_info(con
, job
, auth_info
);
1682 * Remove the auth-info attribute from the attribute data...
1686 ippDeleteAttribute(job
->attrs
, auth_info
);
1689 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1690 IPP_TAG_ZERO
)) != NULL
)
1693 * Request contains a job-originating-host-name attribute; validate it...
1696 if (attr
->value_tag
!= IPP_TAG_NAME
||
1697 attr
->num_values
!= 1 ||
1698 strcmp(con
->http
.hostname
, "localhost"))
1701 * Can't override the value if we aren't connected via localhost.
1702 * Also, we can only have 1 value and it must be a name value.
1705 switch (attr
->value_tag
)
1707 case IPP_TAG_STRING
:
1708 case IPP_TAG_TEXTLANG
:
1709 case IPP_TAG_NAMELANG
:
1712 case IPP_TAG_KEYWORD
:
1714 case IPP_TAG_URISCHEME
:
1715 case IPP_TAG_CHARSET
:
1716 case IPP_TAG_LANGUAGE
:
1717 case IPP_TAG_MIMETYPE
:
1719 * Free old strings...
1722 for (i
= 0; i
< attr
->num_values
; i
++)
1724 _cupsStrFree(attr
->values
[i
].string
.text
);
1725 attr
->values
[i
].string
.text
= NULL
;
1726 if (attr
->values
[i
].string
.charset
)
1728 _cupsStrFree(attr
->values
[i
].string
.charset
);
1729 attr
->values
[i
].string
.charset
= NULL
;
1738 * Use the default connection hostname instead...
1741 attr
->value_tag
= IPP_TAG_NAME
;
1742 attr
->num_values
= 1;
1743 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1746 attr
->group_tag
= IPP_TAG_JOB
;
1751 * No job-originating-host-name attribute, so use the hostname from
1755 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1756 "job-originating-host-name", NULL
, con
->http
.hostname
);
1759 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1761 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1762 "time-at-processing", 0);
1763 attr
->value_tag
= IPP_TAG_NOVALUE
;
1764 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1765 "time-at-completed", 0);
1766 attr
->value_tag
= IPP_TAG_NOVALUE
;
1769 * Add remaining job attributes...
1772 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1773 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1774 "job-state", IPP_JOB_STOPPED
);
1775 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1776 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1777 "job-media-sheets-completed", 0);
1778 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1781 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1782 IPP_TAG_INTEGER
)) != NULL
)
1783 attr
->values
[0].integer
= 0;
1785 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1787 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1788 IPP_TAG_KEYWORD
)) == NULL
)
1789 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1792 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1793 printer
->options
)) == NULL
)
1796 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1797 "job-hold-until", NULL
, val
);
1799 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1802 * Hold job until specified time...
1805 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1807 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1808 job
->state_value
= IPP_JOB_HELD
;
1810 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1812 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1813 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1814 job
->state_value
= IPP_JOB_HELD
;
1818 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1819 job
->state_value
= IPP_JOB_PENDING
;
1822 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1826 * Add job sheets options...
1829 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1830 IPP_TAG_ZERO
)) == NULL
)
1832 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1833 "Adding default job-sheets values \"%s,%s\"...",
1834 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1836 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1838 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1839 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1842 job
->job_sheets
= attr
;
1845 * Enforce classification level if set...
1850 cupsdLogMessage(CUPSD_LOG_INFO
,
1851 "Classification=\"%s\", ClassifyOverride=%d",
1852 Classification
? Classification
: "(null)",
1855 if (ClassifyOverride
)
1857 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1858 (attr
->num_values
== 1 ||
1859 !strcmp(attr
->values
[1].string
.text
, "none")))
1862 * Force the leading banner to have the classification on it...
1865 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1867 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1868 "job-sheets=\"%s,none\", "
1869 "job-originating-user-name=\"%s\"",
1870 Classification
, job
->username
);
1872 else if (attr
->num_values
== 2 &&
1873 strcmp(attr
->values
[0].string
.text
,
1874 attr
->values
[1].string
.text
) &&
1875 strcmp(attr
->values
[0].string
.text
, "none") &&
1876 strcmp(attr
->values
[1].string
.text
, "none"))
1879 * Can't put two different security markings on the same document!
1882 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1884 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1885 "job-sheets=\"%s,%s\", "
1886 "job-originating-user-name=\"%s\"",
1887 attr
->values
[0].string
.text
,
1888 attr
->values
[1].string
.text
, job
->username
);
1890 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1891 strcmp(attr
->values
[0].string
.text
, "none") &&
1892 (attr
->num_values
== 1 ||
1893 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1894 strcmp(attr
->values
[1].string
.text
, "none"))))
1896 if (attr
->num_values
== 1)
1897 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1898 "CLASSIFICATION OVERRIDDEN "
1899 "job-sheets=\"%s\", "
1900 "job-originating-user-name=\"%s\"",
1901 attr
->values
[0].string
.text
, job
->username
);
1903 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1904 "CLASSIFICATION OVERRIDDEN "
1905 "job-sheets=\"%s,%s\",fffff "
1906 "job-originating-user-name=\"%s\"",
1907 attr
->values
[0].string
.text
,
1908 attr
->values
[1].string
.text
, job
->username
);
1911 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1912 (attr
->num_values
== 1 ||
1913 strcmp(attr
->values
[1].string
.text
, Classification
)))
1916 * Force the banner to have the classification on it...
1919 if (attr
->num_values
> 1 &&
1920 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1922 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1923 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1927 if (attr
->num_values
== 1 ||
1928 strcmp(attr
->values
[0].string
.text
, "none"))
1929 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1931 if (attr
->num_values
> 1 &&
1932 strcmp(attr
->values
[1].string
.text
, "none"))
1933 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1936 if (attr
->num_values
> 1)
1937 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1938 "CLASSIFICATION FORCED "
1939 "job-sheets=\"%s,%s\", "
1940 "job-originating-user-name=\"%s\"",
1941 attr
->values
[0].string
.text
,
1942 attr
->values
[1].string
.text
, job
->username
);
1944 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1945 "CLASSIFICATION FORCED "
1946 "job-sheets=\"%s\", "
1947 "job-originating-user-name=\"%s\"",
1948 Classification
, job
->username
);
1953 * See if we need to add the starting sheet...
1956 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1958 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1959 attr
->values
[0].string
.text
);
1961 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1963 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1964 "Aborting job because the start banner could not be "
1969 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1972 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1973 IPP_TAG_ZERO
)) != NULL
)
1977 * Fill in the response info...
1980 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1981 LocalPort
, job
->id
);
1983 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1986 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1988 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1990 add_job_state_reasons(con
, job
);
1992 con
->response
->request
.status
.status_code
= IPP_OK
;
1995 * Add any job subscriptions...
1998 add_job_subscriptions(con
, job
);
2001 * Set all but the first two attributes to the job attributes group...
2004 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
2005 attr
->group_tag
= IPP_TAG_JOB
;
2008 * Fire the "job created" event...
2011 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
2014 * Return the new job...
2022 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
2023 * upon the job and printer state...
2027 add_job_state_reasons(
2028 cupsd_client_t
*con
, /* I - Client connection */
2029 cupsd_job_t
*job
) /* I - Job info */
2031 cupsd_printer_t
*dest
; /* Destination printer */
2034 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
2035 con
, con
->http
.fd
, job
? job
->id
: 0);
2037 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
2039 case IPP_JOB_PENDING
:
2040 dest
= cupsdFindDest(job
->dest
);
2042 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
2043 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2044 "job-state-reasons", NULL
, "printer-stopped");
2046 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2047 "job-state-reasons", NULL
, "none");
2051 if (ippFindAttribute(job
->attrs
, "job-hold-until",
2052 IPP_TAG_KEYWORD
) != NULL
||
2053 ippFindAttribute(job
->attrs
, "job-hold-until",
2054 IPP_TAG_NAME
) != NULL
)
2055 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2056 "job-state-reasons", NULL
, "job-hold-until-specified");
2058 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2059 "job-state-reasons", NULL
, "job-incoming");
2062 case IPP_JOB_PROCESSING
:
2063 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2064 "job-state-reasons", NULL
, "job-printing");
2067 case IPP_JOB_STOPPED
:
2068 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2069 "job-state-reasons", NULL
, "job-stopped");
2072 case IPP_JOB_CANCELED
:
2073 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2074 "job-state-reasons", NULL
, "job-canceled-by-user");
2077 case IPP_JOB_ABORTED
:
2078 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2079 "job-state-reasons", NULL
, "aborted-by-system");
2082 case IPP_JOB_COMPLETED
:
2083 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2084 "job-state-reasons", NULL
, "job-completed-successfully");
2091 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2095 add_job_subscriptions(
2096 cupsd_client_t
*con
, /* I - Client connection */
2097 cupsd_job_t
*job
) /* I - Newly created job */
2099 int i
; /* Looping var */
2100 ipp_attribute_t
*prev
, /* Previous attribute */
2101 *next
, /* Next attribute */
2102 *attr
; /* Current attribute */
2103 cupsd_subscription_t
*sub
; /* Subscription object */
2104 const char *recipient
, /* notify-recipient-uri */
2105 *pullmethod
; /* notify-pull-method */
2106 ipp_attribute_t
*user_data
; /* notify-user-data */
2107 int interval
; /* notify-time-interval */
2108 unsigned mask
; /* notify-events */
2112 * Find the first subscription group attribute; return if we have
2116 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2117 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2124 * Process the subscription attributes in the request...
2133 mask
= CUPSD_EVENT_NONE
;
2135 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2137 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2138 attr
->value_tag
== IPP_TAG_URI
)
2141 * Validate the recipient scheme against the ServerBin/notifier
2145 char notifier
[1024], /* Notifier filename */
2146 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2147 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2148 host
[HTTP_MAX_URI
], /* Host portion of URI */
2149 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2150 int port
; /* Port portion of URI */
2153 recipient
= attr
->values
[0].string
.text
;
2155 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2156 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2157 host
, sizeof(host
), &port
,
2158 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2160 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2161 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
2162 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2163 "notify-status-code", IPP_URI_SCHEME
);
2167 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2169 if (access(notifier
, X_OK
))
2171 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2172 _("notify-recipient-uri URI \"%s\" uses unknown "
2173 "scheme"), recipient
);
2174 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2175 "notify-status-code", IPP_URI_SCHEME
);
2179 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2181 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2182 _("notify-recipient-uri URI \"%s\" is already used"),
2184 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2185 "notify-status-code", IPP_ATTRIBUTES
);
2189 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2190 attr
->value_tag
== IPP_TAG_KEYWORD
)
2192 pullmethod
= attr
->values
[0].string
.text
;
2194 if (strcmp(pullmethod
, "ippget"))
2196 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2197 _("Bad notify-pull-method \"%s\""), pullmethod
);
2198 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2199 "notify-status-code", IPP_ATTRIBUTES
);
2203 else if (!strcmp(attr
->name
, "notify-charset") &&
2204 attr
->value_tag
== IPP_TAG_CHARSET
&&
2205 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2206 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2208 send_ipp_status(con
, IPP_CHARSET
,
2209 _("Character set \"%s\" not supported"),
2210 attr
->values
[0].string
.text
);
2213 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2214 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2215 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2217 send_ipp_status(con
, IPP_CHARSET
,
2218 _("Language \"%s\" not supported"),
2219 attr
->values
[0].string
.text
);
2222 else if (!strcmp(attr
->name
, "notify-user-data") &&
2223 attr
->value_tag
== IPP_TAG_STRING
)
2225 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2227 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2228 _("The notify-user-data value is too large "
2229 "(%d > 63 octets)"),
2230 attr
->values
[0].unknown
.length
);
2236 else if (!strcmp(attr
->name
, "notify-events") &&
2237 attr
->value_tag
== IPP_TAG_KEYWORD
)
2239 for (i
= 0; i
< attr
->num_values
; i
++)
2240 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2242 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2244 send_ipp_status(con
, IPP_BAD_REQUEST
,
2245 _("The notify-lease-duration attribute cannot be "
2246 "used with job subscriptions."));
2249 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2250 attr
->value_tag
== IPP_TAG_INTEGER
)
2251 interval
= attr
->values
[0].integer
;
2256 if (!recipient
&& !pullmethod
)
2259 if (mask
== CUPSD_EVENT_NONE
)
2260 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2262 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2263 recipient
, 0)) != NULL
)
2265 sub
->interval
= interval
;
2267 cupsdSetString(&sub
->owner
, job
->username
);
2271 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2272 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2273 sub
->user_data_len
);
2276 ippAddSeparator(con
->response
);
2277 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2278 "notify-subscription-id", sub
->id
);
2280 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2288 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2291 * Remove all of the subscription attributes from the job request...
2293 * TODO: Optimize this since subscription groups have to come at the
2294 * end of the request...
2297 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2301 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2302 attr
->group_tag
== IPP_TAG_ZERO
)
2305 * Free and remove this attribute...
2313 job
->attrs
->attrs
= next
;
2319 job
->attrs
->last
= prev
;
2320 job
->attrs
->current
= prev
;
2325 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2327 * See RFC 4122 for the definition of UUIDs and the format.
2331 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2332 cupsd_job_t
*job
) /* I - Job */
2334 char uuid
[1024]; /* job-uuid string */
2335 _cups_md5_state_t md5state
; /* MD5 state */
2336 unsigned char md5sum
[16]; /* MD5 digest/sum */
2340 * First see if the job already has a job-uuid attribute; if so, return...
2343 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2347 * No job-uuid attribute, so build a version 3 UUID with the local job
2348 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2349 * the ServerName, server name and port that the client connected to,
2350 * and local job ID...
2353 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2354 con
->serverport
, job
->id
);
2356 _cupsMD5Init(&md5state
);
2357 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2358 _cupsMD5Finish(&md5state
, md5sum
);
2361 * Format the UUID URI using the MD5 sum and job ID.
2364 snprintf(uuid
, sizeof(uuid
),
2365 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2366 "%02x%02x%02x%02x%02x%02x",
2367 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2368 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2369 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2370 md5sum
[14], md5sum
[15]);
2372 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2377 * 'add_printer()' - Add a printer to the system.
2381 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2382 ipp_attribute_t
*uri
) /* I - URI of printer */
2384 http_status_t status
; /* Policy status */
2385 int i
; /* Looping var */
2386 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2387 username
[HTTP_MAX_URI
], /* Username portion of URI */
2388 host
[HTTP_MAX_URI
], /* Host portion of URI */
2389 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2390 int port
; /* Port portion of URI */
2391 cupsd_printer_t
*printer
; /* Printer/class */
2392 ipp_attribute_t
*attr
; /* Printer attribute */
2393 cups_file_t
*fp
; /* Script/PPD file */
2394 char line
[1024]; /* Line from file... */
2395 char srcfile
[1024], /* Source Script/PPD file */
2396 dstfile
[1024]; /* Destination Script/PPD file */
2397 int modify
; /* Non-zero if we are modifying */
2398 char newname
[IPP_MAX_NAME
]; /* New printer name */
2399 int changed_driver
, /* Changed the PPD/interface script? */
2400 need_restart_job
, /* Need to restart job? */
2401 set_device_uri
, /* Did we set the device URI? */
2402 set_port_monitor
; /* Did we set the port monitor? */
2405 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2406 con
->http
.fd
, uri
->values
[0].string
.text
);
2409 * Do we have a valid URI?
2412 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2413 sizeof(scheme
), username
, sizeof(username
), host
,
2414 sizeof(host
), &port
, resource
, sizeof(resource
));
2416 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2419 * No, return an error...
2422 send_ipp_status(con
, IPP_BAD_REQUEST
,
2423 _("The printer-uri must be of the form "
2424 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2429 * Do we have a valid printer name?
2432 if (!validate_name(resource
+ 10))
2435 * No, return an error...
2438 send_ipp_status(con
, IPP_BAD_REQUEST
,
2439 _("The printer-uri \"%s\" contains invalid characters."),
2440 uri
->values
[0].string
.text
);
2445 * See if the printer already exists; if not, create a new printer...
2448 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2451 * Printer doesn't exist; see if we have a class of the same name...
2454 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2455 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2458 * Yes, return an error...
2461 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2462 _("A class named \"%s\" already exists"),
2468 * No, check the default policy then add the printer...
2471 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2473 send_http_error(con
, status
, NULL
);
2477 printer
= cupsdAddPrinter(resource
+ 10);
2480 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2483 * Check the default policy, then rename the implicit printer to
2484 * "AnyPrinter" or delete it...
2487 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2489 send_http_error(con
, status
, NULL
);
2493 if (ImplicitAnyClasses
)
2495 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2496 cupsdRenamePrinter(printer
, newname
);
2499 cupsdDeletePrinter(printer
, 1);
2502 * Add the printer as a new local printer...
2505 printer
= cupsdAddPrinter(resource
+ 10);
2508 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2511 * Check the default policy, then rename the remote printer to
2512 * "Printer@server"...
2515 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2517 send_http_error(con
, status
, NULL
);
2521 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2523 cupsdRenamePrinter(printer
, newname
);
2526 * Add the printer as a new local printer...
2529 printer
= cupsdAddPrinter(resource
+ 10);
2532 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2535 send_http_error(con
, status
, printer
);
2542 * Look for attributes and copy them over as needed...
2546 need_restart_job
= 0;
2548 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2549 IPP_TAG_TEXT
)) != NULL
)
2550 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2552 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2553 IPP_TAG_TEXT
)) != NULL
)
2554 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2558 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2559 IPP_TAG_URI
)) != NULL
)
2562 * Do we have a valid device URI?
2565 http_uri_status_t uri_status
; /* URI separation status */
2566 char old_device_uri
[1024];
2567 /* Old device URI */
2570 need_restart_job
= 1;
2572 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2573 attr
->values
[0].string
.text
,
2574 scheme
, sizeof(scheme
),
2575 username
, sizeof(username
),
2576 host
, sizeof(host
), &port
,
2577 resource
, sizeof(resource
));
2579 if (uri_status
< HTTP_URI_OK
)
2581 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\""),
2582 attr
->values
[0].string
.text
);
2583 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2584 "add_printer: httpSeparateURI returned %d", uri_status
);
2588 if (!strcmp(scheme
, "file"))
2591 * See if the administrator has enabled file devices...
2594 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2597 * File devices are disabled and the URL is not file:/dev/null...
2600 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2601 _("File device URIs have been disabled! "
2602 "To enable, see the FileDevice directive in "
2603 "\"%s/cupsd.conf\"."),
2611 * See if the backend exists and is executable...
2614 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2615 if (access(srcfile
, X_OK
))
2618 * Could not find device in list!
2621 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\""),
2627 if (printer
->sanitized_device_uri
)
2628 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2629 sizeof(old_device_uri
));
2631 old_device_uri
[0] = '\0';
2633 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2635 cupsdLogMessage(CUPSD_LOG_INFO
,
2636 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2637 printer
->name
, printer
->sanitized_device_uri
,
2643 set_port_monitor
= 0;
2645 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2646 IPP_TAG_NAME
)) != NULL
)
2648 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2651 need_restart_job
= 1;
2653 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2657 for (i
= 0; i
< supported
->num_values
; i
++)
2658 if (!strcmp(supported
->values
[i
].string
.text
,
2659 attr
->values
[0].string
.text
))
2663 if (!supported
|| i
>= supported
->num_values
)
2665 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\""),
2666 attr
->values
[0].string
.text
);
2670 cupsdLogMessage(CUPSD_LOG_INFO
,
2671 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2672 printer
->name
, attr
->values
[0].string
.text
,
2673 printer
->port_monitor
? printer
->port_monitor
: "none");
2675 if (strcmp(attr
->values
[0].string
.text
, "none"))
2676 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2678 cupsdClearString(&printer
->port_monitor
);
2680 set_port_monitor
= 1;
2683 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2684 IPP_TAG_BOOLEAN
)) != NULL
&&
2685 attr
->values
[0].boolean
!= printer
->accepting
)
2687 cupsdLogMessage(CUPSD_LOG_INFO
,
2688 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2689 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2691 printer
->accepting
= attr
->values
[0].boolean
;
2692 cupsdAddPrinterHistory(printer
);
2694 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2695 "%s accepting jobs.",
2696 printer
->accepting
? "Now" : "No longer");
2699 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2700 IPP_TAG_BOOLEAN
)) != NULL
)
2702 if (printer
->shared
&& !attr
->values
[0].boolean
)
2703 cupsdDeregisterPrinter(printer
, 1);
2705 cupsdLogMessage(CUPSD_LOG_INFO
,
2706 "Setting %s printer-is-shared to %d (was %d.)",
2707 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2709 printer
->shared
= attr
->values
[0].boolean
;
2712 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2713 IPP_TAG_ENUM
)) != NULL
)
2715 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2716 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2718 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d"),
2719 attr
->values
[0].integer
);
2723 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2724 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2726 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2727 cupsdStopPrinter(printer
, 0);
2730 need_restart_job
= 1;
2731 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2735 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2736 IPP_TAG_TEXT
)) != NULL
)
2738 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2739 sizeof(printer
->state_message
));
2740 cupsdAddPrinterHistory(printer
);
2742 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2743 printer
->state_message
);
2746 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2747 IPP_TAG_KEYWORD
)) != NULL
)
2749 if (attr
->num_values
>
2750 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2752 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2753 _("Too many printer-state-reasons values (%d > %d)"),
2755 (int)(sizeof(printer
->reasons
) /
2756 sizeof(printer
->reasons
[0])));
2760 for (i
= 0; i
< printer
->num_reasons
; i
++)
2761 _cupsStrFree(printer
->reasons
[i
]);
2763 printer
->num_reasons
= 0;
2764 for (i
= 0; i
< attr
->num_values
; i
++)
2766 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2769 printer
->reasons
[printer
->num_reasons
] =
2770 _cupsStrRetain(attr
->values
[i
].string
.text
);
2771 printer
->num_reasons
++;
2773 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2774 printer
->state
!= IPP_PRINTER_STOPPED
)
2776 cupsdLogMessage(CUPSD_LOG_INFO
,
2777 "Setting %s printer-state to %d (was %d.)",
2778 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2779 cupsdStopPrinter(printer
, 0);
2783 if (PrintcapFormat
== PRINTCAP_PLIST
)
2784 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2786 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2787 "Printer \"%s\" state changed.", printer
->name
);
2790 set_printer_defaults(con
, printer
);
2792 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2793 IPP_TAG_KEYWORD
)) != NULL
)
2794 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2797 * See if we have all required attributes...
2800 if (!printer
->device_uri
)
2801 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2804 * See if we have an interface script or PPD file attached to the request...
2809 need_restart_job
= 1;
2812 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2814 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2817 * Yes; get the first line from it...
2821 cupsFileGets(fp
, line
, sizeof(line
));
2825 * Then see what kind of file it is...
2828 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2831 if (!strncmp(line
, "*PPD-Adobe", 10))
2834 * The new file is a PPD file, so remove any old interface script
2835 * that might be lying around...
2843 * This must be an interface script, so move the file over to the
2844 * interfaces directory and make it executable...
2847 if (copy_file(srcfile
, dstfile
))
2849 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2850 _("Unable to copy interface script - %s"),
2855 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2856 "Copied interface script successfully");
2857 chmod(dstfile
, 0755);
2860 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2863 if (!strncmp(line
, "*PPD-Adobe", 10))
2866 * The new file is a PPD file, so move the file over to the
2867 * ppd directory and make it readable by all...
2870 if (copy_file(srcfile
, dstfile
))
2872 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2873 _("Unable to copy PPD file - %s"),
2878 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2879 "Copied PPD file successfully");
2880 chmod(dstfile
, 0644);
2885 * This must be an interface script, so remove any old PPD file that
2886 * may be lying around...
2893 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2894 IPP_TAG_NAME
)) != NULL
)
2896 need_restart_job
= 1;
2899 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2902 * Raw driver, remove any existing PPD or interface script files.
2905 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2909 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2919 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2923 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2926 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2928 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file"));
2932 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2933 "Copied PPD file successfully");
2934 chmod(dstfile
, 0644);
2941 * If we changed the PPD/interface script, then remove the printer's cache
2942 * file and clear the printer-state-reasons...
2945 char cache_name
[1024]; /* Cache filename for printer attrs */
2947 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.ipp2", CacheDir
,
2951 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.pwg", CacheDir
,
2955 cupsdSetPrinterReasons(printer
, "none");
2959 * (Re)register color profiles...
2964 apple_unregister_profiles(printer
);
2965 apple_register_profiles(printer
);
2967 #endif /* __APPLE__ */
2971 * If we set the device URI but not the port monitor, check which port
2972 * monitor to use by default...
2975 if (set_device_uri
&& !set_port_monitor
)
2977 ppd_file_t
*ppd
; /* PPD file */
2978 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2981 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2982 sizeof(scheme
), username
, sizeof(username
), host
,
2983 sizeof(host
), &port
, resource
, sizeof(resource
));
2985 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2987 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2989 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2991 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2992 if (!strcmp(scheme
, ppdattr
->spec
))
2994 cupsdLogMessage(CUPSD_LOG_INFO
,
2995 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2996 printer
->name
, ppdattr
->value
,
2997 printer
->port_monitor
? printer
->port_monitor
3000 if (strcmp(ppdattr
->value
, "none"))
3001 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
3003 cupsdClearString(&printer
->port_monitor
);
3013 * Update the printer attributes and return...
3016 cupsdSetPrinterAttrs(printer
);
3017 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3019 if (need_restart_job
&& printer
->job
)
3022 * Restart the current job...
3025 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
3026 "Job restarted because the printer was modified.");
3029 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3033 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
3034 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
3035 printer
->name
, get_username(con
));
3037 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
3038 printer
->name
, get_username(con
));
3042 cupsdAddPrinterHistory(printer
);
3044 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
3045 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
3046 printer
->name
, get_username(con
));
3048 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
3049 printer
->name
, get_username(con
));
3052 con
->response
->request
.status
.status_code
= IPP_OK
;
3057 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
3058 * based upon the printer state...
3062 add_printer_state_reasons(
3063 cupsd_client_t
*con
, /* I - Client connection */
3064 cupsd_printer_t
*p
) /* I - Printer info */
3066 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3067 "add_printer_state_reasons(%p[%d], %p[%s])",
3068 con
, con
->http
.fd
, p
, p
->name
);
3070 if (p
->num_reasons
== 0)
3071 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3072 "printer-state-reasons", NULL
, "none");
3074 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3075 "printer-state-reasons", p
->num_reasons
, NULL
,
3076 (const char * const *)p
->reasons
);
3081 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
3082 * the specified printer or class.
3086 add_queued_job_count(
3087 cupsd_client_t
*con
, /* I - Client connection */
3088 cupsd_printer_t
*p
) /* I - Printer or class */
3090 int count
; /* Number of jobs on destination */
3093 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3094 con
, con
->http
.fd
, p
, p
->name
);
3096 count
= cupsdGetPrinterJobCount(p
->name
);
3098 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3099 "queued-job-count", count
);
3105 * 'apple_init_profile()' - Initialize a color profile.
3110 ppd_file_t
*ppd
, /* I - PPD file */
3111 cups_array_t
*languages
, /* I - Languages in the PPD file */
3112 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3113 unsigned id
, /* I - Profile ID */
3114 const char *name
, /* I - Profile name */
3115 const char *text
, /* I - Profile UI text */
3116 const char *iccfile
) /* I - ICC filename */
3118 char url
[1024]; /* URL for profile filename */
3119 CFMutableDictionaryRef dict
; /* Dictionary for name */
3120 char *language
; /* Current language */
3121 ppd_attr_t
*attr
; /* Profile attribute */
3122 CFStringRef cflang
, /* Language string */
3123 cftext
; /* Localized text */
3127 * Build the profile name dictionary...
3130 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3131 &kCFTypeDictionaryKeyCallBacks
,
3132 &kCFTypeDictionaryValueCallBacks
);
3134 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3135 kCFStringEncodingUTF8
);
3139 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
3146 * Find localized names for the color profiles...
3149 cupsArraySave(ppd
->sorted_attrs
);
3151 for (language
= (char *)cupsArrayFirst(languages
);
3153 language
= (char *)cupsArrayNext(languages
))
3157 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3159 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3162 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3164 if (attr
&& attr
->text
[0])
3166 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3167 kCFStringEncodingUTF8
);
3168 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3169 kCFStringEncodingUTF8
);
3171 if (cflang
&& cftext
)
3172 CFDictionarySetValue(dict
, cflang
, cftext
);
3182 cupsArrayRestore(ppd
->sorted_attrs
);
3186 * Fill in the profile data...
3190 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3193 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3194 profile
->profileID
= id
;
3195 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3196 profile
->profileName
= dict
;
3199 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3200 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3205 * 'apple_register_profiles()' - Register color profiles for a printer.
3209 apple_register_profiles(
3210 cupsd_printer_t
*p
) /* I - Printer */
3212 int i
; /* Looping var */
3213 char ppdfile
[1024], /* PPD filename */
3214 iccfile
[1024], /* ICC filename */
3215 selector
[PPD_MAX_NAME
];
3216 /* Profile selection string */
3217 ppd_file_t
*ppd
; /* PPD file */
3218 ppd_attr_t
*attr
, /* Profile attributes */
3219 *profileid_attr
,/* cupsProfileID attribute */
3220 *q1_attr
, /* ColorModel (or other) qualifier */
3221 *q2_attr
, /* MediaType (or other) qualifier */
3222 *q3_attr
; /* Resolution (or other) qualifier */
3223 char q_keyword
[PPD_MAX_NAME
];
3224 /* Qualifier keyword */
3225 const char *q1_choice
, /* ColorModel (or other) choice */
3226 *q2_choice
, /* MediaType (or other) choice */
3227 *q3_choice
; /* Resolution (or other) choice */
3228 const char *profile_key
; /* Profile keyword */
3229 ppd_option_t
*cm_option
; /* Color model option */
3230 ppd_choice_t
*cm_choice
; /* Color model choice */
3231 int num_profiles
; /* Number of profiles */
3232 CMError error
; /* Last error */
3233 unsigned device_id
, /* Printer device ID */
3234 profile_id
, /* Profile ID */
3235 default_profile_id
= 0;
3236 /* Default profile ID */
3237 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3238 CFStringRef printer_name
; /* Printer name string */
3239 CMDeviceScope scope
= /* Scope of the registration */
3241 kCFPreferencesAnyUser
,
3242 kCFPreferencesCurrentHost
3244 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3245 CMDeviceProfileInfo
*profile
; /* Current profile */
3246 cups_array_t
*languages
; /* Languages array */
3250 * Make sure ColorSync is available...
3253 if (CMRegisterColorDevice
== NULL
)
3257 * Try opening the PPD file for this printer...
3260 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3261 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3265 * See if we have any profiles...
3268 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3269 profile_key
= "APTiogaProfile";
3272 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3273 profile_key
= "cupsICCProfile";
3276 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3277 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3279 if (attr
->value
[0] != '/')
3280 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3283 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3285 if (access(iccfile
, 0))
3293 * If we have profiles, add them...
3296 if (num_profiles
> 0)
3298 if (profile_key
[0] == 'A')
3301 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3305 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3307 default_profile_id
= atoi(attr
->value
);
3309 q1_choice
= q2_choice
= q3_choice
= NULL
;
3314 * For CUPS PPDs, figure out the default profile selector values...
3317 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3318 attr
->value
&& attr
->value
[0])
3320 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3321 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3323 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3324 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3326 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3327 q1_choice
= q1_attr
->value
;
3331 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3332 attr
->value
&& attr
->value
[0])
3334 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3335 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3338 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3340 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3341 q2_choice
= q2_attr
->value
;
3345 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3346 attr
->value
&& attr
->value
[0])
3348 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3349 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3352 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3354 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3355 q3_choice
= q3_attr
->value
;
3361 * Build the array of profiles...
3363 * Note: This calloc actually requests slightly more memory than needed.
3366 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3368 cupsdLogMessage(CUPSD_LOG_ERROR
,
3369 "Unable to allocate memory for %d profiles",
3375 profiles
->profileCount
= num_profiles
;
3376 languages
= _ppdGetLanguages(ppd
);
3378 for (profile
= profiles
->profiles
,
3379 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3381 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3382 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3385 * Add this profile...
3388 if (attr
->value
[0] != '/')
3389 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3392 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3394 if (access(iccfile
, 0))
3397 if (profile_key
[0] == 'c')
3399 cupsArraySave(ppd
->sorted_attrs
);
3401 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3402 attr
->spec
)) != NULL
&&
3403 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3404 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3406 profile_id
= _ppdHashName(attr
->spec
);
3408 cupsArrayRestore(ppd
->sorted_attrs
);
3411 profile_id
= atoi(attr
->spec
);
3413 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3414 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3419 * See if this is the default profile...
3422 if (!default_profile_id
)
3428 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3429 q1_choice
, q2_choice
, q3_choice
);
3430 if (!strcmp(selector
, attr
->spec
))
3431 default_profile_id
= profile_id
;
3434 if (!default_profile_id
)
3436 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3438 if (!strcmp(selector
, attr
->spec
))
3439 default_profile_id
= profile_id
;
3443 if (!default_profile_id
&& q3_choice
)
3445 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3447 if (!strcmp(selector
, attr
->spec
))
3448 default_profile_id
= profile_id
;
3451 if (!default_profile_id
)
3453 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3454 if (!strcmp(selector
, attr
->spec
))
3455 default_profile_id
= profile_id
;
3460 _ppdFreeLanguages(languages
);
3462 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3465 * Extract profiles from ColorModel option...
3468 const char *profile_name
; /* Name of generic profile */
3471 num_profiles
= cm_option
->num_choices
;
3473 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3475 cupsdLogMessage(CUPSD_LOG_ERROR
,
3476 "Unable to allocate memory for %d profiles",
3482 profiles
->profileCount
= num_profiles
;
3484 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3485 cm_choice
= cm_option
->choices
;
3487 i
--, cm_choice
++, profile
++)
3489 if (!strcmp(cm_choice
->choice
, "Gray") ||
3490 !strcmp(cm_choice
->choice
, "Black"))
3491 profile_name
= "Gray";
3492 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3493 !strcmp(cm_choice
->choice
, "CMY"))
3494 profile_name
= "RGB";
3495 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3496 !strcmp(cm_choice
->choice
, "KCMY"))
3497 profile_name
= "CMYK";
3499 profile_name
= "DeviceN";
3501 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3502 profile_id
= _ppdHashName(selector
);
3504 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3505 cm_choice
->text
, NULL
);
3507 if (cm_choice
->marked
)
3508 default_profile_id
= profile_id
;
3514 * Use the default colorspace...
3517 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3519 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3521 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3523 cupsdLogMessage(CUPSD_LOG_ERROR
,
3524 "Unable to allocate memory for %d profiles",
3530 profiles
->profileCount
= num_profiles
;
3532 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3533 "Gray", "Gray", NULL
);
3535 switch (ppd
->colorspace
)
3539 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3540 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3544 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3545 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3553 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3554 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3560 if (num_profiles
> 0)
3563 * Make sure we have a default profile ID...
3566 if (!default_profile_id
)
3567 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3570 * Get the device ID hash and pathelogical name dictionary.
3573 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3576 device_id
= _ppdHashName(p
->name
);
3577 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3578 &kCFTypeDictionaryKeyCallBacks
,
3579 &kCFTypeDictionaryValueCallBacks
);
3580 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3581 p
->name
, kCFStringEncodingUTF8
);
3583 if (device_name
&& printer_name
)
3585 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3588 * Register the device with ColorSync...
3591 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3592 device_name
, &scope
);
3595 * Register the profiles...
3599 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3600 default_profile_id
, profiles
);
3610 cupsdLogMessage(CUPSD_LOG_ERROR
,
3611 "Unable to register ICC color profiles for \"%s\" - %d",
3612 p
->name
, (int)error
);
3614 for (profile
= profiles
->profiles
;
3616 profile
++, num_profiles
--)
3617 CFRelease(profile
->profileName
);
3622 CFRelease(printer_name
);
3625 CFRelease(device_name
);
3633 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3638 apple_unregister_profiles(
3639 cupsd_printer_t
*p
) /* I - Printer */
3642 * Make sure ColorSync is available...
3645 if (CMUnregisterColorDevice
!= NULL
)
3646 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3648 #endif /* __APPLE__ */
3651 * 'apply_printer_defaults()' - Apply printer default options to a job.
3655 apply_printer_defaults(
3656 cupsd_printer_t
*printer
, /* I - Printer */
3657 cupsd_job_t
*job
) /* I - Job */
3659 int i
, /* Looping var */
3660 num_options
; /* Number of default options */
3661 cups_option_t
*options
, /* Default options */
3662 *option
; /* Current option */
3666 * Collect all of the default options and add the missing ones to the
3670 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3671 option
= printer
->options
;
3674 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3676 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3681 * Encode these options as attributes in the job object...
3684 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3685 cupsFreeOptions(num_options
, options
);
3690 * 'authenticate_job()' - Set job authentication info.
3694 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3695 ipp_attribute_t
*uri
) /* I - Job URI */
3697 ipp_attribute_t
*attr
, /* job-id attribute */
3698 *auth_info
; /* auth-info attribute */
3699 int jobid
; /* Job ID */
3700 cupsd_job_t
*job
; /* Current job */
3701 char scheme
[HTTP_MAX_URI
],
3702 /* Method portion of URI */
3703 username
[HTTP_MAX_URI
],
3704 /* Username portion of URI */
3706 /* Host portion of URI */
3707 resource
[HTTP_MAX_URI
];
3708 /* Resource portion of URI */
3709 int port
; /* Port portion of URI */
3712 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3713 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3716 * Start with "everything is OK" status...
3719 con
->response
->request
.status
.status_code
= IPP_OK
;
3722 * See if we have a job URI or a printer URI...
3725 if (!strcmp(uri
->name
, "printer-uri"))
3728 * Got a printer URI; see if we also have a job-id attribute...
3731 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3732 IPP_TAG_INTEGER
)) == NULL
)
3734 send_ipp_status(con
, IPP_BAD_REQUEST
,
3735 _("Got a printer-uri attribute but no job-id"));
3739 jobid
= attr
->values
[0].integer
;
3744 * Got a job URI; parse it to get the job ID...
3747 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3748 sizeof(scheme
), username
, sizeof(username
), host
,
3749 sizeof(host
), &port
, resource
, sizeof(resource
));
3751 if (strncmp(resource
, "/jobs/", 6))
3757 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\""),
3758 uri
->values
[0].string
.text
);
3762 jobid
= atoi(resource
+ 6);
3766 * See if the job exists...
3769 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3772 * Nope - return a "not found" error...
3775 send_ipp_status(con
, IPP_NOT_FOUND
,
3776 _("Job #%d does not exist"), jobid
);
3781 * See if the job has been completed...
3784 if (job
->state_value
!= IPP_JOB_HELD
)
3787 * Return a "not-possible" error...
3790 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3791 _("Job #%d is not held for authentication"),
3797 * See if we have already authenticated...
3800 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3802 if (!con
->username
[0] && !auth_info
)
3804 cupsd_printer_t
*printer
; /* Job destination */
3808 * No auth data. If we need to authenticate via Kerberos, send a
3809 * HTTP auth challenge, otherwise just return an IPP error...
3812 printer
= cupsdFindDest(job
->dest
);
3814 if (printer
&& printer
->num_auth_info_required
> 0 &&
3815 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3816 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3818 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3819 _("No authentication information provided"));
3824 * See if the job is owned by the requesting user...
3827 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3829 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3830 cupsdFindDest(job
->dest
));
3835 * Save the authentication information for this job...
3838 save_auth_info(con
, job
, auth_info
);
3841 * Reset the job-hold-until value to "no-hold"...
3844 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3845 IPP_TAG_KEYWORD
)) == NULL
)
3846 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3850 attr
->value_tag
= IPP_TAG_KEYWORD
;
3851 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3855 * Release the job and return...
3858 cupsdReleaseJob(job
);
3860 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3865 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3869 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3870 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3872 int i
; /* Looping var */
3873 http_status_t status
; /* Policy status */
3874 cups_ptype_t dtype
; /* Destination type */
3875 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3876 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3877 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3878 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3879 int port
; /* Port portion of URI */
3880 ipp_attribute_t
*attr
; /* Attribute in request */
3881 const char *username
= NULL
; /* Username */
3882 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3884 cupsd_printer_t
*printer
; /* Printer */
3885 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3886 cupsd_job_t
*job
; /* Job */
3889 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3890 con
->http
.fd
, uri
->values
[0].string
.text
);
3893 * Get the jobs to cancel/purge...
3896 switch (con
->request
->request
.op
.operation_id
)
3898 case IPP_PURGE_JOBS
:
3900 * Get the username (if any) for the jobs we want to cancel (only if
3901 * "my-jobs" is specified...
3904 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3905 IPP_TAG_BOOLEAN
)) != NULL
&&
3906 attr
->values
[0].boolean
)
3908 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3909 IPP_TAG_NAME
)) != NULL
)
3910 username
= attr
->values
[0].string
.text
;
3913 send_ipp_status(con
, IPP_BAD_REQUEST
,
3914 _("Missing requesting-user-name attribute"));
3920 * Look for the "purge-jobs" attribute...
3923 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3924 IPP_TAG_BOOLEAN
)) != NULL
)
3925 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3927 purge
= CUPSD_JOB_PURGE
;
3930 case IPP_CANCEL_MY_JOBS
:
3931 if (con
->username
[0])
3932 username
= con
->username
;
3933 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3934 IPP_TAG_NAME
)) != NULL
)
3935 username
= attr
->values
[0].string
.text
;
3938 send_ipp_status(con
, IPP_BAD_REQUEST
,
3939 _("Missing requesting-user-name attribute"));
3947 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3950 * See if we have a printer URI...
3953 if (strcmp(uri
->name
, "printer-uri"))
3955 send_ipp_status(con
, IPP_BAD_REQUEST
,
3956 _("The printer-uri attribute is required"));
3961 * And if the destination is valid...
3964 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3970 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3971 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3972 hostname
, sizeof(hostname
), &port
,
3973 resource
, sizeof(resource
));
3975 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3976 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3978 send_ipp_status(con
, IPP_NOT_FOUND
,
3979 _("The printer or class was not found."));
3987 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3989 send_http_error(con
, status
, NULL
);
3995 for (i
= 0; i
< job_ids
->num_values
; i
++)
3997 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
4001 if (i
< job_ids
->num_values
)
4003 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
4004 job_ids
->values
[i
].integer
);
4008 for (i
= 0; i
< job_ids
->num_values
; i
++)
4010 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4012 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4013 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4014 "Job canceled by user.");
4017 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4018 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4024 * Cancel all jobs on all printers...
4027 cupsdCancelJobs(NULL
, username
, purge
);
4029 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
4030 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4040 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4043 send_http_error(con
, status
, printer
);
4049 for (i
= 0; i
< job_ids
->num_values
; i
++)
4051 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
4052 strcasecmp(job
->dest
, printer
->name
))
4056 if (i
< job_ids
->num_values
)
4058 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
4059 job_ids
->values
[i
].integer
);
4063 for (i
= 0; i
< job_ids
->num_values
; i
++)
4065 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4067 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4068 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4069 "Job canceled by user.");
4072 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4073 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4079 * Cancel all of the jobs on the named printer...
4082 cupsdCancelJobs(printer
->name
, username
, purge
);
4084 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
4086 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4091 con
->response
->request
.status
.status_code
= IPP_OK
;
4096 * 'cancel_job()' - Cancel a print job.
4100 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
4101 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4103 ipp_attribute_t
*attr
; /* Current attribute */
4104 int jobid
; /* Job ID */
4105 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4106 username
[HTTP_MAX_URI
], /* Username portion of URI */
4107 host
[HTTP_MAX_URI
], /* Host portion of URI */
4108 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4109 int port
; /* Port portion of URI */
4110 cupsd_job_t
*job
; /* Job information */
4111 cups_ptype_t dtype
; /* Destination type (printer/class) */
4112 cupsd_printer_t
*printer
; /* Printer data */
4113 cupsd_jobaction_t purge
; /* Purge the job? */
4116 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
4117 con
->http
.fd
, uri
->values
[0].string
.text
);
4120 * See if we have a job URI or a printer URI...
4123 if (!strcmp(uri
->name
, "printer-uri"))
4126 * Got a printer URI; see if we also have a job-id attribute...
4129 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4130 IPP_TAG_INTEGER
)) == NULL
)
4132 send_ipp_status(con
, IPP_BAD_REQUEST
,
4133 _("Got a printer-uri attribute but no job-id"));
4137 if ((jobid
= attr
->values
[0].integer
) == 0)
4140 * Find the current job on the specified printer...
4143 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4149 send_ipp_status(con
, IPP_NOT_FOUND
,
4150 _("The printer or class was not found."));
4155 * See if there are any pending jobs...
4158 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4160 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4161 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
4162 !strcasecmp(job
->dest
, printer
->name
))
4170 * No, try stopped jobs...
4173 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4175 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4176 if (job
->state_value
== IPP_JOB_STOPPED
&&
4177 !strcasecmp(job
->dest
, printer
->name
))
4184 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s"),
4194 * Got a job URI; parse it to get the job ID...
4197 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4198 sizeof(scheme
), username
, sizeof(username
), host
,
4199 sizeof(host
), &port
, resource
, sizeof(resource
));
4201 if (strncmp(resource
, "/jobs/", 6))
4207 send_ipp_status(con
, IPP_BAD_REQUEST
,
4208 _("Bad job-uri attribute \"%s\""),
4209 uri
->values
[0].string
.text
);
4213 jobid
= atoi(resource
+ 6);
4217 * Look for the "purge-job" attribute...
4220 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4221 IPP_TAG_BOOLEAN
)) != NULL
)
4222 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4224 purge
= CUPSD_JOB_DEFAULT
;
4227 * See if the job exists...
4230 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4233 * Nope - return a "not found" error...
4236 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
4241 * See if the job is owned by the requesting user...
4244 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4246 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4247 cupsdFindDest(job
->dest
));
4252 * See if the job is already completed, canceled, or aborted; if so,
4253 * we can't cancel...
4256 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4258 switch (job
->state_value
)
4260 case IPP_JOB_CANCELED
:
4261 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4262 _("Job #%d is already canceled - can\'t cancel."),
4266 case IPP_JOB_ABORTED
:
4267 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4268 _("Job #%d is already aborted - can\'t cancel."),
4273 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4274 _("Job #%d is already completed - can\'t cancel."),
4283 * Cancel the job and return...
4286 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4287 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4288 "Job canceled by \"%s\"",
4292 if (purge
== CUPSD_JOB_PURGE
)
4293 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4296 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4299 con
->response
->request
.status
.status_code
= IPP_OK
;
4304 * 'cancel_subscription()' - Cancel a subscription.
4308 cancel_subscription(
4309 cupsd_client_t
*con
, /* I - Client connection */
4310 int sub_id
) /* I - Subscription ID */
4312 http_status_t status
; /* Policy status */
4313 cupsd_subscription_t
*sub
; /* Subscription */
4316 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4317 "cancel_subscription(con=%p[%d], sub_id=%d)",
4318 con
, con
->http
.fd
, sub_id
);
4321 * Is the subscription ID valid?
4324 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4327 * Bad subscription ID...
4330 send_ipp_status(con
, IPP_NOT_FOUND
,
4331 _("notify-subscription-id %d no good"), sub_id
);
4339 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4341 con
, sub
->owner
)) != HTTP_OK
)
4343 send_http_error(con
, status
, sub
->dest
);
4348 * Cancel the subscription...
4351 cupsdDeleteSubscription(sub
, 1);
4353 con
->response
->request
.status
.status_code
= IPP_OK
;
4358 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4361 static int /* O - 1 if OK, 0 if not */
4362 check_rss_recipient(
4363 const char *recipient
) /* I - Recipient URI */
4365 cupsd_subscription_t
*sub
; /* Current subscription */
4368 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4370 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4374 * Compare the URIs up to the first ?...
4377 const char *r1
, *r2
;
4379 for (r1
= recipient
, r2
= sub
->recipient
;
4380 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4392 * 'check_quotas()' - Check quotas for a printer and user.
4395 static int /* O - 1 if OK, 0 if not */
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 cupsd_printer_t
*printer
; /* Printer */
4637 ipp_attribute_t
*attr
; /* Attribute */
4638 char job_uri
[HTTP_MAX_URI
],
4640 username
[256]; /* User name */
4643 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4644 con
->http
.fd
, uri
->values
[0].string
.text
);
4647 * See if we have a job URI or a printer URI...
4650 if (strcmp(uri
->name
, "printer-uri"))
4653 * job-uri is not supported by Close-Job!
4656 send_ipp_status(con
, IPP_BAD_REQUEST
,
4657 _("Close-Job doesn't support the job-uri attribute."));
4662 * Got a printer URI; see if we also have a job-id attribute...
4665 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4666 IPP_TAG_INTEGER
)) == NULL
)
4668 send_ipp_status(con
, IPP_BAD_REQUEST
,
4669 _("Got a printer-uri attribute but no job-id"));
4673 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4676 * Nope - return a "not found" error...
4679 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
4680 attr
->values
[0].integer
);
4684 printer
= cupsdFindDest(job
->dest
);
4687 * See if the job is owned by the requesting user...
4690 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4692 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4693 cupsdFindDest(job
->dest
));
4698 * Add any ending sheet...
4701 if (cupsdTimeoutJob(job
))
4704 if (job
->state_value
== IPP_JOB_STOPPED
)
4706 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4707 job
->state_value
= IPP_JOB_PENDING
;
4709 else if (job
->state_value
== IPP_JOB_HELD
)
4711 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4712 IPP_TAG_KEYWORD
)) == NULL
)
4713 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4715 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
4717 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
4718 job
->state_value
= IPP_JOB_PENDING
;
4723 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
4726 * Fill in the response info...
4729 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
4730 LocalPort
, job
->id
);
4731 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4734 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4736 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4739 add_job_state_reasons(con
, job
);
4741 con
->response
->request
.status
.status_code
= IPP_OK
;
4744 * Start the job if necessary...
4752 * 'copy_attribute()' - Copy a single attribute.
4755 static ipp_attribute_t
* /* O - New attribute */
4757 ipp_t
*to
, /* O - Destination request/response */
4758 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4759 int quickcopy
) /* I - Do a quick copy? */
4761 int i
; /* Looping var */
4762 ipp_attribute_t
*toattr
; /* Destination attribute */
4765 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4766 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4767 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4770 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4773 toattr
= ippAddSeparator(to
);
4776 case IPP_TAG_INTEGER
:
4778 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4779 attr
->name
, attr
->num_values
, NULL
);
4781 for (i
= 0; i
< attr
->num_values
; i
++)
4782 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4785 case IPP_TAG_BOOLEAN
:
4786 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4787 attr
->num_values
, NULL
);
4789 for (i
= 0; i
< attr
->num_values
; i
++)
4790 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4793 case IPP_TAG_STRING
:
4796 case IPP_TAG_KEYWORD
:
4798 case IPP_TAG_URISCHEME
:
4799 case IPP_TAG_CHARSET
:
4800 case IPP_TAG_LANGUAGE
:
4801 case IPP_TAG_MIMETYPE
:
4802 toattr
= ippAddStrings(to
, attr
->group_tag
,
4803 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4804 attr
->name
, attr
->num_values
, NULL
, NULL
);
4808 for (i
= 0; i
< attr
->num_values
; i
++)
4809 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4811 else if (attr
->value_tag
& IPP_TAG_COPY
)
4813 for (i
= 0; i
< attr
->num_values
; i
++)
4814 toattr
->values
[i
].string
.text
=
4815 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4819 for (i
= 0; i
< attr
->num_values
; i
++)
4820 toattr
->values
[i
].string
.text
=
4821 _cupsStrRetain(attr
->values
[i
].string
.text
);
4826 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4827 attr
->values
[0].date
);
4830 case IPP_TAG_RESOLUTION
:
4831 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4832 attr
->num_values
, IPP_RES_PER_INCH
,
4835 for (i
= 0; i
< attr
->num_values
; i
++)
4837 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4838 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4839 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4843 case IPP_TAG_RANGE
:
4844 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4845 attr
->num_values
, NULL
, NULL
);
4847 for (i
= 0; i
< attr
->num_values
; i
++)
4849 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4850 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4854 case IPP_TAG_TEXTLANG
:
4855 case IPP_TAG_NAMELANG
:
4856 toattr
= ippAddStrings(to
, attr
->group_tag
,
4857 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4858 attr
->name
, attr
->num_values
, NULL
, NULL
);
4862 for (i
= 0; i
< attr
->num_values
; i
++)
4864 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4865 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4868 else if (attr
->value_tag
& IPP_TAG_COPY
)
4870 for (i
= 0; i
< attr
->num_values
; i
++)
4873 toattr
->values
[i
].string
.charset
=
4874 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4876 toattr
->values
[i
].string
.charset
=
4877 toattr
->values
[0].string
.charset
;
4879 toattr
->values
[i
].string
.text
=
4880 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4885 for (i
= 0; i
< attr
->num_values
; i
++)
4888 toattr
->values
[i
].string
.charset
=
4889 _cupsStrRetain(attr
->values
[i
].string
.charset
);
4891 toattr
->values
[i
].string
.charset
=
4892 toattr
->values
[0].string
.charset
;
4894 toattr
->values
[i
].string
.text
=
4895 _cupsStrRetain(attr
->values
[i
].string
.text
);
4900 case IPP_TAG_BEGIN_COLLECTION
:
4901 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4902 attr
->num_values
, NULL
);
4904 for (i
= 0; i
< attr
->num_values
; i
++)
4906 toattr
->values
[i
].collection
= attr
->values
[i
].collection
;
4907 attr
->values
[i
].collection
->use
++;
4912 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4913 attr
->name
, attr
->num_values
, NULL
);
4915 for (i
= 0; i
< attr
->num_values
; i
++)
4917 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4919 if (toattr
->values
[i
].unknown
.length
> 0)
4921 if ((toattr
->values
[i
].unknown
.data
=
4922 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4923 toattr
->values
[i
].unknown
.length
= 0;
4925 memcpy(toattr
->values
[i
].unknown
.data
,
4926 attr
->values
[i
].unknown
.data
,
4927 toattr
->values
[i
].unknown
.length
);
4930 break; /* anti-compiler-warning-code */
4938 * 'copy_attrs()' - Copy attributes from one request to another.
4942 copy_attrs(ipp_t
*to
, /* I - Destination request */
4943 ipp_t
*from
, /* I - Source request */
4944 cups_array_t
*ra
, /* I - Requested attributes */
4945 ipp_tag_t group
, /* I - Group to copy */
4946 int quickcopy
) /* I - Do a quick copy? */
4948 ipp_attribute_t
*fromattr
; /* Source attribute */
4951 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4952 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4953 to
, from
, ra
, group
, quickcopy
);
4958 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4961 * Filter attributes as needed...
4964 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4965 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4968 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4971 * Don't send collection attributes by default to IPP/1.x clients
4972 * since many do not support collections. Also don't send
4973 * media-col-database unless specifically requested by the client.
4976 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4978 (to
->request
.status
.version
[0] == 1 ||
4979 !strcmp(fromattr
->name
, "media-col-database")))
4982 copy_attribute(to
, fromattr
, quickcopy
);
4989 * 'copy_banner()' - Copy a banner file to the requests directory for the
4993 static int /* O - Size of banner file in kbytes */
4994 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4995 cupsd_job_t
*job
, /* I - Job information */
4996 const char *name
) /* I - Name of banner */
4998 int i
; /* Looping var */
4999 int kbytes
; /* Size of banner file in kbytes */
5000 char filename
[1024]; /* Job filename */
5001 cupsd_banner_t
*banner
; /* Pointer to banner */
5002 cups_file_t
*in
; /* Input file */
5003 cups_file_t
*out
; /* Output file */
5004 int ch
; /* Character from file */
5005 char attrname
[255], /* Name of attribute */
5006 *s
; /* Pointer into name */
5007 ipp_attribute_t
*attr
; /* Attribute */
5010 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5011 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
5012 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
5013 name
? name
: "(null)");
5016 * Find the banner; return if not found or "none"...
5019 if (!name
|| !strcmp(name
, "none") ||
5020 (banner
= cupsdFindBanner(name
)) == NULL
)
5024 * Open the banner and job files...
5027 if (add_file(con
, job
, banner
->filetype
, 0))
5030 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
5032 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
5034 cupsdLogMessage(CUPSD_LOG_ERROR
,
5035 "Unable to create banner job file %s - %s",
5036 filename
, strerror(errno
));
5041 fchmod(cupsFileNumber(out
), 0640);
5042 fchown(cupsFileNumber(out
), RunUser
, Group
);
5045 * Try the localized banner file under the subdirectory...
5048 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5050 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5053 * Convert ll-cc to ll_CC...
5057 attrname
[3] = toupper(attrname
[3] & 255);
5058 attrname
[4] = toupper(attrname
[4] & 255);
5061 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5064 if (access(filename
, 0) && strlen(attrname
) > 2)
5067 * Wasn't able to find "ll_CC" locale file; try the non-national
5068 * localization banner directory.
5073 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5077 if (access(filename
, 0))
5080 * Use the non-localized banner file.
5083 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5086 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5090 cupsdLogMessage(CUPSD_LOG_ERROR
,
5091 "Unable to open banner template file %s - %s",
5092 filename
, strerror(errno
));
5098 * Parse the file to the end...
5101 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5105 * Get an attribute name...
5108 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5109 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5111 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5121 * Ignore { followed by stuff that is not an attribute name...
5124 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5129 * See if it is defined...
5132 if (attrname
[0] == '?')
5137 if (!strcmp(s
, "printer-name"))
5139 cupsFilePuts(out
, job
->dest
);
5142 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5145 * See if we have a leading question mark...
5148 if (attrname
[0] != '?')
5151 * Nope, write to file as-is; probably a PostScript procedure...
5154 cupsFilePrintf(out
, "{%s}", attrname
);
5161 * Output value(s)...
5164 for (i
= 0; i
< attr
->num_values
; i
++)
5167 cupsFilePutChar(out
, ',');
5169 switch (attr
->value_tag
)
5171 case IPP_TAG_INTEGER
:
5173 if (!strncmp(s
, "time-at-", 8))
5175 struct timeval tv
= { attr
->values
[i
].integer
, 0 };
5176 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5179 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5182 case IPP_TAG_BOOLEAN
:
5183 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5186 case IPP_TAG_NOVALUE
:
5187 cupsFilePuts(out
, "novalue");
5190 case IPP_TAG_RANGE
:
5191 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5192 attr
->values
[i
].range
.upper
);
5195 case IPP_TAG_RESOLUTION
:
5196 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5197 attr
->values
[i
].resolution
.yres
,
5198 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5203 case IPP_TAG_STRING
:
5206 case IPP_TAG_KEYWORD
:
5207 case IPP_TAG_CHARSET
:
5208 case IPP_TAG_LANGUAGE
:
5209 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
5212 * Need to quote strings for PS banners...
5217 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5219 if (*p
== '(' || *p
== ')' || *p
== '\\')
5221 cupsFilePutChar(out
, '\\');
5222 cupsFilePutChar(out
, *p
);
5224 else if (*p
< 32 || *p
> 126)
5225 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5227 cupsFilePutChar(out
, *p
);
5231 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5235 break; /* anti-compiler-warning-code */
5239 else if (ch
== '\\') /* Quoted char */
5241 ch
= cupsFileGetChar(in
);
5243 if (ch
!= '{') /* Only do special handling for \{ */
5244 cupsFilePutChar(out
, '\\');
5246 cupsFilePutChar(out
, ch
);
5249 cupsFilePutChar(out
, ch
);
5253 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5255 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5256 IPP_TAG_INTEGER
)) != NULL
)
5257 attr
->values
[0].integer
+= kbytes
;
5266 * 'copy_file()' - Copy a PPD file or interface script...
5269 static int /* O - 0 = success, -1 = error */
5270 copy_file(const char *from
, /* I - Source file */
5271 const char *to
) /* I - Destination file */
5273 cups_file_t
*src
, /* Source file */
5274 *dst
; /* Destination file */
5275 int bytes
; /* Bytes to read/write */
5276 char buffer
[2048]; /* Copy buffer */
5279 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5282 * Open the source and destination file for a copy...
5285 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5288 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5295 * Copy the source file to the destination...
5298 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5299 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5307 * Close both files and return...
5312 return (cupsFileClose(dst
));
5317 * 'copy_model()' - Copy a PPD model file, substituting default values
5321 static int /* O - 0 = success, -1 = error */
5322 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5323 const char *from
, /* I - Source file */
5324 const char *to
) /* I - Destination file */
5326 fd_set input
; /* select() input set */
5327 struct timeval timeout
; /* select() timeout */
5328 int maxfd
; /* Max file descriptor for select() */
5329 char tempfile
[1024]; /* Temporary PPD file */
5330 int tempfd
; /* Temporary PPD file descriptor */
5331 int temppid
; /* Process ID of cups-driverd */
5332 int temppipe
[2]; /* Temporary pipes */
5333 char *argv
[4], /* Command-line arguments */
5334 *envp
[MAX_ENV
]; /* Environment */
5335 cups_file_t
*src
, /* Source file */
5336 *dst
; /* Destination file */
5337 ppd_file_t
*ppd
; /* PPD file */
5338 int bytes
, /* Bytes from pipe */
5339 total
; /* Total bytes from pipe */
5340 char buffer
[2048]; /* Copy buffer */
5341 int i
; /* Looping var */
5342 char option
[PPD_MAX_NAME
], /* Option name */
5343 choice
[PPD_MAX_NAME
]; /* Choice name */
5344 ppd_size_t
*size
; /* Default size */
5345 int num_defaults
; /* Number of default options */
5346 cups_option_t
*defaults
; /* Default options */
5347 char cups_protocol
[PPD_MAX_LINE
];
5348 /* cupsProtocol attribute */
5351 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5352 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5356 * Run cups-driverd to get the PPD file...
5359 argv
[0] = "cups-driverd";
5361 argv
[2] = (char *)from
;
5364 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5366 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5367 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5368 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5372 cupsdOpenPipe(temppipe
);
5374 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5375 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5377 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5378 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5389 * Wait up to 30 seconds for the PPD file to be copied...
5394 if (temppipe
[0] > CGIPipes
[0])
5395 maxfd
= temppipe
[0] + 1;
5397 maxfd
= CGIPipes
[0] + 1;
5402 * See if we have data ready...
5406 FD_SET(temppipe
[0], &input
);
5407 FD_SET(CGIPipes
[0], &input
);
5409 timeout
.tv_sec
= 30;
5410 timeout
.tv_usec
= 0;
5412 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5422 * We have timed out...
5428 if (FD_ISSET(temppipe
[0], &input
))
5431 * Read the PPD file from the pipe, and write it to the PPD file.
5434 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5436 if (write(tempfd
, buffer
, bytes
) < bytes
)
5445 if (FD_ISSET(CGIPipes
[0], &input
))
5455 * No data from cups-deviced...
5458 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5464 * Read the source file and see what page sizes are supported...
5467 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5474 * Open the destination (if possible) and set the default options...
5479 cups_protocol
[0] = '\0';
5481 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5484 * Read all of the default lines from the old PPD...
5487 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5488 if (!strncmp(buffer
, "*Default", 8))
5491 * Add the default option...
5494 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5495 choice
, sizeof(choice
)))
5497 ppd_option_t
*ppdo
; /* PPD option */
5501 * Only add the default if the default hasn't already been
5502 * set and the choice exists in the new PPD...
5505 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5506 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5507 ppdFindChoice(ppdo
, choice
))
5508 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5512 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5513 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5517 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5520 * Add the default media sizes...
5523 num_defaults
= cupsAddOption("PageSize", size
->name
,
5524 num_defaults
, &defaults
);
5525 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5526 num_defaults
, &defaults
);
5527 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5528 num_defaults
, &defaults
);
5529 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5530 num_defaults
, &defaults
);
5536 * Open the source file for a copy...
5539 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5541 cupsFreeOptions(num_defaults
, defaults
);
5547 * Open the destination file for a copy...
5550 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5552 cupsFreeOptions(num_defaults
, defaults
);
5559 * Copy the source file to the destination...
5562 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5564 if (!strncmp(buffer
, "*Default", 8))
5567 * Check for an previous default option choice...
5570 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5571 choice
, sizeof(choice
)))
5573 const char *val
; /* Default option value */
5576 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5579 * Substitute the previous choice...
5582 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5587 cupsFilePrintf(dst
, "%s\n", buffer
);
5590 if (cups_protocol
[0])
5591 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5593 cupsFreeOptions(num_defaults
, defaults
);
5596 * Close both files and return...
5603 return (cupsFileClose(dst
));
5608 * 'copy_job_attrs()' - Copy job attributes.
5612 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5613 cupsd_job_t
*job
, /* I - Job */
5614 cups_array_t
*ra
) /* I - Requested attributes array */
5616 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5620 * Send the requested attributes for each job...
5623 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5624 con
->servername
, con
->serverport
, "/jobs/%d",
5627 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5628 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5629 "document-count", job
->num_files
);
5631 if (!ra
|| cupsArrayFind(ra
, "job-media-progress"))
5632 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5633 "job-media-progress", job
->progress
);
5635 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5636 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5637 "job-more-info", NULL
, job_uri
);
5639 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5640 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5641 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5642 job
->num_files
> 0);
5644 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5645 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5646 "job-printer-up-time", time(NULL
));
5648 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5649 add_job_state_reasons(con
, job
);
5651 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5652 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5653 "job-uri", NULL
, job_uri
);
5655 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5660 * 'copy_printer_attrs()' - Copy printer attributes.
5665 cupsd_client_t
*con
, /* I - Client connection */
5666 cupsd_printer_t
*printer
, /* I - Printer */
5667 cups_array_t
*ra
) /* I - Requested attributes array */
5669 char printer_uri
[HTTP_MAX_URI
];
5671 time_t curtime
; /* Current time */
5672 int i
; /* Looping var */
5673 ipp_attribute_t
*history
; /* History collection */
5677 * Copy the printer attributes to the response using requested-attributes
5678 * and document-format attributes that may be provided by the client.
5681 curtime
= time(NULL
);
5683 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5684 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5685 "marker-change-time", printer
->marker_time
);
5687 if (printer
->num_printers
> 0 &&
5688 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5690 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5691 cupsd_printer_t
*p2
; /* Printer in class */
5692 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5695 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5696 IPP_TAG_URI
, "member-uris",
5697 printer
->num_printers
, NULL
,
5700 for (i
= 0; i
< printer
->num_printers
; i
++)
5702 p2
= printer
->printers
[i
];
5704 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5705 IPP_TAG_URI
)) != NULL
)
5706 member_uris
->values
[i
].string
.text
=
5707 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
5710 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5711 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5713 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5714 "/classes/%s" : "/printers/%s", p2
->name
);
5715 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5721 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5722 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5723 "printer-alert", NULL
, printer
->alert
);
5725 if (printer
->alert_description
&&
5726 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5727 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5728 "printer-alert-description", NULL
,
5729 printer
->alert_description
);
5731 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5732 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5733 ippTimeToDate(curtime
));
5736 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5738 if (printer
->reg_name
)
5739 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5740 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5742 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5743 "printer-dns-sd-name", 0);
5745 #endif /* HAVE_DNSSD */
5747 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5748 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5749 "printer-error-policy", NULL
, printer
->error_policy
);
5751 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
5753 static const char * const errors
[] =/* printer-error-policy-supported values */
5756 "retry-current-job",
5761 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
5762 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5763 "printer-error-policy-supported", NULL
, "retry-current-job");
5765 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
5766 "printer-error-policy-supported",
5767 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
5770 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5771 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5772 printer
->accepting
);
5774 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5775 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5778 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5779 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5781 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5782 "http", NULL
, con
->servername
, con
->serverport
,
5783 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5784 "/classes/%s" : "/printers/%s", printer
->name
);
5785 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5786 "printer-more-info", NULL
, printer_uri
);
5789 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5790 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5791 "printer-op-policy", NULL
, printer
->op_policy
);
5793 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5794 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5797 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5798 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5799 "printer-state-change-time", printer
->state_time
);
5801 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5802 cupsArrayFind(ra
, "printer-state-history"))
5805 * Printer history is only sent if specifically requested, so that
5806 * older CUPS/IPP clients won't barf on the collection attributes.
5809 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5810 "printer-state-history",
5811 printer
->num_history
, NULL
);
5813 for (i
= 0; i
< printer
->num_history
; i
++)
5814 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5815 NULL
, IPP_TAG_ZERO
, 0);
5818 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5819 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5820 "printer-state-message", NULL
, printer
->state_message
);
5822 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5823 add_printer_state_reasons(con
, printer
);
5825 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5827 int type
; /* printer-type value */
5831 * Add the CUPS-specific printer-type attribute...
5834 type
= printer
->type
;
5836 if (printer
== DefaultPrinter
)
5837 type
|= CUPS_PRINTER_DEFAULT
;
5839 if (!printer
->accepting
)
5840 type
|= CUPS_PRINTER_REJECTING
;
5842 if (!printer
->shared
)
5843 type
|= CUPS_PRINTER_NOT_SHARED
;
5845 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5849 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5850 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5851 "printer-up-time", curtime
);
5853 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5854 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5856 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5857 "ipp", NULL
, con
->servername
, con
->serverport
,
5858 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5859 "/classes/%s" : "/printers/%s", printer
->name
);
5860 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5861 "printer-uri-supported", NULL
, printer_uri
);
5862 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5866 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5867 add_queued_job_count(con
, printer
);
5869 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5870 if (printer
->ppd_attrs
)
5871 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0);
5872 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5877 * 'copy_subscription_attrs()' - Copy subscription attributes.
5881 copy_subscription_attrs(
5882 cupsd_client_t
*con
, /* I - Client connection */
5883 cupsd_subscription_t
*sub
, /* I - Subscription */
5884 cups_array_t
*ra
) /* I - Requested attributes array */
5886 ipp_attribute_t
*attr
; /* Current attribute */
5887 char printer_uri
[HTTP_MAX_URI
];
5889 int count
; /* Number of events */
5890 unsigned mask
; /* Current event mask */
5891 const char *name
; /* Current event name */
5895 * Copy the subscription attributes to the response using the
5896 * requested-attributes attribute that may be provided by the client.
5899 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5901 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5904 * Simple event list...
5907 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5908 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5909 "notify-events", NULL
, name
);
5914 * Complex event list...
5917 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5918 if (sub
->mask
& mask
)
5921 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5922 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5923 "notify-events", count
, NULL
, NULL
);
5925 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5926 if (sub
->mask
& mask
)
5928 attr
->values
[count
].string
.text
=
5929 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5936 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5937 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5938 "notify-job-id", sub
->job
->id
);
5940 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5941 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5942 "notify-lease-duration", sub
->lease
);
5944 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5946 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5947 "ipp", NULL
, con
->servername
, con
->serverport
,
5948 "/printers/%s", sub
->dest
->name
);
5949 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5950 "notify-printer-uri", NULL
, printer_uri
);
5953 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5954 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5955 "notify-recipient-uri", NULL
, sub
->recipient
);
5956 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5957 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5958 "notify-pull-method", NULL
, "ippget");
5960 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5961 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5962 "notify-subscriber-user-name", NULL
, sub
->owner
);
5964 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5965 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5966 "notify-subscription-id", sub
->id
);
5968 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5969 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5970 "notify-time-interval", sub
->interval
);
5972 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5973 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5974 sub
->user_data
, sub
->user_data_len
);
5979 * 'create_job()' - Print a file to a printer or class.
5983 create_job(cupsd_client_t
*con
, /* I - Client connection */
5984 ipp_attribute_t
*uri
) /* I - Printer URI */
5986 cupsd_printer_t
*printer
; /* Printer */
5987 cupsd_job_t
*job
; /* New job */
5990 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5991 con
->http
.fd
, uri
->values
[0].string
.text
);
5994 * Is the destination valid?
5997 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6003 send_ipp_status(con
, IPP_NOT_FOUND
,
6004 _("The printer or class was not found."));
6009 * Create the job object...
6012 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6015 job
->pending_timeout
= 1;
6018 * Save and log the job...
6021 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6022 job
->dest
, job
->username
);
6027 * 'create_requested_array()' - Create an array for the requested-attributes.
6030 static cups_array_t
* /* O - Array of attributes or NULL */
6031 create_requested_array(ipp_t
*request
) /* I - IPP request */
6033 int i
; /* Looping var */
6034 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6035 cups_array_t
*ra
; /* Requested attributes array */
6036 char *value
; /* Current value */
6040 * Get the requested-attributes attribute, and return NULL if we don't
6044 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6045 IPP_TAG_KEYWORD
)) == NULL
)
6049 * If the attribute contains a single "all" keyword, return NULL...
6052 if (requested
->num_values
== 1 &&
6053 !strcmp(requested
->values
[0].string
.text
, "all"))
6057 * Create an array using "strcmp" as the comparison function...
6060 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6062 for (i
= 0; i
< requested
->num_values
; i
++)
6064 value
= requested
->values
[i
].string
.text
;
6066 if (!strcmp(value
, "job-template"))
6068 cupsArrayAdd(ra
, "copies");
6069 cupsArrayAdd(ra
, "copies-default");
6070 cupsArrayAdd(ra
, "copies-supported");
6071 cupsArrayAdd(ra
, "finishings");
6072 cupsArrayAdd(ra
, "finishings-default");
6073 cupsArrayAdd(ra
, "finishings-supported");
6074 cupsArrayAdd(ra
, "job-hold-until");
6075 cupsArrayAdd(ra
, "job-hold-until-default");
6076 cupsArrayAdd(ra
, "job-hold-until-supported");
6077 cupsArrayAdd(ra
, "job-priority");
6078 cupsArrayAdd(ra
, "job-priority-default");
6079 cupsArrayAdd(ra
, "job-priority-supported");
6080 cupsArrayAdd(ra
, "job-sheets");
6081 cupsArrayAdd(ra
, "job-sheets-default");
6082 cupsArrayAdd(ra
, "job-sheets-supported");
6083 cupsArrayAdd(ra
, "media");
6084 cupsArrayAdd(ra
, "media-default");
6085 cupsArrayAdd(ra
, "media-supported");
6086 cupsArrayAdd(ra
, "multiple-document-handling");
6087 cupsArrayAdd(ra
, "multiple-document-handling-default");
6088 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6089 cupsArrayAdd(ra
, "number-up");
6090 cupsArrayAdd(ra
, "number-up-default");
6091 cupsArrayAdd(ra
, "number-up-supported");
6092 cupsArrayAdd(ra
, "orientation-requested");
6093 cupsArrayAdd(ra
, "orientation-requested-default");
6094 cupsArrayAdd(ra
, "orientation-requested-supported");
6095 cupsArrayAdd(ra
, "page-ranges");
6096 cupsArrayAdd(ra
, "page-ranges-supported");
6097 cupsArrayAdd(ra
, "printer-resolution");
6098 cupsArrayAdd(ra
, "printer-resolution-default");
6099 cupsArrayAdd(ra
, "printer-resolution-supported");
6100 cupsArrayAdd(ra
, "print-quality");
6101 cupsArrayAdd(ra
, "print-quality-default");
6102 cupsArrayAdd(ra
, "print-quality-supported");
6103 cupsArrayAdd(ra
, "sides");
6104 cupsArrayAdd(ra
, "sides-default");
6105 cupsArrayAdd(ra
, "sides-supported");
6107 else if (!strcmp(value
, "job-description"))
6109 cupsArrayAdd(ra
, "date-time-at-completed");
6110 cupsArrayAdd(ra
, "date-time-at-creation");
6111 cupsArrayAdd(ra
, "date-time-at-processing");
6112 cupsArrayAdd(ra
, "job-detailed-status-message");
6113 cupsArrayAdd(ra
, "job-document-access-errors");
6114 cupsArrayAdd(ra
, "job-id");
6115 cupsArrayAdd(ra
, "job-impressions");
6116 cupsArrayAdd(ra
, "job-impressions-completed");
6117 cupsArrayAdd(ra
, "job-k-octets");
6118 cupsArrayAdd(ra
, "job-k-octets-processed");
6119 cupsArrayAdd(ra
, "job-media-progress");
6120 cupsArrayAdd(ra
, "job-media-sheets");
6121 cupsArrayAdd(ra
, "job-media-sheets-completed");
6122 cupsArrayAdd(ra
, "job-message-from-operator");
6123 cupsArrayAdd(ra
, "job-more-info");
6124 cupsArrayAdd(ra
, "job-name");
6125 cupsArrayAdd(ra
, "job-originating-user-name");
6126 cupsArrayAdd(ra
, "job-printer-up-time");
6127 cupsArrayAdd(ra
, "job-printer-uri");
6128 cupsArrayAdd(ra
, "job-state");
6129 cupsArrayAdd(ra
, "job-state-message");
6130 cupsArrayAdd(ra
, "job-state-reasons");
6131 cupsArrayAdd(ra
, "job-uri");
6132 cupsArrayAdd(ra
, "number-of-documents");
6133 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6134 cupsArrayAdd(ra
, "output-device-assigned");
6135 cupsArrayAdd(ra
, "time-at-completed");
6136 cupsArrayAdd(ra
, "time-at-creation");
6137 cupsArrayAdd(ra
, "time-at-processing");
6139 else if (!strcmp(value
, "printer-description"))
6141 cupsArrayAdd(ra
, "charset-configured");
6142 cupsArrayAdd(ra
, "charset-supported");
6143 cupsArrayAdd(ra
, "color-supported");
6144 cupsArrayAdd(ra
, "compression-supported");
6145 cupsArrayAdd(ra
, "document-format-default");
6146 cupsArrayAdd(ra
, "document-format-supported");
6147 cupsArrayAdd(ra
, "generated-natural-language-supported");
6148 cupsArrayAdd(ra
, "ipp-versions-supported");
6149 cupsArrayAdd(ra
, "job-impressions-supported");
6150 cupsArrayAdd(ra
, "job-k-octets-supported");
6151 cupsArrayAdd(ra
, "job-media-sheets-supported");
6152 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6153 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6154 cupsArrayAdd(ra
, "multiple-operation-time-out");
6155 cupsArrayAdd(ra
, "natural-language-configured");
6156 cupsArrayAdd(ra
, "notify-attributes-supported");
6157 cupsArrayAdd(ra
, "notify-lease-duration-default");
6158 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6159 cupsArrayAdd(ra
, "notify-max-events-supported");
6160 cupsArrayAdd(ra
, "notify-events-default");
6161 cupsArrayAdd(ra
, "notify-events-supported");
6162 cupsArrayAdd(ra
, "notify-pull-method-supported");
6163 cupsArrayAdd(ra
, "notify-schemes-supported");
6164 cupsArrayAdd(ra
, "operations-supported");
6165 cupsArrayAdd(ra
, "pages-per-minute");
6166 cupsArrayAdd(ra
, "pages-per-minute-color");
6167 cupsArrayAdd(ra
, "pdl-override-supported");
6168 cupsArrayAdd(ra
, "printer-alert");
6169 cupsArrayAdd(ra
, "printer-alert-description");
6170 cupsArrayAdd(ra
, "printer-commands");
6171 cupsArrayAdd(ra
, "printer-current-time");
6172 cupsArrayAdd(ra
, "printer-driver-installer");
6173 cupsArrayAdd(ra
, "printer-dns-sd-name");
6174 cupsArrayAdd(ra
, "printer-info");
6175 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6176 cupsArrayAdd(ra
, "printer-location");
6177 cupsArrayAdd(ra
, "printer-make-and-model");
6178 cupsArrayAdd(ra
, "printer-message-from-operator");
6179 cupsArrayAdd(ra
, "printer-more-info");
6180 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6181 cupsArrayAdd(ra
, "printer-name");
6182 cupsArrayAdd(ra
, "printer-state");
6183 cupsArrayAdd(ra
, "printer-state-message");
6184 cupsArrayAdd(ra
, "printer-state-reasons");
6185 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6186 cupsArrayAdd(ra
, "printer-type");
6187 cupsArrayAdd(ra
, "printer-up-time");
6188 cupsArrayAdd(ra
, "printer-uri-supported");
6189 cupsArrayAdd(ra
, "queued-job-count");
6190 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6191 cupsArrayAdd(ra
, "uri-authentication-supported");
6192 cupsArrayAdd(ra
, "uri-security-supported");
6194 else if (!strcmp(value
, "printer-defaults"))
6196 char *name
; /* Option name */
6199 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6201 name
= (char *)cupsArrayNext(CommonDefaults
))
6202 cupsArrayAdd(ra
, name
);
6204 else if (!strcmp(value
, "subscription-template"))
6206 cupsArrayAdd(ra
, "notify-attributes");
6207 cupsArrayAdd(ra
, "notify-charset");
6208 cupsArrayAdd(ra
, "notify-events");
6209 cupsArrayAdd(ra
, "notify-lease-duration");
6210 cupsArrayAdd(ra
, "notify-natural-language");
6211 cupsArrayAdd(ra
, "notify-pull-method");
6212 cupsArrayAdd(ra
, "notify-recipient-uri");
6213 cupsArrayAdd(ra
, "notify-time-interval");
6214 cupsArrayAdd(ra
, "notify-user-data");
6217 cupsArrayAdd(ra
, value
);
6225 * 'create_subscription()' - Create a notification subscription.
6229 create_subscription(
6230 cupsd_client_t
*con
, /* I - Client connection */
6231 ipp_attribute_t
*uri
) /* I - Printer URI */
6233 http_status_t status
; /* Policy status */
6234 int i
; /* Looping var */
6235 ipp_attribute_t
*attr
; /* Current attribute */
6236 cups_ptype_t dtype
; /* Destination type (printer/class) */
6237 char scheme
[HTTP_MAX_URI
],
6238 /* Scheme portion of URI */
6239 userpass
[HTTP_MAX_URI
],
6240 /* Username portion of URI */
6242 /* Host portion of URI */
6243 resource
[HTTP_MAX_URI
];
6244 /* Resource portion of URI */
6245 int port
; /* Port portion of URI */
6246 cupsd_printer_t
*printer
; /* Printer/class */
6247 cupsd_job_t
*job
; /* Job */
6248 int jobid
; /* Job ID */
6249 cupsd_subscription_t
*sub
; /* Subscription object */
6250 const char *username
, /* requesting-user-name or
6251 authenticated username */
6252 *recipient
, /* notify-recipient-uri */
6253 *pullmethod
; /* notify-pull-method */
6254 ipp_attribute_t
*user_data
; /* notify-user-data */
6255 int interval
, /* notify-time-interval */
6256 lease
; /* notify-lease-duration */
6257 unsigned mask
; /* notify-events */
6258 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6259 *notify_lease
; /* notify-lease-duration(-default) */
6263 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6265 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6266 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6267 attr
->value_tag
, attr
->name
);
6269 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6274 * Is the destination valid?
6277 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6278 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6279 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6281 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6282 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6283 sizeof(host
), &port
, resource
, sizeof(resource
));
6285 if (!strcmp(resource
, "/"))
6287 dtype
= (cups_ptype_t
)0;
6290 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6292 dtype
= (cups_ptype_t
)0;
6295 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6297 dtype
= CUPS_PRINTER_CLASS
;
6300 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6306 send_ipp_status(con
, IPP_NOT_FOUND
,
6307 _("The printer or class was not found."));
6317 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6320 send_http_error(con
, status
, printer
);
6324 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6326 send_http_error(con
, status
, NULL
);
6331 * Get the user that is requesting the subscription...
6334 username
= get_username(con
);
6337 * Find the first subscription group attribute; return if we have
6341 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6342 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6347 send_ipp_status(con
, IPP_BAD_REQUEST
,
6348 _("No subscription attributes in request"));
6353 * Process the subscription attributes in the request...
6356 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6364 lease
= DefaultLeaseDuration
;
6366 mask
= CUPSD_EVENT_NONE
;
6370 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6372 notify_lease
= ippFindAttribute(printer
->attrs
,
6373 "notify-lease-duration-default",
6377 lease
= notify_lease
->values
[0].integer
;
6381 notify_events
= NULL
;
6382 notify_lease
= NULL
;
6385 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6387 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6388 attr
->value_tag
== IPP_TAG_URI
)
6391 * Validate the recipient scheme against the ServerBin/notifier
6395 char notifier
[1024]; /* Notifier filename */
6398 recipient
= attr
->values
[0].string
.text
;
6400 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6401 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6402 host
, sizeof(host
), &port
,
6403 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6405 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6406 _("Bad notify-recipient-uri URI \"%s\""), recipient
);
6407 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6408 "notify-status-code", IPP_URI_SCHEME
);
6412 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6414 if (access(notifier
, X_OK
))
6416 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6417 _("notify-recipient-uri URI \"%s\" uses unknown "
6418 "scheme"), recipient
);
6419 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6420 "notify-status-code", IPP_URI_SCHEME
);
6424 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6426 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6427 _("notify-recipient-uri URI \"%s\" is already used"),
6429 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6430 "notify-status-code", IPP_ATTRIBUTES
);
6434 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6435 attr
->value_tag
== IPP_TAG_KEYWORD
)
6437 pullmethod
= attr
->values
[0].string
.text
;
6439 if (strcmp(pullmethod
, "ippget"))
6441 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6442 _("Bad notify-pull-method \"%s\""), pullmethod
);
6443 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6444 "notify-status-code", IPP_ATTRIBUTES
);
6448 else if (!strcmp(attr
->name
, "notify-charset") &&
6449 attr
->value_tag
== IPP_TAG_CHARSET
&&
6450 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6451 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6453 send_ipp_status(con
, IPP_CHARSET
,
6454 _("Character set \"%s\" not supported"),
6455 attr
->values
[0].string
.text
);
6458 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6459 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6460 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6462 send_ipp_status(con
, IPP_CHARSET
,
6463 _("Language \"%s\" not supported"),
6464 attr
->values
[0].string
.text
);
6467 else if (!strcmp(attr
->name
, "notify-user-data") &&
6468 attr
->value_tag
== IPP_TAG_STRING
)
6470 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6472 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6473 _("The notify-user-data value is too large "
6474 "(%d > 63 octets)"),
6475 attr
->values
[0].unknown
.length
);
6481 else if (!strcmp(attr
->name
, "notify-events") &&
6482 attr
->value_tag
== IPP_TAG_KEYWORD
)
6483 notify_events
= attr
;
6484 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6485 attr
->value_tag
== IPP_TAG_INTEGER
)
6486 lease
= attr
->values
[0].integer
;
6487 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6488 attr
->value_tag
== IPP_TAG_INTEGER
)
6489 interval
= attr
->values
[0].integer
;
6490 else if (!strcmp(attr
->name
, "notify-job-id") &&
6491 attr
->value_tag
== IPP_TAG_INTEGER
)
6492 jobid
= attr
->values
[0].integer
;
6499 for (i
= 0; i
< notify_events
->num_values
; i
++)
6500 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6504 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6506 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6507 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6508 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6510 if (!recipient
&& !pullmethod
)
6513 if (mask
== CUPSD_EVENT_NONE
)
6516 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6518 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6521 send_ipp_status(con
, IPP_BAD_REQUEST
,
6522 _("notify-events not specified"));
6527 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6529 cupsdLogMessage(CUPSD_LOG_INFO
,
6530 "create_subscription: Limiting notify-lease-duration to "
6533 lease
= MaxLeaseDuration
;
6538 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6540 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found"), jobid
);
6547 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6549 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6550 _("There are too many subscriptions."));
6555 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6558 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6559 "Added subscription %d for printer \"%s\"",
6560 sub
->id
, printer
->name
);
6562 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6565 sub
->interval
= interval
;
6567 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6569 cupsdSetString(&sub
->owner
, username
);
6573 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6574 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6575 sub
->user_data_len
);
6578 ippAddSeparator(con
->response
);
6579 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6580 "notify-subscription-id", sub
->id
);
6582 con
->response
->request
.status
.status_code
= IPP_OK
;
6588 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6593 * 'delete_printer()' - Remove a printer or class from the system.
6597 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6598 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6600 http_status_t status
; /* Policy status */
6601 cups_ptype_t dtype
; /* Destination type (printer/class) */
6602 cupsd_printer_t
*printer
; /* Printer/class */
6603 char filename
[1024]; /* Script/PPD filename */
6606 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6607 con
->http
.fd
, uri
->values
[0].string
.text
);
6610 * Do we have a valid URI?
6613 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6619 send_ipp_status(con
, IPP_NOT_FOUND
,
6620 _("The printer or class was not found."));
6628 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6630 send_http_error(con
, status
, NULL
);
6635 * Remove old jobs...
6638 cupsdCancelJobs(printer
->name
, NULL
, 1);
6641 * Remove old subscriptions and send a "deleted printer" event...
6644 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6645 "%s \"%s\" deleted by \"%s\".",
6646 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6647 printer
->name
, get_username(con
));
6649 cupsdExpireSubscriptions(printer
, NULL
);
6652 * Remove any old PPD or script files...
6655 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6659 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6663 snprintf(filename
, sizeof(filename
), "%s/%s.ipp2", CacheDir
, printer
->name
);
6666 snprintf(filename
, sizeof(filename
), "%s/%s.pwg", CacheDir
, printer
->name
);
6671 * Unregister color profiles...
6674 apple_unregister_profiles(printer
);
6675 #endif /* __APPLE__ */
6677 if (dtype
& CUPS_PRINTER_CLASS
)
6679 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6680 printer
->name
, get_username(con
));
6682 cupsdDeletePrinter(printer
, 0);
6683 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6687 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6688 printer
->name
, get_username(con
));
6690 if (cupsdDeletePrinter(printer
, 0))
6691 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6693 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6696 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6699 * Return with no errors...
6702 con
->response
->request
.status
.status_code
= IPP_OK
;
6707 * 'get_default()' - Get the default destination.
6711 get_default(cupsd_client_t
*con
) /* I - Client connection */
6713 http_status_t status
; /* Policy status */
6714 cups_array_t
*ra
; /* Requested attributes array */
6717 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6723 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6725 send_http_error(con
, status
, NULL
);
6731 ra
= create_requested_array(con
->request
);
6733 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6735 cupsArrayDelete(ra
);
6737 con
->response
->request
.status
.status_code
= IPP_OK
;
6740 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6745 * 'get_devices()' - Get the list of available devices on the local system.
6749 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6751 http_status_t status
; /* Policy status */
6752 ipp_attribute_t
*limit
, /* limit attribute */
6753 *timeout
, /* timeout attribute */
6754 *requested
, /* requested-attributes attribute */
6755 *exclude
, /* exclude-schemes attribute */
6756 *include
; /* include-schemes attribute */
6757 char command
[1024], /* cups-deviced command */
6758 options
[2048], /* Options to pass to command */
6760 /* String for requested attributes */
6762 /* String for excluded schemes */
6764 /* String for included schemes */
6767 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6773 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6775 send_http_error(con
, status
, NULL
);
6780 * Run cups-deviced command with the given options...
6783 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6784 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6785 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6787 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6788 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6791 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6793 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6796 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6798 exclude_str
[0] = '\0';
6801 url_encode_attr(include
, include_str
, sizeof(include_str
));
6803 include_str
[0] = '\0';
6805 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6806 snprintf(options
, sizeof(options
),
6807 "%d+%d+%d+%d+%s%s%s%s%s",
6808 con
->request
->request
.op
.request_id
,
6809 limit
? limit
->values
[0].integer
: 0,
6810 timeout
? timeout
->values
[0].integer
: 15,
6813 exclude_str
[0] ? "%20" : "", exclude_str
,
6814 include_str
[0] ? "%20" : "", include_str
);
6816 if (cupsdSendCommand(con
, command
, options
, 1))
6819 * Command started successfully, don't send an IPP response here...
6822 ippDelete(con
->response
);
6823 con
->response
= NULL
;
6828 * Command failed, return "internal error" so the user knows something
6832 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6833 _("cups-deviced failed to execute."));
6839 * 'get_document()' - Get a copy of a job file.
6843 get_document(cupsd_client_t
*con
, /* I - Client connection */
6844 ipp_attribute_t
*uri
) /* I - Job URI */
6846 http_status_t status
; /* Policy status */
6847 ipp_attribute_t
*attr
; /* Current attribute */
6848 int jobid
; /* Job ID */
6849 int docnum
; /* Document number */
6850 cupsd_job_t
*job
; /* Current job */
6851 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6852 username
[HTTP_MAX_URI
], /* Username portion of URI */
6853 host
[HTTP_MAX_URI
], /* Host portion of URI */
6854 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6855 int port
; /* Port portion of URI */
6856 char filename
[1024], /* Filename for document */
6857 format
[1024]; /* Format for document */
6860 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6861 con
->http
.fd
, uri
->values
[0].string
.text
);
6864 * See if we have a job URI or a printer URI...
6867 if (!strcmp(uri
->name
, "printer-uri"))
6870 * Got a printer URI; see if we also have a job-id attribute...
6873 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6874 IPP_TAG_INTEGER
)) == NULL
)
6876 send_ipp_status(con
, IPP_BAD_REQUEST
,
6877 _("Got a printer-uri attribute but no job-id"));
6881 jobid
= attr
->values
[0].integer
;
6886 * Got a job URI; parse it to get the job ID...
6889 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6890 sizeof(scheme
), username
, sizeof(username
), host
,
6891 sizeof(host
), &port
, resource
, sizeof(resource
));
6893 if (strncmp(resource
, "/jobs/", 6))
6899 send_ipp_status(con
, IPP_BAD_REQUEST
,
6900 _("Bad job-uri attribute \"%s\""),
6901 uri
->values
[0].string
.text
);
6905 jobid
= atoi(resource
+ 6);
6909 * See if the job exists...
6912 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6915 * Nope - return a "not found" error...
6918 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
6926 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6928 send_http_error(con
, status
, NULL
);
6933 * Get the document number...
6936 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6937 IPP_TAG_INTEGER
)) == NULL
)
6939 send_ipp_status(con
, IPP_BAD_REQUEST
,
6940 _("Missing document-number attribute"));
6944 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6945 attr
->num_values
> 1)
6947 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6952 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6954 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6956 cupsdLogMessage(CUPSD_LOG_ERROR
,
6957 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6959 send_ipp_status(con
, IPP_NOT_FOUND
,
6960 _("Unable to open document %d in job %d"), docnum
, jobid
);
6964 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6968 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6969 job
->filetypes
[docnum
- 1]->type
);
6971 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6973 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6975 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6976 IPP_TAG_NAME
)) != NULL
)
6977 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6978 NULL
, attr
->values
[0].string
.text
);
6983 * 'get_job_attrs()' - Get job attributes.
6987 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6988 ipp_attribute_t
*uri
) /* I - Job URI */
6990 http_status_t status
; /* Policy status */
6991 ipp_attribute_t
*attr
; /* Current attribute */
6992 int jobid
; /* Job ID */
6993 cupsd_job_t
*job
; /* Current job */
6994 cupsd_printer_t
*printer
; /* Current printer */
6995 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6996 username
[HTTP_MAX_URI
], /* Username portion of URI */
6997 host
[HTTP_MAX_URI
], /* Host portion of URI */
6998 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6999 int port
; /* Port portion of URI */
7000 cups_array_t
*ra
; /* Requested attributes array */
7003 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7004 con
->http
.fd
, uri
->values
[0].string
.text
);
7007 * See if we have a job URI or a printer URI...
7010 if (!strcmp(uri
->name
, "printer-uri"))
7013 * Got a printer URI; see if we also have a job-id attribute...
7016 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7017 IPP_TAG_INTEGER
)) == NULL
)
7019 send_ipp_status(con
, IPP_BAD_REQUEST
,
7020 _("Got a printer-uri attribute but no job-id"));
7024 jobid
= attr
->values
[0].integer
;
7029 * Got a job URI; parse it to get the job ID...
7032 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7033 sizeof(scheme
), username
, sizeof(username
), host
,
7034 sizeof(host
), &port
, resource
, sizeof(resource
));
7036 if (strncmp(resource
, "/jobs/", 6))
7042 send_ipp_status(con
, IPP_BAD_REQUEST
,
7043 _("Bad job-uri attribute \"%s\""),
7044 uri
->values
[0].string
.text
);
7048 jobid
= atoi(resource
+ 6);
7052 * See if the job exists...
7055 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7058 * Nope - return a "not found" error...
7061 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
7069 if ((printer
= job
->printer
) == NULL
)
7070 printer
= cupsdFindDest(job
->dest
);
7074 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
7077 send_http_error(con
, status
, printer
);
7081 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7083 send_http_error(con
, status
, NULL
);
7088 * Copy attributes...
7093 ra
= create_requested_array(con
->request
);
7094 copy_job_attrs(con
, job
, ra
);
7095 cupsArrayDelete(ra
);
7097 con
->response
->request
.status
.status_code
= IPP_OK
;
7102 * 'get_jobs()' - Get a list of jobs for the specified printer.
7106 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7107 ipp_attribute_t
*uri
) /* I - Printer URI */
7109 http_status_t status
; /* Policy status */
7110 ipp_attribute_t
*attr
; /* Current attribute */
7111 const char *dest
; /* Destination */
7112 cups_ptype_t dtype
; /* Destination type (printer/class) */
7113 cups_ptype_t dmask
; /* Destination type mask */
7114 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7115 username
[HTTP_MAX_URI
], /* Username portion of URI */
7116 host
[HTTP_MAX_URI
], /* Host portion of URI */
7117 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7118 int port
; /* Port portion of URI */
7119 int job_comparison
; /* Job comparison */
7120 ipp_jstate_t job_state
; /* job-state value */
7121 int first_job_id
; /* First job ID */
7122 int limit
; /* Maximum number of jobs to return */
7123 int count
; /* Number of jobs that match */
7124 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7125 cupsd_job_t
*job
; /* Current job pointer */
7126 cupsd_printer_t
*printer
; /* Printer */
7127 cups_array_t
*list
; /* Which job list... */
7128 cups_array_t
*ra
; /* Requested attributes array */
7131 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7132 uri
->values
[0].string
.text
);
7135 * Is the destination valid?
7138 if (strcmp(uri
->name
, "printer-uri"))
7140 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request"));
7144 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7145 sizeof(scheme
), username
, sizeof(username
), host
,
7146 sizeof(host
), &port
, resource
, sizeof(resource
));
7148 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7151 dtype
= (cups_ptype_t
)0;
7152 dmask
= (cups_ptype_t
)0;
7155 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7158 dtype
= (cups_ptype_t
)0;
7159 dmask
= CUPS_PRINTER_CLASS
;
7162 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7165 dtype
= CUPS_PRINTER_CLASS
;
7166 dmask
= CUPS_PRINTER_CLASS
;
7169 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7176 send_ipp_status(con
, IPP_NOT_FOUND
,
7177 _("The printer or class was not found."));
7182 dtype
&= CUPS_PRINTER_CLASS
;
7183 dmask
= CUPS_PRINTER_CLASS
;
7192 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
7195 send_http_error(con
, status
, printer
);
7199 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7201 send_http_error(con
, status
, NULL
);
7205 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7208 * See if the "which-jobs" attribute have been specified...
7211 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7212 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7214 send_ipp_status(con
, IPP_CONFLICT
,
7215 _("The %s attribute cannot be provided with job-ids."),
7219 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7221 job_comparison
= -1;
7222 job_state
= IPP_JOB_STOPPED
;
7225 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7228 job_state
= IPP_JOB_CANCELED
;
7231 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7234 job_state
= IPP_JOB_ABORTED
;
7237 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7240 job_state
= IPP_JOB_PENDING
;
7243 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7246 job_state
= IPP_JOB_CANCELED
;
7249 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7252 job_state
= IPP_JOB_PENDING
;
7255 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7258 job_state
= IPP_JOB_HELD
;
7261 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7264 job_state
= IPP_JOB_PROCESSING
;
7265 list
= PrintingJobs
;
7267 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7270 job_state
= IPP_JOB_STOPPED
;
7275 send_ipp_status(con
, IPP_ATTRIBUTES
,
7276 _("The which-jobs value \"%s\" is not supported."),
7277 attr
->values
[0].string
.text
);
7278 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7279 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7284 * See if they want to limit the number of jobs reported...
7287 if ((attr
= ippFindAttribute(con
->request
, "limit",
7288 IPP_TAG_INTEGER
)) != NULL
)
7292 send_ipp_status(con
, IPP_CONFLICT
,
7293 _("The %s attribute cannot be provided with job-ids."),
7298 limit
= attr
->values
[0].integer
;
7303 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7304 IPP_TAG_INTEGER
)) != NULL
)
7308 send_ipp_status(con
, IPP_CONFLICT
,
7309 _("The %s attribute cannot be provided with job-ids."),
7314 first_job_id
= attr
->values
[0].integer
;
7320 * See if we only want to see jobs for a specific user...
7323 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7324 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7326 send_ipp_status(con
, IPP_CONFLICT
,
7327 _("The %s attribute cannot be provided with job-ids."),
7331 else if (attr
&& attr
->values
[0].boolean
)
7332 strlcpy(username
, get_username(con
), sizeof(username
));
7336 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7337 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7340 * IPP conformance - Get-Jobs has a default requested-attributes value of
7341 * "job-id" and "job-uri".
7344 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7345 cupsArrayAdd(ra
, "job-id");
7346 cupsArrayAdd(ra
, "job-uri");
7350 * OK, build a list of jobs for this printer...
7355 int i
; /* Looping var */
7357 for (i
= 0; i
< job_ids
->num_values
; i
++)
7359 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
7363 if (i
< job_ids
->num_values
)
7365 send_ipp_status(con
, IPP_NOT_FOUND
, _("job-id %d not found."),
7366 job_ids
->values
[i
].integer
);
7370 for (i
= 0; i
< job_ids
->num_values
; i
++)
7372 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7378 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7384 ippAddSeparator(con
->response
);
7386 copy_job_attrs(con
, job
, ra
);
7391 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7392 (limit
<= 0 || count
< limit
) && job
;
7393 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7396 * Filter out jobs that don't match...
7399 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7400 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7401 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7402 job
->username
, job
->state_value
, job
->attrs
);
7404 if (!job
->dest
|| !job
->username
)
7407 if (!job
->dest
|| !job
->username
)
7410 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7411 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7413 if ((job
->dtype
& dmask
) != dtype
&&
7414 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7417 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7418 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7419 (job_comparison
> 0 && job
->state_value
< job_state
))
7422 if (job
->id
< first_job_id
)
7429 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7434 if (username
[0] && strcasecmp(username
, job
->username
))
7438 ippAddSeparator(con
->response
);
7442 copy_job_attrs(con
, job
, ra
);
7445 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7448 cupsArrayDelete(ra
);
7450 con
->response
->request
.status
.status_code
= IPP_OK
;
7455 * 'get_notifications()' - Get events for a subscription.
7459 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7461 int i
, j
; /* Looping vars */
7462 http_status_t status
; /* Policy status */
7463 cupsd_subscription_t
*sub
; /* Subscription */
7464 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7465 *sequences
; /* notify-sequence-numbers */
7466 int min_seq
; /* Minimum sequence number */
7467 int interval
; /* Poll interval */
7470 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7474 * Get subscription attributes...
7477 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7479 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7484 send_ipp_status(con
, IPP_BAD_REQUEST
,
7485 _("Missing notify-subscription-ids attribute"));
7490 * Are the subscription IDs valid?
7493 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7495 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7498 * Bad subscription ID...
7501 send_ipp_status(con
, IPP_NOT_FOUND
,
7502 _("notify-subscription-id %d no good"),
7503 ids
->values
[i
].integer
);
7511 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7513 con
, sub
->owner
)) != HTTP_OK
)
7515 send_http_error(con
, status
, sub
->dest
);
7520 * Check the subscription type and update the interval accordingly.
7523 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7526 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7528 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7534 * Tell the client to poll again in N seconds...
7538 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7539 "notify-get-interval", interval
);
7541 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7542 "printer-up-time", time(NULL
));
7545 * Copy the subscription event attributes to the response.
7548 con
->response
->request
.status
.status_code
=
7549 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7551 for (i
= 0; i
< ids
->num_values
; i
++)
7554 * Get the subscription and sequence number...
7557 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7559 if (sequences
&& i
< sequences
->num_values
)
7560 min_seq
= sequences
->values
[i
].integer
;
7565 * If we don't have any new events, nothing to do here...
7568 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7572 * Otherwise copy all of the new events...
7575 if (sub
->first_event_id
> min_seq
)
7578 j
= min_seq
- sub
->first_event_id
;
7580 for (; j
< sub
->num_events
; j
++)
7582 ippAddSeparator(con
->response
);
7584 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7585 IPP_TAG_EVENT_NOTIFICATION
, 0);
7592 * 'get_ppd()' - Get a named PPD from the local system.
7596 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7597 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7599 http_status_t status
; /* Policy status */
7600 cupsd_printer_t
*dest
; /* Destination */
7601 cups_ptype_t dtype
; /* Destination type */
7604 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7605 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7607 if (!strcmp(uri
->name
, "ppd-name"))
7610 * Return a PPD file from cups-driverd...
7613 char command
[1024], /* cups-driverd command */
7614 options
[1024], /* Options to pass to command */
7615 ppd_name
[1024]; /* ppd-name */
7622 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7624 send_http_error(con
, status
, NULL
);
7629 * Run cups-driverd command with the given options...
7632 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7633 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7634 snprintf(options
, sizeof(options
), "get+%d+%s",
7635 con
->request
->request
.op
.request_id
, ppd_name
);
7637 if (cupsdSendCommand(con
, command
, options
, 0))
7640 * Command started successfully, don't send an IPP response here...
7643 ippDelete(con
->response
);
7644 con
->response
= NULL
;
7649 * Command failed, return "internal error" so the user knows something
7653 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7654 _("cups-driverd failed to execute."));
7657 else if (!strcmp(uri
->name
, "printer-uri") &&
7658 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7660 int i
; /* Looping var */
7661 char filename
[1024]; /* PPD filename */
7668 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7670 send_http_error(con
, status
, dest
);
7675 * See if we need the PPD for a class or remote printer...
7678 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7681 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7683 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7684 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7685 "printer-uri", NULL
, dest
->uri
);
7688 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7690 for (i
= 0; i
< dest
->num_printers
; i
++)
7691 if (!(dest
->printers
[i
]->type
&
7692 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7694 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7695 dest
->printers
[i
]->name
);
7697 if (!access(filename
, 0))
7701 if (i
< dest
->num_printers
)
7702 dest
= dest
->printers
[i
];
7705 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7706 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7707 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7713 * Found the printer with the PPD file, now see if there is one...
7716 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7718 send_ipp_status(con
, IPP_NOT_FOUND
,
7719 _("The PPD file \"%s\" could not be opened: %s"),
7720 uri
->values
[0].string
.text
, strerror(errno
));
7724 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7728 con
->response
->request
.status
.status_code
= IPP_OK
;
7731 send_ipp_status(con
, IPP_NOT_FOUND
,
7732 _("The PPD file \"%s\" could not be found."),
7733 uri
->values
[0].string
.text
);
7738 * 'get_ppds()' - Get the list of PPD files on the local system.
7742 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7744 http_status_t status
; /* Policy status */
7745 ipp_attribute_t
*limit
, /* Limit attribute */
7746 *device
, /* ppd-device-id attribute */
7747 *language
, /* ppd-natural-language attribute */
7748 *make
, /* ppd-make attribute */
7749 *model
, /* ppd-make-and-model attribute */
7750 *model_number
, /* ppd-model-number attribute */
7751 *product
, /* ppd-product attribute */
7752 *psversion
, /* ppd-psverion attribute */
7753 *type
, /* ppd-type attribute */
7754 *requested
, /* requested-attributes attribute */
7755 *exclude
, /* exclude-schemes attribute */
7756 *include
; /* include-schemes attribute */
7757 char command
[1024], /* cups-driverd command */
7758 options
[4096], /* Options to pass to command */
7759 device_str
[256],/* Escaped ppd-device-id string */
7761 /* Escaped ppd-natural-language */
7762 make_str
[256], /* Escaped ppd-make string */
7763 model_str
[256], /* Escaped ppd-make-and-model string */
7764 model_number_str
[256],
7765 /* ppd-model-number string */
7767 /* Escaped ppd-product string */
7769 /* Escaped ppd-psversion string */
7770 type_str
[256], /* Escaped ppd-type string */
7772 /* String for requested attributes */
7774 /* String for excluded schemes */
7776 /* String for included schemes */
7779 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7785 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7787 send_http_error(con
, status
, NULL
);
7792 * Run cups-driverd command with the given options...
7795 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7796 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7797 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7799 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7800 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7802 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7804 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7805 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7806 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7807 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7809 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7811 include
= ippFindAttribute(con
->request
, "include-schemes",
7815 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7817 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7820 url_encode_attr(device
, device_str
, sizeof(device_str
));
7822 device_str
[0] = '\0';
7825 url_encode_attr(language
, language_str
, sizeof(language_str
));
7827 language_str
[0] = '\0';
7830 url_encode_attr(make
, make_str
, sizeof(make_str
));
7835 url_encode_attr(model
, model_str
, sizeof(model_str
));
7837 model_str
[0] = '\0';
7840 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7841 model_number
->values
[0].integer
);
7843 model_number_str
[0] = '\0';
7846 url_encode_attr(product
, product_str
, sizeof(product_str
));
7848 product_str
[0] = '\0';
7851 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7853 psversion_str
[0] = '\0';
7856 url_encode_attr(type
, type_str
, sizeof(type_str
));
7861 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7863 exclude_str
[0] = '\0';
7866 url_encode_attr(include
, include_str
, sizeof(include_str
));
7868 include_str
[0] = '\0';
7870 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7871 snprintf(options
, sizeof(options
),
7872 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7873 con
->request
->request
.op
.request_id
,
7874 limit
? limit
->values
[0].integer
: 0,
7876 device
? "%20" : "", device_str
,
7877 language
? "%20" : "", language_str
,
7878 make
? "%20" : "", make_str
,
7879 model
? "%20" : "", model_str
,
7880 model_number
? "%20" : "", model_number_str
,
7881 product
? "%20" : "", product_str
,
7882 psversion
? "%20" : "", psversion_str
,
7883 type
? "%20" : "", type_str
,
7884 exclude_str
[0] ? "%20" : "", exclude_str
,
7885 include_str
[0] ? "%20" : "", include_str
);
7887 if (cupsdSendCommand(con
, command
, options
, 0))
7890 * Command started successfully, don't send an IPP response here...
7893 ippDelete(con
->response
);
7894 con
->response
= NULL
;
7899 * Command failed, return "internal error" so the user knows something
7903 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7904 _("cups-driverd failed to execute."));
7910 * 'get_printer_attrs()' - Get printer attributes.
7914 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7915 ipp_attribute_t
*uri
) /* I - Printer URI */
7917 http_status_t status
; /* Policy status */
7918 cups_ptype_t dtype
; /* Destination type (printer/class) */
7919 cupsd_printer_t
*printer
; /* Printer/class */
7920 cups_array_t
*ra
; /* Requested attributes array */
7923 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7924 con
->http
.fd
, uri
->values
[0].string
.text
);
7927 * Is the destination valid?
7930 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7936 send_ipp_status(con
, IPP_NOT_FOUND
,
7937 _("The printer or class was not found."));
7945 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7947 send_http_error(con
, status
, printer
);
7952 * Send the attributes...
7955 ra
= create_requested_array(con
->request
);
7957 copy_printer_attrs(con
, printer
, ra
);
7959 cupsArrayDelete(ra
);
7961 con
->response
->request
.status
.status_code
= IPP_OK
;
7966 * 'get_printer_supported()' - Get printer supported values.
7970 get_printer_supported(
7971 cupsd_client_t
*con
, /* I - Client connection */
7972 ipp_attribute_t
*uri
) /* I - Printer URI */
7974 http_status_t status
; /* Policy status */
7975 cups_ptype_t dtype
; /* Destination type (printer/class) */
7976 cupsd_printer_t
*printer
; /* Printer/class */
7979 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7980 con
->http
.fd
, uri
->values
[0].string
.text
);
7983 * Is the destination valid?
7986 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7992 send_ipp_status(con
, IPP_NOT_FOUND
,
7993 _("The printer or class was not found."));
8001 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8003 send_http_error(con
, status
, printer
);
8008 * Return a list of attributes that can be set via Set-Printer-Attributes.
8011 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8013 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8014 "printer-location", 0);
8016 con
->response
->request
.status
.status_code
= IPP_OK
;
8021 * 'get_printers()' - Get a list of printers or classes.
8025 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8026 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8028 http_status_t status
; /* Policy status */
8029 ipp_attribute_t
*attr
; /* Current attribute */
8030 int limit
; /* Max number of printers to return */
8031 int count
; /* Number of printers that match */
8032 cupsd_printer_t
*printer
; /* Current printer pointer */
8033 int printer_type
, /* printer-type attribute */
8034 printer_mask
; /* printer-type-mask attribute */
8035 char *location
; /* Location string */
8036 const char *username
; /* Current user */
8037 char *first_printer_name
; /* first-printer-name attribute */
8038 cups_array_t
*ra
; /* Requested attributes array */
8039 int local
; /* Local connection? */
8042 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8043 con
->http
.fd
, type
);
8049 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8051 send_http_error(con
, status
, NULL
);
8056 * Check for printers...
8059 if (!Printers
|| !cupsArrayCount(Printers
))
8061 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8066 * See if they want to limit the number of printers reported...
8069 if ((attr
= ippFindAttribute(con
->request
, "limit",
8070 IPP_TAG_INTEGER
)) != NULL
)
8071 limit
= attr
->values
[0].integer
;
8075 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8076 IPP_TAG_NAME
)) != NULL
)
8077 first_printer_name
= attr
->values
[0].string
.text
;
8079 first_printer_name
= NULL
;
8082 * Support filtering...
8085 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8086 IPP_TAG_ENUM
)) != NULL
)
8087 printer_type
= attr
->values
[0].integer
;
8091 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8092 IPP_TAG_ENUM
)) != NULL
)
8093 printer_mask
= attr
->values
[0].integer
;
8097 local
= httpAddrLocalhost(&(con
->clientaddr
));
8099 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8100 IPP_TAG_TEXT
)) != NULL
)
8101 location
= attr
->values
[0].string
.text
;
8105 if (con
->username
[0])
8106 username
= con
->username
;
8107 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8108 IPP_TAG_NAME
)) != NULL
)
8109 username
= attr
->values
[0].string
.text
;
8113 ra
= create_requested_array(con
->request
);
8116 * OK, build a list of printers for this printer...
8119 if (first_printer_name
)
8121 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8122 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8125 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8128 count
< limit
&& printer
;
8129 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8131 if (!local
&& !printer
->shared
)
8134 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8135 (printer
->type
& printer_mask
) == printer_type
&&
8137 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
8140 * If HideImplicitMembers is enabled, see if this printer or class
8141 * is a member of an implicit class...
8144 if (ImplicitClasses
&& HideImplicitMembers
&&
8145 printer
->in_implicit_class
)
8149 * If a username is specified, see if it is allowed or denied
8153 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
8157 * Add the group separator as needed...
8161 ippAddSeparator(con
->response
);
8166 * Send the attributes...
8169 copy_printer_attrs(con
, printer
, ra
);
8173 cupsArrayDelete(ra
);
8175 con
->response
->request
.status
.status_code
= IPP_OK
;
8180 * 'get_subscription_attrs()' - Get subscription attributes.
8184 get_subscription_attrs(
8185 cupsd_client_t
*con
, /* I - Client connection */
8186 int sub_id
) /* I - Subscription ID */
8188 http_status_t status
; /* Policy status */
8189 cupsd_subscription_t
*sub
; /* Subscription */
8190 cups_array_t
*ra
; /* Requested attributes array */
8193 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8194 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8195 con
, con
->http
.fd
, sub_id
);
8198 * Is the subscription ID valid?
8201 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8204 * Bad subscription ID...
8207 send_ipp_status(con
, IPP_NOT_FOUND
,
8208 _("notify-subscription-id %d no good"), sub_id
);
8216 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8218 con
, sub
->owner
)) != HTTP_OK
)
8220 send_http_error(con
, status
, sub
->dest
);
8225 * Copy the subscription attributes to the response using the
8226 * requested-attributes attribute that may be provided by the client.
8229 ra
= create_requested_array(con
->request
);
8231 copy_subscription_attrs(con
, sub
, ra
);
8233 cupsArrayDelete(ra
);
8235 con
->response
->request
.status
.status_code
= IPP_OK
;
8240 * 'get_subscriptions()' - Get subscriptions.
8244 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8245 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8247 http_status_t status
; /* Policy status */
8248 int count
; /* Number of subscriptions */
8249 int limit
; /* Limit */
8250 cupsd_subscription_t
*sub
; /* Subscription */
8251 cups_array_t
*ra
; /* Requested attributes array */
8252 ipp_attribute_t
*attr
; /* Attribute */
8253 cups_ptype_t dtype
; /* Destination type (printer/class) */
8254 char scheme
[HTTP_MAX_URI
],
8255 /* Scheme portion of URI */
8256 username
[HTTP_MAX_URI
],
8257 /* Username portion of URI */
8259 /* Host portion of URI */
8260 resource
[HTTP_MAX_URI
];
8261 /* Resource portion of URI */
8262 int port
; /* Port portion of URI */
8263 cupsd_job_t
*job
; /* Job pointer */
8264 cupsd_printer_t
*printer
; /* Printer */
8267 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8268 "get_subscriptions(con=%p[%d], uri=%s)",
8269 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8272 * Is the destination valid?
8275 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8276 sizeof(scheme
), username
, sizeof(username
), host
,
8277 sizeof(host
), &port
, resource
, sizeof(resource
));
8279 if (!strcmp(resource
, "/") ||
8280 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8281 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8282 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8287 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8290 job
= cupsdFindJob(atoi(resource
+ 6));
8294 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist"),
8299 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8305 send_ipp_status(con
, IPP_NOT_FOUND
,
8306 _("The printer or class was not found."));
8309 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8310 IPP_TAG_INTEGER
)) != NULL
)
8312 job
= cupsdFindJob(attr
->values
[0].integer
);
8316 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"),
8317 attr
->values
[0].integer
);
8328 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
8330 con
, NULL
)) != HTTP_OK
)
8332 send_http_error(con
, status
, printer
);
8337 * Copy the subscription attributes to the response using the
8338 * requested-attributes attribute that may be provided by the client.
8341 ra
= create_requested_array(con
->request
);
8343 if ((attr
= ippFindAttribute(con
->request
, "limit",
8344 IPP_TAG_INTEGER
)) != NULL
)
8345 limit
= attr
->values
[0].integer
;
8350 * See if we only want to see subscriptions for a specific user...
8353 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8354 IPP_TAG_BOOLEAN
)) != NULL
&&
8355 attr
->values
[0].boolean
)
8356 strlcpy(username
, get_username(con
), sizeof(username
));
8360 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8362 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8363 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8364 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
8366 ippAddSeparator(con
->response
);
8367 copy_subscription_attrs(con
, sub
, ra
);
8370 if (limit
&& count
>= limit
)
8374 cupsArrayDelete(ra
);
8377 con
->response
->request
.status
.status_code
= IPP_OK
;
8379 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8384 * 'get_username()' - Get the username associated with a request.
8387 static const char * /* O - Username */
8388 get_username(cupsd_client_t
*con
) /* I - Connection */
8390 ipp_attribute_t
*attr
; /* Attribute */
8393 if (con
->username
[0])
8394 return (con
->username
);
8395 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8396 IPP_TAG_NAME
)) != NULL
)
8397 return (attr
->values
[0].string
.text
);
8399 return ("anonymous");
8404 * 'hold_job()' - Hold a print job.
8408 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8409 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8411 ipp_attribute_t
*attr
; /* Current job-hold-until */
8412 const char *when
; /* New value */
8413 int jobid
; /* Job ID */
8414 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8415 username
[HTTP_MAX_URI
], /* Username portion of URI */
8416 host
[HTTP_MAX_URI
], /* Host portion of URI */
8417 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8418 int port
; /* Port portion of URI */
8419 cupsd_job_t
*job
; /* Job information */
8422 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8423 uri
->values
[0].string
.text
);
8426 * See if we have a job URI or a printer URI...
8429 if (!strcmp(uri
->name
, "printer-uri"))
8432 * Got a printer URI; see if we also have a job-id attribute...
8435 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8436 IPP_TAG_INTEGER
)) == NULL
)
8438 send_ipp_status(con
, IPP_BAD_REQUEST
,
8439 _("Got a printer-uri attribute but no job-id"));
8443 jobid
= attr
->values
[0].integer
;
8448 * Got a job URI; parse it to get the job ID...
8451 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8452 sizeof(scheme
), username
, sizeof(username
), host
,
8453 sizeof(host
), &port
, resource
, sizeof(resource
));
8455 if (strncmp(resource
, "/jobs/", 6))
8461 send_ipp_status(con
, IPP_BAD_REQUEST
,
8462 _("Bad job-uri attribute \"%s\""),
8463 uri
->values
[0].string
.text
);
8467 jobid
= atoi(resource
+ 6);
8471 * See if the job exists...
8474 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8477 * Nope - return a "not found" error...
8480 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
8485 * See if the job is owned by the requesting user...
8488 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8490 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8491 cupsdFindDest(job
->dest
));
8496 * Hold the job and return...
8499 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8500 IPP_TAG_KEYWORD
)) == NULL
)
8501 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8505 when
= attr
->values
[0].string
.text
;
8507 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8508 "Job job-hold-until value changed by user.");
8511 when
= "indefinite";
8513 cupsdSetJobHoldUntil(job
, when
, 1);
8514 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8517 con
->response
->request
.status
.status_code
= IPP_OK
;
8522 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8526 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8527 ipp_attribute_t
*uri
) /* I - Printer URI */
8529 http_status_t status
; /* Policy status */
8530 cups_ptype_t dtype
; /* Destination type (printer/class) */
8531 cupsd_printer_t
*printer
; /* Printer data */
8534 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8535 con
->http
.fd
, uri
->values
[0].string
.text
);
8538 * Is the destination valid?
8541 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8547 send_ipp_status(con
, IPP_NOT_FOUND
,
8548 _("The printer or class was not found."));
8556 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8558 send_http_error(con
, status
, printer
);
8563 * Hold pending/new jobs sent to the printer...
8566 printer
->holding_new_jobs
= 1;
8568 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8569 cupsdAddPrinterHistory(printer
);
8571 if (dtype
& CUPS_PRINTER_CLASS
)
8572 cupsdLogMessage(CUPSD_LOG_INFO
,
8573 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8574 printer
->name
, get_username(con
));
8576 cupsdLogMessage(CUPSD_LOG_INFO
,
8577 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8578 printer
->name
, get_username(con
));
8581 * Everything was ok, so return OK status...
8584 con
->response
->request
.status
.status_code
= IPP_OK
;
8589 * 'move_job()' - Move a job to a new destination.
8593 move_job(cupsd_client_t
*con
, /* I - Client connection */
8594 ipp_attribute_t
*uri
) /* I - Job URI */
8596 http_status_t status
; /* Policy status */
8597 ipp_attribute_t
*attr
; /* Current attribute */
8598 int jobid
; /* Job ID */
8599 cupsd_job_t
*job
; /* Current job */
8600 const char *src
; /* Source printer/class */
8601 cups_ptype_t stype
, /* Source type (printer or class) */
8602 dtype
; /* Destination type (printer/class) */
8603 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8604 username
[HTTP_MAX_URI
], /* Username portion of URI */
8605 host
[HTTP_MAX_URI
], /* Host portion of URI */
8606 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8607 int port
; /* Port portion of URI */
8608 cupsd_printer_t
*sprinter
, /* Source printer */
8609 *dprinter
; /* Destination printer */
8612 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8613 uri
->values
[0].string
.text
);
8616 * Get the new printer or class...
8619 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8620 IPP_TAG_URI
)) == NULL
)
8623 * Need job-printer-uri...
8626 send_ipp_status(con
, IPP_BAD_REQUEST
,
8627 _("job-printer-uri attribute missing"));
8631 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8637 send_ipp_status(con
, IPP_NOT_FOUND
,
8638 _("The printer or class was not found."));
8643 * See if we have a job URI or a printer URI...
8646 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8647 sizeof(scheme
), username
, sizeof(username
), host
,
8648 sizeof(host
), &port
, resource
, sizeof(resource
));
8650 if (!strcmp(uri
->name
, "printer-uri"))
8653 * Got a printer URI; see if we also have a job-id attribute...
8656 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8657 IPP_TAG_INTEGER
)) == NULL
)
8663 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8664 &sprinter
)) == NULL
)
8670 send_ipp_status(con
, IPP_NOT_FOUND
,
8671 _("The printer or class was not found."));
8680 * Otherwise, just move a single job...
8683 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8686 * Nope - return a "not found" error...
8689 send_ipp_status(con
, IPP_NOT_FOUND
,
8690 _("Job #%d does not exist"), attr
->values
[0].integer
);
8696 * Job found, initialize source pointers...
8707 * Got a job URI; parse it to get the job ID...
8710 if (strncmp(resource
, "/jobs/", 6))
8716 send_ipp_status(con
, IPP_BAD_REQUEST
,
8717 _("Bad job-uri attribute \"%s\""),
8718 uri
->values
[0].string
.text
);
8723 * See if the job exists...
8726 jobid
= atoi(resource
+ 6);
8728 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8731 * Nope - return a "not found" error...
8734 send_ipp_status(con
, IPP_NOT_FOUND
,
8735 _("Job #%d does not exist"), jobid
);
8741 * Job found, initialize source pointers...
8750 * Check the policy of the destination printer...
8753 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8754 job
? job
->username
: NULL
)) != HTTP_OK
)
8756 send_http_error(con
, status
, dprinter
);
8761 * Now move the job or jobs...
8767 * See if the job has been completed...
8770 if (job
->state_value
> IPP_JOB_STOPPED
)
8773 * Return a "not-possible" error...
8776 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8777 _("Job #%d is finished and cannot be altered"),
8783 * See if the job is owned by the requesting user...
8786 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8788 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8789 cupsdFindDest(job
->dest
));
8794 * Move the job to a different printer or class...
8797 cupsdMoveJob(job
, dprinter
);
8802 * Got the source printer, now look through the jobs...
8805 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8807 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8810 * See if the job is pointing at the source printer or has not been
8814 if (strcasecmp(job
->dest
, src
) ||
8815 job
->state_value
> IPP_JOB_STOPPED
)
8819 * See if the job can be moved by the requesting user...
8822 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8826 * Move the job to a different printer or class...
8829 cupsdMoveJob(job
, dprinter
);
8834 * Start jobs if possible...
8840 * Return with "everything is OK" status...
8843 con
->response
->request
.status
.status_code
= IPP_OK
;
8848 * 'ppd_parse_line()' - Parse a PPD default line.
8851 static int /* O - 0 on success, -1 on failure */
8852 ppd_parse_line(const char *line
, /* I - Line */
8853 char *option
, /* O - Option name */
8854 int olen
, /* I - Size of option name */
8855 char *choice
, /* O - Choice name */
8856 int clen
) /* I - Size of choice name */
8859 * Verify this is a default option line...
8862 if (strncmp(line
, "*Default", 8))
8866 * Read the option name...
8869 for (line
+= 8, olen
--;
8870 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8881 * Skip everything else up to the colon (:)...
8884 while (*line
&& *line
!= ':')
8893 * Now grab the option choice, skipping leading whitespace...
8896 while (isspace(*line
& 255))
8900 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8911 * Return with no errors...
8919 * 'print_job()' - Print a file to a printer or class.
8923 print_job(cupsd_client_t
*con
, /* I - Client connection */
8924 ipp_attribute_t
*uri
) /* I - Printer URI */
8926 ipp_attribute_t
*attr
; /* Current attribute */
8927 ipp_attribute_t
*format
; /* Document-format attribute */
8928 const char *default_format
; /* document-format-default value */
8929 cupsd_job_t
*job
; /* New job */
8930 char filename
[1024]; /* Job filename */
8931 mime_type_t
*filetype
; /* Type of file */
8932 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8933 type
[MIME_MAX_TYPE
], /* Subtype of file */
8934 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8935 /* Textual name of mime type */
8936 cupsd_printer_t
*printer
; /* Printer data */
8937 struct stat fileinfo
; /* File information */
8938 int kbytes
; /* Size of file */
8939 int compression
; /* Document compression */
8942 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8943 uri
->values
[0].string
.text
);
8946 * Validate print file attributes, for now just document-format and
8947 * compression (CUPS only supports "none" and "gzip")...
8950 compression
= CUPS_FILE_NONE
;
8952 if ((attr
= ippFindAttribute(con
->request
, "compression",
8953 IPP_TAG_KEYWORD
)) != NULL
)
8955 if (strcmp(attr
->values
[0].string
.text
, "none")
8957 && strcmp(attr
->values
[0].string
.text
, "gzip")
8958 #endif /* HAVE_LIBZ */
8961 send_ipp_status(con
, IPP_ATTRIBUTES
,
8962 _("Unsupported compression \"%s\""),
8963 attr
->values
[0].string
.text
);
8964 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8965 "compression", NULL
, attr
->values
[0].string
.text
);
8970 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8971 compression
= CUPS_FILE_GZIP
;
8972 #endif /* HAVE_LIBZ */
8976 * Do we have a file to print?
8981 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
8986 * Is the destination valid?
8989 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8995 send_ipp_status(con
, IPP_NOT_FOUND
,
8996 _("The printer or class was not found."));
9001 * Is it a format we support?
9004 if ((format
= ippFindAttribute(con
->request
, "document-format",
9005 IPP_TAG_MIMETYPE
)) != NULL
)
9008 * Grab format from client...
9011 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9014 send_ipp_status(con
, IPP_BAD_REQUEST
,
9015 _("Bad document-format \"%s\""),
9016 format
->values
[0].string
.text
);
9020 else if ((default_format
= cupsGetOption("document-format",
9021 printer
->num_options
,
9022 printer
->options
)) != NULL
)
9025 * Use default document format...
9028 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9030 send_ipp_status(con
, IPP_BAD_REQUEST
,
9031 _("Bad document-format \"%s\""),
9042 strcpy(super
, "application");
9043 strcpy(type
, "octet-stream");
9046 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9049 * Auto-type the file...
9052 ipp_attribute_t
*doc_name
; /* document-name attribute */
9055 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9057 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9058 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9059 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9063 filetype
= mimeType(MimeDatabase
, super
, type
);
9065 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9066 filetype
->super
, filetype
->type
);
9069 filetype
= mimeType(MimeDatabase
, super
, type
);
9073 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9076 * Replace the document-format attribute value with the auto-typed or
9080 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9085 _cupsStrFree(format
->values
[0].string
.text
);
9087 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9090 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9091 "document-format", NULL
, mimetype
);
9095 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9096 _("Unsupported document-format \"%s\""),
9097 format
? format
->values
[0].string
.text
:
9098 "application/octet-stream");
9099 cupsdLogMessage(CUPSD_LOG_INFO
,
9100 "Hint: Do you have the raw file printing rules enabled?");
9103 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9104 "document-format", NULL
, format
->values
[0].string
.text
);
9110 * Read any embedded job ticket info from PS files...
9113 if (!strcasecmp(filetype
->super
, "application") &&
9114 (!strcasecmp(filetype
->type
, "postscript") ||
9115 !strcasecmp(filetype
->type
, "pdf")))
9116 read_job_ticket(con
);
9119 * Create the job object...
9122 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9126 * Update quota data...
9129 if (stat(con
->filename
, &fileinfo
))
9132 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9134 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9136 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9137 IPP_TAG_INTEGER
)) != NULL
)
9138 attr
->values
[0].integer
+= kbytes
;
9141 * Add the job file...
9144 if (add_file(con
, job
, filetype
, compression
))
9147 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9149 rename(con
->filename
, filename
);
9150 cupsdClearString(&con
->filename
);
9153 * See if we need to add the ending sheet...
9156 if (cupsdTimeoutJob(job
))
9160 * Log and save the job...
9163 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9164 "File of type %s/%s queued by \"%s\".",
9165 filetype
->super
, filetype
->type
, job
->username
);
9166 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9167 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9168 job
->dest
, job
->username
);
9171 * Start the job if possible...
9179 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9181 * This function only gets called when printing a single PDF or PostScript
9182 * file using the Print-Job operation. It doesn't work for Create-Job +
9183 * Send-File, since the job attributes need to be set at job creation
9184 * time for banners to work. The embedded job ticket stuff is here
9185 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9186 * options and IPP attributes which otherwise would be lost.
9188 * The format of a job ticket is simple:
9190 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9192 * %cupsJobTicket: attr1=value1
9193 * %cupsJobTicket: attr2=value2
9195 * %cupsJobTicket: attrN=valueN
9197 * Job ticket lines must appear immediately after the first line that
9198 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9199 * stops looking for job ticket info when it finds a line that does not begin
9200 * with "%cupsJobTicket:".
9202 * The maximum length of a job ticket line, including the prefix, is
9203 * 255 characters to conform with the Adobe DSC.
9205 * Read-only attributes are rejected with a notice to the error log in
9206 * case a malicious user tries anything. Since the job ticket is read
9207 * prior to attribute validation in print_job(), job ticket attributes
9208 * will go through the same validation as IPP attributes...
9212 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9214 cups_file_t
*fp
; /* File to read from */
9215 char line
[256]; /* Line data */
9216 int num_options
; /* Number of options */
9217 cups_option_t
*options
; /* Options */
9218 ipp_t
*ticket
; /* New attributes */
9219 ipp_attribute_t
*attr
, /* Current attribute */
9220 *attr2
, /* Job attribute */
9221 *prev2
; /* Previous job attribute */
9225 * First open the print file...
9228 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9230 cupsdLogMessage(CUPSD_LOG_ERROR
,
9231 "Unable to open print file for job ticket - %s",
9237 * Skip the first line...
9240 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9242 cupsdLogMessage(CUPSD_LOG_ERROR
,
9243 "Unable to read from print file for job ticket - %s",
9249 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9252 * Not a DSC-compliant file, so no job ticket info will be available...
9260 * Read job ticket info from the file...
9266 while (cupsFileGets(fp
, line
, sizeof(line
)))
9269 * Stop at the first non-ticket line...
9272 if (strncmp(line
, "%cupsJobTicket:", 15))
9276 * Add the options to the option array...
9279 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9283 * Done with the file; see if we have any options...
9288 if (num_options
== 0)
9292 * OK, convert the options to an attribute list, and apply them to
9297 cupsEncodeOptions(ticket
, num_options
, options
);
9300 * See what the user wants to change.
9303 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9305 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9308 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9309 !strcmp(attr
->name
, "job-originating-user-name") ||
9310 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9311 !strcmp(attr
->name
, "job-k-octets") ||
9312 !strcmp(attr
->name
, "job-id") ||
9313 !strncmp(attr
->name
, "job-state", 9) ||
9314 !strncmp(attr
->name
, "time-at-", 8))
9315 continue; /* Read-only attrs */
9317 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9318 IPP_TAG_ZERO
)) != NULL
)
9321 * Some other value; first free the old value...
9324 if (con
->request
->attrs
== attr2
)
9326 con
->request
->attrs
= attr2
->next
;
9331 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9332 if (prev2
->next
== attr2
)
9334 prev2
->next
= attr2
->next
;
9339 if (con
->request
->last
== attr2
)
9340 con
->request
->last
= prev2
;
9342 _ippFreeAttr(attr2
);
9346 * Add new option by copying it...
9349 copy_attribute(con
->request
, attr
, 0);
9353 * Then free the attribute list and option array...
9357 cupsFreeOptions(num_options
, options
);
9362 * 'reject_jobs()' - Reject print jobs to a printer.
9366 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9367 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9369 http_status_t status
; /* Policy status */
9370 cups_ptype_t dtype
; /* Destination type (printer/class) */
9371 cupsd_printer_t
*printer
; /* Printer data */
9372 ipp_attribute_t
*attr
; /* printer-state-message text */
9375 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9376 con
->http
.fd
, uri
->values
[0].string
.text
);
9379 * Is the destination valid?
9382 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9388 send_ipp_status(con
, IPP_NOT_FOUND
,
9389 _("The printer or class was not found."));
9397 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9399 send_http_error(con
, status
, printer
);
9404 * Reject jobs sent to the printer...
9407 printer
->accepting
= 0;
9409 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9410 IPP_TAG_TEXT
)) == NULL
)
9411 strcpy(printer
->state_message
, "Rejecting Jobs");
9413 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9414 sizeof(printer
->state_message
));
9416 cupsdAddPrinterHistory(printer
);
9418 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9419 "No longer accepting jobs.");
9421 if (dtype
& CUPS_PRINTER_CLASS
)
9423 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9425 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9426 printer
->name
, get_username(con
));
9430 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9432 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9433 printer
->name
, get_username(con
));
9437 * Everything was ok, so return OK status...
9440 con
->response
->request
.status
.status_code
= IPP_OK
;
9445 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9449 release_held_new_jobs(
9450 cupsd_client_t
*con
, /* I - Connection */
9451 ipp_attribute_t
*uri
) /* I - Printer URI */
9453 http_status_t status
; /* Policy status */
9454 cups_ptype_t dtype
; /* Destination type (printer/class) */
9455 cupsd_printer_t
*printer
; /* Printer data */
9458 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9459 con
->http
.fd
, uri
->values
[0].string
.text
);
9462 * Is the destination valid?
9465 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9471 send_ipp_status(con
, IPP_NOT_FOUND
,
9472 _("The printer or class was not found."));
9480 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9482 send_http_error(con
, status
, printer
);
9487 * Hold pending/new jobs sent to the printer...
9490 printer
->holding_new_jobs
= 0;
9492 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9493 cupsdAddPrinterHistory(printer
);
9495 if (dtype
& CUPS_PRINTER_CLASS
)
9496 cupsdLogMessage(CUPSD_LOG_INFO
,
9497 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9498 printer
->name
, get_username(con
));
9500 cupsdLogMessage(CUPSD_LOG_INFO
,
9501 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9502 printer
->name
, get_username(con
));
9505 * Everything was ok, so return OK status...
9508 con
->response
->request
.status
.status_code
= IPP_OK
;
9513 * 'release_job()' - Release a held print job.
9517 release_job(cupsd_client_t
*con
, /* I - Client connection */
9518 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9520 ipp_attribute_t
*attr
; /* Current attribute */
9521 int jobid
; /* Job ID */
9522 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9523 username
[HTTP_MAX_URI
], /* Username portion of URI */
9524 host
[HTTP_MAX_URI
], /* Host portion of URI */
9525 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9526 int port
; /* Port portion of URI */
9527 cupsd_job_t
*job
; /* Job information */
9530 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9531 con
->http
.fd
, uri
->values
[0].string
.text
);
9534 * See if we have a job URI or a printer URI...
9537 if (!strcmp(uri
->name
, "printer-uri"))
9540 * Got a printer URI; see if we also have a job-id attribute...
9543 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9544 IPP_TAG_INTEGER
)) == NULL
)
9546 send_ipp_status(con
, IPP_BAD_REQUEST
,
9547 _("Got a printer-uri attribute but no job-id"));
9551 jobid
= attr
->values
[0].integer
;
9556 * Got a job URI; parse it to get the job ID...
9559 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9560 sizeof(scheme
), username
, sizeof(username
), host
,
9561 sizeof(host
), &port
, resource
, sizeof(resource
));
9563 if (strncmp(resource
, "/jobs/", 6))
9569 send_ipp_status(con
, IPP_BAD_REQUEST
,
9570 _("Bad job-uri attribute \"%s\""),
9571 uri
->values
[0].string
.text
);
9575 jobid
= atoi(resource
+ 6);
9579 * See if the job exists...
9582 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9585 * Nope - return a "not found" error...
9588 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9593 * See if job is "held"...
9596 if (job
->state_value
!= IPP_JOB_HELD
)
9599 * Nope - return a "not possible" error...
9602 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held"), jobid
);
9607 * See if the job is owned by the requesting user...
9610 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9612 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9613 cupsdFindDest(job
->dest
));
9618 * Reset the job-hold-until value to "no-hold"...
9621 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9622 IPP_TAG_KEYWORD
)) == NULL
)
9623 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9627 _cupsStrFree(attr
->values
[0].string
.text
);
9629 attr
->value_tag
= IPP_TAG_KEYWORD
;
9630 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9632 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9633 "Job job-hold-until value changed by user.");
9637 * Release the job and return...
9640 cupsdReleaseJob(job
);
9642 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9643 "Job released by user.");
9645 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9647 con
->response
->request
.status
.status_code
= IPP_OK
;
9654 * 'renew_subscription()' - Renew an existing subscription...
9659 cupsd_client_t
*con
, /* I - Client connection */
9660 int sub_id
) /* I - Subscription ID */
9662 http_status_t status
; /* Policy status */
9663 cupsd_subscription_t
*sub
; /* Subscription */
9664 ipp_attribute_t
*lease
; /* notify-lease-duration */
9667 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9668 "renew_subscription(con=%p[%d], sub_id=%d)",
9669 con
, con
->http
.fd
, sub_id
);
9672 * Is the subscription ID valid?
9675 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9678 * Bad subscription ID...
9681 send_ipp_status(con
, IPP_NOT_FOUND
,
9682 _("notify-subscription-id %d no good"), sub_id
);
9689 * Job subscriptions cannot be renewed...
9692 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9693 _("Job subscriptions cannot be renewed"));
9701 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9703 con
, sub
->owner
)) != HTTP_OK
)
9705 send_http_error(con
, status
, sub
->dest
);
9710 * Renew the subscription...
9713 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9716 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9718 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9720 cupsdLogMessage(CUPSD_LOG_INFO
,
9721 "renew_subscription: Limiting notify-lease-duration to "
9724 sub
->lease
= MaxLeaseDuration
;
9727 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9729 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9731 con
->response
->request
.status
.status_code
= IPP_OK
;
9733 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9734 "notify-lease-duration", sub
->lease
);
9739 * 'restart_job()' - Restart an old print job.
9743 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9744 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9746 ipp_attribute_t
*attr
; /* Current attribute */
9747 int jobid
; /* Job ID */
9748 cupsd_job_t
*job
; /* Job information */
9749 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9750 username
[HTTP_MAX_URI
], /* Username portion of URI */
9751 host
[HTTP_MAX_URI
], /* Host portion of URI */
9752 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9753 int port
; /* Port portion of URI */
9756 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9757 con
->http
.fd
, uri
->values
[0].string
.text
);
9760 * See if we have a job URI or a printer URI...
9763 if (!strcmp(uri
->name
, "printer-uri"))
9766 * Got a printer URI; see if we also have a job-id attribute...
9769 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9770 IPP_TAG_INTEGER
)) == NULL
)
9772 send_ipp_status(con
, IPP_BAD_REQUEST
,
9773 _("Got a printer-uri attribute but no job-id"));
9777 jobid
= attr
->values
[0].integer
;
9782 * Got a job URI; parse it to get the job ID...
9785 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9786 sizeof(scheme
), username
, sizeof(username
), host
,
9787 sizeof(host
), &port
, resource
, sizeof(resource
));
9789 if (strncmp(resource
, "/jobs/", 6))
9795 send_ipp_status(con
, IPP_BAD_REQUEST
,
9796 _("Bad job-uri attribute \"%s\""),
9797 uri
->values
[0].string
.text
);
9801 jobid
= atoi(resource
+ 6);
9805 * See if the job exists...
9808 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9811 * Nope - return a "not found" error...
9814 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
9819 * See if job is in any of the "completed" states...
9822 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9825 * Nope - return a "not possible" error...
9828 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete"),
9834 * See if we have retained the job files...
9839 if (!job
->attrs
|| job
->num_files
== 0)
9842 * Nope - return a "not possible" error...
9845 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9846 _("Job #%d cannot be restarted - no files"), jobid
);
9851 * See if the job is owned by the requesting user...
9854 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9856 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9857 cupsdFindDest(job
->dest
));
9862 * See if the job-hold-until attribute is specified...
9865 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9866 IPP_TAG_KEYWORD
)) == NULL
)
9867 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9869 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9872 * Return the job to a held state...
9875 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9876 "Restarted by \"%s\" with job-hold-until=%s.",
9877 username
, attr
->values
[0].string
.text
);
9878 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9880 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9881 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9882 attr
->values
[0].string
.text
);
9887 * Restart the job...
9890 cupsdRestartJob(job
);
9894 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9896 con
->response
->request
.status
.status_code
= IPP_OK
;
9901 * 'save_auth_info()' - Save authentication information for a job.
9906 cupsd_client_t
*con
, /* I - Client connection */
9907 cupsd_job_t
*job
, /* I - Job */
9908 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9910 int i
; /* Looping var */
9911 char filename
[1024]; /* Job authentication filename */
9912 cups_file_t
*fp
; /* Job authentication file */
9913 char line
[2048]; /* Line for file */
9914 cupsd_printer_t
*dest
; /* Destination printer/class */
9918 * This function saves the in-memory authentication information for
9919 * a job so that it can be used to authenticate with a remote host.
9920 * The information is stored in a file that is readable only by the
9921 * root user. The fields are Base-64 encoded, each on a separate line,
9922 * followed by random number (up to 1024) of newlines to limit the
9923 * amount of information that is exposed.
9925 * Because of the potential for exposing of authentication information,
9926 * this functionality is only enabled when running cupsd as root.
9928 * This caching only works for the Basic and BasicDigest authentication
9929 * types. Digest authentication cannot be cached this way, and in
9930 * the future Kerberos authentication may make all of this obsolete.
9932 * Authentication information is saved whenever an authenticated
9933 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9936 * This information is deleted after a job is completed or canceled,
9937 * so reprints may require subsequent re-authentication.
9943 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9947 * Create the authentication file and change permissions...
9950 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9951 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9953 cupsdLogMessage(CUPSD_LOG_ERROR
,
9954 "Unable to save authentication info to \"%s\" - %s",
9955 filename
, strerror(errno
));
9959 fchown(cupsFileNumber(fp
), 0, 0);
9960 fchmod(cupsFileNumber(fp
), 0400);
9962 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9965 * Write 1 to 3 auth values...
9968 cupsdClearString(&job
->auth_username
);
9969 cupsdClearString(&job
->auth_domain
);
9970 cupsdClearString(&job
->auth_password
);
9972 for (i
= 0; i
< auth_info
->num_values
; i
++)
9974 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9975 strlen(auth_info
->values
[i
].string
.text
));
9976 cupsFilePrintf(fp
, "%s\n", line
);
9978 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9979 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9980 auth_info
->values
[i
].string
.text
);
9981 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9982 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9983 auth_info
->values
[i
].string
.text
);
9984 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9985 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9986 auth_info
->values
[i
].string
.text
);
9989 else if (con
->username
[0])
9992 * Write the authenticated username...
9995 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9996 cupsFilePrintf(fp
, "%s\n", line
);
9998 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9999 cupsdClearString(&job
->auth_domain
);
10002 * Write the authenticated password...
10005 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10006 cupsFilePrintf(fp
, "%s\n", line
);
10008 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
10012 * Write a random number of newlines to the end of the file...
10015 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10016 cupsFilePutChar(fp
, '\n');
10019 * Close the file and return...
10024 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10025 # ifdef HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID
10026 if (con
->have_gss
&&
10027 (con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
|| con
->gss_creds
))
10029 if (con
->have_gss
&& con
->gss_creds
)
10030 # endif /* HAVE_KRB5_IPC_CLIENT_SET_TARGET_UID */
10031 save_krb5_creds(con
, job
);
10032 else if (job
->ccname
)
10033 cupsdClearString(&(job
->ccname
));
10034 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10038 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
10040 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
10044 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
10045 cupsd_job_t
*job
) /* I - Job */
10048 * Get the credentials...
10051 job
->ccache
= cupsdCopyKrb5Creds(con
);
10054 * Add the KRB5CCNAME environment variable to the job so that the
10055 * backend can use the credentials when printing.
10060 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
10061 krb5_cc_get_name(KerberosContext
, job
->ccache
));
10063 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
10066 cupsdClearString(&(job
->ccname
));
10068 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
10072 * 'send_document()' - Send a file to a printer or class.
10076 send_document(cupsd_client_t
*con
, /* I - Client connection */
10077 ipp_attribute_t
*uri
) /* I - Printer URI */
10079 ipp_attribute_t
*attr
; /* Current attribute */
10080 ipp_attribute_t
*format
; /* Request's document-format attribute */
10081 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10082 const char *default_format
;/* document-format-default value */
10083 int jobid
; /* Job ID number */
10084 cupsd_job_t
*job
; /* Current job */
10085 char job_uri
[HTTP_MAX_URI
],
10087 scheme
[HTTP_MAX_URI
],
10088 /* Method portion of URI */
10089 username
[HTTP_MAX_URI
],
10090 /* Username portion of URI */
10091 host
[HTTP_MAX_URI
],
10092 /* Host portion of URI */
10093 resource
[HTTP_MAX_URI
];
10094 /* Resource portion of URI */
10095 int port
; /* Port portion of URI */
10096 mime_type_t
*filetype
; /* Type of file */
10097 char super
[MIME_MAX_SUPER
],
10098 /* Supertype of file */
10099 type
[MIME_MAX_TYPE
],
10100 /* Subtype of file */
10101 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10102 /* Textual name of mime type */
10103 char filename
[1024]; /* Job filename */
10104 cupsd_printer_t
*printer
; /* Current printer */
10105 struct stat fileinfo
; /* File information */
10106 int kbytes
; /* Size of file */
10107 int compression
; /* Type of compression */
10108 int start_job
; /* Start the job? */
10111 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10112 con
->http
.fd
, uri
->values
[0].string
.text
);
10115 * See if we have a job URI or a printer URI...
10118 if (!strcmp(uri
->name
, "printer-uri"))
10121 * Got a printer URI; see if we also have a job-id attribute...
10124 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10125 IPP_TAG_INTEGER
)) == NULL
)
10127 send_ipp_status(con
, IPP_BAD_REQUEST
,
10128 _("Got a printer-uri attribute but no job-id"));
10132 jobid
= attr
->values
[0].integer
;
10137 * Got a job URI; parse it to get the job ID...
10140 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10141 sizeof(scheme
), username
, sizeof(username
), host
,
10142 sizeof(host
), &port
, resource
, sizeof(resource
));
10144 if (strncmp(resource
, "/jobs/", 6))
10150 send_ipp_status(con
, IPP_BAD_REQUEST
,
10151 _("Bad job-uri attribute \"%s\""),
10152 uri
->values
[0].string
.text
);
10156 jobid
= atoi(resource
+ 6);
10160 * See if the job exists...
10163 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10166 * Nope - return a "not found" error...
10169 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10173 printer
= cupsdFindDest(job
->dest
);
10176 * See if the job is owned by the requesting user...
10179 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10181 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10182 cupsdFindDest(job
->dest
));
10187 * OK, see if the client is sending the document compressed - CUPS
10188 * only supports "none" and "gzip".
10191 compression
= CUPS_FILE_NONE
;
10193 if ((attr
= ippFindAttribute(con
->request
, "compression",
10194 IPP_TAG_KEYWORD
)) != NULL
)
10196 if (strcmp(attr
->values
[0].string
.text
, "none")
10198 && strcmp(attr
->values
[0].string
.text
, "gzip")
10199 #endif /* HAVE_LIBZ */
10202 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\""),
10203 attr
->values
[0].string
.text
);
10204 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10205 "compression", NULL
, attr
->values
[0].string
.text
);
10210 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10211 compression
= CUPS_FILE_GZIP
;
10212 #endif /* HAVE_LIBZ */
10216 * Do we have a file to print?
10219 if (!con
->filename
)
10222 * Check for an empty request with "last-document" set to true, which is
10223 * used to close an "open" job by RFC 2911, section 3.3.2.
10226 if (job
->num_files
> 0 &&
10227 (attr
= ippFindAttribute(con
->request
, "last-document",
10228 IPP_TAG_BOOLEAN
)) != NULL
&&
10229 attr
->values
[0].boolean
)
10230 goto last_document
;
10232 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?"));
10237 * Is it a format we support?
10240 if ((format
= ippFindAttribute(con
->request
, "document-format",
10241 IPP_TAG_MIMETYPE
)) != NULL
)
10244 * Grab format from client...
10247 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10250 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
10251 format
->values
[0].string
.text
);
10255 else if ((default_format
= cupsGetOption("document-format",
10256 printer
->num_options
,
10257 printer
->options
)) != NULL
)
10260 * Use default document format...
10263 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10265 send_ipp_status(con
, IPP_BAD_REQUEST
,
10266 _("Could not scan type \"%s\""),
10274 * No document format attribute? Auto-type it!
10277 strcpy(super
, "application");
10278 strcpy(type
, "octet-stream");
10281 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10284 * Auto-type the file...
10287 ipp_attribute_t
*doc_name
; /* document-name attribute */
10290 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10292 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10293 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10294 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10298 filetype
= mimeType(MimeDatabase
, super
, type
);
10300 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10301 filetype
->super
, filetype
->type
);
10304 filetype
= mimeType(MimeDatabase
, super
, type
);
10309 * Replace the document-format attribute value with the auto-typed or
10313 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10316 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10317 IPP_TAG_MIMETYPE
)) != NULL
)
10319 _cupsStrFree(jformat
->values
[0].string
.text
);
10321 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10324 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10325 "document-format", NULL
, mimetype
);
10327 else if (!filetype
)
10329 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10330 _("Unsupported format \'%s/%s\'"), super
, type
);
10331 cupsdLogMessage(CUPSD_LOG_INFO
,
10332 "Hint: Do you have the raw file printing rules enabled?");
10335 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10336 "document-format", NULL
, format
->values
[0].string
.text
);
10341 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10343 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10346 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10347 _("Unsupported format \'%s\'"), mimetype
);
10349 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10350 "document-format", NULL
, mimetype
);
10356 * Add the file to the job...
10361 if (add_file(con
, job
, filetype
, compression
))
10364 if (stat(con
->filename
, &fileinfo
))
10367 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10369 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10371 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10372 IPP_TAG_INTEGER
)) != NULL
)
10373 attr
->values
[0].integer
+= kbytes
;
10375 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10377 rename(con
->filename
, filename
);
10379 cupsdClearString(&con
->filename
);
10381 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10382 filetype
->super
, filetype
->type
, job
->username
);
10385 * Start the job if this is the last document...
10390 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10391 IPP_TAG_BOOLEAN
)) != NULL
&&
10392 attr
->values
[0].boolean
)
10395 * See if we need to add the ending sheet...
10398 if (cupsdTimeoutJob(job
))
10401 if (job
->state_value
== IPP_JOB_STOPPED
)
10403 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10404 job
->state_value
= IPP_JOB_PENDING
;
10406 else if (job
->state_value
== IPP_JOB_HELD
)
10408 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10409 IPP_TAG_KEYWORD
)) == NULL
)
10410 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10412 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10414 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10415 job
->state_value
= IPP_JOB_PENDING
;
10420 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10426 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10427 IPP_TAG_KEYWORD
)) == NULL
)
10428 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10430 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10432 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10433 job
->state_value
= IPP_JOB_HELD
;
10434 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10437 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10444 * Fill in the response info...
10447 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10450 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10453 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10455 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10457 add_job_state_reasons(con
, job
);
10459 con
->response
->request
.status
.status_code
= IPP_OK
;
10462 * Start the job if necessary...
10471 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10476 cupsd_client_t
*con
, /* I - Client connection */
10477 http_status_t status
, /* I - HTTP status code */
10478 cupsd_printer_t
*printer
) /* I - Printer, if any */
10480 ipp_attribute_t
*uri
; /* Request URI, if any */
10483 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10484 IPP_TAG_URI
)) == NULL
)
10485 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10487 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10488 "Returning HTTP %s for %s (%s) from %s",
10489 httpStatus(status
),
10490 ippOpString(con
->request
->request
.op
.operation_id
),
10491 uri
? uri
->values
[0].string
.text
: "no URI",
10492 con
->http
.hostname
);
10496 int auth_type
; /* Type of authentication required */
10499 auth_type
= CUPSD_AUTH_NONE
;
10501 if (status
== HTTP_UNAUTHORIZED
&&
10502 printer
->num_auth_info_required
> 0 &&
10503 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10505 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10506 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10507 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10510 * Creating and authenticating jobs requires Kerberos...
10513 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10518 * Use policy/location-defined authentication requirements...
10521 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10522 cupsd_location_t
*auth
; /* Pointer to authentication element */
10525 if (printer
->type
& CUPS_PRINTER_CLASS
)
10526 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10528 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10530 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10531 auth
->type
== CUPSD_AUTH_NONE
)
10532 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10534 con
->request
->request
.op
.operation_id
:
10539 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10540 auth_type
= DefaultAuthType
;
10542 auth_type
= auth
->type
;
10546 cupsdSendError(con
, status
, auth_type
);
10549 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10551 ippDelete(con
->response
);
10552 con
->response
= NULL
;
10559 * 'send_ipp_status()' - Send a status back to the IPP client.
10563 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10564 ipp_status_t status
, /* I - IPP status code */
10565 const char *message
,/* I - Status message */
10566 ...) /* I - Additional args as needed */
10568 va_list ap
; /* Pointer to additional args */
10569 char formatted
[1024]; /* Formatted errror message */
10572 va_start(ap
, message
);
10573 vsnprintf(formatted
, sizeof(formatted
),
10574 _cupsLangString(con
->language
, message
), ap
);
10577 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10578 ippOpString(con
->request
->request
.op
.operation_id
),
10579 ippErrorString(status
), formatted
);
10581 con
->response
->request
.status
.status_code
= status
;
10583 if (ippFindAttribute(con
->response
, "attributes-charset",
10584 IPP_TAG_ZERO
) == NULL
)
10585 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10586 "attributes-charset", NULL
, "utf-8");
10588 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10589 IPP_TAG_ZERO
) == NULL
)
10590 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10591 "attributes-natural-language", NULL
, DefaultLanguage
);
10593 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10594 "status-message", NULL
, formatted
);
10599 * 'set_default()' - Set the default destination...
10603 set_default(cupsd_client_t
*con
, /* I - Client connection */
10604 ipp_attribute_t
*uri
) /* I - Printer URI */
10606 http_status_t status
; /* Policy status */
10607 cups_ptype_t dtype
; /* Destination type (printer/class) */
10608 cupsd_printer_t
*printer
, /* Printer */
10609 *oldprinter
; /* Old default printer */
10612 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10613 con
->http
.fd
, uri
->values
[0].string
.text
);
10616 * Is the destination valid?
10619 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10625 send_ipp_status(con
, IPP_NOT_FOUND
,
10626 _("The printer or class was not found."));
10634 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10636 send_http_error(con
, status
, NULL
);
10641 * Set it as the default...
10644 oldprinter
= DefaultPrinter
;
10645 DefaultPrinter
= printer
;
10648 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10649 "%s is no longer the default printer.", oldprinter
->name
);
10651 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10652 "%s is now the default printer.", printer
->name
);
10654 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10655 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10657 cupsdLogMessage(CUPSD_LOG_INFO
,
10658 "Default destination set to \"%s\" by \"%s\".",
10659 printer
->name
, get_username(con
));
10662 * Everything was ok, so return OK status...
10665 con
->response
->request
.status
.status_code
= IPP_OK
;
10670 * 'set_job_attrs()' - Set job attributes.
10674 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10675 ipp_attribute_t
*uri
) /* I - Job URI */
10677 ipp_attribute_t
*attr
, /* Current attribute */
10678 *attr2
; /* Job attribute */
10679 int jobid
; /* Job ID */
10680 cupsd_job_t
*job
; /* Current job */
10681 char scheme
[HTTP_MAX_URI
],
10682 /* Method portion of URI */
10683 username
[HTTP_MAX_URI
],
10684 /* Username portion of URI */
10685 host
[HTTP_MAX_URI
],
10686 /* Host portion of URI */
10687 resource
[HTTP_MAX_URI
];
10688 /* Resource portion of URI */
10689 int port
; /* Port portion of URI */
10690 int event
; /* Events? */
10691 int check_jobs
; /* Check jobs? */
10694 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10695 con
->http
.fd
, uri
->values
[0].string
.text
);
10698 * Start with "everything is OK" status...
10701 con
->response
->request
.status
.status_code
= IPP_OK
;
10704 * See if we have a job URI or a printer URI...
10707 if (!strcmp(uri
->name
, "printer-uri"))
10710 * Got a printer URI; see if we also have a job-id attribute...
10713 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10714 IPP_TAG_INTEGER
)) == NULL
)
10716 send_ipp_status(con
, IPP_BAD_REQUEST
,
10717 _("Got a printer-uri attribute but no job-id"));
10721 jobid
= attr
->values
[0].integer
;
10726 * Got a job URI; parse it to get the job ID...
10729 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10730 sizeof(scheme
), username
, sizeof(username
), host
,
10731 sizeof(host
), &port
, resource
, sizeof(resource
));
10733 if (strncmp(resource
, "/jobs/", 6))
10739 send_ipp_status(con
, IPP_BAD_REQUEST
,
10740 _("Bad job-uri attribute \"%s\""),
10741 uri
->values
[0].string
.text
);
10745 jobid
= atoi(resource
+ 6);
10749 * See if the job exists...
10752 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10755 * Nope - return a "not found" error...
10758 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist"), jobid
);
10763 * See if the job has been completed...
10766 if (job
->state_value
> IPP_JOB_STOPPED
)
10769 * Return a "not-possible" error...
10772 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10773 _("Job #%d is finished and cannot be altered"), jobid
);
10778 * See if the job is owned by the requesting user...
10781 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10783 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10784 cupsdFindDest(job
->dest
));
10789 * See what the user wants to change.
10797 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10799 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10802 if (!strcmp(attr
->name
, "attributes-charset") ||
10803 !strcmp(attr
->name
, "attributes-natural-language") ||
10804 !strcmp(attr
->name
, "document-compression") ||
10805 !strcmp(attr
->name
, "document-format") ||
10806 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10807 !strcmp(attr
->name
, "job-document-access-errors") ||
10808 !strcmp(attr
->name
, "job-id") ||
10809 !strcmp(attr
->name
, "job-impressions-completed") ||
10810 !strcmp(attr
->name
, "job-k-octets") ||
10811 !strcmp(attr
->name
, "job-originating-host-name") ||
10812 !strcmp(attr
->name
, "job-originating-user-name") ||
10813 !strcmp(attr
->name
, "job-printer-up-time") ||
10814 !strcmp(attr
->name
, "job-printer-uri") ||
10815 !strcmp(attr
->name
, "job-sheets") ||
10816 !strcmp(attr
->name
, "job-state-message") ||
10817 !strcmp(attr
->name
, "job-state-reasons") ||
10818 !strcmp(attr
->name
, "job-uri") ||
10819 !strcmp(attr
->name
, "number-of-documents") ||
10820 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10821 !strcmp(attr
->name
, "output-device-assigned") ||
10822 !strncmp(attr
->name
, "date-time-at-", 13) ||
10823 !strncmp(attr
->name
, "job-k-octets", 12) ||
10824 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10825 !strncmp(attr
->name
, "time-at-", 8))
10831 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10832 _("%s cannot be changed."), attr
->name
);
10834 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10835 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10840 if (!strcmp(attr
->name
, "job-priority"))
10843 * Change the job priority...
10846 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10848 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value"));
10850 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10851 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10853 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10855 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10856 _("Job is completed and cannot be changed."));
10859 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10861 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10862 attr
->values
[0].integer
);
10863 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10866 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10867 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10870 else if (!strcmp(attr
->name
, "job-state"))
10873 * Change the job state...
10876 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10878 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value"));
10880 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10881 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10885 switch (attr
->values
[0].integer
)
10887 case IPP_JOB_PENDING
:
10888 case IPP_JOB_HELD
:
10889 if (job
->state_value
> IPP_JOB_HELD
)
10891 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10892 _("Job state cannot be changed."));
10895 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10897 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10898 attr
->values
[0].integer
);
10899 cupsdSetJobState(job
, attr
->values
[0].integer
,
10901 "Job state changed by \"%s\"", username
);
10906 case IPP_JOB_PROCESSING
:
10907 case IPP_JOB_STOPPED
:
10908 if (job
->state_value
!= attr
->values
[0].integer
)
10910 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10911 _("Job state cannot be changed."));
10916 case IPP_JOB_CANCELED
:
10917 case IPP_JOB_ABORTED
:
10918 case IPP_JOB_COMPLETED
:
10919 if (job
->state_value
> IPP_JOB_PROCESSING
)
10921 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10922 _("Job state cannot be changed."));
10925 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10927 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10928 attr
->values
[0].integer
);
10929 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10931 "Job state changed by \"%s\"", username
);
10938 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10940 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10941 IPP_TAG_ZERO
)) != NULL
)
10944 * Some other value; first free the old value...
10947 if (job
->attrs
->prev
)
10948 job
->attrs
->prev
->next
= attr2
->next
;
10950 job
->attrs
->attrs
= attr2
->next
;
10952 if (job
->attrs
->last
== attr2
)
10953 job
->attrs
->last
= job
->attrs
->prev
;
10955 _ippFreeAttr(attr2
);
10958 * Then copy the attribute...
10961 copy_attribute(job
->attrs
, attr
, 0);
10964 * See if the job-name or job-hold-until is being changed.
10967 if (!strcmp(attr
->name
, "job-hold-until"))
10969 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10970 attr
->values
[0].string
.text
);
10971 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10973 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10975 cupsdReleaseJob(job
);
10979 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10980 "Job held by \"%s\".", username
);
10982 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10985 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10988 * Delete the attribute...
10991 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10992 IPP_TAG_ZERO
)) != NULL
)
10994 if (job
->attrs
->prev
)
10995 job
->attrs
->prev
->next
= attr2
->next
;
10997 job
->attrs
->attrs
= attr2
->next
;
10999 if (attr2
== job
->attrs
->last
)
11000 job
->attrs
->last
= job
->attrs
->prev
;
11002 _ippFreeAttr(attr2
);
11004 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11010 * Add new option by copying it...
11013 copy_attribute(job
->attrs
, attr
, 0);
11015 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11024 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11027 * Send events as needed...
11030 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11031 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11032 cupsdFindDest(job
->dest
), job
,
11033 "Job priority changed by user.");
11035 if (event
& CUPSD_EVENT_JOB_STATE
)
11036 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11037 job
->state_value
== IPP_JOB_HELD
?
11038 "Job held by user." : "Job restarted by user.");
11040 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11041 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11042 "Job options changed by user.");
11045 * Start jobs if possible...
11054 * 'set_printer_attrs()' - Set printer attributes.
11058 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11059 ipp_attribute_t
*uri
) /* I - Printer */
11061 http_status_t status
; /* Policy status */
11062 cups_ptype_t dtype
; /* Destination type (printer/class) */
11063 cupsd_printer_t
*printer
; /* Printer/class */
11064 ipp_attribute_t
*attr
; /* Printer attribute */
11065 int changed
= 0; /* Was anything changed? */
11068 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11069 con
->http
.fd
, uri
->values
[0].string
.text
);
11072 * Is the destination valid?
11075 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11081 send_ipp_status(con
, IPP_NOT_FOUND
,
11082 _("The printer or class was not found."));
11090 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11092 send_http_error(con
, status
, printer
);
11097 * Return a list of attributes that can be set via Set-Printer-Attributes.
11100 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11101 IPP_TAG_TEXT
)) != NULL
)
11103 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11107 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11108 IPP_TAG_TEXT
)) != NULL
)
11110 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11115 * Update the printer attributes and return...
11120 cupsdSetPrinterAttrs(printer
);
11121 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11123 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11124 "Printer \"%s\" description or location changed by \"%s\".",
11125 printer
->name
, get_username(con
));
11127 cupsdLogMessage(CUPSD_LOG_INFO
,
11128 "Printer \"%s\" description or location changed by \"%s\".",
11129 printer
->name
, get_username(con
));
11132 con
->response
->request
.status
.status_code
= IPP_OK
;
11137 * 'set_printer_defaults()' - Set printer default options from a request.
11141 set_printer_defaults(
11142 cupsd_client_t
*con
, /* I - Client connection */
11143 cupsd_printer_t
*printer
) /* I - Printer */
11145 int i
; /* Looping var */
11146 ipp_attribute_t
*attr
; /* Current attribute */
11147 int namelen
; /* Length of attribute name */
11148 char name
[256], /* New attribute name */
11149 value
[256]; /* String version of integer attrs */
11152 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11155 * Skip non-printer attributes...
11158 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11161 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11163 if (!strcmp(attr
->name
, "job-sheets-default"))
11166 * Only allow keywords and names...
11169 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11173 * Only allow job-sheets-default to be set when running without a
11174 * system high classification level...
11177 if (Classification
)
11180 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11182 if (attr
->num_values
> 1)
11183 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11185 cupsdSetString(&printer
->job_sheets
[1], "none");
11187 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11189 cupsdFreePrinterUsers(printer
);
11191 printer
->deny_users
= 0;
11193 if (attr
->value_tag
== IPP_TAG_NAME
&&
11194 (attr
->num_values
> 1 ||
11195 strcmp(attr
->values
[0].string
.text
, "all")))
11197 for (i
= 0; i
< attr
->num_values
; i
++)
11198 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
11201 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11203 cupsdFreePrinterUsers(printer
);
11205 printer
->deny_users
= 1;
11207 if (attr
->value_tag
== IPP_TAG_NAME
&&
11208 (attr
->num_values
> 1 ||
11209 strcmp(attr
->values
[0].string
.text
, "none")))
11211 for (i
= 0; i
< attr
->num_values
; i
++)
11212 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
11215 else if (!strcmp(attr
->name
, "job-quota-period"))
11217 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11220 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11221 attr
->values
[0].integer
);
11222 cupsdFreeQuotas(printer
);
11224 printer
->quota_period
= attr
->values
[0].integer
;
11226 else if (!strcmp(attr
->name
, "job-k-limit"))
11228 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11231 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11232 attr
->values
[0].integer
);
11233 cupsdFreeQuotas(printer
);
11235 printer
->k_limit
= attr
->values
[0].integer
;
11237 else if (!strcmp(attr
->name
, "job-page-limit"))
11239 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11242 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11243 attr
->values
[0].integer
);
11244 cupsdFreeQuotas(printer
);
11246 printer
->page_limit
= attr
->values
[0].integer
;
11248 else if (!strcmp(attr
->name
, "printer-op-policy"))
11250 cupsd_policy_t
*p
; /* Policy */
11253 if (attr
->value_tag
!= IPP_TAG_NAME
)
11256 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11258 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11259 "Setting printer-op-policy to \"%s\"...",
11260 attr
->values
[0].string
.text
);
11261 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11262 printer
->op_policy_ptr
= p
;
11266 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11267 _("Unknown printer-op-policy \"%s\"."),
11268 attr
->values
[0].string
.text
);
11272 else if (!strcmp(attr
->name
, "printer-error-policy"))
11274 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11277 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11278 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
11279 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11280 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11281 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11283 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11284 _("Unknown printer-error-policy \"%s\"."),
11285 attr
->values
[0].string
.text
);
11289 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11290 "Setting printer-error-policy to \"%s\"...",
11291 attr
->values
[0].string
.text
);
11292 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11296 * Skip any other non-default attributes...
11299 namelen
= strlen(attr
->name
);
11300 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11301 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11305 * OK, anything else must be a user-defined default...
11308 strlcpy(name
, attr
->name
, sizeof(name
));
11309 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11311 switch (attr
->value_tag
)
11313 case IPP_TAG_DELETEATTR
:
11314 printer
->num_options
= cupsRemoveOption(name
,
11315 printer
->num_options
,
11316 &(printer
->options
));
11317 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11318 "Deleting %s", attr
->name
);
11321 case IPP_TAG_NAME
:
11322 case IPP_TAG_KEYWORD
:
11324 printer
->num_options
= cupsAddOption(name
,
11325 attr
->values
[0].string
.text
,
11326 printer
->num_options
,
11327 &(printer
->options
));
11328 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11329 "Setting %s to \"%s\"...", attr
->name
,
11330 attr
->values
[0].string
.text
);
11333 case IPP_TAG_BOOLEAN
:
11334 printer
->num_options
= cupsAddOption(name
,
11335 attr
->values
[0].boolean
?
11337 printer
->num_options
,
11338 &(printer
->options
));
11339 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11340 "Setting %s to %s...", attr
->name
,
11341 attr
->values
[0].boolean
? "true" : "false");
11344 case IPP_TAG_INTEGER
:
11345 case IPP_TAG_ENUM
:
11346 sprintf(value
, "%d", attr
->values
[0].integer
);
11347 printer
->num_options
= cupsAddOption(name
, value
,
11348 printer
->num_options
,
11349 &(printer
->options
));
11350 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11351 "Setting %s to %s...", attr
->name
, value
);
11354 case IPP_TAG_RANGE
:
11355 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11356 attr
->values
[0].range
.upper
);
11357 printer
->num_options
= cupsAddOption(name
, value
,
11358 printer
->num_options
,
11359 &(printer
->options
));
11360 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11361 "Setting %s to %s...", attr
->name
, value
);
11364 case IPP_TAG_RESOLUTION
:
11365 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11366 attr
->values
[0].resolution
.yres
,
11367 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
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
);
11377 /* Do nothing for other values */
11385 * 'start_printer()' - Start a printer.
11389 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11390 ipp_attribute_t
*uri
) /* I - Printer URI */
11392 http_status_t status
; /* Policy status */
11393 cups_ptype_t dtype
; /* Destination type (printer/class) */
11394 cupsd_printer_t
*printer
; /* Printer data */
11397 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11398 con
->http
.fd
, uri
->values
[0].string
.text
);
11401 * Is the destination valid?
11404 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11410 send_ipp_status(con
, IPP_NOT_FOUND
,
11411 _("The printer or class was not found."));
11419 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11421 send_http_error(con
, status
, printer
);
11426 * Start the printer...
11429 printer
->state_message
[0] = '\0';
11431 cupsdStartPrinter(printer
, 1);
11433 if (dtype
& CUPS_PRINTER_CLASS
)
11434 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11435 printer
->name
, get_username(con
));
11437 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11438 printer
->name
, get_username(con
));
11443 * Everything was ok, so return OK status...
11446 con
->response
->request
.status
.status_code
= IPP_OK
;
11451 * 'stop_printer()' - Stop a printer.
11455 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11456 ipp_attribute_t
*uri
) /* I - Printer URI */
11458 http_status_t status
; /* Policy status */
11459 cups_ptype_t dtype
; /* Destination type (printer/class) */
11460 cupsd_printer_t
*printer
; /* Printer data */
11461 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11464 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11465 con
->http
.fd
, uri
->values
[0].string
.text
);
11468 * Is the destination valid?
11471 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11477 send_ipp_status(con
, IPP_NOT_FOUND
,
11478 _("The printer or class was not found."));
11486 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11488 send_http_error(con
, status
, printer
);
11493 * Stop the printer...
11496 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11497 IPP_TAG_TEXT
)) == NULL
)
11498 strcpy(printer
->state_message
, "Paused");
11501 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11502 sizeof(printer
->state_message
));
11505 cupsdStopPrinter(printer
, 1);
11507 if (dtype
& CUPS_PRINTER_CLASS
)
11508 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11509 printer
->name
, get_username(con
));
11511 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11512 printer
->name
, get_username(con
));
11515 * Everything was ok, so return OK status...
11518 con
->response
->request
.status
.status_code
= IPP_OK
;
11523 * 'url_encode_attr()' - URL-encode a string attribute.
11527 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11528 char *buffer
,/* I - String buffer */
11529 int bufsize
)/* I - Size of buffer */
11531 int i
; /* Looping var */
11532 char *bufptr
, /* Pointer into buffer */
11533 *bufend
; /* End of buffer */
11536 strlcpy(buffer
, attr
->name
, bufsize
);
11537 bufptr
= buffer
+ strlen(buffer
);
11538 bufend
= buffer
+ bufsize
- 1;
11540 for (i
= 0; i
< attr
->num_values
; i
++)
11542 if (bufptr
>= bufend
)
11550 if (bufptr
>= bufend
)
11555 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11556 bufptr
, bufend
- bufptr
+ 1);
11558 if (bufptr
>= bufend
)
11569 * 'url_encode_string()' - URL-encode a string.
11572 static char * /* O - End of string */
11573 url_encode_string(const char *s
, /* I - String */
11574 char *buffer
, /* I - String buffer */
11575 int bufsize
) /* I - Size of buffer */
11577 char *bufptr
, /* Pointer into buffer */
11578 *bufend
; /* End of buffer */
11579 static const char *hex
= "0123456789ABCDEF";
11584 bufend
= buffer
+ bufsize
- 1;
11586 while (*s
&& bufptr
< bufend
)
11588 if (*s
== ' ' || *s
== '%' || *s
== '+')
11590 if (bufptr
>= (bufend
- 2))
11594 *bufptr
++ = hex
[(*s
>> 4) & 15];
11595 *bufptr
++ = hex
[*s
& 15];
11599 else if (*s
== '\'' || *s
== '\\')
11601 if (bufptr
>= (bufend
- 1))
11618 * 'user_allowed()' - See if a user is allowed to print to a queue.
11621 static int /* O - 0 if not allowed, 1 if allowed */
11622 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11623 const char *username
) /* I - Username */
11625 int i
; /* Looping var */
11626 struct passwd
*pw
; /* User password data */
11627 char baseuser
[256], /* Base username */
11628 *baseptr
; /* Pointer to "@" in base username */
11631 if (p
->num_users
== 0)
11634 if (!strcmp(username
, "root"))
11637 if (strchr(username
, '@'))
11640 * Strip @REALM for username check...
11643 strlcpy(baseuser
, username
, sizeof(baseuser
));
11645 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11648 username
= baseuser
;
11651 pw
= getpwnam(username
);
11654 for (i
= 0; i
< p
->num_users
; i
++)
11656 if (p
->users
[i
][0] == '@')
11659 * Check group membership...
11662 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
11665 else if (p
->users
[i
][0] == '#')
11671 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
11674 else if (!strcasecmp(username
, p
->users
[i
]))
11678 return ((i
< p
->num_users
) != p
->deny_users
);
11683 * 'validate_job()' - Validate printer options and destination.
11687 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11688 ipp_attribute_t
*uri
) /* I - Printer URI */
11690 http_status_t status
; /* Policy status */
11691 ipp_attribute_t
*attr
, /* Current attribute */
11692 *auth_info
; /* auth-info attribute */
11693 ipp_attribute_t
*format
; /* Document-format attribute */
11694 cups_ptype_t dtype
; /* Destination type (printer/class) */
11695 char super
[MIME_MAX_SUPER
],
11696 /* Supertype of file */
11697 type
[MIME_MAX_TYPE
];
11698 /* Subtype of file */
11699 cupsd_printer_t
*printer
; /* Printer */
11702 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11703 con
->http
.fd
, uri
->values
[0].string
.text
);
11706 * OK, see if the client is sending the document compressed - CUPS
11707 * doesn't support compression yet...
11710 if ((attr
= ippFindAttribute(con
->request
, "compression",
11711 IPP_TAG_KEYWORD
)) != NULL
)
11713 if (strcmp(attr
->values
[0].string
.text
, "none")
11715 && strcmp(attr
->values
[0].string
.text
, "gzip")
11716 #endif /* HAVE_LIBZ */
11719 send_ipp_status(con
, IPP_ATTRIBUTES
,
11720 _("Unsupported compression \"%s\""),
11721 attr
->values
[0].string
.text
);
11722 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11723 "compression", NULL
, attr
->values
[0].string
.text
);
11729 * Is it a format we support?
11732 if ((format
= ippFindAttribute(con
->request
, "document-format",
11733 IPP_TAG_MIMETYPE
)) != NULL
)
11735 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11738 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\""),
11739 format
->values
[0].string
.text
);
11743 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11744 !mimeType(MimeDatabase
, super
, type
))
11746 cupsdLogMessage(CUPSD_LOG_INFO
,
11747 "Hint: Do you have the raw file printing rules enabled?");
11748 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11749 _("Unsupported document-format \"%s\""),
11750 format
->values
[0].string
.text
);
11751 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11752 "document-format", NULL
, format
->values
[0].string
.text
);
11758 * Is the destination valid?
11761 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11767 send_ipp_status(con
, IPP_NOT_FOUND
,
11768 _("The printer or class was not found."));
11776 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11778 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11780 send_http_error(con
, status
, printer
);
11783 else if (printer
->num_auth_info_required
== 1 &&
11784 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11787 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11791 else if (auth_info
&& !con
->http
.tls
&&
11792 !httpAddrLocalhost(con
->http
.hostaddr
))
11795 * Require encryption of auth-info over non-local connections...
11798 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11801 #endif /* HAVE_SSL */
11804 * Everything was ok, so return OK status...
11807 con
->response
->request
.status
.status_code
= IPP_OK
;
11812 * 'validate_name()' - Make sure the printer name only contains valid chars.
11815 static int /* O - 0 if name is no good, 1 if good */
11816 validate_name(const char *name
) /* I - Name to check */
11818 const char *ptr
; /* Pointer into name */
11822 * Scan the whole name...
11825 for (ptr
= name
; *ptr
; ptr
++)
11826 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11830 * All the characters are good; validate the length, too...
11833 return ((ptr
- name
) < 128);
11838 * 'validate_user()' - Validate the user for the request.
11841 static int /* O - 1 if permitted, 0 otherwise */
11842 validate_user(cupsd_job_t
*job
, /* I - Job */
11843 cupsd_client_t
*con
, /* I - Client connection */
11844 const char *owner
, /* I - Owner of job/resource */
11845 char *username
, /* O - Authenticated username */
11846 int userlen
) /* I - Length of username */
11848 cupsd_printer_t
*printer
; /* Printer for job */
11851 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11852 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11854 job
->id
, con
? con
->http
.fd
: 0,
11855 owner
? owner
: "(null)", username
, userlen
);
11858 * Validate input...
11861 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11865 * Get the best authenticated username that is available.
11868 strlcpy(username
, get_username(con
), userlen
);
11871 * Check the username against the owner...
11874 printer
= cupsdFindDest(job
->dest
);
11876 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11877 con
, owner
) == HTTP_OK
);
11882 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".