2 * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2011 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 * send_document() - Send a file to a printer or class.
92 * send_http_error() - Send a HTTP error back to the IPP client.
93 * send_ipp_status() - Send a status back to the IPP client.
94 * set_default() - Set the default destination...
95 * set_job_attrs() - Set job attributes.
96 * set_printer_attrs() - Set printer attributes.
97 * set_printer_defaults() - Set printer default options from a request.
98 * start_printer() - Start a printer.
99 * stop_printer() - Stop a printer.
100 * url_encode_attr() - URL-encode a string attribute.
101 * url_encode_string() - URL-encode a string.
102 * user_allowed() - See if a user is allowed to print to a queue.
103 * validate_job() - Validate printer options and destination.
104 * validate_name() - Make sure the printer name only contains
106 * validate_user() - Validate the user for the request.
110 * Include necessary headers...
114 #include <cups/ppd-private.h>
117 # include <ApplicationServices/ApplicationServices.h>
118 # ifdef HAVE_COLORSYNCREGISTERDEVICE
119 extern CFUUIDRef
ColorSyncCreateUUIDFromUInt32(unsigned id
);
120 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
121 # include <CoreFoundation/CoreFoundation.h>
122 # ifdef HAVE_MEMBERSHIP_H
123 # include <membership.h>
124 # endif /* HAVE_MEMBERSHIP_H */
125 # ifdef HAVE_MEMBERSHIPPRIV_H
126 # include <membershipPriv.h>
128 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
129 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
130 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
131 # endif /* HAVE_MEMBERSHIPPRIV_H */
132 #endif /* __APPLE__ */
139 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
140 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
141 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
142 mime_type_t
*filetype
, int compression
);
143 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
144 mime_type_t
*filetype
);
145 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
146 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
147 static void add_job_uuid(cupsd_job_t
*job
);
148 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
149 static void add_printer_state_reasons(cupsd_client_t
*con
,
151 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
153 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
154 # ifdef HAVE_COLORSYNCREGISTERDEVICE
155 CFMutableDictionaryRef profile
,
157 CMDeviceProfileInfo
*profile
,
158 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
159 unsigned id
, const char *name
,
160 const char *text
, const char *iccfile
);
161 static void apple_register_profiles(cupsd_printer_t
*p
);
162 static void apple_unregister_profiles(cupsd_printer_t
*p
);
163 #endif /* __APPLE__ */
164 static void apply_printer_defaults(cupsd_printer_t
*printer
,
166 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
167 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
168 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
169 static void cancel_subscription(cupsd_client_t
*con
, int id
);
170 static int check_rss_recipient(const char *recipient
);
171 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
172 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
174 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
175 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
176 ipp_tag_t group
, int quickcopy
,
177 cups_array_t
*exclude
);
178 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
180 static int copy_file(const char *from
, const char *to
);
181 static int copy_model(cupsd_client_t
*con
, const char *from
,
183 static void copy_job_attrs(cupsd_client_t
*con
,
185 cups_array_t
*ra
, cups_array_t
*exclude
);
186 static void copy_printer_attrs(cupsd_client_t
*con
,
187 cupsd_printer_t
*printer
,
189 static void copy_subscription_attrs(cupsd_client_t
*con
,
190 cupsd_subscription_t
*sub
,
192 cups_array_t
*exclude
);
193 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
194 static cups_array_t
*create_requested_array(ipp_t
*request
);
195 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
196 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
197 static void get_default(cupsd_client_t
*con
);
198 static void get_devices(cupsd_client_t
*con
);
199 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
200 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
201 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
202 static void get_notifications(cupsd_client_t
*con
);
203 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
204 static void get_ppds(cupsd_client_t
*con
);
205 static void get_printers(cupsd_client_t
*con
, int type
);
206 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
207 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
208 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
209 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
210 static const char *get_username(cupsd_client_t
*con
);
211 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
212 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
213 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
214 static int ppd_parse_line(const char *line
, char *option
, int olen
,
215 char *choice
, int clen
);
216 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
217 static void read_job_ticket(cupsd_client_t
*con
);
218 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
219 static void release_held_new_jobs(cupsd_client_t
*con
,
220 ipp_attribute_t
*uri
);
221 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
222 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
223 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
224 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
225 ipp_attribute_t
*auth_info
);
226 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
227 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
228 cupsd_printer_t
*printer
);
229 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
230 const char *message
, ...)
231 __attribute__((__format__(__printf__
, 3, 4)));
232 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
233 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
234 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
235 static void set_printer_defaults(cupsd_client_t
*con
,
236 cupsd_printer_t
*printer
);
237 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
238 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
239 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
241 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
242 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
243 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
244 static int validate_name(const char *name
);
245 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
246 const char *owner
, char *username
,
251 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
254 int /* O - 1 on success, 0 on failure */
255 cupsdProcessIPPRequest(
256 cupsd_client_t
*con
) /* I - Client connection */
258 ipp_tag_t group
; /* Current group tag */
259 ipp_attribute_t
*attr
; /* Current attribute */
260 ipp_attribute_t
*charset
; /* Character set attribute */
261 ipp_attribute_t
*language
; /* Language attribute */
262 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
263 ipp_attribute_t
*username
; /* requesting-user-name attr */
264 int sub_id
; /* Subscription ID */
267 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
268 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
269 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
272 * First build an empty response message for this request...
275 con
->response
= ippNew();
277 con
->response
->request
.status
.version
[0] =
278 con
->request
->request
.op
.version
[0];
279 con
->response
->request
.status
.version
[1] =
280 con
->request
->request
.op
.version
[1];
281 con
->response
->request
.status
.request_id
=
282 con
->request
->request
.op
.request_id
;
285 * Then validate the request header and required attributes...
288 if (con
->request
->request
.any
.version
[0] != 1 &&
289 con
->request
->request
.any
.version
[0] != 2)
292 * Return an error, since we only support IPP 1.x and 2.x.
295 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
296 "%04X %s Bad request version number %d.%d",
297 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
298 con
->request
->request
.any
.version
[0],
299 con
->request
->request
.any
.version
[1]);
301 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
302 _("Bad request version number %d.%d."),
303 con
->request
->request
.any
.version
[0],
304 con
->request
->request
.any
.version
[1]);
306 else if (con
->request
->request
.any
.request_id
< 1)
309 * Return an error, since request IDs must be between 1 and 2^31-1
312 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
313 "%04X %s Bad request ID %d",
314 IPP_BAD_REQUEST
, con
->http
.hostname
,
315 con
->request
->request
.any
.request_id
);
317 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
318 con
->request
->request
.any
.request_id
);
320 else if (!con
->request
->attrs
)
322 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
323 "%04X %s No attributes in request",
324 IPP_BAD_REQUEST
, con
->http
.hostname
);
326 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
331 * Make sure that the attributes are provided in the correct order and
332 * don't repeat groups...
335 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
338 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
341 * Out of order; return an error...
344 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
345 "%04X %s Attribute groups are out of order",
346 IPP_BAD_REQUEST
, con
->http
.hostname
);
348 send_ipp_status(con
, IPP_BAD_REQUEST
,
349 _("Attribute groups are out of order (%x < %x)."),
350 attr
->group_tag
, group
);
354 group
= attr
->group_tag
;
359 * Then make sure that the first three attributes are:
362 * attributes-natural-language
363 * printer-uri/job-uri
366 attr
= con
->request
->attrs
;
367 if (attr
&& attr
->name
&&
368 !strcmp(attr
->name
, "attributes-charset") &&
369 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
377 if (attr
&& attr
->name
&&
378 !strcmp(attr
->name
, "attributes-natural-language") &&
379 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
384 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
385 IPP_TAG_URI
)) != NULL
)
387 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
388 IPP_TAG_URI
)) != NULL
)
390 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
391 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
396 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
397 "attributes-charset", NULL
,
398 charset
->values
[0].string
.text
);
400 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
401 "attributes-charset", NULL
, "utf-8");
404 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
405 "attributes-natural-language", NULL
,
406 language
->values
[0].string
.text
);
408 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
409 "attributes-natural-language", NULL
, DefaultLanguage
);
412 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
413 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
416 * Bad character set...
419 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
420 charset
->values
[0].string
.text
);
421 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
422 "%04X %s Unsupported attributes-charset value \"%s\"",
423 IPP_CHARSET
, con
->http
.hostname
,
424 charset
->values
[0].string
.text
);
425 send_ipp_status(con
, IPP_BAD_REQUEST
,
426 _("Unsupported character set \"%s\"."),
427 charset
->values
[0].string
.text
);
429 else if (!charset
|| !language
||
431 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
432 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
433 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
434 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
435 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
438 * Return an error, since attributes-charset,
439 * attributes-natural-language, and printer-uri/job-uri are required
440 * for all operations.
445 cupsdLogMessage(CUPSD_LOG_ERROR
,
446 "Missing attributes-charset attribute");
448 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
449 "%04X %s Missing attributes-charset attribute",
450 IPP_BAD_REQUEST
, con
->http
.hostname
);
455 cupsdLogMessage(CUPSD_LOG_ERROR
,
456 "Missing attributes-natural-language attribute");
458 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
459 "%04X %s Missing attributes-natural-language attribute",
460 IPP_BAD_REQUEST
, con
->http
.hostname
);
465 cupsdLogMessage(CUPSD_LOG_ERROR
,
466 "Missing printer-uri, job-uri, or ppd-name "
469 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
470 "%04X %s Missing printer-uri, job-uri, or ppd-name "
471 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
474 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
476 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
477 cupsdLogMessage(CUPSD_LOG_DEBUG
,
478 "attr \"%s\": group_tag = %x, value_tag = %x",
479 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
482 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
484 send_ipp_status(con
, IPP_BAD_REQUEST
,
485 _("Missing required attributes."));
490 * OK, all the checks pass so far; make sure requesting-user-name is
491 * not "root" from a remote host...
494 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
495 IPP_TAG_NAME
)) != NULL
)
498 * Check for root user...
501 if (!strcmp(username
->values
[0].string
.text
, "root") &&
502 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
503 strcmp(con
->username
, "root"))
506 * Remote unauthenticated user masquerading as local root...
509 _cupsStrFree(username
->values
[0].string
.text
);
510 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
514 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
515 IPP_TAG_INTEGER
)) != NULL
)
516 sub_id
= attr
->values
[0].integer
;
521 * Then try processing the operation...
525 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
526 ippOpString(con
->request
->request
.op
.operation_id
),
527 uri
->values
[0].string
.text
);
529 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
530 ippOpString(con
->request
->request
.op
.operation_id
));
532 switch (con
->request
->request
.op
.operation_id
)
538 case IPP_VALIDATE_JOB
:
539 validate_job(con
, uri
);
542 case IPP_CREATE_JOB
:
543 create_job(con
, uri
);
546 case IPP_SEND_DOCUMENT
:
547 send_document(con
, uri
);
550 case IPP_CANCEL_JOB
:
551 cancel_job(con
, uri
);
554 case IPP_GET_JOB_ATTRIBUTES
:
555 get_job_attrs(con
, uri
);
562 case IPP_GET_PRINTER_ATTRIBUTES
:
563 get_printer_attrs(con
, uri
);
566 case IPP_GET_PRINTER_SUPPORTED_VALUES
:
567 get_printer_supported(con
, uri
);
574 case IPP_RELEASE_JOB
:
575 release_job(con
, uri
);
578 case IPP_RESTART_JOB
:
579 restart_job(con
, uri
);
582 case IPP_PAUSE_PRINTER
:
583 stop_printer(con
, uri
);
586 case IPP_RESUME_PRINTER
:
587 start_printer(con
, uri
);
590 case IPP_PURGE_JOBS
:
591 case IPP_CANCEL_JOBS
:
592 case IPP_CANCEL_MY_JOBS
:
593 cancel_all_jobs(con
, uri
);
596 case IPP_SET_JOB_ATTRIBUTES
:
597 set_job_attrs(con
, uri
);
600 case IPP_SET_PRINTER_ATTRIBUTES
:
601 set_printer_attrs(con
, uri
);
604 case IPP_HOLD_NEW_JOBS
:
605 hold_new_jobs(con
, uri
);
608 case IPP_RELEASE_HELD_NEW_JOBS
:
609 release_held_new_jobs(con
, uri
);
616 case CUPS_GET_DEFAULT
:
620 case CUPS_GET_PRINTERS
:
621 get_printers(con
, 0);
624 case CUPS_GET_CLASSES
:
625 get_printers(con
, CUPS_PRINTER_CLASS
);
628 case CUPS_ADD_PRINTER
:
629 add_printer(con
, uri
);
632 case CUPS_DELETE_PRINTER
:
633 delete_printer(con
, uri
);
636 case CUPS_ADD_CLASS
:
640 case CUPS_DELETE_CLASS
:
641 delete_printer(con
, uri
);
644 case CUPS_ACCEPT_JOBS
:
645 case IPP_ENABLE_PRINTER
:
646 accept_jobs(con
, uri
);
649 case CUPS_REJECT_JOBS
:
650 case IPP_DISABLE_PRINTER
:
651 reject_jobs(con
, uri
);
654 case CUPS_SET_DEFAULT
:
655 set_default(con
, uri
);
658 case CUPS_GET_DEVICES
:
662 case CUPS_GET_DOCUMENT
:
663 get_document(con
, uri
);
678 case CUPS_AUTHENTICATE_JOB
:
679 authenticate_job(con
, uri
);
682 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
683 case IPP_CREATE_JOB_SUBSCRIPTION
:
684 create_subscription(con
, uri
);
687 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
688 get_subscription_attrs(con
, sub_id
);
691 case IPP_GET_SUBSCRIPTIONS
:
692 get_subscriptions(con
, uri
);
695 case IPP_RENEW_SUBSCRIPTION
:
696 renew_subscription(con
, sub_id
);
699 case IPP_CANCEL_SUBSCRIPTION
:
700 cancel_subscription(con
, sub_id
);
703 case IPP_GET_NOTIFICATIONS
:
704 get_notifications(con
);
708 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
709 "%04X %s Operation %04X (%s) not supported",
710 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
711 con
->request
->request
.op
.operation_id
,
712 ippOpString(con
->request
->request
.op
.operation_id
));
714 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
715 _("%s not supported."),
717 con
->request
->request
.op
.operation_id
));
727 * Sending data from the scheduler...
730 cupsdLogMessage(con
->response
->request
.status
.status_code
731 >= IPP_BAD_REQUEST
&&
732 con
->response
->request
.status
.status_code
733 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
734 "Returning IPP %s for %s (%s) from %s",
735 ippErrorString(con
->response
->request
.status
.status_code
),
736 ippOpString(con
->request
->request
.op
.operation_id
),
737 uri
? uri
->values
[0].string
.text
: "no URI",
740 if (LogLevel
== CUPSD_LOG_DEBUG2
)
741 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
742 "cupsdProcessIPPRequest: ippLength(response)=%ld",
743 (long)ippLength(con
->response
));
745 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
747 #ifdef CUPSD_USE_CHUNKING
749 * Because older versions of CUPS (1.1.17 and older) and some IPP
750 * clients do not implement chunking properly, we cannot use
751 * chunking by default. This may become the default in future
752 * CUPS releases, or we might add a configuration directive for
756 if (con
->http
.version
== HTTP_1_1
)
758 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
761 if (cupsdFlushHeader(con
) < 0)
764 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
767 #endif /* CUPSD_USE_CHUNKING */
769 size_t length
; /* Length of response */
772 length
= ippLength(con
->response
);
774 if (con
->file
>= 0 && !con
->pipe_pid
)
776 struct stat fileinfo
; /* File information */
779 if (!fstat(con
->file
, &fileinfo
))
780 length
+= fileinfo
.st_size
;
783 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
784 CUPS_LLCAST length
) < 0)
787 if (cupsdFlushHeader(con
) < 0)
790 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
791 con
->http
.data_remaining
= length
;
793 if (con
->http
.data_remaining
<= INT_MAX
)
794 con
->http
._data_remaining
= con
->http
.data_remaining
;
796 con
->http
._data_remaining
= INT_MAX
;
799 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
800 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
803 * Tell the caller the response header was sent successfully...
811 * Tell the caller the response header could not be sent...
820 * Sending data from a subprocess like cups-deviced; tell the caller
821 * everything is A-OK so far...
830 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
833 int /* O - 0 on success, -1 on error */
834 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
836 cupsd_printer_t
*printer
; /* Destination printer or class */
837 ipp_attribute_t
*attr
; /* job-sheets attribute */
838 int kbytes
; /* Kilobytes in banner */
841 job
->pending_timeout
= 0;
844 * See if we need to add the ending sheet...
847 if (!cupsdLoadJob(job
))
850 printer
= cupsdFindDest(job
->dest
);
851 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
854 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
855 attr
&& attr
->num_values
> 1)
861 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
862 attr
->values
[1].string
.text
);
864 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
867 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
875 * 'accept_jobs()' - Accept print jobs to a printer.
879 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
880 ipp_attribute_t
*uri
) /* I - Printer or class URI */
882 http_status_t status
; /* Policy status */
883 cups_ptype_t dtype
; /* Destination type (printer/class) */
884 cupsd_printer_t
*printer
; /* Printer data */
887 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
888 con
->http
.fd
, uri
->values
[0].string
.text
);
891 * Is the destination valid?
894 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
900 send_ipp_status(con
, IPP_NOT_FOUND
,
901 _("The printer or class does not exist."));
909 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
911 send_http_error(con
, status
, printer
);
916 * Accept jobs sent to the printer...
919 printer
->accepting
= 1;
920 printer
->state_message
[0] = '\0';
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
;
1132 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
1133 pclass
->accepting
? "Now" : "No longer");
1136 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1137 IPP_TAG_BOOLEAN
)) != NULL
)
1139 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1140 cupsdDeregisterPrinter(pclass
, 1);
1142 cupsdLogMessage(CUPSD_LOG_INFO
,
1143 "Setting %s printer-is-shared to %d (was %d.)",
1144 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1146 pclass
->shared
= attr
->values
[0].boolean
;
1149 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1150 IPP_TAG_ENUM
)) != NULL
)
1152 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1153 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1155 send_ipp_status(con
, IPP_BAD_REQUEST
,
1156 _("Attempt to set %s printer-state to bad value %d."),
1157 pclass
->name
, attr
->values
[0].integer
);
1161 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1162 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1164 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1165 cupsdStopPrinter(pclass
, 0);
1168 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1169 need_restart_job
= 1;
1172 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1173 IPP_TAG_TEXT
)) != NULL
)
1175 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1176 sizeof(pclass
->state_message
));
1178 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1179 pclass
->state_message
);
1181 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1182 IPP_TAG_URI
)) != NULL
)
1185 * Clear the printer array as needed...
1188 need_restart_job
= 1;
1190 if (pclass
->num_printers
> 0)
1192 free(pclass
->printers
);
1193 pclass
->num_printers
= 0;
1197 * Add each printer or class that is listed...
1200 for (i
= 0; i
< attr
->num_values
; i
++)
1203 * Search for the printer or class URI...
1206 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1212 send_ipp_status(con
, IPP_NOT_FOUND
,
1213 _("The printer or class does not exist."));
1216 else if (dtype
& CUPS_PRINTER_CLASS
)
1218 send_ipp_status(con
, IPP_BAD_REQUEST
,
1219 _("Nested classes are not allowed."));
1224 * Add it to the class...
1227 cupsdAddPrinterToClass(pclass
, member
);
1231 set_printer_defaults(con
, pclass
);
1233 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1234 IPP_TAG_KEYWORD
)) != NULL
)
1235 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1238 * Update the printer class attributes and return...
1241 cupsdSetPrinterAttrs(pclass
);
1242 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1244 if (need_restart_job
&& pclass
->job
)
1247 * Reset the current job to a "pending" status...
1250 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1251 "Job restarted because the class was modified.");
1254 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1258 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1259 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1260 pclass
->name
, get_username(con
));
1262 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1263 pclass
->name
, get_username(con
));
1267 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1268 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1269 pclass
->name
, get_username(con
));
1271 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1272 pclass
->name
, get_username(con
));
1275 con
->response
->request
.status
.status_code
= IPP_OK
;
1280 * 'add_file()' - Add a file to a job.
1283 static int /* O - 0 on success, -1 on error */
1284 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1285 cupsd_job_t
*job
, /* I - Job to add to */
1286 mime_type_t
*filetype
, /* I - Type of file */
1287 int compression
) /* I - Compression */
1289 mime_type_t
**filetypes
; /* New filetypes array... */
1290 int *compressions
; /* New compressions array... */
1293 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1294 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1295 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1296 filetype
->super
, filetype
->type
, compression
);
1299 * Add the file to the job...
1302 if (job
->num_files
== 0)
1304 compressions
= (int *)malloc(sizeof(int));
1305 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1309 compressions
= (int *)realloc(job
->compressions
,
1310 (job
->num_files
+ 1) * sizeof(int));
1311 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1312 (job
->num_files
+ 1) *
1313 sizeof(mime_type_t
*));
1316 if (!compressions
|| !filetypes
)
1318 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1319 "Job aborted because the scheduler ran out of memory.");
1322 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1323 _("Unable to allocate memory for file types."));
1328 job
->compressions
= compressions
;
1329 job
->compressions
[job
->num_files
] = compression
;
1330 job
->filetypes
= filetypes
;
1331 job
->filetypes
[job
->num_files
] = filetype
;
1336 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1343 * 'add_job()' - Add a job to a print queue.
1346 static cupsd_job_t
* /* O - Job object */
1347 add_job(cupsd_client_t
*con
, /* I - Client connection */
1348 cupsd_printer_t
*printer
, /* I - Destination printer */
1349 mime_type_t
*filetype
) /* I - First print file type, if any */
1351 http_status_t status
; /* Policy status */
1352 ipp_attribute_t
*attr
, /* Current attribute */
1353 *auth_info
; /* auth-info attribute */
1354 const char *val
; /* Default option value */
1355 int priority
; /* Job priority */
1356 cupsd_job_t
*job
; /* Current job */
1357 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1358 int kbytes
; /* Size of print file */
1359 int i
; /* Looping var */
1360 int lowerpagerange
; /* Page range bound */
1361 int exact
; /* Did we have an exact match? */
1362 ipp_attribute_t
*media_col
, /* media-col attribute */
1363 *media_margin
; /* media-*-margin attribute */
1364 ipp_t
*unsup_col
; /* media-col in unsupported response */
1367 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1368 con
, con
->http
.fd
, printer
, printer
->name
,
1369 filetype
, filetype
? filetype
->super
: "none",
1370 filetype
? filetype
->type
: "none");
1373 * Check remote printing to non-shared printer...
1376 if (!printer
->shared
&&
1377 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
1378 _cups_strcasecmp(con
->http
.hostname
, ServerName
))
1380 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1381 _("The printer or class is not shared."));
1389 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1391 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1393 send_http_error(con
, status
, printer
);
1396 else if (printer
->num_auth_info_required
== 1 &&
1397 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1400 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1404 else if (auth_info
&& !con
->http
.tls
&&
1405 !httpAddrLocalhost(con
->http
.hostaddr
))
1408 * Require encryption of auth-info over non-local connections...
1411 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1414 #endif /* HAVE_SSL */
1417 * See if the printer is accepting jobs...
1420 if (!printer
->accepting
)
1422 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1423 _("Destination \"%s\" is not accepting jobs."),
1429 * Validate job template attributes; for now just document-format,
1430 * copies, number-up, and page-ranges...
1433 if (filetype
&& printer
->filetypes
&&
1434 !cupsArrayFind(printer
->filetypes
, filetype
))
1436 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1437 /* MIME media type string */
1440 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1443 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1444 _("Unsupported format \"%s\"."), mimetype
);
1446 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1447 "document-format", NULL
, mimetype
);
1452 if ((attr
= ippFindAttribute(con
->request
, "copies",
1453 IPP_TAG_INTEGER
)) != NULL
)
1455 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1457 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1458 attr
->values
[0].integer
);
1459 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1460 "copies", attr
->values
[0].integer
);
1465 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1466 IPP_TAG_ZERO
)) != NULL
)
1468 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1469 attr
->value_tag
!= IPP_TAG_NAME
)
1471 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1475 if (attr
->num_values
> 2)
1477 send_ipp_status(con
, IPP_BAD_REQUEST
,
1478 _("Too many job-sheets values (%d > 2)."),
1483 for (i
= 0; i
< attr
->num_values
; i
++)
1484 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1485 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1487 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1488 attr
->values
[i
].string
.text
);
1493 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1494 IPP_TAG_INTEGER
)) != NULL
)
1496 if (attr
->values
[0].integer
!= 1 &&
1497 attr
->values
[0].integer
!= 2 &&
1498 attr
->values
[0].integer
!= 4 &&
1499 attr
->values
[0].integer
!= 6 &&
1500 attr
->values
[0].integer
!= 9 &&
1501 attr
->values
[0].integer
!= 16)
1503 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1504 attr
->values
[0].integer
);
1505 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1506 "number-up", attr
->values
[0].integer
);
1511 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1512 IPP_TAG_RANGE
)) != NULL
)
1514 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1516 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1517 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1519 send_ipp_status(con
, IPP_BAD_REQUEST
,
1520 _("Bad page-ranges values %d-%d."),
1521 attr
->values
[i
].range
.lower
,
1522 attr
->values
[i
].range
.upper
);
1526 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1531 * Do media selection as needed...
1534 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1535 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1536 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1539 (media_col
= ippFindAttribute(con
->request
, "media-col",
1540 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1542 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1544 unsup_col
= ippNew();
1545 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1546 "media-bottom-margin",
1547 IPP_TAG_INTEGER
)) != NULL
)
1548 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1549 "media-bottom-margin", media_margin
->values
[0].integer
);
1551 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1552 "media-left-margin",
1553 IPP_TAG_INTEGER
)) != NULL
)
1554 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1555 "media-left-margin", media_margin
->values
[0].integer
);
1557 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1558 "media-right-margin",
1559 IPP_TAG_INTEGER
)) != NULL
)
1560 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1561 "media-right-margin", media_margin
->values
[0].integer
);
1563 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1565 IPP_TAG_INTEGER
)) != NULL
)
1566 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1567 "media-top-margin", media_margin
->values
[0].integer
);
1569 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1571 ippDelete(unsup_col
);
1576 * Make sure we aren't over our limit...
1579 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1582 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1584 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1588 if ((i
= check_quotas(con
, printer
)) < 0)
1590 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1595 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1600 * Create the job and set things up...
1603 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1604 IPP_TAG_INTEGER
)) != NULL
)
1605 priority
= attr
->values
[0].integer
;
1608 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1609 printer
->options
)) != NULL
)
1610 priority
= atoi(val
);
1614 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1618 if (!ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
))
1619 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1622 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1624 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1625 _("Unable to add job for destination \"%s\"."),
1630 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1631 CUPS_PRINTER_REMOTE
);
1632 job
->attrs
= con
->request
;
1634 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1636 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1639 apply_printer_defaults(printer
, job
);
1641 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1643 if (con
->username
[0])
1645 cupsdSetString(&job
->username
, con
->username
);
1648 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1652 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1653 "add_job: requesting-user-name=\"%s\"",
1654 attr
->values
[0].string
.text
);
1656 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1659 cupsdSetString(&job
->username
, "anonymous");
1662 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1663 "job-originating-user-name", NULL
, job
->username
);
1666 attr
->group_tag
= IPP_TAG_JOB
;
1667 _cupsStrFree(attr
->name
);
1668 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1671 if (con
->username
[0] || auth_info
)
1673 save_auth_info(con
, job
, auth_info
);
1676 * Remove the auth-info attribute from the attribute data...
1680 ippDeleteAttribute(job
->attrs
, auth_info
);
1683 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1684 IPP_TAG_ZERO
)) != NULL
)
1687 * Request contains a job-originating-host-name attribute; validate it...
1690 if (attr
->value_tag
!= IPP_TAG_NAME
||
1691 attr
->num_values
!= 1 ||
1692 strcmp(con
->http
.hostname
, "localhost"))
1695 * Can't override the value if we aren't connected via localhost.
1696 * Also, we can only have 1 value and it must be a name value.
1699 switch (attr
->value_tag
)
1701 case IPP_TAG_STRING
:
1702 case IPP_TAG_TEXTLANG
:
1703 case IPP_TAG_NAMELANG
:
1706 case IPP_TAG_KEYWORD
:
1708 case IPP_TAG_URISCHEME
:
1709 case IPP_TAG_CHARSET
:
1710 case IPP_TAG_LANGUAGE
:
1711 case IPP_TAG_MIMETYPE
:
1713 * Free old strings...
1716 for (i
= 0; i
< attr
->num_values
; i
++)
1718 _cupsStrFree(attr
->values
[i
].string
.text
);
1719 attr
->values
[i
].string
.text
= NULL
;
1720 if (attr
->values
[i
].string
.charset
)
1722 _cupsStrFree(attr
->values
[i
].string
.charset
);
1723 attr
->values
[i
].string
.charset
= NULL
;
1732 * Use the default connection hostname instead...
1735 attr
->value_tag
= IPP_TAG_NAME
;
1736 attr
->num_values
= 1;
1737 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1740 attr
->group_tag
= IPP_TAG_JOB
;
1745 * No job-originating-host-name attribute, so use the hostname from
1749 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1750 "job-originating-host-name", NULL
, con
->http
.hostname
);
1753 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1755 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1756 "time-at-processing", 0);
1757 attr
->value_tag
= IPP_TAG_NOVALUE
;
1758 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1759 "time-at-completed", 0);
1760 attr
->value_tag
= IPP_TAG_NOVALUE
;
1763 * Add remaining job attributes...
1766 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1767 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1768 "job-state", IPP_JOB_STOPPED
);
1769 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1770 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1771 "job-media-sheets-completed", 0);
1772 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1775 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1776 IPP_TAG_INTEGER
)) != NULL
)
1777 attr
->values
[0].integer
= 0;
1779 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1781 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1782 IPP_TAG_KEYWORD
)) == NULL
)
1783 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1786 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1787 printer
->options
)) == NULL
)
1790 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1791 "job-hold-until", NULL
, val
);
1793 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1796 * Hold job until specified time...
1799 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1801 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1802 job
->state_value
= IPP_JOB_HELD
;
1804 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1806 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1807 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1808 job
->state_value
= IPP_JOB_HELD
;
1812 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1813 job
->state_value
= IPP_JOB_PENDING
;
1816 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1820 * Add job sheets options...
1823 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1824 IPP_TAG_ZERO
)) == NULL
)
1826 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1827 "Adding default job-sheets values \"%s,%s\"...",
1828 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1830 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1832 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1833 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1836 job
->job_sheets
= attr
;
1839 * Enforce classification level if set...
1844 cupsdLogMessage(CUPSD_LOG_INFO
,
1845 "Classification=\"%s\", ClassifyOverride=%d",
1846 Classification
? Classification
: "(null)",
1849 if (ClassifyOverride
)
1851 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1852 (attr
->num_values
== 1 ||
1853 !strcmp(attr
->values
[1].string
.text
, "none")))
1856 * Force the leading banner to have the classification on it...
1859 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1861 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1862 "job-sheets=\"%s,none\", "
1863 "job-originating-user-name=\"%s\"",
1864 Classification
, job
->username
);
1866 else if (attr
->num_values
== 2 &&
1867 strcmp(attr
->values
[0].string
.text
,
1868 attr
->values
[1].string
.text
) &&
1869 strcmp(attr
->values
[0].string
.text
, "none") &&
1870 strcmp(attr
->values
[1].string
.text
, "none"))
1873 * Can't put two different security markings on the same document!
1876 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1878 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1879 "job-sheets=\"%s,%s\", "
1880 "job-originating-user-name=\"%s\"",
1881 attr
->values
[0].string
.text
,
1882 attr
->values
[1].string
.text
, job
->username
);
1884 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1885 strcmp(attr
->values
[0].string
.text
, "none") &&
1886 (attr
->num_values
== 1 ||
1887 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1888 strcmp(attr
->values
[1].string
.text
, "none"))))
1890 if (attr
->num_values
== 1)
1891 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1892 "CLASSIFICATION OVERRIDDEN "
1893 "job-sheets=\"%s\", "
1894 "job-originating-user-name=\"%s\"",
1895 attr
->values
[0].string
.text
, job
->username
);
1897 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1898 "CLASSIFICATION OVERRIDDEN "
1899 "job-sheets=\"%s,%s\",fffff "
1900 "job-originating-user-name=\"%s\"",
1901 attr
->values
[0].string
.text
,
1902 attr
->values
[1].string
.text
, job
->username
);
1905 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1906 (attr
->num_values
== 1 ||
1907 strcmp(attr
->values
[1].string
.text
, Classification
)))
1910 * Force the banner to have the classification on it...
1913 if (attr
->num_values
> 1 &&
1914 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1916 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1917 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1921 if (attr
->num_values
== 1 ||
1922 strcmp(attr
->values
[0].string
.text
, "none"))
1923 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1925 if (attr
->num_values
> 1 &&
1926 strcmp(attr
->values
[1].string
.text
, "none"))
1927 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1930 if (attr
->num_values
> 1)
1931 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1932 "CLASSIFICATION FORCED "
1933 "job-sheets=\"%s,%s\", "
1934 "job-originating-user-name=\"%s\"",
1935 attr
->values
[0].string
.text
,
1936 attr
->values
[1].string
.text
, job
->username
);
1938 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1939 "CLASSIFICATION FORCED "
1940 "job-sheets=\"%s\", "
1941 "job-originating-user-name=\"%s\"",
1942 Classification
, job
->username
);
1947 * See if we need to add the starting sheet...
1950 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1952 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1953 attr
->values
[0].string
.text
);
1955 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1957 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1958 "Aborting job because the start banner could not be "
1963 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1966 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1967 IPP_TAG_ZERO
)) != NULL
)
1968 job
->job_sheets
= attr
;
1971 * Fill in the response info...
1974 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1975 LocalPort
, job
->id
);
1977 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1980 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1982 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1984 add_job_state_reasons(con
, job
);
1986 con
->response
->request
.status
.status_code
= IPP_OK
;
1989 * Add any job subscriptions...
1992 add_job_subscriptions(con
, job
);
1995 * Set all but the first two attributes to the job attributes group...
1998 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1999 attr
->group_tag
= IPP_TAG_JOB
;
2002 * Fire the "job created" event...
2005 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
2008 * Return the new job...
2016 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
2017 * upon the job and printer state...
2021 add_job_state_reasons(
2022 cupsd_client_t
*con
, /* I - Client connection */
2023 cupsd_job_t
*job
) /* I - Job info */
2025 cupsd_printer_t
*dest
; /* Destination printer */
2028 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
2029 con
, con
->http
.fd
, job
? job
->id
: 0);
2031 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
2033 case IPP_JOB_PENDING
:
2034 dest
= cupsdFindDest(job
->dest
);
2036 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
2037 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2038 "job-state-reasons", NULL
, "printer-stopped");
2040 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2041 "job-state-reasons", NULL
, "none");
2045 if (ippFindAttribute(job
->attrs
, "job-hold-until",
2046 IPP_TAG_KEYWORD
) != NULL
||
2047 ippFindAttribute(job
->attrs
, "job-hold-until",
2048 IPP_TAG_NAME
) != NULL
)
2049 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2050 "job-state-reasons", NULL
, "job-hold-until-specified");
2052 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2053 "job-state-reasons", NULL
, "job-incoming");
2056 case IPP_JOB_PROCESSING
:
2057 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2058 "job-state-reasons", NULL
, "job-printing");
2061 case IPP_JOB_STOPPED
:
2062 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2063 "job-state-reasons", NULL
, "job-stopped");
2066 case IPP_JOB_CANCELED
:
2067 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2068 "job-state-reasons", NULL
, "job-canceled-by-user");
2071 case IPP_JOB_ABORTED
:
2072 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2073 "job-state-reasons", NULL
, "aborted-by-system");
2076 case IPP_JOB_COMPLETED
:
2077 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
2078 "job-state-reasons", NULL
, "job-completed-successfully");
2085 * 'add_job_subscriptions()' - Add any subscriptions for a job.
2089 add_job_subscriptions(
2090 cupsd_client_t
*con
, /* I - Client connection */
2091 cupsd_job_t
*job
) /* I - Newly created job */
2093 int i
; /* Looping var */
2094 ipp_attribute_t
*prev
, /* Previous attribute */
2095 *next
, /* Next attribute */
2096 *attr
; /* Current attribute */
2097 cupsd_subscription_t
*sub
; /* Subscription object */
2098 const char *recipient
, /* notify-recipient-uri */
2099 *pullmethod
; /* notify-pull-method */
2100 ipp_attribute_t
*user_data
; /* notify-user-data */
2101 int interval
; /* notify-time-interval */
2102 unsigned mask
; /* notify-events */
2106 * Find the first subscription group attribute; return if we have
2110 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2111 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2118 * Process the subscription attributes in the request...
2127 mask
= CUPSD_EVENT_NONE
;
2129 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2131 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2132 attr
->value_tag
== IPP_TAG_URI
)
2135 * Validate the recipient scheme against the ServerBin/notifier
2139 char notifier
[1024], /* Notifier filename */
2140 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2141 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2142 host
[HTTP_MAX_URI
], /* Host portion of URI */
2143 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2144 int port
; /* Port portion of URI */
2147 recipient
= attr
->values
[0].string
.text
;
2149 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2150 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2151 host
, sizeof(host
), &port
,
2152 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2154 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2155 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2156 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2157 "notify-status-code", IPP_URI_SCHEME
);
2161 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2163 if (access(notifier
, X_OK
))
2165 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2166 _("notify-recipient-uri URI \"%s\" uses unknown "
2167 "scheme."), recipient
);
2168 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2169 "notify-status-code", IPP_URI_SCHEME
);
2173 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2175 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2176 _("notify-recipient-uri URI \"%s\" is already used."),
2178 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2179 "notify-status-code", IPP_ATTRIBUTES
);
2183 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2184 attr
->value_tag
== IPP_TAG_KEYWORD
)
2186 pullmethod
= attr
->values
[0].string
.text
;
2188 if (strcmp(pullmethod
, "ippget"))
2190 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2191 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2192 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2193 "notify-status-code", IPP_ATTRIBUTES
);
2197 else if (!strcmp(attr
->name
, "notify-charset") &&
2198 attr
->value_tag
== IPP_TAG_CHARSET
&&
2199 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2200 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2202 send_ipp_status(con
, IPP_CHARSET
,
2203 _("Character set \"%s\" not supported."),
2204 attr
->values
[0].string
.text
);
2207 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2208 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2209 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2211 send_ipp_status(con
, IPP_CHARSET
,
2212 _("Language \"%s\" not supported."),
2213 attr
->values
[0].string
.text
);
2216 else if (!strcmp(attr
->name
, "notify-user-data") &&
2217 attr
->value_tag
== IPP_TAG_STRING
)
2219 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2221 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2222 _("The notify-user-data value is too large "
2223 "(%d > 63 octets)."),
2224 attr
->values
[0].unknown
.length
);
2230 else if (!strcmp(attr
->name
, "notify-events") &&
2231 attr
->value_tag
== IPP_TAG_KEYWORD
)
2233 for (i
= 0; i
< attr
->num_values
; i
++)
2234 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2236 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2238 send_ipp_status(con
, IPP_BAD_REQUEST
,
2239 _("The notify-lease-duration attribute cannot be "
2240 "used with job subscriptions."));
2243 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2244 attr
->value_tag
== IPP_TAG_INTEGER
)
2245 interval
= attr
->values
[0].integer
;
2250 if (!recipient
&& !pullmethod
)
2253 if (mask
== CUPSD_EVENT_NONE
)
2254 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2256 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2257 recipient
, 0)) != NULL
)
2259 sub
->interval
= interval
;
2261 cupsdSetString(&sub
->owner
, job
->username
);
2265 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2266 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2267 sub
->user_data_len
);
2270 ippAddSeparator(con
->response
);
2271 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2272 "notify-subscription-id", sub
->id
);
2274 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2282 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2285 * Remove all of the subscription attributes from the job request...
2287 * TODO: Optimize this since subscription groups have to come at the
2288 * end of the request...
2291 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2295 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2296 attr
->group_tag
== IPP_TAG_ZERO
)
2299 * Free and remove this attribute...
2307 job
->attrs
->attrs
= next
;
2313 job
->attrs
->last
= prev
;
2314 job
->attrs
->current
= prev
;
2319 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2321 * See RFC 4122 for the definition of UUIDs and the format.
2325 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2327 char uuid
[64]; /* job-uuid string */
2331 * Add a job-uuid attribute if none exists...
2334 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2335 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2336 _httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2337 uuid
, sizeof(uuid
)));
2342 * 'add_printer()' - Add a printer to the system.
2346 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2347 ipp_attribute_t
*uri
) /* I - URI of printer */
2349 http_status_t status
; /* Policy status */
2350 int i
; /* Looping var */
2351 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2352 username
[HTTP_MAX_URI
], /* Username portion of URI */
2353 host
[HTTP_MAX_URI
], /* Host portion of URI */
2354 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2355 int port
; /* Port portion of URI */
2356 cupsd_printer_t
*printer
; /* Printer/class */
2357 ipp_attribute_t
*attr
; /* Printer attribute */
2358 cups_file_t
*fp
; /* Script/PPD file */
2359 char line
[1024]; /* Line from file... */
2360 char srcfile
[1024], /* Source Script/PPD file */
2361 dstfile
[1024]; /* Destination Script/PPD file */
2362 int modify
; /* Non-zero if we are modifying */
2363 char newname
[IPP_MAX_NAME
]; /* New printer name */
2364 int changed_driver
, /* Changed the PPD/interface script? */
2365 need_restart_job
, /* Need to restart job? */
2366 set_device_uri
, /* Did we set the device URI? */
2367 set_port_monitor
; /* Did we set the port monitor? */
2370 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2371 con
->http
.fd
, uri
->values
[0].string
.text
);
2374 * Do we have a valid URI?
2377 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2378 sizeof(scheme
), username
, sizeof(username
), host
,
2379 sizeof(host
), &port
, resource
, sizeof(resource
));
2381 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2384 * No, return an error...
2387 send_ipp_status(con
, IPP_BAD_REQUEST
,
2388 _("The printer-uri must be of the form "
2389 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2394 * Do we have a valid printer name?
2397 if (!validate_name(resource
+ 10))
2400 * No, return an error...
2403 send_ipp_status(con
, IPP_BAD_REQUEST
,
2404 _("The printer-uri \"%s\" contains invalid characters."),
2405 uri
->values
[0].string
.text
);
2410 * See if the printer already exists; if not, create a new printer...
2413 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2416 * Printer doesn't exist; see if we have a class of the same name...
2419 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2420 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2423 * Yes, return an error...
2426 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2427 _("A class named \"%s\" already exists."),
2433 * No, check the default policy then add the printer...
2436 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2438 send_http_error(con
, status
, NULL
);
2442 printer
= cupsdAddPrinter(resource
+ 10);
2445 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2448 * Check the default policy, then rename the implicit printer to
2449 * "AnyPrinter" or delete it...
2452 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2454 send_http_error(con
, status
, NULL
);
2458 if (ImplicitAnyClasses
)
2460 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2461 cupsdRenamePrinter(printer
, newname
);
2464 cupsdDeletePrinter(printer
, 1);
2467 * Add the printer as a new local printer...
2470 printer
= cupsdAddPrinter(resource
+ 10);
2473 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2476 * Check the default policy, then rename the remote printer to
2477 * "Printer@server"...
2480 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2482 send_http_error(con
, status
, NULL
);
2486 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2488 cupsdRenamePrinter(printer
, newname
);
2491 * Add the printer as a new local printer...
2494 printer
= cupsdAddPrinter(resource
+ 10);
2497 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2500 send_http_error(con
, status
, printer
);
2507 * Look for attributes and copy them over as needed...
2511 need_restart_job
= 0;
2513 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2514 IPP_TAG_TEXT
)) != NULL
)
2515 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2517 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2518 IPP_TAG_TEXT
)) != NULL
)
2519 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2523 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2524 IPP_TAG_URI
)) != NULL
)
2527 * Do we have a valid device URI?
2530 http_uri_status_t uri_status
; /* URI separation status */
2531 char old_device_uri
[1024];
2532 /* Old device URI */
2535 need_restart_job
= 1;
2537 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2538 attr
->values
[0].string
.text
,
2539 scheme
, sizeof(scheme
),
2540 username
, sizeof(username
),
2541 host
, sizeof(host
), &port
,
2542 resource
, sizeof(resource
));
2544 if (uri_status
< HTTP_URI_OK
)
2546 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2547 attr
->values
[0].string
.text
);
2548 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2549 "add_printer: httpSeparateURI returned %d", uri_status
);
2553 if (!strcmp(scheme
, "file"))
2556 * See if the administrator has enabled file devices...
2559 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2562 * File devices are disabled and the URL is not file:/dev/null...
2565 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2566 _("File device URIs have been disabled. "
2567 "To enable, see the FileDevice directive in "
2568 "\"%s/cupsd.conf\"."),
2576 * See if the backend exists and is executable...
2579 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2580 if (access(srcfile
, X_OK
))
2583 * Could not find device in list!
2586 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2587 _("Bad device-uri scheme \"%s\"."), scheme
);
2592 if (printer
->sanitized_device_uri
)
2593 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2594 sizeof(old_device_uri
));
2596 old_device_uri
[0] = '\0';
2598 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2600 cupsdLogMessage(CUPSD_LOG_INFO
,
2601 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2602 printer
->name
, printer
->sanitized_device_uri
,
2608 set_port_monitor
= 0;
2610 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2611 IPP_TAG_NAME
)) != NULL
)
2613 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2616 need_restart_job
= 1;
2618 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2622 for (i
= 0; i
< supported
->num_values
; i
++)
2623 if (!strcmp(supported
->values
[i
].string
.text
,
2624 attr
->values
[0].string
.text
))
2628 if (!supported
|| i
>= supported
->num_values
)
2630 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2631 attr
->values
[0].string
.text
);
2635 cupsdLogMessage(CUPSD_LOG_INFO
,
2636 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2637 printer
->name
, attr
->values
[0].string
.text
,
2638 printer
->port_monitor
? printer
->port_monitor
: "none");
2640 if (strcmp(attr
->values
[0].string
.text
, "none"))
2641 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2643 cupsdClearString(&printer
->port_monitor
);
2645 set_port_monitor
= 1;
2648 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2649 IPP_TAG_BOOLEAN
)) != NULL
&&
2650 attr
->values
[0].boolean
!= printer
->accepting
)
2652 cupsdLogMessage(CUPSD_LOG_INFO
,
2653 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2654 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2656 printer
->accepting
= attr
->values
[0].boolean
;
2658 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2659 "%s accepting jobs.",
2660 printer
->accepting
? "Now" : "No longer");
2663 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2664 IPP_TAG_BOOLEAN
)) != NULL
)
2666 if (attr
->values
[0].boolean
&&
2667 printer
->num_auth_info_required
== 1 &&
2668 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2670 send_ipp_status(con
, IPP_BAD_REQUEST
,
2671 _("Cannot share a remote Kerberized printer."));
2675 if (printer
->shared
&& !attr
->values
[0].boolean
)
2676 cupsdDeregisterPrinter(printer
, 1);
2678 cupsdLogMessage(CUPSD_LOG_INFO
,
2679 "Setting %s printer-is-shared to %d (was %d.)",
2680 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2682 printer
->shared
= attr
->values
[0].boolean
;
2685 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2686 IPP_TAG_ENUM
)) != NULL
)
2688 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2689 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2691 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2692 attr
->values
[0].integer
);
2696 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2697 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2699 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2700 cupsdStopPrinter(printer
, 0);
2703 need_restart_job
= 1;
2704 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2708 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2709 IPP_TAG_TEXT
)) != NULL
)
2711 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2712 sizeof(printer
->state_message
));
2714 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2715 printer
->state_message
);
2718 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2719 IPP_TAG_KEYWORD
)) != NULL
)
2721 if (attr
->num_values
>
2722 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2724 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2725 _("Too many printer-state-reasons values (%d > %d)."),
2727 (int)(sizeof(printer
->reasons
) /
2728 sizeof(printer
->reasons
[0])));
2732 for (i
= 0; i
< printer
->num_reasons
; i
++)
2733 _cupsStrFree(printer
->reasons
[i
]);
2735 printer
->num_reasons
= 0;
2736 for (i
= 0; i
< attr
->num_values
; i
++)
2738 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2741 printer
->reasons
[printer
->num_reasons
] =
2742 _cupsStrRetain(attr
->values
[i
].string
.text
);
2743 printer
->num_reasons
++;
2745 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2746 printer
->state
!= IPP_PRINTER_STOPPED
)
2748 cupsdLogMessage(CUPSD_LOG_INFO
,
2749 "Setting %s printer-state to %d (was %d.)",
2750 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2751 cupsdStopPrinter(printer
, 0);
2755 if (PrintcapFormat
== PRINTCAP_PLIST
)
2756 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2758 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2759 "Printer \"%s\" state changed.", printer
->name
);
2762 set_printer_defaults(con
, printer
);
2764 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2765 IPP_TAG_KEYWORD
)) != NULL
)
2766 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2769 * See if we have all required attributes...
2772 if (!printer
->device_uri
)
2773 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2776 * See if we have an interface script or PPD file attached to the request...
2781 need_restart_job
= 1;
2784 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2786 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2789 * Yes; get the first line from it...
2793 cupsFileGets(fp
, line
, sizeof(line
));
2797 * Then see what kind of file it is...
2800 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2803 if (!strncmp(line
, "*PPD-Adobe", 10))
2806 * The new file is a PPD file, so remove any old interface script
2807 * that might be lying around...
2815 * This must be an interface script, so move the file over to the
2816 * interfaces directory and make it executable...
2819 if (copy_file(srcfile
, dstfile
))
2821 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2822 _("Unable to copy interface script - %s"),
2827 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2828 "Copied interface script successfully");
2829 chmod(dstfile
, 0755);
2832 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2835 if (!strncmp(line
, "*PPD-Adobe", 10))
2838 * The new file is a PPD file, so move the file over to the
2839 * ppd directory and make it readable by all...
2842 if (copy_file(srcfile
, dstfile
))
2844 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2845 _("Unable to copy PPD file - %s"),
2850 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2851 "Copied PPD file successfully");
2852 chmod(dstfile
, 0644);
2857 * This must be an interface script, so remove any old PPD file that
2858 * may be lying around...
2865 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2866 IPP_TAG_NAME
)) != NULL
)
2868 need_restart_job
= 1;
2871 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2874 * Raw driver, remove any existing PPD or interface script files.
2877 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2881 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2891 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2895 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2898 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2900 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2904 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2905 "Copied PPD file successfully");
2906 chmod(dstfile
, 0644);
2913 * If we changed the PPD/interface script, then remove the printer's cache
2914 * file and clear the printer-state-reasons...
2917 char cache_name
[1024]; /* Cache filename for printer attrs */
2919 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2923 cupsdSetPrinterReasons(printer
, "none");
2927 * (Re)register color profiles...
2932 apple_unregister_profiles(printer
);
2933 apple_register_profiles(printer
);
2935 #endif /* __APPLE__ */
2939 * If we set the device URI but not the port monitor, check which port
2940 * monitor to use by default...
2943 if (set_device_uri
&& !set_port_monitor
)
2945 ppd_file_t
*ppd
; /* PPD file */
2946 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2949 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2950 sizeof(scheme
), username
, sizeof(username
), host
,
2951 sizeof(host
), &port
, resource
, sizeof(resource
));
2953 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2955 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2957 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2959 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2960 if (!strcmp(scheme
, ppdattr
->spec
))
2962 cupsdLogMessage(CUPSD_LOG_INFO
,
2963 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2964 printer
->name
, ppdattr
->value
,
2965 printer
->port_monitor
? printer
->port_monitor
2968 if (strcmp(ppdattr
->value
, "none"))
2969 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2971 cupsdClearString(&printer
->port_monitor
);
2981 * Update the printer attributes and return...
2984 cupsdSetPrinterAttrs(printer
);
2985 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2987 if (need_restart_job
&& printer
->job
)
2990 * Restart the current job...
2993 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2994 "Job restarted because the printer was modified.");
2997 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3001 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
3002 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
3003 printer
->name
, get_username(con
));
3005 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
3006 printer
->name
, get_username(con
));
3010 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
3011 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
3012 printer
->name
, get_username(con
));
3014 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
3015 printer
->name
, get_username(con
));
3018 con
->response
->request
.status
.status_code
= IPP_OK
;
3023 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
3024 * based upon the printer state...
3028 add_printer_state_reasons(
3029 cupsd_client_t
*con
, /* I - Client connection */
3030 cupsd_printer_t
*p
) /* I - Printer info */
3032 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3033 "add_printer_state_reasons(%p[%d], %p[%s])",
3034 con
, con
->http
.fd
, p
, p
->name
);
3036 if (p
->num_reasons
== 0)
3037 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3038 "printer-state-reasons", NULL
, "none");
3040 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3041 "printer-state-reasons", p
->num_reasons
, NULL
,
3042 (const char * const *)p
->reasons
);
3047 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
3048 * the specified printer or class.
3052 add_queued_job_count(
3053 cupsd_client_t
*con
, /* I - Client connection */
3054 cupsd_printer_t
*p
) /* I - Printer or class */
3056 int count
; /* Number of jobs on destination */
3059 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
3060 con
, con
->http
.fd
, p
, p
->name
);
3062 count
= cupsdGetPrinterJobCount(p
->name
);
3064 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3065 "queued-job-count", count
);
3071 * 'apple_init_profile()' - Initialize a color profile.
3076 ppd_file_t
*ppd
, /* I - PPD file */
3077 cups_array_t
*languages
, /* I - Languages in the PPD file */
3078 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3079 CFMutableDictionaryRef profile
, /* I - Profile dictionary */
3081 CMDeviceProfileInfo
*profile
, /* I - Profile record */
3082 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3083 unsigned id
, /* I - Profile ID */
3084 const char *name
, /* I - Profile name */
3085 const char *text
, /* I - Profile UI text */
3086 const char *iccfile
) /* I - ICC filename */
3088 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3089 CFURLRef url
; /* URL for profile filename */
3090 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3091 CFMutableDictionaryRef dict
; /* Dictionary for name */
3092 char *language
; /* Current language */
3093 ppd_attr_t
*attr
; /* Profile attribute */
3094 CFStringRef cflang
, /* Language string */
3095 cftext
; /* Localized text */
3101 * Build the profile name dictionary...
3104 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3105 &kCFTypeDictionaryKeyCallBacks
,
3106 &kCFTypeDictionaryValueCallBacks
);
3109 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to initialize profile \"%s\".",
3114 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3115 kCFStringEncodingUTF8
);
3119 CFDictionarySetValue(dict
, CFSTR("en_US"), cftext
);
3126 * Find localized names for the color profiles...
3129 cupsArraySave(ppd
->sorted_attrs
);
3131 for (language
= (char *)cupsArrayFirst(languages
);
3133 language
= (char *)cupsArrayNext(languages
))
3137 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3139 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3142 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3144 if (attr
&& attr
->text
[0])
3146 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3147 kCFStringEncodingUTF8
);
3148 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3149 kCFStringEncodingUTF8
);
3151 if (cflang
&& cftext
)
3152 CFDictionarySetValue(dict
, cflang
, cftext
);
3162 cupsArrayRestore(ppd
->sorted_attrs
);
3166 * Fill in the profile data...
3169 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3172 url
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
3173 (const UInt8
*)iccfile
,
3174 strlen(iccfile
), false);
3178 CFDictionarySetValue(profile
, kColorSyncDeviceProfileURL
, url
);
3183 CFDictionarySetValue(profile
, kColorSyncDeviceModeDescriptions
, dict
);
3187 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3188 profile
->profileID
= id
;
3189 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3190 profile
->profileName
= dict
;
3193 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3194 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3195 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3200 * 'apple_register_profiles()' - Register color profiles for a printer.
3204 apple_register_profiles(
3205 cupsd_printer_t
*p
) /* I - Printer */
3207 int i
; /* Looping var */
3208 char ppdfile
[1024], /* PPD filename */
3209 iccfile
[1024], /* ICC filename */
3210 selector
[PPD_MAX_NAME
];
3211 /* Profile selection string */
3212 ppd_file_t
*ppd
; /* PPD file */
3213 ppd_attr_t
*attr
, /* Profile attributes */
3214 *profileid_attr
,/* cupsProfileID attribute */
3215 *q1_attr
, /* ColorModel (or other) qualifier */
3216 *q2_attr
, /* MediaType (or other) qualifier */
3217 *q3_attr
; /* Resolution (or other) qualifier */
3218 char q_keyword
[PPD_MAX_NAME
];
3219 /* Qualifier keyword */
3220 const char *q1_choice
, /* ColorModel (or other) choice */
3221 *q2_choice
, /* MediaType (or other) choice */
3222 *q3_choice
; /* Resolution (or other) choice */
3223 const char *profile_key
; /* Profile keyword */
3224 ppd_option_t
*cm_option
; /* Color model option */
3225 ppd_choice_t
*cm_choice
; /* Color model choice */
3226 int num_profiles
; /* Number of profiles */
3227 OSStatus error
= 0; /* Last error */
3228 unsigned device_id
, /* Printer device ID */
3229 profile_id
= 0, /* Profile ID */
3230 default_profile_id
= 0;
3231 /* Default profile ID */
3232 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3233 CFStringRef printer_name
; /* Printer name string */
3234 cups_array_t
*languages
; /* Languages array */
3235 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3236 CFMutableDictionaryRef profiles
, /* Dictionary of profiles */
3237 profile
; /* Current profile info dictionary */
3238 CFStringRef dict_key
; /* Key in factory profile dictionary */
3240 CMDeviceScope scope
= /* Scope of the registration */
3242 kCFPreferencesAnyUser
,
3243 kCFPreferencesCurrentHost
3245 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3246 CMDeviceProfileInfo
*profile
; /* Current profile */
3247 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3251 * Make sure ColorSync is available...
3254 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3255 if (ColorSyncRegisterDevice
== NULL
)
3259 if (CMRegisterColorDevice
== NULL
)
3261 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3264 * Try opening the PPD file for this printer...
3267 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3268 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3272 * See if we have any profiles...
3275 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3276 profile_key
= "APTiogaProfile";
3279 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3280 profile_key
= "cupsICCProfile";
3283 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3284 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3286 if (attr
->value
[0] != '/')
3287 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3290 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3292 if (access(iccfile
, 0))
3294 cupsdLogMessage(CUPSD_LOG_ERROR
,
3295 "%s: ICC Profile \"%s\" does not exist.", p
->name
,
3303 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3305 * Create a dictionary for the factory profiles...
3308 profiles
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3309 &kCFTypeDictionaryKeyCallBacks
,
3310 &kCFTypeDictionaryValueCallBacks
);
3313 cupsdLogMessage(CUPSD_LOG_ERROR
,
3314 "Unable to allocate memory for factory profiles.");
3318 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3321 * If we have profiles, add them...
3324 if (num_profiles
> 0)
3326 if (profile_key
[0] == 'A')
3329 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3333 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3335 default_profile_id
= atoi(attr
->value
);
3337 q1_choice
= q2_choice
= q3_choice
= NULL
;
3342 * For CUPS PPDs, figure out the default profile selector values...
3345 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3346 attr
->value
&& attr
->value
[0])
3348 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3349 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3351 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3352 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3354 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3355 q1_choice
= q1_attr
->value
;
3359 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3360 attr
->value
&& attr
->value
[0])
3362 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3363 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3366 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3368 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3369 q2_choice
= q2_attr
->value
;
3373 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3374 attr
->value
&& attr
->value
[0])
3376 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3377 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3380 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3382 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3383 q3_choice
= q3_attr
->value
;
3388 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3390 * Build the array of profiles...
3392 * Note: This calloc actually requests slightly more memory than needed.
3395 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3397 cupsdLogMessage(CUPSD_LOG_ERROR
,
3398 "Unable to allocate memory for factory profiles.");
3403 profiles
->profileCount
= num_profiles
;
3404 profile
= profiles
->profiles
;
3405 # endif /* !HAVE_COLORSYNCREGISTERDEVICE */
3408 * Loop through the profiles listed in the PPD...
3411 languages
= _ppdGetLanguages(ppd
);
3413 for (attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3415 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3416 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3419 * Add this profile...
3422 if (attr
->value
[0] != '/')
3423 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3426 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3428 if (_cupsFileCheck(iccfile
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
3429 cupsdLogFCMessage
, p
))
3432 if (profile_key
[0] == 'c')
3434 cupsArraySave(ppd
->sorted_attrs
);
3436 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3437 attr
->spec
)) != NULL
&&
3438 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3439 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3441 profile_id
= _ppdHashName(attr
->spec
);
3443 cupsArrayRestore(ppd
->sorted_attrs
);
3446 profile_id
= atoi(attr
->spec
);
3448 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3449 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3450 &kCFTypeDictionaryKeyCallBacks
,
3451 &kCFTypeDictionaryValueCallBacks
);
3454 cupsdLogMessage(CUPSD_LOG_ERROR
,
3455 "Unable to allocate memory for color profile.");
3456 CFRelease(profiles
);
3461 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3462 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3464 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3465 CFSTR("%u"), profile_id
);
3468 CFDictionarySetValue(profiles
, dict_key
, profile
);
3469 CFRelease(dict_key
);
3475 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3476 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3479 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3482 * See if this is the default profile...
3485 if (!default_profile_id
&& q1_choice
&& q2_choice
&& q3_choice
)
3487 snprintf(selector
, sizeof(selector
), "%s.%s.%s", q1_choice
, q2_choice
,
3489 if (!strcmp(selector
, attr
->spec
))
3490 default_profile_id
= profile_id
;
3493 if (!default_profile_id
&& q1_choice
&& q2_choice
)
3495 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
, q2_choice
);
3496 if (!strcmp(selector
, attr
->spec
))
3497 default_profile_id
= profile_id
;
3500 if (!default_profile_id
&& q1_choice
&& q3_choice
)
3502 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
, q3_choice
);
3503 if (!strcmp(selector
, attr
->spec
))
3504 default_profile_id
= profile_id
;
3507 if (!default_profile_id
&& q1_choice
)
3509 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3510 if (!strcmp(selector
, attr
->spec
))
3511 default_profile_id
= profile_id
;
3514 if (!default_profile_id
&& q2_choice
&& q3_choice
)
3516 snprintf(selector
, sizeof(selector
), ".%s.%s", q2_choice
, q3_choice
);
3517 if (!strcmp(selector
, attr
->spec
))
3518 default_profile_id
= profile_id
;
3521 if (!default_profile_id
&& q2_choice
)
3523 snprintf(selector
, sizeof(selector
), ".%s.", q2_choice
);
3524 if (!strcmp(selector
, attr
->spec
))
3525 default_profile_id
= profile_id
;
3528 if (!default_profile_id
&& q3_choice
)
3530 snprintf(selector
, sizeof(selector
), "..%s", q3_choice
);
3531 if (!strcmp(selector
, attr
->spec
))
3532 default_profile_id
= profile_id
;
3536 _ppdFreeLanguages(languages
);
3538 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3541 * Extract profiles from ColorModel option...
3544 const char *profile_name
; /* Name of generic profile */
3547 num_profiles
= cm_option
->num_choices
;
3549 # ifndef HAVE_COLORSYNCREGISTERDEVICE
3551 * Create an array for the factory profiles...
3554 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3556 cupsdLogMessage(CUPSD_LOG_ERROR
,
3557 "Unable to allocate memory for factory profiles.");
3562 profiles
->profileCount
= num_profiles
;
3563 profile
= profiles
->profiles
;
3564 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3566 for (i
= cm_option
->num_choices
, cm_choice
= cm_option
->choices
;
3570 if (!strcmp(cm_choice
->choice
, "Gray") ||
3571 !strcmp(cm_choice
->choice
, "Black"))
3572 profile_name
= "Gray";
3573 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3574 !strcmp(cm_choice
->choice
, "CMY"))
3575 profile_name
= "RGB";
3576 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3577 !strcmp(cm_choice
->choice
, "KCMY"))
3578 profile_name
= "CMYK";
3580 profile_name
= "DeviceN";
3582 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3583 profile_id
= _ppdHashName(selector
);
3585 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3586 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3587 &kCFTypeDictionaryKeyCallBacks
,
3588 &kCFTypeDictionaryValueCallBacks
);
3591 cupsdLogMessage(CUPSD_LOG_ERROR
,
3592 "Unable to allocate memory for color profile.");
3593 CFRelease(profiles
);
3598 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3599 cm_choice
->text
, NULL
);
3601 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3602 CFSTR("%u"), profile_id
);
3605 CFDictionarySetValue(profiles
, dict_key
, profile
);
3606 CFRelease(dict_key
);
3612 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3613 cm_choice
->text
, NULL
);
3615 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3617 if (cm_choice
->marked
)
3618 default_profile_id
= profile_id
;
3624 * Use the default colorspace...
3627 attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3629 num_profiles
= (attr
&& ppd
->colorspace
== PPD_CS_GRAY
) ? 1 : 2;
3631 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3633 * Add the grayscale profile first. We always have a grayscale profile.
3636 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3637 &kCFTypeDictionaryKeyCallBacks
,
3638 &kCFTypeDictionaryValueCallBacks
);
3642 cupsdLogMessage(CUPSD_LOG_ERROR
,
3643 "Unable to allocate memory for color profile.");
3644 CFRelease(profiles
);
3649 profile_id
= _ppdHashName("Gray..");
3650 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "Gray", "Gray", NULL
);
3652 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3656 CFDictionarySetValue(profiles
, dict_key
, profile
);
3657 CFRelease(dict_key
);
3663 * Then add the RGB/CMYK/DeviceN color profile...
3666 profile
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3667 &kCFTypeDictionaryKeyCallBacks
,
3668 &kCFTypeDictionaryValueCallBacks
);
3672 cupsdLogMessage(CUPSD_LOG_ERROR
,
3673 "Unable to allocate memory for color profile.");
3674 CFRelease(profiles
);
3679 switch (ppd
->colorspace
)
3684 profile_id
= _ppdHashName("RGB..");
3685 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "RGB", "RGB",
3691 profile_id
= _ppdHashName("CMYK..");
3692 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "CMYK", "CMYK",
3701 profile_id
= _ppdHashName("DeviceN..");
3702 apple_init_profile(ppd
, NULL
, profile
, profile_id
, "DeviceN",
3707 if (CFDictionaryGetCount(profile
) > 0)
3709 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
,
3710 CFSTR("%u"), profile_id
);
3713 CFDictionarySetValue(profiles
, dict_key
, profile
);
3714 CFRelease(dict_key
);
3722 * Create an array for the factory profiles...
3725 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3727 cupsdLogMessage(CUPSD_LOG_ERROR
,
3728 "Unable to allocate memory for factory profiles.");
3733 profiles
->profileCount
= num_profiles
;
3736 * Add the grayscale profile first. We always have a grayscale profile.
3739 profile_id
= _ppdHashName("Gray..");
3740 apple_init_profile(ppd
, NULL
, profiles
->profiles
, profile_id
, "Gray",
3744 * Then add the RGB/CMYK/DeviceN color profile...
3747 switch (ppd
->colorspace
)
3752 profile_id
= _ppdHashName("RGB..");
3753 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3754 "RGB", "RGB", NULL
);
3758 profile_id
= _ppdHashName("CMYK..");
3759 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3760 "CMYK", "CMYK", NULL
);
3768 profile_id
= _ppdHashName("DeviceN..");
3769 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1, profile_id
,
3770 "DeviceN", "DeviceN", NULL
);
3773 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3776 if (num_profiles
> 0)
3779 * Make sure we have a default profile ID...
3782 if (!default_profile_id
)
3783 default_profile_id
= profile_id
; /* Last profile */
3785 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3786 dict_key
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%u"),
3787 default_profile_id
);
3790 CFDictionarySetValue(profiles
, kColorSyncDeviceDefaultProfileID
,
3792 CFRelease(dict_key
);
3794 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3797 * Get the device ID hash and pathelogical name dictionary.
3800 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3803 device_id
= _ppdHashName(p
->name
);
3804 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3805 &kCFTypeDictionaryKeyCallBacks
,
3806 &kCFTypeDictionaryValueCallBacks
);
3807 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3808 p
->name
, kCFStringEncodingUTF8
);
3810 if (device_name
&& printer_name
)
3812 CFDictionarySetValue(device_name
, CFSTR("en_US"), printer_name
);
3815 * Register the device with ColorSync...
3818 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3819 CFTypeRef deviceDictKeys
[] =
3821 kColorSyncDeviceDescriptions
,
3822 kColorSyncFactoryProfiles
,
3823 kColorSyncDeviceUserScope
,
3824 kColorSyncDeviceHostScope
3826 CFTypeRef deviceDictVals
[] =
3827 { /* Device values */
3830 kCFPreferencesAnyUser
,
3831 kCFPreferencesCurrentHost
3833 CFDictionaryRef deviceDict
; /* Device dictionary */
3834 CFUUIDRef deviceUUID
; /* Device UUID */
3836 deviceDict
= CFDictionaryCreate(kCFAllocatorDefault
,
3837 (const void **)deviceDictKeys
,
3838 (const void **)deviceDictVals
,
3839 sizeof(deviceDictKeys
) /
3840 sizeof(deviceDictKeys
[0]),
3841 &kCFTypeDictionaryKeyCallBacks
,
3842 &kCFTypeDictionaryValueCallBacks
);
3843 deviceUUID
= ColorSyncCreateUUIDFromUInt32(device_id
);
3845 if (!deviceDict
|| !deviceUUID
||
3846 !ColorSyncRegisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
,
3851 CFRelease(deviceUUID
);
3854 CFRelease(deviceDict
);
3857 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3858 device_name
, &scope
);
3861 * Register the profiles...
3865 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3866 default_profile_id
, profiles
);
3867 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3877 cupsdLogMessage(CUPSD_LOG_ERROR
,
3878 "Unable to register ICC color profiles for \"%s\": %d",
3879 p
->name
, (int)error
);
3882 CFRelease(printer_name
);
3885 CFRelease(device_name
);
3889 * Free any memory we used...
3892 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3893 CFRelease(profiles
);
3896 if (num_profiles
> 0)
3898 for (profile
= profiles
->profiles
;
3900 profile
++, num_profiles
--)
3901 CFRelease(profile
->profileName
);
3905 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3912 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3917 apple_unregister_profiles(
3918 cupsd_printer_t
*p
) /* I - Printer */
3921 * Make sure ColorSync is available...
3924 # ifdef HAVE_COLORSYNCREGISTERDEVICE
3925 if (ColorSyncUnregisterDevice
!= NULL
)
3928 * Because we may have registered the printer profiles using a prior device
3929 * ID-based UUID, remove both the old style UUID and current UUID for the
3933 CFUUIDRef deviceUUID
; /* Device UUID */
3935 deviceUUID
= ColorSyncCreateUUIDFromUInt32(_ppdHashName(p
->name
));
3938 ColorSyncUnregisterDevice(kColorSyncPrinterDeviceClass
, deviceUUID
);
3939 CFRelease(deviceUUID
);
3944 if (CMUnregisterColorDevice
!= NULL
)
3945 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3946 # endif /* HAVE_COLORSYNCREGISTERDEVICE */
3948 #endif /* __APPLE__ */
3952 * 'apply_printer_defaults()' - Apply printer default options to a job.
3956 apply_printer_defaults(
3957 cupsd_printer_t
*printer
, /* I - Printer */
3958 cupsd_job_t
*job
) /* I - Job */
3960 int i
, /* Looping var */
3961 num_options
; /* Number of default options */
3962 cups_option_t
*options
, /* Default options */
3963 *option
; /* Current option */
3967 * Collect all of the default options and add the missing ones to the
3971 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3972 option
= printer
->options
;
3975 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3977 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3982 * Encode these options as attributes in the job object...
3985 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3986 cupsFreeOptions(num_options
, options
);
3991 * 'authenticate_job()' - Set job authentication info.
3995 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3996 ipp_attribute_t
*uri
) /* I - Job URI */
3998 ipp_attribute_t
*attr
, /* job-id attribute */
3999 *auth_info
; /* auth-info attribute */
4000 int jobid
; /* Job ID */
4001 cupsd_job_t
*job
; /* Current job */
4002 char scheme
[HTTP_MAX_URI
],
4003 /* Method portion of URI */
4004 username
[HTTP_MAX_URI
],
4005 /* Username portion of URI */
4007 /* Host portion of URI */
4008 resource
[HTTP_MAX_URI
];
4009 /* Resource portion of URI */
4010 int port
; /* Port portion of URI */
4013 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
4014 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
4017 * Start with "everything is OK" status...
4020 con
->response
->request
.status
.status_code
= IPP_OK
;
4023 * See if we have a job URI or a printer URI...
4026 if (!strcmp(uri
->name
, "printer-uri"))
4029 * Got a printer URI; see if we also have a job-id attribute...
4032 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4033 IPP_TAG_INTEGER
)) == NULL
)
4035 send_ipp_status(con
, IPP_BAD_REQUEST
,
4036 _("Got a printer-uri attribute but no job-id."));
4040 jobid
= attr
->values
[0].integer
;
4045 * Got a job URI; parse it to get the job ID...
4048 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4049 sizeof(scheme
), username
, sizeof(username
), host
,
4050 sizeof(host
), &port
, resource
, sizeof(resource
));
4052 if (strncmp(resource
, "/jobs/", 6))
4058 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
4059 uri
->values
[0].string
.text
);
4063 jobid
= atoi(resource
+ 6);
4067 * See if the job exists...
4070 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4073 * Nope - return a "not found" error...
4076 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
4081 * See if the job has been completed...
4084 if (job
->state_value
!= IPP_JOB_HELD
)
4087 * Return a "not-possible" error...
4090 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4091 _("Job #%d is not held for authentication."),
4097 * See if we have already authenticated...
4100 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
4102 if (!con
->username
[0] && !auth_info
)
4104 cupsd_printer_t
*printer
; /* Job destination */
4108 * No auth data. If we need to authenticate via Kerberos, send a
4109 * HTTP auth challenge, otherwise just return an IPP error...
4112 printer
= cupsdFindDest(job
->dest
);
4114 if (printer
&& printer
->num_auth_info_required
> 0 &&
4115 !strcmp(printer
->auth_info_required
[0], "negotiate"))
4116 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
4118 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
4119 _("No authentication information provided."));
4124 * See if the job is owned by the requesting user...
4127 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4129 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4130 cupsdFindDest(job
->dest
));
4135 * Save the authentication information for this job...
4138 save_auth_info(con
, job
, auth_info
);
4141 * Reset the job-hold-until value to "no-hold"...
4144 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4145 IPP_TAG_KEYWORD
)) == NULL
)
4146 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4150 attr
->value_tag
= IPP_TAG_KEYWORD
;
4151 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
4155 * Release the job and return...
4158 cupsdReleaseJob(job
);
4160 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
4162 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
4169 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
4173 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
4174 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4176 int i
; /* Looping var */
4177 http_status_t status
; /* Policy status */
4178 cups_ptype_t dtype
; /* Destination type */
4179 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4180 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
4181 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
4182 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4183 int port
; /* Port portion of URI */
4184 ipp_attribute_t
*attr
; /* Attribute in request */
4185 const char *username
= NULL
; /* Username */
4186 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
4188 cupsd_printer_t
*printer
; /* Printer */
4189 ipp_attribute_t
*job_ids
; /* job-ids attribute */
4190 cupsd_job_t
*job
; /* Job */
4193 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
4194 con
->http
.fd
, uri
->values
[0].string
.text
);
4197 * Get the jobs to cancel/purge...
4200 switch (con
->request
->request
.op
.operation_id
)
4202 case IPP_PURGE_JOBS
:
4204 * Get the username (if any) for the jobs we want to cancel (only if
4205 * "my-jobs" is specified...
4208 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
4209 IPP_TAG_BOOLEAN
)) != NULL
&&
4210 attr
->values
[0].boolean
)
4212 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4213 IPP_TAG_NAME
)) != NULL
)
4214 username
= attr
->values
[0].string
.text
;
4217 send_ipp_status(con
, IPP_BAD_REQUEST
,
4218 _("Missing requesting-user-name attribute."));
4224 * Look for the "purge-jobs" attribute...
4227 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
4228 IPP_TAG_BOOLEAN
)) != NULL
)
4229 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4231 purge
= CUPSD_JOB_PURGE
;
4234 case IPP_CANCEL_MY_JOBS
:
4235 if (con
->username
[0])
4236 username
= con
->username
;
4237 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
4238 IPP_TAG_NAME
)) != NULL
)
4239 username
= attr
->values
[0].string
.text
;
4242 send_ipp_status(con
, IPP_BAD_REQUEST
,
4243 _("Missing requesting-user-name attribute."));
4251 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
4254 * See if we have a printer URI...
4257 if (strcmp(uri
->name
, "printer-uri"))
4259 send_ipp_status(con
, IPP_BAD_REQUEST
,
4260 _("The printer-uri attribute is required."));
4265 * And if the destination is valid...
4268 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4274 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
4275 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
4276 hostname
, sizeof(hostname
), &port
,
4277 resource
, sizeof(resource
));
4279 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
4280 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
4282 send_ipp_status(con
, IPP_NOT_FOUND
,
4283 _("The printer or class does not exist."));
4291 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
4293 send_http_error(con
, status
, NULL
);
4299 for (i
= 0; i
< job_ids
->num_values
; i
++)
4301 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
4305 if (i
< job_ids
->num_values
)
4307 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4308 job_ids
->values
[i
].integer
);
4312 for (i
= 0; i
< job_ids
->num_values
; i
++)
4314 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4316 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4317 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4318 "Job canceled by user.");
4321 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4322 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4328 * Cancel all jobs on all printers...
4331 cupsdCancelJobs(NULL
, username
, purge
);
4333 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
4334 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4344 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4347 send_http_error(con
, status
, printer
);
4353 for (i
= 0; i
< job_ids
->num_values
; i
++)
4355 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
4356 _cups_strcasecmp(job
->dest
, printer
->name
))
4360 if (i
< job_ids
->num_values
)
4362 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4363 job_ids
->values
[i
].integer
);
4367 for (i
= 0; i
< job_ids
->num_values
; i
++)
4369 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
4371 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4372 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
4373 "Job canceled by user.");
4376 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
4377 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4383 * Cancel all of the jobs on the named printer...
4386 cupsdCancelJobs(printer
->name
, username
, purge
);
4388 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
4390 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
4395 con
->response
->request
.status
.status_code
= IPP_OK
;
4400 * 'cancel_job()' - Cancel a print job.
4404 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
4405 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
4407 ipp_attribute_t
*attr
; /* Current attribute */
4408 int jobid
; /* Job ID */
4409 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
4410 username
[HTTP_MAX_URI
], /* Username portion of URI */
4411 host
[HTTP_MAX_URI
], /* Host portion of URI */
4412 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4413 int port
; /* Port portion of URI */
4414 cupsd_job_t
*job
; /* Job information */
4415 cups_ptype_t dtype
; /* Destination type (printer/class) */
4416 cupsd_printer_t
*printer
; /* Printer data */
4417 cupsd_jobaction_t purge
; /* Purge the job? */
4420 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
4421 con
->http
.fd
, uri
->values
[0].string
.text
);
4424 * See if we have a job URI or a printer URI...
4427 if (!strcmp(uri
->name
, "printer-uri"))
4430 * Got a printer URI; see if we also have a job-id attribute...
4433 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4434 IPP_TAG_INTEGER
)) == NULL
)
4436 send_ipp_status(con
, IPP_BAD_REQUEST
,
4437 _("Got a printer-uri attribute but no job-id."));
4441 if ((jobid
= attr
->values
[0].integer
) == 0)
4444 * Find the current job on the specified printer...
4447 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4453 send_ipp_status(con
, IPP_NOT_FOUND
,
4454 _("The printer or class does not exist."));
4459 * See if there are any pending jobs...
4462 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4464 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4465 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
4466 !_cups_strcasecmp(job
->dest
, printer
->name
))
4474 * No, try stopped jobs...
4477 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
4479 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
4480 if (job
->state_value
== IPP_JOB_STOPPED
&&
4481 !_cups_strcasecmp(job
->dest
, printer
->name
))
4488 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
4498 * Got a job URI; parse it to get the job ID...
4501 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4502 sizeof(scheme
), username
, sizeof(username
), host
,
4503 sizeof(host
), &port
, resource
, sizeof(resource
));
4505 if (strncmp(resource
, "/jobs/", 6))
4511 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
4512 uri
->values
[0].string
.text
);
4516 jobid
= atoi(resource
+ 6);
4520 * Look for the "purge-job" attribute...
4523 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4524 IPP_TAG_BOOLEAN
)) != NULL
)
4525 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
4527 purge
= CUPSD_JOB_DEFAULT
;
4530 * See if the job exists...
4533 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4536 * Nope - return a "not found" error...
4539 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
4544 * See if the job is owned by the requesting user...
4547 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4549 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4550 cupsdFindDest(job
->dest
));
4555 * See if the job is already completed, canceled, or aborted; if so,
4556 * we can't cancel...
4559 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
4561 switch (job
->state_value
)
4563 case IPP_JOB_CANCELED
:
4564 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4565 _("Job #%d is already canceled - can\'t cancel."),
4569 case IPP_JOB_ABORTED
:
4570 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4571 _("Job #%d is already aborted - can\'t cancel."),
4576 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4577 _("Job #%d is already completed - can\'t cancel."),
4586 * Cancel the job and return...
4589 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
4590 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
4591 "Job canceled by \"%s\"",
4595 if (purge
== CUPSD_JOB_PURGE
)
4596 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4599 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4602 con
->response
->request
.status
.status_code
= IPP_OK
;
4607 * 'cancel_subscription()' - Cancel a subscription.
4611 cancel_subscription(
4612 cupsd_client_t
*con
, /* I - Client connection */
4613 int sub_id
) /* I - Subscription ID */
4615 http_status_t status
; /* Policy status */
4616 cupsd_subscription_t
*sub
; /* Subscription */
4619 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4620 "cancel_subscription(con=%p[%d], sub_id=%d)",
4621 con
, con
->http
.fd
, sub_id
);
4624 * Is the subscription ID valid?
4627 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4630 * Bad subscription ID...
4633 send_ipp_status(con
, IPP_NOT_FOUND
,
4634 _("Subscription #%d does not exist."), sub_id
);
4642 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4644 con
, sub
->owner
)) != HTTP_OK
)
4646 send_http_error(con
, status
, sub
->dest
);
4651 * Cancel the subscription...
4654 cupsdDeleteSubscription(sub
, 1);
4656 con
->response
->request
.status
.status_code
= IPP_OK
;
4661 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4664 static int /* O - 1 if OK, 0 if not */
4665 check_rss_recipient(
4666 const char *recipient
) /* I - Recipient URI */
4668 cupsd_subscription_t
*sub
; /* Current subscription */
4671 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4673 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4677 * Compare the URIs up to the first ?...
4680 const char *r1
, *r2
;
4682 for (r1
= recipient
, r2
= sub
->recipient
;
4683 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4695 * 'check_quotas()' - Check quotas for a printer and user.
4698 static int /* O - 1 if OK, 0 if forbidden,
4699 -1 if limit reached */
4700 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4701 cupsd_printer_t
*p
) /* I - Printer or class */
4703 char username
[33], /* Username */
4704 *name
; /* Current user name */
4705 cupsd_quota_t
*q
; /* Quota data */
4706 #ifdef HAVE_MBR_UID_TO_UUID
4708 * Use Apple membership APIs which require that all names represent
4709 * valid user account or group records accessible by the server.
4712 uuid_t usr_uuid
; /* UUID for job requesting user */
4713 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4714 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4715 int mbr_err
; /* Error from membership function */
4716 int is_member
; /* Is this user a member? */
4719 * Use standard POSIX APIs for checking users and groups...
4722 struct passwd
*pw
; /* User password data */
4723 #endif /* HAVE_MBR_UID_TO_UUID */
4726 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4727 con
, con
->http
.fd
, p
, p
->name
);
4730 * Figure out who is printing...
4733 strlcpy(username
, get_username(con
), sizeof(username
));
4736 * Check global active job limits for printers and users...
4739 if (MaxJobsPerPrinter
)
4742 * Check if there are too many pending jobs on this printer...
4745 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4747 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4756 * Check if there are too many pending jobs for this user...
4759 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4761 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4768 * Check against users...
4771 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4774 if (cupsArrayCount(p
->users
))
4776 #ifdef HAVE_MBR_UID_TO_UUID
4778 * Get UUID for job requesting user...
4781 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4787 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4788 "check_quotas: UUID lookup failed for user \"%s\"",
4790 cupsdLogMessage(CUPSD_LOG_INFO
,
4791 "Denying user \"%s\" access to printer \"%s\" "
4792 "(unknown user)...",
4798 * Get UID and GID of requesting user...
4801 pw
= getpwnam(username
);
4803 #endif /* HAVE_MBR_UID_TO_UUID */
4805 for (name
= (char *)cupsArrayFirst(p
->users
);
4807 name
= (char *)cupsArrayNext(p
->users
))
4811 * Check group membership...
4814 #ifdef HAVE_MBR_UID_TO_UUID
4817 if (uuid_parse(name
+ 2, grp_uuid
))
4818 uuid_clear(grp_uuid
);
4820 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
4823 * Invalid ACL entries are ignored for matching; just record a
4824 * warning in the log...
4827 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4828 "check_quotas: UUID lookup failed for ACL entry "
4829 "\"%s\" (err=%d)", name
, mbr_err
);
4830 cupsdLogMessage(CUPSD_LOG_WARN
,
4831 "Access control entry \"%s\" not a valid group name; "
4832 "entry ignored", name
);
4835 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4839 * At this point, there should be no errors, but check anyways...
4842 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4843 "check_quotas: group \"%s\" membership check "
4844 "failed (err=%d)", name
+ 1, mbr_err
);
4849 * Stop if we found a match...
4856 if (cupsdCheckGroup(username
, pw
, name
+ 1))
4858 #endif /* HAVE_MBR_UID_TO_UUID */
4860 #ifdef HAVE_MBR_UID_TO_UUID
4865 if (uuid_parse(name
+ 1, usr2_uuid
))
4866 uuid_clear(usr2_uuid
);
4868 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
4871 * Invalid ACL entries are ignored for matching; just record a
4872 * warning in the log...
4875 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4876 "check_quotas: UUID lookup failed for ACL entry "
4877 "\"%s\" (err=%d)", name
, mbr_err
);
4878 cupsdLogMessage(CUPSD_LOG_WARN
,
4879 "Access control entry \"%s\" not a valid user name; "
4880 "entry ignored", name
);
4883 if (!uuid_compare(usr_uuid
, usr2_uuid
))
4887 else if (!_cups_strcasecmp(username
, name
))
4889 #endif /* HAVE_MBR_UID_TO_UUID */
4891 if ((name
!= NULL
) == p
->deny_users
)
4893 cupsdLogMessage(CUPSD_LOG_INFO
,
4894 "Denying user \"%s\" access to printer \"%s\"...",
4904 if (p
->k_limit
|| p
->page_limit
)
4906 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4908 cupsdLogMessage(CUPSD_LOG_ERROR
,
4909 "Unable to allocate quota data for user \"%s\"",
4914 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4915 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4917 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4924 * If we have gotten this far, we're done!
4932 * 'close_job()' - Close a multi-file job.
4936 close_job(cupsd_client_t
*con
, /* I - Client connection */
4937 ipp_attribute_t
*uri
) /* I - Printer URI */
4939 cupsd_job_t
*job
; /* Job */
4940 ipp_attribute_t
*attr
; /* Attribute */
4941 char job_uri
[HTTP_MAX_URI
],
4943 username
[256]; /* User name */
4946 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
4947 con
->http
.fd
, uri
->values
[0].string
.text
);
4950 * See if we have a job URI or a printer URI...
4953 if (strcmp(uri
->name
, "printer-uri"))
4956 * job-uri is not supported by Close-Job!
4959 send_ipp_status(con
, IPP_BAD_REQUEST
,
4960 _("Close-Job doesn't support the job-uri attribute."));
4965 * Got a printer URI; see if we also have a job-id attribute...
4968 if ((attr
= ippFindAttribute(con
->request
, "job-id",
4969 IPP_TAG_INTEGER
)) == NULL
)
4971 send_ipp_status(con
, IPP_BAD_REQUEST
,
4972 _("Got a printer-uri attribute but no job-id."));
4976 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
4979 * Nope - return a "not found" error...
4982 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
4983 attr
->values
[0].integer
);
4988 * See if the job is owned by the requesting user...
4991 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4993 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
4994 cupsdFindDest(job
->dest
));
4999 * Add any ending sheet...
5002 if (cupsdTimeoutJob(job
))
5005 if (job
->state_value
== IPP_JOB_STOPPED
)
5007 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5008 job
->state_value
= IPP_JOB_PENDING
;
5010 else if (job
->state_value
== IPP_JOB_HELD
)
5012 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
5013 IPP_TAG_KEYWORD
)) == NULL
)
5014 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
5016 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
5018 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
5019 job
->state_value
= IPP_JOB_PENDING
;
5024 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
5027 * Fill in the response info...
5030 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
5031 LocalPort
, job
->id
);
5032 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
5035 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
5037 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
5040 add_job_state_reasons(con
, job
);
5042 con
->response
->request
.status
.status_code
= IPP_OK
;
5045 * Start the job if necessary...
5053 * 'copy_attribute()' - Copy a single attribute.
5056 static ipp_attribute_t
* /* O - New attribute */
5058 ipp_t
*to
, /* O - Destination request/response */
5059 ipp_attribute_t
*attr
, /* I - Attribute to copy */
5060 int quickcopy
) /* I - Do a quick copy? */
5062 int i
; /* Looping var */
5063 ipp_attribute_t
*toattr
; /* Destination attribute */
5066 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5067 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
5068 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
5071 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
5074 toattr
= ippAddSeparator(to
);
5077 case IPP_TAG_INTEGER
:
5079 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5080 attr
->name
, attr
->num_values
, NULL
);
5082 for (i
= 0; i
< attr
->num_values
; i
++)
5083 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
5086 case IPP_TAG_BOOLEAN
:
5087 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
5088 attr
->num_values
, NULL
);
5090 for (i
= 0; i
< attr
->num_values
; i
++)
5091 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
5094 case IPP_TAG_STRING
:
5097 case IPP_TAG_KEYWORD
:
5099 case IPP_TAG_URISCHEME
:
5100 case IPP_TAG_CHARSET
:
5101 case IPP_TAG_LANGUAGE
:
5102 case IPP_TAG_MIMETYPE
:
5103 toattr
= ippAddStrings(to
, attr
->group_tag
,
5104 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5105 attr
->name
, attr
->num_values
, NULL
, NULL
);
5109 for (i
= 0; i
< attr
->num_values
; i
++)
5110 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5112 else if (attr
->value_tag
& IPP_TAG_COPY
)
5114 for (i
= 0; i
< attr
->num_values
; i
++)
5115 toattr
->values
[i
].string
.text
=
5116 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5120 for (i
= 0; i
< attr
->num_values
; i
++)
5121 toattr
->values
[i
].string
.text
=
5122 _cupsStrRetain(attr
->values
[i
].string
.text
);
5127 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
5128 attr
->values
[0].date
);
5131 case IPP_TAG_RESOLUTION
:
5132 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
5133 attr
->num_values
, IPP_RES_PER_INCH
,
5136 for (i
= 0; i
< attr
->num_values
; i
++)
5138 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
5139 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
5140 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
5144 case IPP_TAG_RANGE
:
5145 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
5146 attr
->num_values
, NULL
, NULL
);
5148 for (i
= 0; i
< attr
->num_values
; i
++)
5150 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
5151 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
5155 case IPP_TAG_TEXTLANG
:
5156 case IPP_TAG_NAMELANG
:
5157 toattr
= ippAddStrings(to
, attr
->group_tag
,
5158 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
5159 attr
->name
, attr
->num_values
, NULL
, NULL
);
5163 for (i
= 0; i
< attr
->num_values
; i
++)
5165 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
5166 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
5169 else if (attr
->value_tag
& IPP_TAG_COPY
)
5171 for (i
= 0; i
< attr
->num_values
; i
++)
5174 toattr
->values
[i
].string
.charset
=
5175 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
5177 toattr
->values
[i
].string
.charset
=
5178 toattr
->values
[0].string
.charset
;
5180 toattr
->values
[i
].string
.text
=
5181 _cupsStrAlloc(attr
->values
[i
].string
.text
);
5186 for (i
= 0; i
< attr
->num_values
; i
++)
5189 toattr
->values
[i
].string
.charset
=
5190 _cupsStrRetain(attr
->values
[i
].string
.charset
);
5192 toattr
->values
[i
].string
.charset
=
5193 toattr
->values
[0].string
.charset
;
5195 toattr
->values
[i
].string
.text
=
5196 _cupsStrRetain(attr
->values
[i
].string
.text
);
5201 case IPP_TAG_BEGIN_COLLECTION
:
5202 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
5203 attr
->num_values
, NULL
);
5205 for (i
= 0; i
< attr
->num_values
; i
++)
5207 toattr
->values
[i
].collection
= attr
->values
[i
].collection
;
5208 attr
->values
[i
].collection
->use
++;
5213 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
5214 attr
->name
, attr
->num_values
, NULL
);
5216 for (i
= 0; i
< attr
->num_values
; i
++)
5218 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
5220 if (toattr
->values
[i
].unknown
.length
> 0)
5222 if ((toattr
->values
[i
].unknown
.data
=
5223 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
5224 toattr
->values
[i
].unknown
.length
= 0;
5226 memcpy(toattr
->values
[i
].unknown
.data
,
5227 attr
->values
[i
].unknown
.data
,
5228 toattr
->values
[i
].unknown
.length
);
5231 break; /* anti-compiler-warning-code */
5239 * 'copy_attrs()' - Copy attributes from one request to another.
5243 copy_attrs(ipp_t
*to
, /* I - Destination request */
5244 ipp_t
*from
, /* I - Source request */
5245 cups_array_t
*ra
, /* I - Requested attributes */
5246 ipp_tag_t group
, /* I - Group to copy */
5247 int quickcopy
, /* I - Do a quick copy? */
5248 cups_array_t
*exclude
) /* I - Attributes to exclude? */
5250 ipp_attribute_t
*fromattr
; /* Source attribute */
5253 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5254 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
5255 to
, from
, ra
, group
, quickcopy
);
5260 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
5263 * Filter attributes as needed...
5266 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
5267 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
5270 if (!strcmp(fromattr
->name
, "job-printer-uri"))
5274 (cupsArrayFind(exclude
, fromattr
->name
) ||
5275 cupsArrayFind(exclude
, "all")))
5278 * We need to exclude this attribute for security reasons; we require the
5279 * job-id attribute regardless of the security settings for IPP
5282 * The job-printer-uri attribute is handled by copy_job_attrs().
5284 * Subscription attribute security is handled by copy_subscription_attrs().
5287 if (strcmp(fromattr
->name
, "job-id"))
5291 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
5294 * Don't send collection attributes by default to IPP/1.x clients
5295 * since many do not support collections. Also don't send
5296 * media-col-database unless specifically requested by the client.
5299 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
5301 (to
->request
.status
.version
[0] == 1 ||
5302 !strcmp(fromattr
->name
, "media-col-database")))
5305 copy_attribute(to
, fromattr
, quickcopy
);
5312 * 'copy_banner()' - Copy a banner file to the requests directory for the
5316 static int /* O - Size of banner file in kbytes */
5317 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
5318 cupsd_job_t
*job
, /* I - Job information */
5319 const char *name
) /* I - Name of banner */
5321 int i
; /* Looping var */
5322 int kbytes
; /* Size of banner file in kbytes */
5323 char filename
[1024]; /* Job filename */
5324 cupsd_banner_t
*banner
; /* Pointer to banner */
5325 cups_file_t
*in
; /* Input file */
5326 cups_file_t
*out
; /* Output file */
5327 int ch
; /* Character from file */
5328 char attrname
[255], /* Name of attribute */
5329 *s
; /* Pointer into name */
5330 ipp_attribute_t
*attr
; /* Attribute */
5333 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5334 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
5335 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
5336 name
? name
: "(null)");
5339 * Find the banner; return if not found or "none"...
5342 if (!name
|| !strcmp(name
, "none") ||
5343 (banner
= cupsdFindBanner(name
)) == NULL
)
5347 * Open the banner and job files...
5350 if (add_file(con
, job
, banner
->filetype
, 0))
5353 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
5355 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
5357 cupsdLogMessage(CUPSD_LOG_ERROR
,
5358 "Unable to create banner job file %s - %s",
5359 filename
, strerror(errno
));
5364 fchmod(cupsFileNumber(out
), 0640);
5365 fchown(cupsFileNumber(out
), RunUser
, Group
);
5368 * Try the localized banner file under the subdirectory...
5371 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
5373 if (strlen(attrname
) > 2 && attrname
[2] == '-')
5376 * Convert ll-cc to ll_CC...
5380 attrname
[3] = toupper(attrname
[3] & 255);
5381 attrname
[4] = toupper(attrname
[4] & 255);
5384 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5387 if (access(filename
, 0) && strlen(attrname
) > 2)
5390 * Wasn't able to find "ll_CC" locale file; try the non-national
5391 * localization banner directory.
5396 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
5400 if (access(filename
, 0))
5403 * Use the non-localized banner file.
5406 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
5409 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
5413 cupsdLogMessage(CUPSD_LOG_ERROR
,
5414 "Unable to open banner template file %s - %s",
5415 filename
, strerror(errno
));
5421 * Parse the file to the end...
5424 while ((ch
= cupsFileGetChar(in
)) != EOF
)
5428 * Get an attribute name...
5431 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
5432 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
5434 else if (s
< (attrname
+ sizeof(attrname
) - 1))
5444 * Ignore { followed by stuff that is not an attribute name...
5447 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
5452 * See if it is defined...
5455 if (attrname
[0] == '?')
5460 if (!strcmp(s
, "printer-name"))
5462 cupsFilePuts(out
, job
->dest
);
5465 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
5468 * See if we have a leading question mark...
5471 if (attrname
[0] != '?')
5474 * Nope, write to file as-is; probably a PostScript procedure...
5477 cupsFilePrintf(out
, "{%s}", attrname
);
5484 * Output value(s)...
5487 for (i
= 0; i
< attr
->num_values
; i
++)
5490 cupsFilePutChar(out
, ',');
5492 switch (attr
->value_tag
)
5494 case IPP_TAG_INTEGER
:
5496 if (!strncmp(s
, "time-at-", 8))
5498 struct timeval tv
; /* Time value */
5500 tv
.tv_sec
= attr
->values
[i
].integer
;
5503 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
5506 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
5509 case IPP_TAG_BOOLEAN
:
5510 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
5513 case IPP_TAG_NOVALUE
:
5514 cupsFilePuts(out
, "novalue");
5517 case IPP_TAG_RANGE
:
5518 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
5519 attr
->values
[i
].range
.upper
);
5522 case IPP_TAG_RESOLUTION
:
5523 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
5524 attr
->values
[i
].resolution
.yres
,
5525 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5530 case IPP_TAG_STRING
:
5533 case IPP_TAG_KEYWORD
:
5534 case IPP_TAG_CHARSET
:
5535 case IPP_TAG_LANGUAGE
:
5536 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
5539 * Need to quote strings for PS banners...
5544 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
5546 if (*p
== '(' || *p
== ')' || *p
== '\\')
5548 cupsFilePutChar(out
, '\\');
5549 cupsFilePutChar(out
, *p
);
5551 else if (*p
< 32 || *p
> 126)
5552 cupsFilePrintf(out
, "\\%03o", *p
& 255);
5554 cupsFilePutChar(out
, *p
);
5558 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
5562 break; /* anti-compiler-warning-code */
5566 else if (ch
== '\\') /* Quoted char */
5568 ch
= cupsFileGetChar(in
);
5570 if (ch
!= '{') /* Only do special handling for \{ */
5571 cupsFilePutChar(out
, '\\');
5573 cupsFilePutChar(out
, ch
);
5576 cupsFilePutChar(out
, ch
);
5580 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
5582 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
5583 IPP_TAG_INTEGER
)) != NULL
)
5584 attr
->values
[0].integer
+= kbytes
;
5593 * 'copy_file()' - Copy a PPD file or interface script...
5596 static int /* O - 0 = success, -1 = error */
5597 copy_file(const char *from
, /* I - Source file */
5598 const char *to
) /* I - Destination file */
5600 cups_file_t
*src
, /* Source file */
5601 *dst
; /* Destination file */
5602 int bytes
; /* Bytes to read/write */
5603 char buffer
[2048]; /* Copy buffer */
5606 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
5609 * Open the source and destination file for a copy...
5612 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
5615 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5622 * Copy the source file to the destination...
5625 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
5626 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5634 * Close both files and return...
5639 return (cupsFileClose(dst
));
5644 * 'copy_model()' - Copy a PPD model file, substituting default values
5648 static int /* O - 0 = success, -1 = error */
5649 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5650 const char *from
, /* I - Source file */
5651 const char *to
) /* I - Destination file */
5653 fd_set input
; /* select() input set */
5654 struct timeval timeout
; /* select() timeout */
5655 int maxfd
; /* Max file descriptor for select() */
5656 char tempfile
[1024]; /* Temporary PPD file */
5657 int tempfd
; /* Temporary PPD file descriptor */
5658 int temppid
; /* Process ID of cups-driverd */
5659 int temppipe
[2]; /* Temporary pipes */
5660 char *argv
[4], /* Command-line arguments */
5661 *envp
[MAX_ENV
]; /* Environment */
5662 cups_file_t
*src
, /* Source file */
5663 *dst
; /* Destination file */
5664 ppd_file_t
*ppd
; /* PPD file */
5665 int bytes
, /* Bytes from pipe */
5666 total
; /* Total bytes from pipe */
5667 char buffer
[2048]; /* Copy buffer */
5668 int i
; /* Looping var */
5669 char option
[PPD_MAX_NAME
], /* Option name */
5670 choice
[PPD_MAX_NAME
]; /* Choice name */
5671 ppd_size_t
*size
; /* Default size */
5672 int num_defaults
; /* Number of default options */
5673 cups_option_t
*defaults
; /* Default options */
5674 char cups_protocol
[PPD_MAX_LINE
];
5675 /* cupsProtocol attribute */
5678 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5679 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5683 * Run cups-driverd to get the PPD file...
5686 argv
[0] = "cups-driverd";
5688 argv
[2] = (char *)from
;
5691 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5693 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5694 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5695 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5696 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
5699 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5700 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5702 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5703 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
5714 * Wait up to 30 seconds for the PPD file to be copied...
5719 if (temppipe
[0] > CGIPipes
[0])
5720 maxfd
= temppipe
[0] + 1;
5722 maxfd
= CGIPipes
[0] + 1;
5727 * See if we have data ready...
5731 FD_SET(temppipe
[0], &input
);
5732 FD_SET(CGIPipes
[0], &input
);
5734 timeout
.tv_sec
= 30;
5735 timeout
.tv_usec
= 0;
5737 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5747 * We have timed out...
5753 if (FD_ISSET(temppipe
[0], &input
))
5756 * Read the PPD file from the pipe, and write it to the PPD file.
5759 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5761 if (write(tempfd
, buffer
, bytes
) < bytes
)
5770 if (FD_ISSET(CGIPipes
[0], &input
))
5780 * No data from cups-deviced...
5783 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
5789 * Read the source file and see what page sizes are supported...
5792 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5799 * Open the destination (if possible) and set the default options...
5804 cups_protocol
[0] = '\0';
5806 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5809 * Read all of the default lines from the old PPD...
5812 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5813 if (!strncmp(buffer
, "*Default", 8))
5816 * Add the default option...
5819 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5820 choice
, sizeof(choice
)))
5822 ppd_option_t
*ppdo
; /* PPD option */
5826 * Only add the default if the default hasn't already been
5827 * set and the choice exists in the new PPD...
5830 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5831 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5832 ppdFindChoice(ppdo
, choice
))
5833 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5837 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5838 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5842 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
5845 * Add the default media sizes...
5848 num_defaults
= cupsAddOption("PageSize", size
->name
,
5849 num_defaults
, &defaults
);
5850 num_defaults
= cupsAddOption("PageRegion", size
->name
,
5851 num_defaults
, &defaults
);
5852 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
5853 num_defaults
, &defaults
);
5854 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
5855 num_defaults
, &defaults
);
5861 * Open the source file for a copy...
5864 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5866 cupsFreeOptions(num_defaults
, defaults
);
5872 * Open the destination file for a copy...
5875 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5877 cupsFreeOptions(num_defaults
, defaults
);
5884 * Copy the source file to the destination...
5887 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5889 if (!strncmp(buffer
, "*Default", 8))
5892 * Check for an previous default option choice...
5895 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5896 choice
, sizeof(choice
)))
5898 const char *val
; /* Default option value */
5901 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5904 * Substitute the previous choice...
5907 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5912 cupsFilePrintf(dst
, "%s\n", buffer
);
5915 if (cups_protocol
[0])
5916 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5918 cupsFreeOptions(num_defaults
, defaults
);
5921 * Close both files and return...
5928 return (cupsFileClose(dst
));
5933 * 'copy_job_attrs()' - Copy job attributes.
5937 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5938 cupsd_job_t
*job
, /* I - Job */
5939 cups_array_t
*ra
, /* I - Requested attributes array */
5940 cups_array_t
*exclude
) /* I - Private attributes array */
5942 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5946 * Send the requested attributes for each job...
5949 if (!cupsArrayFind(exclude
, "all"))
5951 if ((!exclude
|| !cupsArrayFind(exclude
, "document-count")) &&
5952 (!ra
|| cupsArrayFind(ra
, "document-count")))
5953 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5954 "document-count", job
->num_files
);
5956 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
5957 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
5958 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5959 "job-media-progress", job
->progress
);
5961 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
5962 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
5964 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
5965 NULL
, con
->servername
, con
->serverport
, "/jobs/%d",
5967 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5968 "job-more-info", NULL
, job_uri
);
5971 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5972 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
5973 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5974 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5975 job
->num_files
> 0);
5977 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
5978 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
5979 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5980 "job-printer-up-time", time(NULL
));
5983 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
5985 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5986 con
->servername
, con
->serverport
,
5987 job
->dtype
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
) ?
5988 "/classes/%s" : "/printers/%s",
5990 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5991 "job-printer-uri", NULL
, job_uri
);
5994 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5995 add_job_state_reasons(con
, job
);
5997 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5999 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
6000 con
->servername
, con
->serverport
, "/jobs/%d",
6002 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
6003 "job-uri", NULL
, job_uri
);
6006 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
6011 * 'copy_printer_attrs()' - Copy printer attributes.
6016 cupsd_client_t
*con
, /* I - Client connection */
6017 cupsd_printer_t
*printer
, /* I - Printer */
6018 cups_array_t
*ra
) /* I - Requested attributes array */
6020 char printer_uri
[HTTP_MAX_URI
];
6022 char printer_icons
[HTTP_MAX_URI
];
6024 time_t curtime
; /* Current time */
6025 int i
; /* Looping var */
6029 * Copy the printer attributes to the response using requested-attributes
6030 * and document-format attributes that may be provided by the client.
6033 curtime
= time(NULL
);
6035 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
6036 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6037 "marker-change-time", printer
->marker_time
);
6039 if (printer
->num_printers
> 0 &&
6040 (!ra
|| cupsArrayFind(ra
, "member-uris")))
6042 ipp_attribute_t
*member_uris
; /* member-uris attribute */
6043 cupsd_printer_t
*p2
; /* Printer in class */
6044 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
6047 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
6048 IPP_TAG_URI
, "member-uris",
6049 printer
->num_printers
, NULL
,
6052 for (i
= 0; i
< printer
->num_printers
; i
++)
6054 p2
= printer
->printers
[i
];
6056 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
6057 IPP_TAG_URI
)) != NULL
)
6058 member_uris
->values
[i
].string
.text
=
6059 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
6062 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
6063 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
6065 (p2
->type
& CUPS_PRINTER_CLASS
) ?
6066 "/classes/%s" : "/printers/%s", p2
->name
);
6067 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
6073 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
6074 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
6075 "printer-alert", NULL
, printer
->alert
);
6077 if (printer
->alert_description
&&
6078 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
6079 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
6080 "printer-alert-description", NULL
,
6081 printer
->alert_description
);
6083 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
6084 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
6085 ippTimeToDate(curtime
));
6088 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
6090 if (printer
->reg_name
)
6091 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6092 "printer-dns-sd-name", NULL
, printer
->reg_name
);
6094 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
6095 "printer-dns-sd-name", 0);
6097 #endif /* HAVE_DNSSD */
6099 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
6100 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6101 "printer-error-policy", NULL
, printer
->error_policy
);
6103 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
6105 static const char * const errors
[] =/* printer-error-policy-supported values */
6108 "retry-current-job",
6113 if (printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
))
6114 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6115 "printer-error-policy-supported", NULL
, "retry-current-job");
6117 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
6118 "printer-error-policy-supported",
6119 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
6122 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
6124 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
6125 "http", NULL
, con
->servername
, con
->serverport
,
6126 "/icons/%s.png", printer
->name
);
6127 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
6128 NULL
, printer_icons
);
6129 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
6132 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
6133 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
6134 printer
->accepting
);
6136 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
6137 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
6140 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
6141 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6143 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6144 "http", NULL
, con
->servername
, con
->serverport
,
6145 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6146 "/classes/%s" : "/printers/%s", printer
->name
);
6147 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6148 "printer-more-info", NULL
, printer_uri
);
6151 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
6152 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
6153 "printer-op-policy", NULL
, printer
->op_policy
);
6155 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
6156 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
6159 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
6160 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6161 "printer-state-change-time", printer
->state_time
);
6163 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
6164 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
6165 "printer-state-message", NULL
, printer
->state_message
);
6167 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
6168 add_printer_state_reasons(con
, printer
);
6170 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
6172 int type
; /* printer-type value */
6175 * Add the CUPS-specific printer-type attribute...
6178 type
= printer
->type
;
6180 if (printer
== DefaultPrinter
)
6181 type
|= CUPS_PRINTER_DEFAULT
;
6183 if (!printer
->accepting
)
6184 type
|= CUPS_PRINTER_REJECTING
;
6186 if (!printer
->shared
)
6187 type
|= CUPS_PRINTER_NOT_SHARED
;
6189 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
6193 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
6194 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
6195 "printer-up-time", curtime
);
6197 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
6198 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
6200 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6201 "ipp", NULL
, con
->servername
, con
->serverport
,
6202 (printer
->type
& CUPS_PRINTER_CLASS
) ?
6203 "/classes/%s" : "/printers/%s", printer
->name
);
6204 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
6205 "printer-uri-supported", NULL
, printer_uri
);
6206 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
6210 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
6211 add_queued_job_count(con
, printer
);
6213 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6214 if (printer
->ppd_attrs
)
6215 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
6216 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
6221 * 'copy_subscription_attrs()' - Copy subscription attributes.
6225 copy_subscription_attrs(
6226 cupsd_client_t
*con
, /* I - Client connection */
6227 cupsd_subscription_t
*sub
, /* I - Subscription */
6228 cups_array_t
*ra
, /* I - Requested attributes array */
6229 cups_array_t
*exclude
) /* I - Private attributes array */
6231 ipp_attribute_t
*attr
; /* Current attribute */
6232 char printer_uri
[HTTP_MAX_URI
];
6234 int count
; /* Number of events */
6235 unsigned mask
; /* Current event mask */
6236 const char *name
; /* Current event name */
6239 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6240 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
6241 con
, sub
, ra
, exclude
);
6244 * Copy the subscription attributes to the response using the
6245 * requested-attributes attribute that may be provided by the client.
6248 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
6250 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
6251 (!ra
|| cupsArrayFind(ra
, "notify-events")))
6253 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
6255 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
6258 * Simple event list...
6261 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
6262 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6263 "notify-events", NULL
, name
);
6268 * Complex event list...
6271 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6272 if (sub
->mask
& mask
)
6275 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
6276 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
6277 "notify-events", count
, NULL
, NULL
);
6279 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
6280 if (sub
->mask
& mask
)
6282 attr
->values
[count
].string
.text
=
6283 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
6290 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
6291 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
6292 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6293 "notify-lease-duration", sub
->lease
);
6295 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
6296 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
6297 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6298 "notify-recipient-uri", NULL
, sub
->recipient
);
6299 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
6300 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
6301 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
6302 "notify-pull-method", NULL
, "ippget");
6304 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
6305 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
6306 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
6307 "notify-subscriber-user-name", NULL
, sub
->owner
);
6309 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
6310 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
6311 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6312 "notify-time-interval", sub
->interval
);
6314 if (sub
->user_data_len
> 0 &&
6315 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
6316 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
6317 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
6318 sub
->user_data
, sub
->user_data_len
);
6321 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
6322 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6323 "notify-job-id", sub
->job
->id
);
6325 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
6327 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
6328 "ipp", NULL
, con
->servername
, con
->serverport
,
6329 "/printers/%s", sub
->dest
->name
);
6330 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
6331 "notify-printer-uri", NULL
, printer_uri
);
6334 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
6335 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6336 "notify-subscription-id", sub
->id
);
6341 * 'create_job()' - Print a file to a printer or class.
6345 create_job(cupsd_client_t
*con
, /* I - Client connection */
6346 ipp_attribute_t
*uri
) /* I - Printer URI */
6348 cupsd_printer_t
*printer
; /* Printer */
6349 cupsd_job_t
*job
; /* New job */
6352 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
6353 con
->http
.fd
, uri
->values
[0].string
.text
);
6356 * Is the destination valid?
6359 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6365 send_ipp_status(con
, IPP_NOT_FOUND
,
6366 _("The printer or class does not exist."));
6371 * Create the job object...
6374 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
6377 job
->pending_timeout
= 1;
6380 * Save and log the job...
6383 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
6384 job
->dest
, job
->username
);
6389 * 'create_requested_array()' - Create an array for the requested-attributes.
6392 static cups_array_t
* /* O - Array of attributes or NULL */
6393 create_requested_array(ipp_t
*request
) /* I - IPP request */
6395 int i
; /* Looping var */
6396 ipp_attribute_t
*requested
; /* requested-attributes attribute */
6397 cups_array_t
*ra
; /* Requested attributes array */
6398 char *value
; /* Current value */
6402 * Get the requested-attributes attribute, and return NULL if we don't
6406 if ((requested
= ippFindAttribute(request
, "requested-attributes",
6407 IPP_TAG_KEYWORD
)) == NULL
)
6411 * If the attribute contains a single "all" keyword, return NULL...
6414 if (requested
->num_values
== 1 &&
6415 !strcmp(requested
->values
[0].string
.text
, "all"))
6419 * Create an array using "strcmp" as the comparison function...
6422 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
6424 for (i
= 0; i
< requested
->num_values
; i
++)
6426 value
= requested
->values
[i
].string
.text
;
6428 if (!strcmp(value
, "job-template"))
6430 cupsArrayAdd(ra
, "copies");
6431 cupsArrayAdd(ra
, "copies-default");
6432 cupsArrayAdd(ra
, "copies-supported");
6433 cupsArrayAdd(ra
, "finishings");
6434 cupsArrayAdd(ra
, "finishings-default");
6435 cupsArrayAdd(ra
, "finishings-supported");
6436 cupsArrayAdd(ra
, "job-hold-until");
6437 cupsArrayAdd(ra
, "job-hold-until-default");
6438 cupsArrayAdd(ra
, "job-hold-until-supported");
6439 cupsArrayAdd(ra
, "job-priority");
6440 cupsArrayAdd(ra
, "job-priority-default");
6441 cupsArrayAdd(ra
, "job-priority-supported");
6442 cupsArrayAdd(ra
, "job-sheets");
6443 cupsArrayAdd(ra
, "job-sheets-default");
6444 cupsArrayAdd(ra
, "job-sheets-supported");
6445 cupsArrayAdd(ra
, "media");
6446 cupsArrayAdd(ra
, "media-default");
6447 cupsArrayAdd(ra
, "media-supported");
6448 cupsArrayAdd(ra
, "multiple-document-handling");
6449 cupsArrayAdd(ra
, "multiple-document-handling-default");
6450 cupsArrayAdd(ra
, "multiple-document-handling-supported");
6451 cupsArrayAdd(ra
, "number-up");
6452 cupsArrayAdd(ra
, "number-up-default");
6453 cupsArrayAdd(ra
, "number-up-supported");
6454 cupsArrayAdd(ra
, "orientation-requested");
6455 cupsArrayAdd(ra
, "orientation-requested-default");
6456 cupsArrayAdd(ra
, "orientation-requested-supported");
6457 cupsArrayAdd(ra
, "page-ranges");
6458 cupsArrayAdd(ra
, "page-ranges-supported");
6459 cupsArrayAdd(ra
, "printer-resolution");
6460 cupsArrayAdd(ra
, "printer-resolution-default");
6461 cupsArrayAdd(ra
, "printer-resolution-supported");
6462 cupsArrayAdd(ra
, "print-quality");
6463 cupsArrayAdd(ra
, "print-quality-default");
6464 cupsArrayAdd(ra
, "print-quality-supported");
6465 cupsArrayAdd(ra
, "sides");
6466 cupsArrayAdd(ra
, "sides-default");
6467 cupsArrayAdd(ra
, "sides-supported");
6469 else if (!strcmp(value
, "job-description"))
6471 cupsArrayAdd(ra
, "date-time-at-completed");
6472 cupsArrayAdd(ra
, "date-time-at-creation");
6473 cupsArrayAdd(ra
, "date-time-at-processing");
6474 cupsArrayAdd(ra
, "job-detailed-status-message");
6475 cupsArrayAdd(ra
, "job-document-access-errors");
6476 cupsArrayAdd(ra
, "job-id");
6477 cupsArrayAdd(ra
, "job-impressions");
6478 cupsArrayAdd(ra
, "job-impressions-completed");
6479 cupsArrayAdd(ra
, "job-k-octets");
6480 cupsArrayAdd(ra
, "job-k-octets-processed");
6481 cupsArrayAdd(ra
, "job-media-progress");
6482 cupsArrayAdd(ra
, "job-media-sheets");
6483 cupsArrayAdd(ra
, "job-media-sheets-completed");
6484 cupsArrayAdd(ra
, "job-message-from-operator");
6485 cupsArrayAdd(ra
, "job-more-info");
6486 cupsArrayAdd(ra
, "job-name");
6487 cupsArrayAdd(ra
, "job-originating-user-name");
6488 cupsArrayAdd(ra
, "job-printer-up-time");
6489 cupsArrayAdd(ra
, "job-printer-uri");
6490 cupsArrayAdd(ra
, "job-state");
6491 cupsArrayAdd(ra
, "job-state-message");
6492 cupsArrayAdd(ra
, "job-state-reasons");
6493 cupsArrayAdd(ra
, "job-uri");
6494 cupsArrayAdd(ra
, "number-of-documents");
6495 cupsArrayAdd(ra
, "number-of-intervening-jobs");
6496 cupsArrayAdd(ra
, "output-device-assigned");
6497 cupsArrayAdd(ra
, "time-at-completed");
6498 cupsArrayAdd(ra
, "time-at-creation");
6499 cupsArrayAdd(ra
, "time-at-processing");
6501 else if (!strcmp(value
, "printer-description"))
6503 cupsArrayAdd(ra
, "charset-configured");
6504 cupsArrayAdd(ra
, "charset-supported");
6505 cupsArrayAdd(ra
, "color-supported");
6506 cupsArrayAdd(ra
, "compression-supported");
6507 cupsArrayAdd(ra
, "document-format-default");
6508 cupsArrayAdd(ra
, "document-format-supported");
6509 cupsArrayAdd(ra
, "generated-natural-language-supported");
6510 cupsArrayAdd(ra
, "ipp-versions-supported");
6511 cupsArrayAdd(ra
, "job-impressions-supported");
6512 cupsArrayAdd(ra
, "job-k-octets-supported");
6513 cupsArrayAdd(ra
, "job-media-sheets-supported");
6514 cupsArrayAdd(ra
, "job-settable-attributes-supported");
6515 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
6516 cupsArrayAdd(ra
, "multiple-operation-time-out");
6517 cupsArrayAdd(ra
, "natural-language-configured");
6518 cupsArrayAdd(ra
, "notify-attributes-supported");
6519 cupsArrayAdd(ra
, "notify-lease-duration-default");
6520 cupsArrayAdd(ra
, "notify-lease-duration-supported");
6521 cupsArrayAdd(ra
, "notify-max-events-supported");
6522 cupsArrayAdd(ra
, "notify-events-default");
6523 cupsArrayAdd(ra
, "notify-events-supported");
6524 cupsArrayAdd(ra
, "notify-pull-method-supported");
6525 cupsArrayAdd(ra
, "notify-schemes-supported");
6526 cupsArrayAdd(ra
, "operations-supported");
6527 cupsArrayAdd(ra
, "pages-per-minute");
6528 cupsArrayAdd(ra
, "pages-per-minute-color");
6529 cupsArrayAdd(ra
, "pdl-override-supported");
6530 cupsArrayAdd(ra
, "printer-alert");
6531 cupsArrayAdd(ra
, "printer-alert-description");
6532 cupsArrayAdd(ra
, "printer-commands");
6533 cupsArrayAdd(ra
, "printer-current-time");
6534 cupsArrayAdd(ra
, "printer-driver-installer");
6535 cupsArrayAdd(ra
, "printer-dns-sd-name");
6536 cupsArrayAdd(ra
, "printer-info");
6537 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
6538 cupsArrayAdd(ra
, "printer-location");
6539 cupsArrayAdd(ra
, "printer-make-and-model");
6540 cupsArrayAdd(ra
, "printer-message-from-operator");
6541 cupsArrayAdd(ra
, "printer-more-info");
6542 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
6543 cupsArrayAdd(ra
, "printer-name");
6544 cupsArrayAdd(ra
, "printer-state");
6545 cupsArrayAdd(ra
, "printer-state-message");
6546 cupsArrayAdd(ra
, "printer-state-reasons");
6547 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
6548 cupsArrayAdd(ra
, "printer-type");
6549 cupsArrayAdd(ra
, "printer-up-time");
6550 cupsArrayAdd(ra
, "printer-uri-supported");
6551 cupsArrayAdd(ra
, "queued-job-count");
6552 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
6553 cupsArrayAdd(ra
, "uri-authentication-supported");
6554 cupsArrayAdd(ra
, "uri-security-supported");
6556 else if (!strcmp(value
, "printer-defaults"))
6558 char *name
; /* Option name */
6561 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
6563 name
= (char *)cupsArrayNext(CommonDefaults
))
6564 cupsArrayAdd(ra
, name
);
6566 else if (!strcmp(value
, "subscription-template"))
6568 cupsArrayAdd(ra
, "notify-attributes");
6569 cupsArrayAdd(ra
, "notify-charset");
6570 cupsArrayAdd(ra
, "notify-events");
6571 cupsArrayAdd(ra
, "notify-lease-duration");
6572 cupsArrayAdd(ra
, "notify-natural-language");
6573 cupsArrayAdd(ra
, "notify-pull-method");
6574 cupsArrayAdd(ra
, "notify-recipient-uri");
6575 cupsArrayAdd(ra
, "notify-time-interval");
6576 cupsArrayAdd(ra
, "notify-user-data");
6579 cupsArrayAdd(ra
, value
);
6587 * 'create_subscription()' - Create a notification subscription.
6591 create_subscription(
6592 cupsd_client_t
*con
, /* I - Client connection */
6593 ipp_attribute_t
*uri
) /* I - Printer URI */
6595 http_status_t status
; /* Policy status */
6596 int i
; /* Looping var */
6597 ipp_attribute_t
*attr
; /* Current attribute */
6598 cups_ptype_t dtype
; /* Destination type (printer/class) */
6599 char scheme
[HTTP_MAX_URI
],
6600 /* Scheme portion of URI */
6601 userpass
[HTTP_MAX_URI
],
6602 /* Username portion of URI */
6604 /* Host portion of URI */
6605 resource
[HTTP_MAX_URI
];
6606 /* Resource portion of URI */
6607 int port
; /* Port portion of URI */
6608 cupsd_printer_t
*printer
; /* Printer/class */
6609 cupsd_job_t
*job
; /* Job */
6610 int jobid
; /* Job ID */
6611 cupsd_subscription_t
*sub
; /* Subscription object */
6612 const char *username
, /* requesting-user-name or
6613 authenticated username */
6614 *recipient
, /* notify-recipient-uri */
6615 *pullmethod
; /* notify-pull-method */
6616 ipp_attribute_t
*user_data
; /* notify-user-data */
6617 int interval
, /* notify-time-interval */
6618 lease
; /* notify-lease-duration */
6619 unsigned mask
; /* notify-events */
6620 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
6621 *notify_lease
; /* notify-lease-duration(-default) */
6625 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6627 if (attr
->group_tag
!= IPP_TAG_ZERO
)
6628 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
6629 attr
->value_tag
, attr
->name
);
6631 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
6636 * Is the destination valid?
6639 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6640 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
6641 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6643 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6644 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
6645 sizeof(host
), &port
, resource
, sizeof(resource
));
6647 if (!strcmp(resource
, "/"))
6649 dtype
= (cups_ptype_t
)0;
6652 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6654 dtype
= (cups_ptype_t
)0;
6657 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6659 dtype
= CUPS_PRINTER_CLASS
;
6662 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6668 send_ipp_status(con
, IPP_NOT_FOUND
,
6669 _("The printer or class does not exist."));
6679 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6682 send_http_error(con
, status
, printer
);
6686 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6688 send_http_error(con
, status
, NULL
);
6693 * Get the user that is requesting the subscription...
6696 username
= get_username(con
);
6699 * Find the first subscription group attribute; return if we have
6703 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6704 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6709 send_ipp_status(con
, IPP_BAD_REQUEST
,
6710 _("No subscription attributes in request."));
6715 * Process the subscription attributes in the request...
6718 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6726 lease
= DefaultLeaseDuration
;
6728 mask
= CUPSD_EVENT_NONE
;
6732 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6734 notify_lease
= ippFindAttribute(printer
->attrs
,
6735 "notify-lease-duration-default",
6739 lease
= notify_lease
->values
[0].integer
;
6743 notify_events
= NULL
;
6744 notify_lease
= NULL
;
6747 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6749 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6750 attr
->value_tag
== IPP_TAG_URI
)
6753 * Validate the recipient scheme against the ServerBin/notifier
6757 char notifier
[1024]; /* Notifier filename */
6760 recipient
= attr
->values
[0].string
.text
;
6762 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6763 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6764 host
, sizeof(host
), &port
,
6765 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6767 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6768 _("Bad notify-recipient-uri \"%s\"."), recipient
);
6769 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6770 "notify-status-code", IPP_URI_SCHEME
);
6774 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6776 if (access(notifier
, X_OK
))
6778 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6779 _("notify-recipient-uri URI \"%s\" uses unknown "
6780 "scheme."), recipient
);
6781 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6782 "notify-status-code", IPP_URI_SCHEME
);
6786 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6788 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6789 _("notify-recipient-uri URI \"%s\" is already used."),
6791 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6792 "notify-status-code", IPP_ATTRIBUTES
);
6796 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6797 attr
->value_tag
== IPP_TAG_KEYWORD
)
6799 pullmethod
= attr
->values
[0].string
.text
;
6801 if (strcmp(pullmethod
, "ippget"))
6803 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6804 _("Bad notify-pull-method \"%s\"."), pullmethod
);
6805 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6806 "notify-status-code", IPP_ATTRIBUTES
);
6810 else if (!strcmp(attr
->name
, "notify-charset") &&
6811 attr
->value_tag
== IPP_TAG_CHARSET
&&
6812 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6813 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6815 send_ipp_status(con
, IPP_CHARSET
,
6816 _("Character set \"%s\" not supported."),
6817 attr
->values
[0].string
.text
);
6820 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6821 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6822 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6824 send_ipp_status(con
, IPP_CHARSET
,
6825 _("Language \"%s\" not supported."),
6826 attr
->values
[0].string
.text
);
6829 else if (!strcmp(attr
->name
, "notify-user-data") &&
6830 attr
->value_tag
== IPP_TAG_STRING
)
6832 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6834 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6835 _("The notify-user-data value is too large "
6836 "(%d > 63 octets)."),
6837 attr
->values
[0].unknown
.length
);
6843 else if (!strcmp(attr
->name
, "notify-events") &&
6844 attr
->value_tag
== IPP_TAG_KEYWORD
)
6845 notify_events
= attr
;
6846 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6847 attr
->value_tag
== IPP_TAG_INTEGER
)
6848 lease
= attr
->values
[0].integer
;
6849 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6850 attr
->value_tag
== IPP_TAG_INTEGER
)
6851 interval
= attr
->values
[0].integer
;
6852 else if (!strcmp(attr
->name
, "notify-job-id") &&
6853 attr
->value_tag
== IPP_TAG_INTEGER
)
6854 jobid
= attr
->values
[0].integer
;
6861 for (i
= 0; i
< notify_events
->num_values
; i
++)
6862 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6866 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6868 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6869 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6870 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6872 if (!recipient
&& !pullmethod
)
6875 if (mask
== CUPSD_EVENT_NONE
)
6878 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6880 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6883 send_ipp_status(con
, IPP_BAD_REQUEST
,
6884 _("notify-events not specified."));
6889 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6891 cupsdLogMessage(CUPSD_LOG_INFO
,
6892 "create_subscription: Limiting notify-lease-duration to "
6895 lease
= MaxLeaseDuration
;
6900 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6902 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6910 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
6912 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
6913 _("There are too many subscriptions."));
6918 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
6921 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6922 "Added subscription #%d for printer \"%s\".",
6923 sub
->id
, printer
->name
);
6925 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
6928 sub
->interval
= interval
;
6930 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6932 cupsdSetString(&sub
->owner
, username
);
6936 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6937 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6938 sub
->user_data_len
);
6941 ippAddSeparator(con
->response
);
6942 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6943 "notify-subscription-id", sub
->id
);
6945 con
->response
->request
.status
.status_code
= IPP_OK
;
6951 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6956 * 'delete_printer()' - Remove a printer or class from the system.
6960 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6961 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6963 http_status_t status
; /* Policy status */
6964 cups_ptype_t dtype
; /* Destination type (printer/class) */
6965 cupsd_printer_t
*printer
; /* Printer/class */
6966 char filename
[1024]; /* Script/PPD filename */
6969 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6970 con
->http
.fd
, uri
->values
[0].string
.text
);
6973 * Do we have a valid URI?
6976 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6982 send_ipp_status(con
, IPP_NOT_FOUND
,
6983 _("The printer or class does not exist."));
6991 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6993 send_http_error(con
, status
, NULL
);
6998 * Remove old jobs...
7001 cupsdCancelJobs(printer
->name
, NULL
, 1);
7004 * Remove old subscriptions and send a "deleted printer" event...
7007 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
7008 "%s \"%s\" deleted by \"%s\".",
7009 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
7010 printer
->name
, get_username(con
));
7012 cupsdExpireSubscriptions(printer
, NULL
);
7015 * Remove any old PPD or script files...
7018 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
7022 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7026 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
7029 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
7034 * Unregister color profiles...
7037 apple_unregister_profiles(printer
);
7038 #endif /* __APPLE__ */
7040 if (dtype
& CUPS_PRINTER_CLASS
)
7042 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
7043 printer
->name
, get_username(con
));
7045 cupsdDeletePrinter(printer
, 0);
7046 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7050 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
7051 printer
->name
, get_username(con
));
7053 if (cupsdDeletePrinter(printer
, 0))
7054 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
7056 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
7059 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
7062 * Return with no errors...
7065 con
->response
->request
.status
.status_code
= IPP_OK
;
7070 * 'get_default()' - Get the default destination.
7074 get_default(cupsd_client_t
*con
) /* I - Client connection */
7076 http_status_t status
; /* Policy status */
7077 cups_array_t
*ra
; /* Requested attributes array */
7080 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
7086 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7088 send_http_error(con
, status
, NULL
);
7094 ra
= create_requested_array(con
->request
);
7096 copy_printer_attrs(con
, DefaultPrinter
, ra
);
7098 cupsArrayDelete(ra
);
7100 con
->response
->request
.status
.status_code
= IPP_OK
;
7103 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
7108 * 'get_devices()' - Get the list of available devices on the local system.
7112 get_devices(cupsd_client_t
*con
) /* I - Client connection */
7114 http_status_t status
; /* Policy status */
7115 ipp_attribute_t
*limit
, /* limit attribute */
7116 *timeout
, /* timeout attribute */
7117 *requested
, /* requested-attributes attribute */
7118 *exclude
, /* exclude-schemes attribute */
7119 *include
; /* include-schemes attribute */
7120 char command
[1024], /* cups-deviced command */
7121 options
[2048], /* Options to pass to command */
7123 /* String for requested attributes */
7125 /* String for excluded schemes */
7127 /* String for included schemes */
7130 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
7136 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7138 send_http_error(con
, status
, NULL
);
7143 * Run cups-deviced command with the given options...
7146 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7147 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
7148 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7150 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
7151 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
7154 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7156 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7159 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7161 exclude_str
[0] = '\0';
7164 url_encode_attr(include
, include_str
, sizeof(include_str
));
7166 include_str
[0] = '\0';
7168 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
7169 snprintf(options
, sizeof(options
),
7170 "%d+%d+%d+%d+%s%s%s%s%s",
7171 con
->request
->request
.op
.request_id
,
7172 limit
? limit
->values
[0].integer
: 0,
7173 timeout
? timeout
->values
[0].integer
: 15,
7176 exclude_str
[0] ? "%20" : "", exclude_str
,
7177 include_str
[0] ? "%20" : "", include_str
);
7179 if (cupsdSendCommand(con
, command
, options
, 1))
7182 * Command started successfully, don't send an IPP response here...
7185 ippDelete(con
->response
);
7186 con
->response
= NULL
;
7191 * Command failed, return "internal error" so the user knows something
7195 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7196 _("cups-deviced failed to execute."));
7202 * 'get_document()' - Get a copy of a job file.
7206 get_document(cupsd_client_t
*con
, /* I - Client connection */
7207 ipp_attribute_t
*uri
) /* I - Job URI */
7209 http_status_t status
; /* Policy status */
7210 ipp_attribute_t
*attr
; /* Current attribute */
7211 int jobid
; /* Job ID */
7212 int docnum
; /* Document number */
7213 cupsd_job_t
*job
; /* Current job */
7214 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7215 username
[HTTP_MAX_URI
], /* Username portion of URI */
7216 host
[HTTP_MAX_URI
], /* Host portion of URI */
7217 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7218 int port
; /* Port portion of URI */
7219 char filename
[1024], /* Filename for document */
7220 format
[1024]; /* Format for document */
7223 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
7224 con
->http
.fd
, uri
->values
[0].string
.text
);
7227 * See if we have a job URI or a printer URI...
7230 if (!strcmp(uri
->name
, "printer-uri"))
7233 * Got a printer URI; see if we also have a job-id attribute...
7236 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7237 IPP_TAG_INTEGER
)) == NULL
)
7239 send_ipp_status(con
, IPP_BAD_REQUEST
,
7240 _("Got a printer-uri attribute but no job-id."));
7244 jobid
= attr
->values
[0].integer
;
7249 * Got a job URI; parse it to get the job ID...
7252 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7253 sizeof(scheme
), username
, sizeof(username
), host
,
7254 sizeof(host
), &port
, resource
, sizeof(resource
));
7256 if (strncmp(resource
, "/jobs/", 6))
7262 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7263 uri
->values
[0].string
.text
);
7267 jobid
= atoi(resource
+ 6);
7271 * See if the job exists...
7274 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7277 * Nope - return a "not found" error...
7280 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7288 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
7289 job
->username
)) != HTTP_OK
)
7291 send_http_error(con
, status
, NULL
);
7296 * Get the document number...
7299 if ((attr
= ippFindAttribute(con
->request
, "document-number",
7300 IPP_TAG_INTEGER
)) == NULL
)
7302 send_ipp_status(con
, IPP_BAD_REQUEST
,
7303 _("Missing document-number attribute."));
7307 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
7308 attr
->num_values
> 1)
7310 send_ipp_status(con
, IPP_NOT_FOUND
,
7311 _("Document #%d does not exist in job #%d."), docnum
,
7316 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
7318 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
7320 cupsdLogMessage(CUPSD_LOG_ERROR
,
7321 "Unable to open document %d in job %d - %s", docnum
, jobid
,
7323 send_ipp_status(con
, IPP_NOT_FOUND
,
7324 _("Unable to open document #%d in job #%d."), docnum
,
7329 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7333 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
7334 job
->filetypes
[docnum
- 1]->type
);
7336 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
7338 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
7340 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
7341 IPP_TAG_NAME
)) != NULL
)
7342 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
7343 NULL
, attr
->values
[0].string
.text
);
7348 * 'get_job_attrs()' - Get job attributes.
7352 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
7353 ipp_attribute_t
*uri
) /* I - Job URI */
7355 http_status_t status
; /* Policy status */
7356 ipp_attribute_t
*attr
; /* Current attribute */
7357 int jobid
; /* Job ID */
7358 cupsd_job_t
*job
; /* Current job */
7359 cupsd_printer_t
*printer
; /* Current printer */
7360 cupsd_policy_t
*policy
; /* Current security policy */
7361 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7362 username
[HTTP_MAX_URI
], /* Username portion of URI */
7363 host
[HTTP_MAX_URI
], /* Host portion of URI */
7364 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7365 int port
; /* Port portion of URI */
7366 cups_array_t
*ra
, /* Requested attributes array */
7367 *exclude
; /* Private attributes array */
7370 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
7371 con
->http
.fd
, uri
->values
[0].string
.text
);
7374 * See if we have a job URI or a printer URI...
7377 if (!strcmp(uri
->name
, "printer-uri"))
7380 * Got a printer URI; see if we also have a job-id attribute...
7383 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7384 IPP_TAG_INTEGER
)) == NULL
)
7386 send_ipp_status(con
, IPP_BAD_REQUEST
,
7387 _("Got a printer-uri attribute but no job-id."));
7391 jobid
= attr
->values
[0].integer
;
7396 * Got a job URI; parse it to get the job ID...
7399 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7400 sizeof(scheme
), username
, sizeof(username
), host
,
7401 sizeof(host
), &port
, resource
, sizeof(resource
));
7403 if (strncmp(resource
, "/jobs/", 6))
7409 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7410 uri
->values
[0].string
.text
);
7414 jobid
= atoi(resource
+ 6);
7418 * See if the job exists...
7421 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7424 * Nope - return a "not found" error...
7427 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7435 if ((printer
= job
->printer
) == NULL
)
7436 printer
= cupsdFindDest(job
->dest
);
7439 policy
= printer
->op_policy_ptr
;
7441 policy
= DefaultPolicyPtr
;
7443 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
7445 send_http_error(con
, status
, NULL
);
7449 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
7452 * Copy attributes...
7457 ra
= create_requested_array(con
->request
);
7458 copy_job_attrs(con
, job
, ra
, exclude
);
7459 cupsArrayDelete(ra
);
7461 con
->response
->request
.status
.status_code
= IPP_OK
;
7466 * 'get_jobs()' - Get a list of jobs for the specified printer.
7470 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
7471 ipp_attribute_t
*uri
) /* I - Printer URI */
7473 http_status_t status
; /* Policy status */
7474 ipp_attribute_t
*attr
; /* Current attribute */
7475 const char *dest
; /* Destination */
7476 cups_ptype_t dtype
; /* Destination type (printer/class) */
7477 cups_ptype_t dmask
; /* Destination type mask */
7478 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7479 username
[HTTP_MAX_URI
], /* Username portion of URI */
7480 host
[HTTP_MAX_URI
], /* Host portion of URI */
7481 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7482 int port
; /* Port portion of URI */
7483 int job_comparison
; /* Job comparison */
7484 ipp_jstate_t job_state
; /* job-state value */
7485 int first_job_id
; /* First job ID */
7486 int limit
; /* Maximum number of jobs to return */
7487 int count
; /* Number of jobs that match */
7488 ipp_attribute_t
*job_ids
; /* job-ids attribute */
7489 cupsd_job_t
*job
; /* Current job pointer */
7490 cupsd_printer_t
*printer
; /* Printer */
7491 cups_array_t
*list
; /* Which job list... */
7492 cups_array_t
*ra
, /* Requested attributes array */
7493 *exclude
; /* Private attributes array */
7494 cupsd_policy_t
*policy
; /* Current policy */
7497 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
7498 uri
->values
[0].string
.text
);
7501 * Is the destination valid?
7504 if (strcmp(uri
->name
, "printer-uri"))
7506 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
7510 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7511 sizeof(scheme
), username
, sizeof(username
), host
,
7512 sizeof(host
), &port
, resource
, sizeof(resource
));
7514 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
7517 dtype
= (cups_ptype_t
)0;
7518 dmask
= (cups_ptype_t
)0;
7521 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
7524 dtype
= (cups_ptype_t
)0;
7525 dmask
= CUPS_PRINTER_CLASS
;
7528 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
7531 dtype
= CUPS_PRINTER_CLASS
;
7532 dmask
= CUPS_PRINTER_CLASS
;
7535 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
7542 send_ipp_status(con
, IPP_NOT_FOUND
,
7543 _("The printer or class does not exist."));
7548 dtype
&= CUPS_PRINTER_CLASS
;
7549 dmask
= CUPS_PRINTER_CLASS
;
7557 policy
= printer
->op_policy_ptr
;
7559 policy
= DefaultPolicyPtr
;
7561 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7563 send_http_error(con
, status
, NULL
);
7567 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
7570 * See if the "which-jobs" attribute have been specified...
7573 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
7574 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
7576 send_ipp_status(con
, IPP_CONFLICT
,
7577 _("The %s attribute cannot be provided with job-ids."),
7581 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
7583 job_comparison
= -1;
7584 job_state
= IPP_JOB_STOPPED
;
7587 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
7590 job_state
= IPP_JOB_CANCELED
;
7593 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
7596 job_state
= IPP_JOB_ABORTED
;
7599 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
7602 job_state
= IPP_JOB_PENDING
;
7605 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
7608 job_state
= IPP_JOB_CANCELED
;
7611 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
7614 job_state
= IPP_JOB_PENDING
;
7617 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
7620 job_state
= IPP_JOB_HELD
;
7623 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
7626 job_state
= IPP_JOB_PROCESSING
;
7627 list
= PrintingJobs
;
7629 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
7632 job_state
= IPP_JOB_STOPPED
;
7637 send_ipp_status(con
, IPP_ATTRIBUTES
,
7638 _("The which-jobs value \"%s\" is not supported."),
7639 attr
->values
[0].string
.text
);
7640 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7641 "which-jobs", NULL
, attr
->values
[0].string
.text
);
7646 * See if they want to limit the number of jobs reported...
7649 if ((attr
= ippFindAttribute(con
->request
, "limit",
7650 IPP_TAG_INTEGER
)) != NULL
)
7654 send_ipp_status(con
, IPP_CONFLICT
,
7655 _("The %s attribute cannot be provided with job-ids."),
7660 limit
= attr
->values
[0].integer
;
7665 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
7666 IPP_TAG_INTEGER
)) != NULL
)
7670 send_ipp_status(con
, IPP_CONFLICT
,
7671 _("The %s attribute cannot be provided with job-ids."),
7676 first_job_id
= attr
->values
[0].integer
;
7682 * See if we only want to see jobs for a specific user...
7685 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
7686 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
7688 send_ipp_status(con
, IPP_CONFLICT
,
7689 _("The %s attribute cannot be provided with job-ids."),
7693 else if (attr
&& attr
->values
[0].boolean
)
7694 strlcpy(username
, get_username(con
), sizeof(username
));
7698 if ((ra
= create_requested_array(con
->request
)) == NULL
&&
7699 !ippFindAttribute(con
->request
, "requested-attributes", IPP_TAG_KEYWORD
))
7702 * IPP conformance - Get-Jobs has a default requested-attributes value of
7703 * "job-id" and "job-uri".
7706 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
7707 cupsArrayAdd(ra
, "job-id");
7708 cupsArrayAdd(ra
, "job-uri");
7712 * OK, build a list of jobs for this printer...
7717 int i
; /* Looping var */
7719 for (i
= 0; i
< job_ids
->num_values
; i
++)
7721 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
7725 if (i
< job_ids
->num_values
)
7727 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7728 job_ids
->values
[i
].integer
);
7732 for (i
= 0; i
< job_ids
->num_values
; i
++)
7734 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
7740 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7746 ippAddSeparator(con
->response
);
7748 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7749 job
->printer
->op_policy_ptr
:
7750 policy
, con
, job
->printer
,
7753 copy_job_attrs(con
, job
, ra
, exclude
);
7758 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
7759 (limit
<= 0 || count
< limit
) && job
;
7760 job
= (cupsd_job_t
*)cupsArrayNext(list
))
7763 * Filter out jobs that don't match...
7766 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7767 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
7768 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
7769 job
->username
, job
->state_value
, job
->attrs
);
7771 if (!job
->dest
|| !job
->username
)
7774 if (!job
->dest
|| !job
->username
)
7777 if ((dest
&& strcmp(job
->dest
, dest
)) &&
7778 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
7780 if ((job
->dtype
& dmask
) != dtype
&&
7781 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
7784 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
7785 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
7786 (job_comparison
> 0 && job
->state_value
< job_state
))
7789 if (job
->id
< first_job_id
)
7796 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
7801 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
7805 ippAddSeparator(con
->response
);
7809 exclude
= cupsdGetPrivateAttrs(job
->printer
?
7810 job
->printer
->op_policy_ptr
:
7811 policy
, con
, job
->printer
,
7814 copy_job_attrs(con
, job
, ra
, exclude
);
7817 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
7820 cupsArrayDelete(ra
);
7822 con
->response
->request
.status
.status_code
= IPP_OK
;
7827 * 'get_notifications()' - Get events for a subscription.
7831 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
7833 int i
, j
; /* Looping vars */
7834 http_status_t status
; /* Policy status */
7835 cupsd_subscription_t
*sub
; /* Subscription */
7836 ipp_attribute_t
*ids
, /* notify-subscription-ids */
7837 *sequences
; /* notify-sequence-numbers */
7838 int min_seq
; /* Minimum sequence number */
7839 int interval
; /* Poll interval */
7842 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
7846 * Get subscription attributes...
7849 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
7851 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
7856 send_ipp_status(con
, IPP_BAD_REQUEST
,
7857 _("Missing notify-subscription-ids attribute."));
7862 * Are the subscription IDs valid?
7865 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7867 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7870 * Bad subscription ID...
7873 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7874 ids
->values
[i
].integer
);
7882 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7884 con
, sub
->owner
)) != HTTP_OK
)
7886 send_http_error(con
, status
, sub
->dest
);
7891 * Check the subscription type and update the interval accordingly.
7894 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7897 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7899 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7905 * Tell the client to poll again in N seconds...
7909 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7910 "notify-get-interval", interval
);
7912 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7913 "printer-up-time", time(NULL
));
7916 * Copy the subscription event attributes to the response.
7919 con
->response
->request
.status
.status_code
=
7920 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7922 for (i
= 0; i
< ids
->num_values
; i
++)
7925 * Get the subscription and sequence number...
7928 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7930 if (sequences
&& i
< sequences
->num_values
)
7931 min_seq
= sequences
->values
[i
].integer
;
7936 * If we don't have any new events, nothing to do here...
7939 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
7943 * Otherwise copy all of the new events...
7946 if (sub
->first_event_id
> min_seq
)
7949 j
= min_seq
- sub
->first_event_id
;
7951 for (; j
< cupsArrayCount(sub
->events
); j
++)
7953 ippAddSeparator(con
->response
);
7955 copy_attrs(con
->response
,
7956 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7957 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7964 * 'get_ppd()' - Get a named PPD from the local system.
7968 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7969 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7971 http_status_t status
; /* Policy status */
7972 cupsd_printer_t
*dest
; /* Destination */
7973 cups_ptype_t dtype
; /* Destination type */
7976 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7977 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7979 if (!strcmp(uri
->name
, "ppd-name"))
7982 * Return a PPD file from cups-driverd...
7985 char command
[1024], /* cups-driverd command */
7986 options
[1024], /* Options to pass to command */
7987 ppd_name
[1024]; /* ppd-name */
7994 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7996 send_http_error(con
, status
, NULL
);
8001 * Run cups-driverd command with the given options...
8004 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
8005 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
8006 snprintf(options
, sizeof(options
), "get+%d+%s",
8007 con
->request
->request
.op
.request_id
, ppd_name
);
8009 if (cupsdSendCommand(con
, command
, options
, 0))
8012 * Command started successfully, don't send an IPP response here...
8015 ippDelete(con
->response
);
8016 con
->response
= NULL
;
8021 * Command failed, return "internal error" so the user knows something
8025 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8026 _("cups-driverd failed to execute."));
8029 else if (!strcmp(uri
->name
, "printer-uri") &&
8030 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
8032 int i
; /* Looping var */
8033 char filename
[1024]; /* PPD filename */
8040 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8042 send_http_error(con
, status
, dest
);
8047 * See if we need the PPD for a class or remote printer...
8050 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8053 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
8055 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8056 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8057 "printer-uri", NULL
, dest
->uri
);
8060 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
8062 for (i
= 0; i
< dest
->num_printers
; i
++)
8063 if (!(dest
->printers
[i
]->type
&
8064 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
8066 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
8067 dest
->printers
[i
]->name
);
8069 if (!access(filename
, 0))
8073 if (i
< dest
->num_printers
)
8074 dest
= dest
->printers
[i
];
8077 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
8078 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
8079 "printer-uri", NULL
, dest
->printers
[0]->uri
);
8085 * Found the printer with the PPD file, now see if there is one...
8088 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
8090 send_ipp_status(con
, IPP_NOT_FOUND
,
8091 _("The PPD file \"%s\" could not be opened: %s"),
8092 uri
->values
[0].string
.text
, strerror(errno
));
8096 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
8100 con
->response
->request
.status
.status_code
= IPP_OK
;
8103 send_ipp_status(con
, IPP_NOT_FOUND
,
8104 _("The PPD file \"%s\" could not be found."),
8105 uri
->values
[0].string
.text
);
8110 * 'get_ppds()' - Get the list of PPD files on the local system.
8114 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
8116 http_status_t status
; /* Policy status */
8117 ipp_attribute_t
*limit
, /* Limit attribute */
8118 *device
, /* ppd-device-id attribute */
8119 *language
, /* ppd-natural-language attribute */
8120 *make
, /* ppd-make attribute */
8121 *model
, /* ppd-make-and-model attribute */
8122 *model_number
, /* ppd-model-number attribute */
8123 *product
, /* ppd-product attribute */
8124 *psversion
, /* ppd-psverion attribute */
8125 *type
, /* ppd-type attribute */
8126 *requested
, /* requested-attributes attribute */
8127 *exclude
, /* exclude-schemes attribute */
8128 *include
; /* include-schemes attribute */
8129 char command
[1024], /* cups-driverd command */
8130 options
[4096], /* Options to pass to command */
8131 device_str
[256],/* Escaped ppd-device-id string */
8133 /* Escaped ppd-natural-language */
8134 make_str
[256], /* Escaped ppd-make string */
8135 model_str
[256], /* Escaped ppd-make-and-model string */
8136 model_number_str
[256],
8137 /* ppd-model-number string */
8139 /* Escaped ppd-product string */
8141 /* Escaped ppd-psversion string */
8142 type_str
[256], /* Escaped ppd-type string */
8144 /* String for requested attributes */
8146 /* String for excluded schemes */
8148 /* String for included schemes */
8151 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
8157 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8159 send_http_error(con
, status
, NULL
);
8164 * Run cups-driverd command with the given options...
8167 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
8168 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
8169 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
8171 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
8172 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
8174 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
8176 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
8177 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
8178 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
8179 requested
= ippFindAttribute(con
->request
, "requested-attributes",
8181 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
8183 include
= ippFindAttribute(con
->request
, "include-schemes",
8187 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
8189 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
8192 url_encode_attr(device
, device_str
, sizeof(device_str
));
8194 device_str
[0] = '\0';
8197 url_encode_attr(language
, language_str
, sizeof(language_str
));
8199 language_str
[0] = '\0';
8202 url_encode_attr(make
, make_str
, sizeof(make_str
));
8207 url_encode_attr(model
, model_str
, sizeof(model_str
));
8209 model_str
[0] = '\0';
8212 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
8213 model_number
->values
[0].integer
);
8215 model_number_str
[0] = '\0';
8218 url_encode_attr(product
, product_str
, sizeof(product_str
));
8220 product_str
[0] = '\0';
8223 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
8225 psversion_str
[0] = '\0';
8228 url_encode_attr(type
, type_str
, sizeof(type_str
));
8233 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
8235 exclude_str
[0] = '\0';
8238 url_encode_attr(include
, include_str
, sizeof(include_str
));
8240 include_str
[0] = '\0';
8242 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
8243 snprintf(options
, sizeof(options
),
8244 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
8245 con
->request
->request
.op
.request_id
,
8246 limit
? limit
->values
[0].integer
: 0,
8248 device
? "%20" : "", device_str
,
8249 language
? "%20" : "", language_str
,
8250 make
? "%20" : "", make_str
,
8251 model
? "%20" : "", model_str
,
8252 model_number
? "%20" : "", model_number_str
,
8253 product
? "%20" : "", product_str
,
8254 psversion
? "%20" : "", psversion_str
,
8255 type
? "%20" : "", type_str
,
8256 exclude_str
[0] ? "%20" : "", exclude_str
,
8257 include_str
[0] ? "%20" : "", include_str
);
8259 if (cupsdSendCommand(con
, command
, options
, 0))
8262 * Command started successfully, don't send an IPP response here...
8265 ippDelete(con
->response
);
8266 con
->response
= NULL
;
8271 * Command failed, return "internal error" so the user knows something
8275 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
8276 _("cups-driverd failed to execute."));
8282 * 'get_printer_attrs()' - Get printer attributes.
8286 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
8287 ipp_attribute_t
*uri
) /* I - Printer URI */
8289 http_status_t status
; /* Policy status */
8290 cups_ptype_t dtype
; /* Destination type (printer/class) */
8291 cupsd_printer_t
*printer
; /* Printer/class */
8292 cups_array_t
*ra
; /* Requested attributes array */
8295 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
8296 con
->http
.fd
, uri
->values
[0].string
.text
);
8299 * Is the destination valid?
8302 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8308 send_ipp_status(con
, IPP_NOT_FOUND
,
8309 _("The printer or class does not exist."));
8317 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8319 send_http_error(con
, status
, printer
);
8324 * Send the attributes...
8327 ra
= create_requested_array(con
->request
);
8329 copy_printer_attrs(con
, printer
, ra
);
8331 cupsArrayDelete(ra
);
8333 con
->response
->request
.status
.status_code
= IPP_OK
;
8338 * 'get_printer_supported()' - Get printer supported values.
8342 get_printer_supported(
8343 cupsd_client_t
*con
, /* I - Client connection */
8344 ipp_attribute_t
*uri
) /* I - Printer URI */
8346 http_status_t status
; /* Policy status */
8347 cups_ptype_t dtype
; /* Destination type (printer/class) */
8348 cupsd_printer_t
*printer
; /* Printer/class */
8351 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
8352 con
->http
.fd
, uri
->values
[0].string
.text
);
8355 * Is the destination valid?
8358 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8364 send_ipp_status(con
, IPP_NOT_FOUND
,
8365 _("The printer or class does not exist."));
8373 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8375 send_http_error(con
, status
, printer
);
8380 * Return a list of attributes that can be set via Set-Printer-Attributes.
8383 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8385 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
8386 "printer-location", 0);
8388 con
->response
->request
.status
.status_code
= IPP_OK
;
8393 * 'get_printers()' - Get a list of printers or classes.
8397 get_printers(cupsd_client_t
*con
, /* I - Client connection */
8398 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
8400 http_status_t status
; /* Policy status */
8401 ipp_attribute_t
*attr
; /* Current attribute */
8402 int limit
; /* Max number of printers to return */
8403 int count
; /* Number of printers that match */
8404 cupsd_printer_t
*printer
; /* Current printer pointer */
8405 int printer_type
, /* printer-type attribute */
8406 printer_mask
; /* printer-type-mask attribute */
8407 char *location
; /* Location string */
8408 const char *username
; /* Current user */
8409 char *first_printer_name
; /* first-printer-name attribute */
8410 cups_array_t
*ra
; /* Requested attributes array */
8411 int local
; /* Local connection? */
8414 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
8415 con
->http
.fd
, type
);
8421 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8423 send_http_error(con
, status
, NULL
);
8428 * Check for printers...
8431 if (!Printers
|| !cupsArrayCount(Printers
))
8433 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
8438 * See if they want to limit the number of printers reported...
8441 if ((attr
= ippFindAttribute(con
->request
, "limit",
8442 IPP_TAG_INTEGER
)) != NULL
)
8443 limit
= attr
->values
[0].integer
;
8447 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
8448 IPP_TAG_NAME
)) != NULL
)
8449 first_printer_name
= attr
->values
[0].string
.text
;
8451 first_printer_name
= NULL
;
8454 * Support filtering...
8457 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
8458 IPP_TAG_ENUM
)) != NULL
)
8459 printer_type
= attr
->values
[0].integer
;
8463 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
8464 IPP_TAG_ENUM
)) != NULL
)
8465 printer_mask
= attr
->values
[0].integer
;
8469 local
= httpAddrLocalhost(&(con
->clientaddr
));
8471 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
8472 IPP_TAG_TEXT
)) != NULL
)
8473 location
= attr
->values
[0].string
.text
;
8477 if (con
->username
[0])
8478 username
= con
->username
;
8479 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8480 IPP_TAG_NAME
)) != NULL
)
8481 username
= attr
->values
[0].string
.text
;
8485 ra
= create_requested_array(con
->request
);
8488 * OK, build a list of printers for this printer...
8491 if (first_printer_name
)
8493 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
8494 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8497 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
8500 count
< limit
&& printer
;
8501 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
8503 if (!local
&& !printer
->shared
)
8506 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
8507 (printer
->type
& printer_mask
) == printer_type
&&
8509 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
8512 * If HideImplicitMembers is enabled, see if this printer or class
8513 * is a member of an implicit class...
8516 if (ImplicitClasses
&& HideImplicitMembers
&&
8517 printer
->in_implicit_class
)
8521 * If a username is specified, see if it is allowed or denied
8525 if (cupsArrayCount(printer
->users
) && username
&&
8526 !user_allowed(printer
, username
))
8530 * Add the group separator as needed...
8534 ippAddSeparator(con
->response
);
8539 * Send the attributes...
8542 copy_printer_attrs(con
, printer
, ra
);
8546 cupsArrayDelete(ra
);
8548 con
->response
->request
.status
.status_code
= IPP_OK
;
8553 * 'get_subscription_attrs()' - Get subscription attributes.
8557 get_subscription_attrs(
8558 cupsd_client_t
*con
, /* I - Client connection */
8559 int sub_id
) /* I - Subscription ID */
8561 http_status_t status
; /* Policy status */
8562 cupsd_subscription_t
*sub
; /* Subscription */
8563 cupsd_policy_t
*policy
; /* Current security policy */
8564 cups_array_t
*ra
, /* Requested attributes array */
8565 *exclude
; /* Private attributes array */
8568 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8569 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
8570 con
, con
->http
.fd
, sub_id
);
8573 * Is the subscription ID valid?
8576 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8579 * Bad subscription ID...
8582 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8592 policy
= sub
->dest
->op_policy_ptr
;
8594 policy
= DefaultPolicyPtr
;
8596 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
8598 send_http_error(con
, status
, sub
->dest
);
8602 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
8605 * Copy the subscription attributes to the response using the
8606 * requested-attributes attribute that may be provided by the client.
8609 ra
= create_requested_array(con
->request
);
8611 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8613 cupsArrayDelete(ra
);
8615 con
->response
->request
.status
.status_code
= IPP_OK
;
8620 * 'get_subscriptions()' - Get subscriptions.
8624 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
8625 ipp_attribute_t
*uri
) /* I - Printer/job URI */
8627 http_status_t status
; /* Policy status */
8628 int count
; /* Number of subscriptions */
8629 int limit
; /* Limit */
8630 cupsd_subscription_t
*sub
; /* Subscription */
8631 cups_array_t
*ra
; /* Requested attributes array */
8632 ipp_attribute_t
*attr
; /* Attribute */
8633 cups_ptype_t dtype
; /* Destination type (printer/class) */
8634 char scheme
[HTTP_MAX_URI
],
8635 /* Scheme portion of URI */
8636 username
[HTTP_MAX_URI
],
8637 /* Username portion of URI */
8639 /* Host portion of URI */
8640 resource
[HTTP_MAX_URI
];
8641 /* Resource portion of URI */
8642 int port
; /* Port portion of URI */
8643 cupsd_job_t
*job
; /* Job pointer */
8644 cupsd_printer_t
*printer
; /* Printer */
8645 cupsd_policy_t
*policy
; /* Policy */
8646 cups_array_t
*exclude
; /* Private attributes array */
8649 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8650 "get_subscriptions(con=%p[%d], uri=%s)",
8651 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
8654 * Is the destination valid?
8657 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8658 sizeof(scheme
), username
, sizeof(username
), host
,
8659 sizeof(host
), &port
, resource
, sizeof(resource
));
8661 if (!strcmp(resource
, "/") ||
8662 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
8663 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
8664 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
8669 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
8672 job
= cupsdFindJob(atoi(resource
+ 6));
8676 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
8677 atoi(resource
+ 6));
8681 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8687 send_ipp_status(con
, IPP_NOT_FOUND
,
8688 _("The printer or class does not exist."));
8691 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
8692 IPP_TAG_INTEGER
)) != NULL
)
8694 job
= cupsdFindJob(attr
->values
[0].integer
);
8698 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
8699 attr
->values
[0].integer
);
8711 policy
= printer
->op_policy_ptr
;
8713 policy
= DefaultPolicyPtr
;
8715 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
8717 send_http_error(con
, status
, printer
);
8722 * Copy the subscription attributes to the response using the
8723 * requested-attributes attribute that may be provided by the client.
8726 ra
= create_requested_array(con
->request
);
8728 if ((attr
= ippFindAttribute(con
->request
, "limit",
8729 IPP_TAG_INTEGER
)) != NULL
)
8730 limit
= attr
->values
[0].integer
;
8735 * See if we only want to see subscriptions for a specific user...
8738 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
8739 IPP_TAG_BOOLEAN
)) != NULL
&&
8740 attr
->values
[0].boolean
)
8741 strlcpy(username
, get_username(con
), sizeof(username
));
8745 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
8747 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
8748 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
8749 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
8751 ippAddSeparator(con
->response
);
8753 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
8754 policy
, con
, sub
->dest
,
8757 copy_subscription_attrs(con
, sub
, ra
, exclude
);
8760 if (limit
&& count
>= limit
)
8764 cupsArrayDelete(ra
);
8767 con
->response
->request
.status
.status_code
= IPP_OK
;
8769 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
8774 * 'get_username()' - Get the username associated with a request.
8777 static const char * /* O - Username */
8778 get_username(cupsd_client_t
*con
) /* I - Connection */
8780 ipp_attribute_t
*attr
; /* Attribute */
8783 if (con
->username
[0])
8784 return (con
->username
);
8785 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
8786 IPP_TAG_NAME
)) != NULL
)
8787 return (attr
->values
[0].string
.text
);
8789 return ("anonymous");
8794 * 'hold_job()' - Hold a print job.
8798 hold_job(cupsd_client_t
*con
, /* I - Client connection */
8799 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8801 ipp_attribute_t
*attr
; /* Current job-hold-until */
8802 const char *when
; /* New value */
8803 int jobid
; /* Job ID */
8804 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8805 username
[HTTP_MAX_URI
], /* Username portion of URI */
8806 host
[HTTP_MAX_URI
], /* Host portion of URI */
8807 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8808 int port
; /* Port portion of URI */
8809 cupsd_job_t
*job
; /* Job information */
8812 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
8813 uri
->values
[0].string
.text
);
8816 * See if we have a job URI or a printer URI...
8819 if (!strcmp(uri
->name
, "printer-uri"))
8822 * Got a printer URI; see if we also have a job-id attribute...
8825 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8826 IPP_TAG_INTEGER
)) == NULL
)
8828 send_ipp_status(con
, IPP_BAD_REQUEST
,
8829 _("Got a printer-uri attribute but no job-id."));
8833 jobid
= attr
->values
[0].integer
;
8838 * Got a job URI; parse it to get the job ID...
8841 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8842 sizeof(scheme
), username
, sizeof(username
), host
,
8843 sizeof(host
), &port
, resource
, sizeof(resource
));
8845 if (strncmp(resource
, "/jobs/", 6))
8851 send_ipp_status(con
, IPP_BAD_REQUEST
,
8852 _("Bad job-uri \"%s\"."),
8853 uri
->values
[0].string
.text
);
8857 jobid
= atoi(resource
+ 6);
8861 * See if the job exists...
8864 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8867 * Nope - return a "not found" error...
8870 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8875 * See if the job is owned by the requesting user...
8878 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8880 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8881 cupsdFindDest(job
->dest
));
8886 * See if the job is in a state that allows holding...
8889 if (job
->state_value
> IPP_JOB_STOPPED
)
8892 * Return a "not-possible" error...
8895 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8896 _("Job #%d is finished and cannot be altered."),
8902 * Hold the job and return...
8905 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8906 IPP_TAG_KEYWORD
)) == NULL
)
8907 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8911 when
= attr
->values
[0].string
.text
;
8913 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8914 "Job job-hold-until value changed by user.");
8917 when
= "indefinite";
8919 cupsdSetJobHoldUntil(job
, when
, 1);
8920 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
8923 con
->response
->request
.status
.status_code
= IPP_OK
;
8928 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8932 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8933 ipp_attribute_t
*uri
) /* I - Printer URI */
8935 http_status_t status
; /* Policy status */
8936 cups_ptype_t dtype
; /* Destination type (printer/class) */
8937 cupsd_printer_t
*printer
; /* Printer data */
8940 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8941 con
->http
.fd
, uri
->values
[0].string
.text
);
8944 * Is the destination valid?
8947 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8953 send_ipp_status(con
, IPP_NOT_FOUND
,
8954 _("The printer or class does not exist."));
8962 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8964 send_http_error(con
, status
, printer
);
8969 * Hold pending/new jobs sent to the printer...
8972 printer
->holding_new_jobs
= 1;
8974 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8976 if (dtype
& CUPS_PRINTER_CLASS
)
8977 cupsdLogMessage(CUPSD_LOG_INFO
,
8978 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8979 printer
->name
, get_username(con
));
8981 cupsdLogMessage(CUPSD_LOG_INFO
,
8982 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8983 printer
->name
, get_username(con
));
8986 * Everything was ok, so return OK status...
8989 con
->response
->request
.status
.status_code
= IPP_OK
;
8994 * 'move_job()' - Move a job to a new destination.
8998 move_job(cupsd_client_t
*con
, /* I - Client connection */
8999 ipp_attribute_t
*uri
) /* I - Job URI */
9001 http_status_t status
; /* Policy status */
9002 ipp_attribute_t
*attr
; /* Current attribute */
9003 int jobid
; /* Job ID */
9004 cupsd_job_t
*job
; /* Current job */
9005 const char *src
; /* Source printer/class */
9006 cups_ptype_t stype
, /* Source type (printer or class) */
9007 dtype
; /* Destination type (printer/class) */
9008 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
9009 username
[HTTP_MAX_URI
], /* Username portion of URI */
9010 host
[HTTP_MAX_URI
], /* Host portion of URI */
9011 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9012 int port
; /* Port portion of URI */
9013 cupsd_printer_t
*sprinter
, /* Source printer */
9014 *dprinter
; /* Destination printer */
9017 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
9018 uri
->values
[0].string
.text
);
9021 * Get the new printer or class...
9024 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
9025 IPP_TAG_URI
)) == NULL
)
9028 * Need job-printer-uri...
9031 send_ipp_status(con
, IPP_BAD_REQUEST
,
9032 _("job-printer-uri attribute missing."));
9036 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
9042 send_ipp_status(con
, IPP_NOT_FOUND
,
9043 _("The printer or class does not exist."));
9048 * See if we have a job URI or a printer URI...
9051 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9052 sizeof(scheme
), username
, sizeof(username
), host
,
9053 sizeof(host
), &port
, resource
, sizeof(resource
));
9055 if (!strcmp(uri
->name
, "printer-uri"))
9058 * Got a printer URI; see if we also have a job-id attribute...
9061 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9062 IPP_TAG_INTEGER
)) == NULL
)
9068 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
9069 &sprinter
)) == NULL
)
9075 send_ipp_status(con
, IPP_NOT_FOUND
,
9076 _("The printer or class does not exist."));
9085 * Otherwise, just move a single job...
9088 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
9091 * Nope - return a "not found" error...
9094 send_ipp_status(con
, IPP_NOT_FOUND
,
9095 _("Job #%d does not exist."), attr
->values
[0].integer
);
9101 * Job found, initialize source pointers...
9112 * Got a job URI; parse it to get the job ID...
9115 if (strncmp(resource
, "/jobs/", 6))
9121 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9122 uri
->values
[0].string
.text
);
9127 * See if the job exists...
9130 jobid
= atoi(resource
+ 6);
9132 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9135 * Nope - return a "not found" error...
9138 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9144 * Job found, initialize source pointers...
9153 * Check the policy of the destination printer...
9156 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
9157 job
? job
->username
: NULL
)) != HTTP_OK
)
9159 send_http_error(con
, status
, dprinter
);
9164 * Now move the job or jobs...
9170 * See if the job has been completed...
9173 if (job
->state_value
> IPP_JOB_STOPPED
)
9176 * Return a "not-possible" error...
9179 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9180 _("Job #%d is finished and cannot be altered."),
9186 * See if the job is owned by the requesting user...
9189 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9191 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9192 cupsdFindDest(job
->dest
));
9197 * Move the job to a different printer or class...
9200 cupsdMoveJob(job
, dprinter
);
9205 * Got the source printer, now look through the jobs...
9208 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
9210 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
9213 * See if the job is pointing at the source printer or has not been
9217 if (_cups_strcasecmp(job
->dest
, src
) ||
9218 job
->state_value
> IPP_JOB_STOPPED
)
9222 * See if the job can be moved by the requesting user...
9225 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9229 * Move the job to a different printer or class...
9232 cupsdMoveJob(job
, dprinter
);
9237 * Start jobs if possible...
9243 * Return with "everything is OK" status...
9246 con
->response
->request
.status
.status_code
= IPP_OK
;
9251 * 'ppd_parse_line()' - Parse a PPD default line.
9254 static int /* O - 0 on success, -1 on failure */
9255 ppd_parse_line(const char *line
, /* I - Line */
9256 char *option
, /* O - Option name */
9257 int olen
, /* I - Size of option name */
9258 char *choice
, /* O - Choice name */
9259 int clen
) /* I - Size of choice name */
9262 * Verify this is a default option line...
9265 if (strncmp(line
, "*Default", 8))
9269 * Read the option name...
9272 for (line
+= 8, olen
--;
9273 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9284 * Skip everything else up to the colon (:)...
9287 while (*line
&& *line
!= ':')
9296 * Now grab the option choice, skipping leading whitespace...
9299 while (isspace(*line
& 255))
9303 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
9314 * Return with no errors...
9322 * 'print_job()' - Print a file to a printer or class.
9326 print_job(cupsd_client_t
*con
, /* I - Client connection */
9327 ipp_attribute_t
*uri
) /* I - Printer URI */
9329 ipp_attribute_t
*attr
; /* Current attribute */
9330 ipp_attribute_t
*format
; /* Document-format attribute */
9331 const char *default_format
; /* document-format-default value */
9332 cupsd_job_t
*job
; /* New job */
9333 char filename
[1024]; /* Job filename */
9334 mime_type_t
*filetype
; /* Type of file */
9335 char super
[MIME_MAX_SUPER
], /* Supertype of file */
9336 type
[MIME_MAX_TYPE
], /* Subtype of file */
9337 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9338 /* Textual name of mime type */
9339 cupsd_printer_t
*printer
; /* Printer data */
9340 struct stat fileinfo
; /* File information */
9341 int kbytes
; /* Size of file */
9342 int compression
; /* Document compression */
9345 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
9346 uri
->values
[0].string
.text
);
9349 * Validate print file attributes, for now just document-format and
9350 * compression (CUPS only supports "none" and "gzip")...
9353 compression
= CUPS_FILE_NONE
;
9355 if ((attr
= ippFindAttribute(con
->request
, "compression",
9356 IPP_TAG_KEYWORD
)) != NULL
)
9358 if (strcmp(attr
->values
[0].string
.text
, "none")
9360 && strcmp(attr
->values
[0].string
.text
, "gzip")
9361 #endif /* HAVE_LIBZ */
9364 send_ipp_status(con
, IPP_ATTRIBUTES
,
9365 _("Unsupported compression \"%s\"."),
9366 attr
->values
[0].string
.text
);
9367 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9368 "compression", NULL
, attr
->values
[0].string
.text
);
9373 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9374 compression
= CUPS_FILE_GZIP
;
9375 #endif /* HAVE_LIBZ */
9379 * Do we have a file to print?
9384 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9389 * Is the destination valid?
9392 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
9398 send_ipp_status(con
, IPP_NOT_FOUND
,
9399 _("The printer or class does not exist."));
9404 * Is it a format we support?
9407 if ((format
= ippFindAttribute(con
->request
, "document-format",
9408 IPP_TAG_MIMETYPE
)) != NULL
)
9411 * Grab format from client...
9414 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
9417 send_ipp_status(con
, IPP_BAD_REQUEST
,
9418 _("Bad document-format \"%s\"."),
9419 format
->values
[0].string
.text
);
9423 else if ((default_format
= cupsGetOption("document-format",
9424 printer
->num_options
,
9425 printer
->options
)) != NULL
)
9428 * Use default document format...
9431 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9433 send_ipp_status(con
, IPP_BAD_REQUEST
,
9434 _("Bad document-format \"%s\"."),
9445 strcpy(super
, "application");
9446 strcpy(type
, "octet-stream");
9449 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9452 * Auto-type the file...
9455 ipp_attribute_t
*doc_name
; /* document-name attribute */
9458 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
9460 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9461 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9462 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9466 filetype
= mimeType(MimeDatabase
, super
, type
);
9468 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
9469 filetype
->super
, filetype
->type
);
9472 filetype
= mimeType(MimeDatabase
, super
, type
);
9476 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9479 * Replace the document-format attribute value with the auto-typed or
9483 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9488 _cupsStrFree(format
->values
[0].string
.text
);
9490 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9493 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9494 "document-format", NULL
, mimetype
);
9498 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9499 _("Unsupported document-format \"%s\"."),
9500 format
? format
->values
[0].string
.text
:
9501 "application/octet-stream");
9502 cupsdLogMessage(CUPSD_LOG_INFO
,
9503 "Hint: Do you have the raw file printing rules enabled?");
9506 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9507 "document-format", NULL
, format
->values
[0].string
.text
);
9513 * Read any embedded job ticket info from PS files...
9516 if (!_cups_strcasecmp(filetype
->super
, "application") &&
9517 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
9518 !_cups_strcasecmp(filetype
->type
, "pdf")))
9519 read_job_ticket(con
);
9522 * Create the job object...
9525 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
9529 * Update quota data...
9532 if (stat(con
->filename
, &fileinfo
))
9535 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9537 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9539 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9540 IPP_TAG_INTEGER
)) != NULL
)
9541 attr
->values
[0].integer
+= kbytes
;
9544 * Add the job file...
9547 if (add_file(con
, job
, filetype
, compression
))
9550 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9552 rename(con
->filename
, filename
);
9553 cupsdClearString(&con
->filename
);
9556 * See if we need to add the ending sheet...
9559 if (cupsdTimeoutJob(job
))
9563 * Log and save the job...
9566 cupsdLogJob(job
, CUPSD_LOG_INFO
,
9567 "File of type %s/%s queued by \"%s\".",
9568 filetype
->super
, filetype
->type
, job
->username
);
9569 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
9570 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
9571 job
->dest
, job
->username
);
9574 * Start the job if possible...
9582 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
9584 * This function only gets called when printing a single PDF or PostScript
9585 * file using the Print-Job operation. It doesn't work for Create-Job +
9586 * Send-File, since the job attributes need to be set at job creation
9587 * time for banners to work. The embedded job ticket stuff is here
9588 * primarily to allow the Windows printer driver for CUPS to pass in JCL
9589 * options and IPP attributes which otherwise would be lost.
9591 * The format of a job ticket is simple:
9593 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
9595 * %cupsJobTicket: attr1=value1
9596 * %cupsJobTicket: attr2=value2
9598 * %cupsJobTicket: attrN=valueN
9600 * Job ticket lines must appear immediately after the first line that
9601 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
9602 * stops looking for job ticket info when it finds a line that does not begin
9603 * with "%cupsJobTicket:".
9605 * The maximum length of a job ticket line, including the prefix, is
9606 * 255 characters to conform with the Adobe DSC.
9608 * Read-only attributes are rejected with a notice to the error log in
9609 * case a malicious user tries anything. Since the job ticket is read
9610 * prior to attribute validation in print_job(), job ticket attributes
9611 * will go through the same validation as IPP attributes...
9615 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
9617 cups_file_t
*fp
; /* File to read from */
9618 char line
[256]; /* Line data */
9619 int num_options
; /* Number of options */
9620 cups_option_t
*options
; /* Options */
9621 ipp_t
*ticket
; /* New attributes */
9622 ipp_attribute_t
*attr
, /* Current attribute */
9623 *attr2
, /* Job attribute */
9624 *prev2
; /* Previous job attribute */
9628 * First open the print file...
9631 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
9633 cupsdLogMessage(CUPSD_LOG_ERROR
,
9634 "Unable to open print file for job ticket - %s",
9640 * Skip the first line...
9643 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
9645 cupsdLogMessage(CUPSD_LOG_ERROR
,
9646 "Unable to read from print file for job ticket - %s",
9652 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
9655 * Not a DSC-compliant file, so no job ticket info will be available...
9663 * Read job ticket info from the file...
9669 while (cupsFileGets(fp
, line
, sizeof(line
)))
9672 * Stop at the first non-ticket line...
9675 if (strncmp(line
, "%cupsJobTicket:", 15))
9679 * Add the options to the option array...
9682 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
9686 * Done with the file; see if we have any options...
9691 if (num_options
== 0)
9695 * OK, convert the options to an attribute list, and apply them to
9700 cupsEncodeOptions(ticket
, num_options
, options
);
9703 * See what the user wants to change.
9706 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
9708 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9711 if (!strcmp(attr
->name
, "job-originating-host-name") ||
9712 !strcmp(attr
->name
, "job-originating-user-name") ||
9713 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9714 !strcmp(attr
->name
, "job-k-octets") ||
9715 !strcmp(attr
->name
, "job-id") ||
9716 !strncmp(attr
->name
, "job-state", 9) ||
9717 !strncmp(attr
->name
, "time-at-", 8))
9718 continue; /* Read-only attrs */
9720 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
9721 IPP_TAG_ZERO
)) != NULL
)
9724 * Some other value; first free the old value...
9727 if (con
->request
->attrs
== attr2
)
9729 con
->request
->attrs
= attr2
->next
;
9734 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
9735 if (prev2
->next
== attr2
)
9737 prev2
->next
= attr2
->next
;
9742 if (con
->request
->last
== attr2
)
9743 con
->request
->last
= prev2
;
9745 _ippFreeAttr(attr2
);
9749 * Add new option by copying it...
9752 copy_attribute(con
->request
, attr
, 0);
9756 * Then free the attribute list and option array...
9760 cupsFreeOptions(num_options
, options
);
9765 * 'reject_jobs()' - Reject print jobs to a printer.
9769 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
9770 ipp_attribute_t
*uri
) /* I - Printer or class URI */
9772 http_status_t status
; /* Policy status */
9773 cups_ptype_t dtype
; /* Destination type (printer/class) */
9774 cupsd_printer_t
*printer
; /* Printer data */
9775 ipp_attribute_t
*attr
; /* printer-state-message text */
9778 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
9779 con
->http
.fd
, uri
->values
[0].string
.text
);
9782 * Is the destination valid?
9785 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9791 send_ipp_status(con
, IPP_NOT_FOUND
,
9792 _("The printer or class does not exist."));
9800 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9802 send_http_error(con
, status
, printer
);
9807 * Reject jobs sent to the printer...
9810 printer
->accepting
= 0;
9812 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9813 IPP_TAG_TEXT
)) == NULL
)
9814 strcpy(printer
->state_message
, "Rejecting Jobs");
9816 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9817 sizeof(printer
->state_message
));
9819 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9820 "No longer accepting jobs.");
9822 if (dtype
& CUPS_PRINTER_CLASS
)
9824 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
9826 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
9827 printer
->name
, get_username(con
));
9831 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
9833 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
9834 printer
->name
, get_username(con
));
9838 * Everything was ok, so return OK status...
9841 con
->response
->request
.status
.status_code
= IPP_OK
;
9846 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
9850 release_held_new_jobs(
9851 cupsd_client_t
*con
, /* I - Connection */
9852 ipp_attribute_t
*uri
) /* I - Printer URI */
9854 http_status_t status
; /* Policy status */
9855 cups_ptype_t dtype
; /* Destination type (printer/class) */
9856 cupsd_printer_t
*printer
; /* Printer data */
9859 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
9860 con
->http
.fd
, uri
->values
[0].string
.text
);
9863 * Is the destination valid?
9866 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9872 send_ipp_status(con
, IPP_NOT_FOUND
,
9873 _("The printer or class does not exist."));
9881 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9883 send_http_error(con
, status
, printer
);
9888 * Hold pending/new jobs sent to the printer...
9891 printer
->holding_new_jobs
= 0;
9893 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
9895 if (dtype
& CUPS_PRINTER_CLASS
)
9896 cupsdLogMessage(CUPSD_LOG_INFO
,
9897 "Class \"%s\" now printing pending/new jobs (\"%s\").",
9898 printer
->name
, get_username(con
));
9900 cupsdLogMessage(CUPSD_LOG_INFO
,
9901 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
9902 printer
->name
, get_username(con
));
9905 * Everything was ok, so return OK status...
9908 con
->response
->request
.status
.status_code
= IPP_OK
;
9913 * 'release_job()' - Release a held print job.
9917 release_job(cupsd_client_t
*con
, /* I - Client connection */
9918 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9920 ipp_attribute_t
*attr
; /* Current attribute */
9921 int jobid
; /* Job ID */
9922 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9923 username
[HTTP_MAX_URI
], /* Username portion of URI */
9924 host
[HTTP_MAX_URI
], /* Host portion of URI */
9925 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9926 int port
; /* Port portion of URI */
9927 cupsd_job_t
*job
; /* Job information */
9930 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9931 con
->http
.fd
, uri
->values
[0].string
.text
);
9934 * See if we have a job URI or a printer URI...
9937 if (!strcmp(uri
->name
, "printer-uri"))
9940 * Got a printer URI; see if we also have a job-id attribute...
9943 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9944 IPP_TAG_INTEGER
)) == NULL
)
9946 send_ipp_status(con
, IPP_BAD_REQUEST
,
9947 _("Got a printer-uri attribute but no job-id."));
9951 jobid
= attr
->values
[0].integer
;
9956 * Got a job URI; parse it to get the job ID...
9959 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9960 sizeof(scheme
), username
, sizeof(username
), host
,
9961 sizeof(host
), &port
, resource
, sizeof(resource
));
9963 if (strncmp(resource
, "/jobs/", 6))
9969 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9970 uri
->values
[0].string
.text
);
9974 jobid
= atoi(resource
+ 6);
9978 * See if the job exists...
9981 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9984 * Nope - return a "not found" error...
9987 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9992 * See if job is "held"...
9995 if (job
->state_value
!= IPP_JOB_HELD
)
9998 * Nope - return a "not possible" error...
10001 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
10006 * See if the job is owned by the requesting user...
10009 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10011 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10012 cupsdFindDest(job
->dest
));
10017 * Reset the job-hold-until value to "no-hold"...
10020 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10021 IPP_TAG_KEYWORD
)) == NULL
)
10022 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10026 _cupsStrFree(attr
->values
[0].string
.text
);
10028 attr
->value_tag
= IPP_TAG_KEYWORD
;
10029 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
10031 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10032 "Job job-hold-until value changed by user.");
10036 * Release the job and return...
10039 cupsdReleaseJob(job
);
10041 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10042 "Job released by user.");
10044 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
10046 con
->response
->request
.status
.status_code
= IPP_OK
;
10053 * 'renew_subscription()' - Renew an existing subscription...
10057 renew_subscription(
10058 cupsd_client_t
*con
, /* I - Client connection */
10059 int sub_id
) /* I - Subscription ID */
10061 http_status_t status
; /* Policy status */
10062 cupsd_subscription_t
*sub
; /* Subscription */
10063 ipp_attribute_t
*lease
; /* notify-lease-duration */
10066 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
10067 "renew_subscription(con=%p[%d], sub_id=%d)",
10068 con
, con
->http
.fd
, sub_id
);
10071 * Is the subscription ID valid?
10074 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
10077 * Bad subscription ID...
10080 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
10088 * Job subscriptions cannot be renewed...
10091 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10092 _("Job subscriptions cannot be renewed."));
10100 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
10102 con
, sub
->owner
)) != HTTP_OK
)
10104 send_http_error(con
, status
, sub
->dest
);
10109 * Renew the subscription...
10112 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
10115 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
10117 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
10119 cupsdLogMessage(CUPSD_LOG_INFO
,
10120 "renew_subscription: Limiting notify-lease-duration to "
10123 sub
->lease
= MaxLeaseDuration
;
10126 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
10128 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
10130 con
->response
->request
.status
.status_code
= IPP_OK
;
10132 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
10133 "notify-lease-duration", sub
->lease
);
10138 * 'restart_job()' - Restart an old print job.
10142 restart_job(cupsd_client_t
*con
, /* I - Client connection */
10143 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
10145 ipp_attribute_t
*attr
; /* Current attribute */
10146 int jobid
; /* Job ID */
10147 cupsd_job_t
*job
; /* Job information */
10148 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
10149 username
[HTTP_MAX_URI
], /* Username portion of URI */
10150 host
[HTTP_MAX_URI
], /* Host portion of URI */
10151 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10152 int port
; /* Port portion of URI */
10155 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
10156 con
->http
.fd
, uri
->values
[0].string
.text
);
10159 * See if we have a job URI or a printer URI...
10162 if (!strcmp(uri
->name
, "printer-uri"))
10165 * Got a printer URI; see if we also have a job-id attribute...
10168 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10169 IPP_TAG_INTEGER
)) == NULL
)
10171 send_ipp_status(con
, IPP_BAD_REQUEST
,
10172 _("Got a printer-uri attribute but no job-id."));
10176 jobid
= attr
->values
[0].integer
;
10181 * Got a job URI; parse it to get the job ID...
10184 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10185 sizeof(scheme
), username
, sizeof(username
), host
,
10186 sizeof(host
), &port
, resource
, sizeof(resource
));
10188 if (strncmp(resource
, "/jobs/", 6))
10194 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10195 uri
->values
[0].string
.text
);
10199 jobid
= atoi(resource
+ 6);
10203 * See if the job exists...
10206 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10209 * Nope - return a "not found" error...
10212 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10217 * See if job is in any of the "completed" states...
10220 if (job
->state_value
<= IPP_JOB_PROCESSING
)
10223 * Nope - return a "not possible" error...
10226 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
10232 * See if we have retained the job files...
10237 if (!job
->attrs
|| job
->num_files
== 0)
10240 * Nope - return a "not possible" error...
10243 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10244 _("Job #%d cannot be restarted - no files."), jobid
);
10249 * See if the job is owned by the requesting user...
10252 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10254 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10255 cupsdFindDest(job
->dest
));
10260 * See if the job-hold-until attribute is specified...
10263 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
10264 IPP_TAG_KEYWORD
)) == NULL
)
10265 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
10267 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
10270 * Return the job to a held state...
10273 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
10274 "Restarted by \"%s\" with job-hold-until=%s.",
10275 username
, attr
->values
[0].string
.text
);
10276 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10278 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
10279 NULL
, job
, "Job restarted by user with job-hold-until=%s",
10280 attr
->values
[0].string
.text
);
10285 * Restart the job...
10288 cupsdRestartJob(job
);
10292 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
10294 con
->response
->request
.status
.status_code
= IPP_OK
;
10299 * 'save_auth_info()' - Save authentication information for a job.
10304 cupsd_client_t
*con
, /* I - Client connection */
10305 cupsd_job_t
*job
, /* I - Job */
10306 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
10308 int i
; /* Looping var */
10309 char filename
[1024]; /* Job authentication filename */
10310 cups_file_t
*fp
; /* Job authentication file */
10311 char line
[65536]; /* Line for file */
10312 cupsd_printer_t
*dest
; /* Destination printer/class */
10316 * This function saves the in-memory authentication information for
10317 * a job so that it can be used to authenticate with a remote host.
10318 * The information is stored in a file that is readable only by the
10319 * root user. The fields are Base-64 encoded, each on a separate line,
10320 * followed by random number (up to 1024) of newlines to limit the
10321 * amount of information that is exposed.
10323 * Because of the potential for exposing of authentication information,
10324 * this functionality is only enabled when running cupsd as root.
10326 * This caching only works for the Basic and BasicDigest authentication
10327 * types. Digest authentication cannot be cached this way, and in
10328 * the future Kerberos authentication may make all of this obsolete.
10330 * Authentication information is saved whenever an authenticated
10331 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
10334 * This information is deleted after a job is completed or canceled,
10335 * so reprints may require subsequent re-authentication.
10341 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
10345 * Create the authentication file and change permissions...
10348 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
10349 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
10351 cupsdLogMessage(CUPSD_LOG_ERROR
,
10352 "Unable to save authentication info to \"%s\" - %s",
10353 filename
, strerror(errno
));
10357 fchown(cupsFileNumber(fp
), 0, 0);
10358 fchmod(cupsFileNumber(fp
), 0400);
10361 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
10363 cupsdClearString(job
->auth_env
+ i
);
10365 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
10368 * Write 1 to 3 auth values...
10372 i
< auth_info
->num_values
&&
10373 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
10376 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
10377 strlen(auth_info
->values
[i
].string
.text
));
10378 cupsFilePrintf(fp
, "%s\n", line
);
10380 if (!strcmp(dest
->auth_info_required
[i
], "username"))
10381 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
10382 auth_info
->values
[i
].string
.text
);
10383 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
10384 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
10385 auth_info
->values
[i
].string
.text
);
10386 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
10387 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
10388 auth_info
->values
[i
].string
.text
);
10389 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
10390 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
10391 auth_info
->values
[i
].string
.text
);
10393 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_%s=%s",
10394 dest
->auth_info_required
[i
],
10395 auth_info
->values
[i
].string
.text
);
10398 else if (con
->username
[0])
10401 * Write the authenticated username...
10404 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
10405 cupsFilePrintf(fp
, "%s\n", line
);
10407 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
10410 * Write the authenticated password...
10413 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
10414 cupsFilePrintf(fp
, "%s\n", line
);
10416 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
10420 if (con
->gss_uid
> 0)
10422 cupsFilePrintf(fp
, "%d\n", (int)con
->gss_uid
);
10423 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
10425 #endif /* HAVE_GSSAPI */
10428 * Write a random number of newlines to the end of the file...
10431 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
10432 cupsFilePutChar(fp
, '\n');
10435 * Close the file and return...
10443 * 'send_document()' - Send a file to a printer or class.
10447 send_document(cupsd_client_t
*con
, /* I - Client connection */
10448 ipp_attribute_t
*uri
) /* I - Printer URI */
10450 ipp_attribute_t
*attr
; /* Current attribute */
10451 ipp_attribute_t
*format
; /* Request's document-format attribute */
10452 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
10453 const char *default_format
;/* document-format-default value */
10454 int jobid
; /* Job ID number */
10455 cupsd_job_t
*job
; /* Current job */
10456 char job_uri
[HTTP_MAX_URI
],
10458 scheme
[HTTP_MAX_URI
],
10459 /* Method portion of URI */
10460 username
[HTTP_MAX_URI
],
10461 /* Username portion of URI */
10462 host
[HTTP_MAX_URI
],
10463 /* Host portion of URI */
10464 resource
[HTTP_MAX_URI
];
10465 /* Resource portion of URI */
10466 int port
; /* Port portion of URI */
10467 mime_type_t
*filetype
; /* Type of file */
10468 char super
[MIME_MAX_SUPER
],
10469 /* Supertype of file */
10470 type
[MIME_MAX_TYPE
],
10471 /* Subtype of file */
10472 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
10473 /* Textual name of mime type */
10474 char filename
[1024]; /* Job filename */
10475 cupsd_printer_t
*printer
; /* Current printer */
10476 struct stat fileinfo
; /* File information */
10477 int kbytes
; /* Size of file */
10478 int compression
; /* Type of compression */
10479 int start_job
; /* Start the job? */
10482 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
10483 con
->http
.fd
, uri
->values
[0].string
.text
);
10486 * See if we have a job URI or a printer URI...
10489 if (!strcmp(uri
->name
, "printer-uri"))
10492 * Got a printer URI; see if we also have a job-id attribute...
10495 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10496 IPP_TAG_INTEGER
)) == NULL
)
10498 send_ipp_status(con
, IPP_BAD_REQUEST
,
10499 _("Got a printer-uri attribute but no job-id."));
10503 jobid
= attr
->values
[0].integer
;
10508 * Got a job URI; parse it to get the job ID...
10511 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10512 sizeof(scheme
), username
, sizeof(username
), host
,
10513 sizeof(host
), &port
, resource
, sizeof(resource
));
10515 if (strncmp(resource
, "/jobs/", 6))
10521 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10522 uri
->values
[0].string
.text
);
10526 jobid
= atoi(resource
+ 6);
10530 * See if the job exists...
10533 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10536 * Nope - return a "not found" error...
10539 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10543 printer
= cupsdFindDest(job
->dest
);
10546 * See if the job is owned by the requesting user...
10549 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10551 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10552 cupsdFindDest(job
->dest
));
10557 * OK, see if the client is sending the document compressed - CUPS
10558 * only supports "none" and "gzip".
10561 compression
= CUPS_FILE_NONE
;
10563 if ((attr
= ippFindAttribute(con
->request
, "compression",
10564 IPP_TAG_KEYWORD
)) != NULL
)
10566 if (strcmp(attr
->values
[0].string
.text
, "none")
10568 && strcmp(attr
->values
[0].string
.text
, "gzip")
10569 #endif /* HAVE_LIBZ */
10572 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
10573 attr
->values
[0].string
.text
);
10574 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10575 "compression", NULL
, attr
->values
[0].string
.text
);
10580 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
10581 compression
= CUPS_FILE_GZIP
;
10582 #endif /* HAVE_LIBZ */
10586 * Do we have a file to print?
10589 if (!con
->filename
)
10592 * Check for an empty request with "last-document" set to true, which is
10593 * used to close an "open" job by RFC 2911, section 3.3.2.
10596 if (job
->num_files
> 0 &&
10597 (attr
= ippFindAttribute(con
->request
, "last-document",
10598 IPP_TAG_BOOLEAN
)) != NULL
&&
10599 attr
->values
[0].boolean
)
10600 goto last_document
;
10602 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
10607 * Is it a format we support?
10610 if ((format
= ippFindAttribute(con
->request
, "document-format",
10611 IPP_TAG_MIMETYPE
)) != NULL
)
10614 * Grab format from client...
10617 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10620 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
10621 format
->values
[0].string
.text
);
10625 else if ((default_format
= cupsGetOption("document-format",
10626 printer
->num_options
,
10627 printer
->options
)) != NULL
)
10630 * Use default document format...
10633 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
10635 send_ipp_status(con
, IPP_BAD_REQUEST
,
10636 _("Bad document-format-default \"%s\"."), default_format
);
10643 * No document format attribute? Auto-type it!
10646 strcpy(super
, "application");
10647 strcpy(type
, "octet-stream");
10650 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
10653 * Auto-type the file...
10656 ipp_attribute_t
*doc_name
; /* document-name attribute */
10659 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
10661 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
10662 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
10663 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
10667 filetype
= mimeType(MimeDatabase
, super
, type
);
10670 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
10671 filetype
->super
, filetype
->type
);
10674 filetype
= mimeType(MimeDatabase
, super
, type
);
10679 * Replace the document-format attribute value with the auto-typed or
10683 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10686 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
10687 IPP_TAG_MIMETYPE
)) != NULL
)
10689 _cupsStrFree(jformat
->values
[0].string
.text
);
10691 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
10694 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
10695 "document-format", NULL
, mimetype
);
10697 else if (!filetype
)
10699 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10700 _("Unsupported document-format \"%s/%s\"."), super
, type
);
10701 cupsdLogMessage(CUPSD_LOG_INFO
,
10702 "Hint: Do you have the raw file printing rules enabled?");
10705 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10706 "document-format", NULL
, format
->values
[0].string
.text
);
10711 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
10713 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
10716 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10717 _("Unsupported document-format \"%s\"."), mimetype
);
10719 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10720 "document-format", NULL
, mimetype
);
10726 * Add the file to the job...
10731 if (add_file(con
, job
, filetype
, compression
))
10734 if (stat(con
->filename
, &fileinfo
))
10737 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
10739 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
10741 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
10742 IPP_TAG_INTEGER
)) != NULL
)
10743 attr
->values
[0].integer
+= kbytes
;
10745 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
10747 rename(con
->filename
, filename
);
10749 cupsdClearString(&con
->filename
);
10751 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
10752 filetype
->super
, filetype
->type
, job
->username
);
10755 * Start the job if this is the last document...
10760 if ((attr
= ippFindAttribute(con
->request
, "last-document",
10761 IPP_TAG_BOOLEAN
)) != NULL
&&
10762 attr
->values
[0].boolean
)
10765 * See if we need to add the ending sheet...
10768 if (cupsdTimeoutJob(job
))
10771 if (job
->state_value
== IPP_JOB_STOPPED
)
10773 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10774 job
->state_value
= IPP_JOB_PENDING
;
10776 else if (job
->state_value
== IPP_JOB_HELD
)
10778 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10779 IPP_TAG_KEYWORD
)) == NULL
)
10780 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10782 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10784 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
10785 job
->state_value
= IPP_JOB_PENDING
;
10790 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10796 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
10797 IPP_TAG_KEYWORD
)) == NULL
)
10798 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
10800 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
10802 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
10803 job
->state_value
= IPP_JOB_HELD
;
10804 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
10807 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10814 * Fill in the response info...
10817 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
10820 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
10823 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
10825 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
10827 add_job_state_reasons(con
, job
);
10829 con
->response
->request
.status
.status_code
= IPP_OK
;
10832 * Start the job if necessary...
10841 * 'send_http_error()' - Send a HTTP error back to the IPP client.
10846 cupsd_client_t
*con
, /* I - Client connection */
10847 http_status_t status
, /* I - HTTP status code */
10848 cupsd_printer_t
*printer
) /* I - Printer, if any */
10850 ipp_attribute_t
*uri
; /* Request URI, if any */
10853 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
10854 IPP_TAG_URI
)) == NULL
)
10855 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
10857 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
10858 "Returning HTTP %s for %s (%s) from %s",
10859 httpStatus(status
),
10861 ippOpString(con
->request
->request
.op
.operation_id
) :
10863 uri
? uri
->values
[0].string
.text
: "no URI",
10864 con
->http
.hostname
);
10868 int auth_type
; /* Type of authentication required */
10871 auth_type
= CUPSD_AUTH_NONE
;
10873 if (status
== HTTP_UNAUTHORIZED
&&
10874 printer
->num_auth_info_required
> 0 &&
10875 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10877 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10878 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10879 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10882 * Creating and authenticating jobs requires Kerberos...
10885 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10890 * Use policy/location-defined authentication requirements...
10893 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10894 cupsd_location_t
*auth
; /* Pointer to authentication element */
10897 if (printer
->type
& CUPS_PRINTER_CLASS
)
10898 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10900 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10902 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10903 auth
->type
== CUPSD_AUTH_NONE
)
10904 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10906 con
->request
->request
.op
.operation_id
:
10911 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10912 auth_type
= DefaultAuthType
;
10914 auth_type
= auth
->type
;
10918 cupsdSendError(con
, status
, auth_type
);
10921 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10923 ippDelete(con
->response
);
10924 con
->response
= NULL
;
10931 * 'send_ipp_status()' - Send a status back to the IPP client.
10935 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10936 ipp_status_t status
, /* I - IPP status code */
10937 const char *message
,/* I - Status message */
10938 ...) /* I - Additional args as needed */
10940 va_list ap
; /* Pointer to additional args */
10941 char formatted
[1024]; /* Formatted errror message */
10944 va_start(ap
, message
);
10945 vsnprintf(formatted
, sizeof(formatted
),
10946 _cupsLangString(con
->language
, message
), ap
);
10949 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10950 ippOpString(con
->request
->request
.op
.operation_id
),
10951 ippErrorString(status
), formatted
);
10953 con
->response
->request
.status
.status_code
= status
;
10955 if (ippFindAttribute(con
->response
, "attributes-charset",
10956 IPP_TAG_ZERO
) == NULL
)
10957 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10958 "attributes-charset", NULL
, "utf-8");
10960 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10961 IPP_TAG_ZERO
) == NULL
)
10962 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10963 "attributes-natural-language", NULL
, DefaultLanguage
);
10965 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10966 "status-message", NULL
, formatted
);
10971 * 'set_default()' - Set the default destination...
10975 set_default(cupsd_client_t
*con
, /* I - Client connection */
10976 ipp_attribute_t
*uri
) /* I - Printer URI */
10978 http_status_t status
; /* Policy status */
10979 cups_ptype_t dtype
; /* Destination type (printer/class) */
10980 cupsd_printer_t
*printer
, /* Printer */
10981 *oldprinter
; /* Old default printer */
10984 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10985 con
->http
.fd
, uri
->values
[0].string
.text
);
10988 * Is the destination valid?
10991 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10997 send_ipp_status(con
, IPP_NOT_FOUND
,
10998 _("The printer or class does not exist."));
11006 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
11008 send_http_error(con
, status
, NULL
);
11013 * Set it as the default...
11016 oldprinter
= DefaultPrinter
;
11017 DefaultPrinter
= printer
;
11020 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
11021 "%s is no longer the default printer.", oldprinter
->name
);
11023 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
11024 "%s is now the default printer.", printer
->name
);
11026 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
11027 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
11029 cupsdLogMessage(CUPSD_LOG_INFO
,
11030 "Default destination set to \"%s\" by \"%s\".",
11031 printer
->name
, get_username(con
));
11034 * Everything was ok, so return OK status...
11037 con
->response
->request
.status
.status_code
= IPP_OK
;
11042 * 'set_job_attrs()' - Set job attributes.
11046 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
11047 ipp_attribute_t
*uri
) /* I - Job URI */
11049 ipp_attribute_t
*attr
, /* Current attribute */
11050 *attr2
; /* Job attribute */
11051 int jobid
; /* Job ID */
11052 cupsd_job_t
*job
; /* Current job */
11053 char scheme
[HTTP_MAX_URI
],
11054 /* Method portion of URI */
11055 username
[HTTP_MAX_URI
],
11056 /* Username portion of URI */
11057 host
[HTTP_MAX_URI
],
11058 /* Host portion of URI */
11059 resource
[HTTP_MAX_URI
];
11060 /* Resource portion of URI */
11061 int port
; /* Port portion of URI */
11062 int event
; /* Events? */
11063 int check_jobs
; /* Check jobs? */
11066 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
11067 con
->http
.fd
, uri
->values
[0].string
.text
);
11070 * Start with "everything is OK" status...
11073 con
->response
->request
.status
.status_code
= IPP_OK
;
11076 * See if we have a job URI or a printer URI...
11079 if (!strcmp(uri
->name
, "printer-uri"))
11082 * Got a printer URI; see if we also have a job-id attribute...
11085 if ((attr
= ippFindAttribute(con
->request
, "job-id",
11086 IPP_TAG_INTEGER
)) == NULL
)
11088 send_ipp_status(con
, IPP_BAD_REQUEST
,
11089 _("Got a printer-uri attribute but no job-id."));
11093 jobid
= attr
->values
[0].integer
;
11098 * Got a job URI; parse it to get the job ID...
11101 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
11102 sizeof(scheme
), username
, sizeof(username
), host
,
11103 sizeof(host
), &port
, resource
, sizeof(resource
));
11105 if (strncmp(resource
, "/jobs/", 6))
11111 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
11112 uri
->values
[0].string
.text
);
11116 jobid
= atoi(resource
+ 6);
11120 * See if the job exists...
11123 if ((job
= cupsdFindJob(jobid
)) == NULL
)
11126 * Nope - return a "not found" error...
11129 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
11134 * See if the job has been completed...
11137 if (job
->state_value
> IPP_JOB_STOPPED
)
11140 * Return a "not-possible" error...
11143 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11144 _("Job #%d is finished and cannot be altered."), jobid
);
11149 * See if the job is owned by the requesting user...
11152 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
11154 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
11155 cupsdFindDest(job
->dest
));
11160 * See what the user wants to change.
11168 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11170 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
11173 if (!strcmp(attr
->name
, "attributes-charset") ||
11174 !strcmp(attr
->name
, "attributes-natural-language") ||
11175 !strcmp(attr
->name
, "document-compression") ||
11176 !strcmp(attr
->name
, "document-format") ||
11177 !strcmp(attr
->name
, "job-detailed-status-messages") ||
11178 !strcmp(attr
->name
, "job-document-access-errors") ||
11179 !strcmp(attr
->name
, "job-id") ||
11180 !strcmp(attr
->name
, "job-impressions-completed") ||
11181 !strcmp(attr
->name
, "job-k-octets") ||
11182 !strcmp(attr
->name
, "job-originating-host-name") ||
11183 !strcmp(attr
->name
, "job-originating-user-name") ||
11184 !strcmp(attr
->name
, "job-printer-up-time") ||
11185 !strcmp(attr
->name
, "job-printer-uri") ||
11186 !strcmp(attr
->name
, "job-sheets") ||
11187 !strcmp(attr
->name
, "job-state-message") ||
11188 !strcmp(attr
->name
, "job-state-reasons") ||
11189 !strcmp(attr
->name
, "job-uri") ||
11190 !strcmp(attr
->name
, "number-of-documents") ||
11191 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
11192 !strcmp(attr
->name
, "output-device-assigned") ||
11193 !strncmp(attr
->name
, "date-time-at-", 13) ||
11194 !strncmp(attr
->name
, "job-k-octets", 12) ||
11195 !strncmp(attr
->name
, "job-media-sheets", 16) ||
11196 !strncmp(attr
->name
, "time-at-", 8))
11202 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
11203 _("%s cannot be changed."), attr
->name
);
11205 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11206 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11211 if (!strcmp(attr
->name
, "job-priority"))
11214 * Change the job priority...
11217 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11219 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
11221 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11222 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11224 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
11226 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11227 _("Job is completed and cannot be changed."));
11230 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11232 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
11233 attr
->values
[0].integer
);
11234 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
11237 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
11238 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
11241 else if (!strcmp(attr
->name
, "job-state"))
11244 * Change the job state...
11247 if (attr
->value_tag
!= IPP_TAG_ENUM
)
11249 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
11251 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
11252 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
11256 switch (attr
->values
[0].integer
)
11258 case IPP_JOB_PENDING
:
11259 case IPP_JOB_HELD
:
11260 if (job
->state_value
> IPP_JOB_HELD
)
11262 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11263 _("Job state cannot be changed."));
11266 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11268 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11269 attr
->values
[0].integer
);
11270 cupsdSetJobState(job
, attr
->values
[0].integer
,
11272 "Job state changed by \"%s\"", username
);
11277 case IPP_JOB_PROCESSING
:
11278 case IPP_JOB_STOPPED
:
11279 if (job
->state_value
!= attr
->values
[0].integer
)
11281 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11282 _("Job state cannot be changed."));
11287 case IPP_JOB_CANCELED
:
11288 case IPP_JOB_ABORTED
:
11289 case IPP_JOB_COMPLETED
:
11290 if (job
->state_value
> IPP_JOB_PROCESSING
)
11292 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11293 _("Job state cannot be changed."));
11296 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
11298 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
11299 attr
->values
[0].integer
);
11300 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
11302 "Job state changed by \"%s\"", username
);
11309 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
11311 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11312 IPP_TAG_ZERO
)) != NULL
)
11315 * Some other value; first free the old value...
11318 if (job
->attrs
->prev
)
11319 job
->attrs
->prev
->next
= attr2
->next
;
11321 job
->attrs
->attrs
= attr2
->next
;
11323 if (job
->attrs
->last
== attr2
)
11324 job
->attrs
->last
= job
->attrs
->prev
;
11326 _ippFreeAttr(attr2
);
11329 * Then copy the attribute...
11332 copy_attribute(job
->attrs
, attr
, 0);
11335 * See if the job-name or job-hold-until is being changed.
11338 if (!strcmp(attr
->name
, "job-hold-until"))
11340 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
11341 attr
->values
[0].string
.text
);
11342 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
11344 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
11346 cupsdReleaseJob(job
);
11350 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
11351 "Job held by \"%s\".", username
);
11353 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
11356 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
11359 * Delete the attribute...
11362 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
11363 IPP_TAG_ZERO
)) != NULL
)
11365 if (job
->attrs
->prev
)
11366 job
->attrs
->prev
->next
= attr2
->next
;
11368 job
->attrs
->attrs
= attr2
->next
;
11370 if (attr2
== job
->attrs
->last
)
11371 job
->attrs
->last
= job
->attrs
->prev
;
11373 _ippFreeAttr(attr2
);
11375 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11381 * Add new option by copying it...
11384 copy_attribute(job
->attrs
, attr
, 0);
11386 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
11395 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
11398 * Send events as needed...
11401 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
11402 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
11403 cupsdFindDest(job
->dest
), job
,
11404 "Job priority changed by user.");
11406 if (event
& CUPSD_EVENT_JOB_STATE
)
11407 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
11408 job
->state_value
== IPP_JOB_HELD
?
11409 "Job held by user." : "Job restarted by user.");
11411 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
11412 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
11413 "Job options changed by user.");
11416 * Start jobs if possible...
11425 * 'set_printer_attrs()' - Set printer attributes.
11429 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
11430 ipp_attribute_t
*uri
) /* I - Printer */
11432 http_status_t status
; /* Policy status */
11433 cups_ptype_t dtype
; /* Destination type (printer/class) */
11434 cupsd_printer_t
*printer
; /* Printer/class */
11435 ipp_attribute_t
*attr
; /* Printer attribute */
11436 int changed
= 0; /* Was anything changed? */
11439 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
11440 con
->http
.fd
, uri
->values
[0].string
.text
);
11443 * Is the destination valid?
11446 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11452 send_ipp_status(con
, IPP_NOT_FOUND
,
11453 _("The printer or class does not exist."));
11461 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11463 send_http_error(con
, status
, printer
);
11468 * Return a list of attributes that can be set via Set-Printer-Attributes.
11471 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
11472 IPP_TAG_TEXT
)) != NULL
)
11474 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
11478 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
11479 IPP_TAG_TEXT
)) != NULL
)
11481 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
11486 * Update the printer attributes and return...
11491 cupsdSetPrinterAttrs(printer
);
11492 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
11494 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
11495 "Printer \"%s\" description or location changed by \"%s\".",
11496 printer
->name
, get_username(con
));
11498 cupsdLogMessage(CUPSD_LOG_INFO
,
11499 "Printer \"%s\" description or location changed by \"%s\".",
11500 printer
->name
, get_username(con
));
11503 con
->response
->request
.status
.status_code
= IPP_OK
;
11508 * 'set_printer_defaults()' - Set printer default options from a request.
11512 set_printer_defaults(
11513 cupsd_client_t
*con
, /* I - Client connection */
11514 cupsd_printer_t
*printer
) /* I - Printer */
11516 int i
; /* Looping var */
11517 ipp_attribute_t
*attr
; /* Current attribute */
11518 int namelen
; /* Length of attribute name */
11519 char name
[256], /* New attribute name */
11520 value
[256]; /* String version of integer attrs */
11523 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
11526 * Skip non-printer attributes...
11529 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
11532 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
11534 if (!strcmp(attr
->name
, "job-sheets-default"))
11537 * Only allow keywords and names...
11540 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11544 * Only allow job-sheets-default to be set when running without a
11545 * system high classification level...
11548 if (Classification
)
11551 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
11553 if (attr
->num_values
> 1)
11554 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
11556 cupsdSetString(&printer
->job_sheets
[1], "none");
11558 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
11560 cupsdFreeStrings(&(printer
->users
));
11562 printer
->deny_users
= 0;
11564 if (attr
->value_tag
== IPP_TAG_NAME
&&
11565 (attr
->num_values
> 1 ||
11566 strcmp(attr
->values
[0].string
.text
, "all")))
11568 for (i
= 0; i
< attr
->num_values
; i
++)
11569 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11572 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
11574 cupsdFreeStrings(&(printer
->users
));
11576 printer
->deny_users
= 1;
11578 if (attr
->value_tag
== IPP_TAG_NAME
&&
11579 (attr
->num_values
> 1 ||
11580 strcmp(attr
->values
[0].string
.text
, "none")))
11582 for (i
= 0; i
< attr
->num_values
; i
++)
11583 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
11586 else if (!strcmp(attr
->name
, "job-quota-period"))
11588 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11591 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
11592 attr
->values
[0].integer
);
11593 cupsdFreeQuotas(printer
);
11595 printer
->quota_period
= attr
->values
[0].integer
;
11597 else if (!strcmp(attr
->name
, "job-k-limit"))
11599 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11602 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
11603 attr
->values
[0].integer
);
11604 cupsdFreeQuotas(printer
);
11606 printer
->k_limit
= attr
->values
[0].integer
;
11608 else if (!strcmp(attr
->name
, "job-page-limit"))
11610 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
11613 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
11614 attr
->values
[0].integer
);
11615 cupsdFreeQuotas(printer
);
11617 printer
->page_limit
= attr
->values
[0].integer
;
11619 else if (!strcmp(attr
->name
, "printer-op-policy"))
11621 cupsd_policy_t
*p
; /* Policy */
11624 if (attr
->value_tag
!= IPP_TAG_NAME
)
11627 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
11629 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11630 "Setting printer-op-policy to \"%s\"...",
11631 attr
->values
[0].string
.text
);
11632 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
11633 printer
->op_policy_ptr
= p
;
11637 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11638 _("Unknown printer-op-policy \"%s\"."),
11639 attr
->values
[0].string
.text
);
11643 else if (!strcmp(attr
->name
, "printer-error-policy"))
11645 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
11648 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
11649 ((printer
->type
& (CUPS_PRINTER_IMPLICIT
| CUPS_PRINTER_CLASS
)) ||
11650 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
11651 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
11652 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
11654 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
11655 _("Unknown printer-error-policy \"%s\"."),
11656 attr
->values
[0].string
.text
);
11660 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11661 "Setting printer-error-policy to \"%s\"...",
11662 attr
->values
[0].string
.text
);
11663 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
11667 * Skip any other non-default attributes...
11670 namelen
= strlen(attr
->name
);
11671 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
11672 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
11676 * OK, anything else must be a user-defined default...
11679 strlcpy(name
, attr
->name
, sizeof(name
));
11680 name
[namelen
- 8] = '\0'; /* Strip "-default" */
11682 switch (attr
->value_tag
)
11684 case IPP_TAG_DELETEATTR
:
11685 printer
->num_options
= cupsRemoveOption(name
,
11686 printer
->num_options
,
11687 &(printer
->options
));
11688 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11689 "Deleting %s", attr
->name
);
11692 case IPP_TAG_NAME
:
11693 case IPP_TAG_KEYWORD
:
11695 printer
->num_options
= cupsAddOption(name
,
11696 attr
->values
[0].string
.text
,
11697 printer
->num_options
,
11698 &(printer
->options
));
11699 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11700 "Setting %s to \"%s\"...", attr
->name
,
11701 attr
->values
[0].string
.text
);
11704 case IPP_TAG_BOOLEAN
:
11705 printer
->num_options
= cupsAddOption(name
,
11706 attr
->values
[0].boolean
?
11708 printer
->num_options
,
11709 &(printer
->options
));
11710 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11711 "Setting %s to %s...", attr
->name
,
11712 attr
->values
[0].boolean
? "true" : "false");
11715 case IPP_TAG_INTEGER
:
11716 case IPP_TAG_ENUM
:
11717 sprintf(value
, "%d", attr
->values
[0].integer
);
11718 printer
->num_options
= cupsAddOption(name
, value
,
11719 printer
->num_options
,
11720 &(printer
->options
));
11721 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11722 "Setting %s to %s...", attr
->name
, value
);
11725 case IPP_TAG_RANGE
:
11726 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
11727 attr
->values
[0].range
.upper
);
11728 printer
->num_options
= cupsAddOption(name
, value
,
11729 printer
->num_options
,
11730 &(printer
->options
));
11731 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11732 "Setting %s to %s...", attr
->name
, value
);
11735 case IPP_TAG_RESOLUTION
:
11736 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
11737 attr
->values
[0].resolution
.yres
,
11738 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
11740 printer
->num_options
= cupsAddOption(name
, value
,
11741 printer
->num_options
,
11742 &(printer
->options
));
11743 cupsdLogMessage(CUPSD_LOG_DEBUG
,
11744 "Setting %s to %s...", attr
->name
, value
);
11748 /* Do nothing for other values */
11756 * 'start_printer()' - Start a printer.
11760 start_printer(cupsd_client_t
*con
, /* I - Client connection */
11761 ipp_attribute_t
*uri
) /* I - Printer URI */
11763 int i
; /* Temporary variable */
11764 http_status_t status
; /* Policy status */
11765 cups_ptype_t dtype
; /* Destination type (printer/class) */
11766 cupsd_printer_t
*printer
; /* Printer data */
11769 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
11770 con
->http
.fd
, uri
->values
[0].string
.text
);
11773 * Is the destination valid?
11776 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11782 send_ipp_status(con
, IPP_NOT_FOUND
,
11783 _("The printer or class does not exist."));
11791 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11793 send_http_error(con
, status
, printer
);
11798 * Start the printer...
11801 printer
->state_message
[0] = '\0';
11803 cupsdStartPrinter(printer
, 1);
11805 if (dtype
& CUPS_PRINTER_CLASS
)
11806 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
11807 printer
->name
, get_username(con
));
11809 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
11810 printer
->name
, get_username(con
));
11818 if ((i
= check_quotas(con
, printer
)) < 0)
11820 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
11825 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
11830 * Everything was ok, so return OK status...
11833 con
->response
->request
.status
.status_code
= IPP_OK
;
11838 * 'stop_printer()' - Stop a printer.
11842 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11843 ipp_attribute_t
*uri
) /* I - Printer URI */
11845 http_status_t status
; /* Policy status */
11846 cups_ptype_t dtype
; /* Destination type (printer/class) */
11847 cupsd_printer_t
*printer
; /* Printer data */
11848 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11851 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11852 con
->http
.fd
, uri
->values
[0].string
.text
);
11855 * Is the destination valid?
11858 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11864 send_ipp_status(con
, IPP_NOT_FOUND
,
11865 _("The printer or class does not exist."));
11873 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11875 send_http_error(con
, status
, printer
);
11880 * Stop the printer...
11883 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11884 IPP_TAG_TEXT
)) == NULL
)
11885 strcpy(printer
->state_message
, "Paused");
11888 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11889 sizeof(printer
->state_message
));
11892 cupsdStopPrinter(printer
, 1);
11894 if (dtype
& CUPS_PRINTER_CLASS
)
11895 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11896 printer
->name
, get_username(con
));
11898 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11899 printer
->name
, get_username(con
));
11902 * Everything was ok, so return OK status...
11905 con
->response
->request
.status
.status_code
= IPP_OK
;
11910 * 'url_encode_attr()' - URL-encode a string attribute.
11914 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11915 char *buffer
,/* I - String buffer */
11916 int bufsize
)/* I - Size of buffer */
11918 int i
; /* Looping var */
11919 char *bufptr
, /* Pointer into buffer */
11920 *bufend
; /* End of buffer */
11923 strlcpy(buffer
, attr
->name
, bufsize
);
11924 bufptr
= buffer
+ strlen(buffer
);
11925 bufend
= buffer
+ bufsize
- 1;
11927 for (i
= 0; i
< attr
->num_values
; i
++)
11929 if (bufptr
>= bufend
)
11937 if (bufptr
>= bufend
)
11942 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
11943 bufptr
, bufend
- bufptr
+ 1);
11945 if (bufptr
>= bufend
)
11956 * 'url_encode_string()' - URL-encode a string.
11959 static char * /* O - End of string */
11960 url_encode_string(const char *s
, /* I - String */
11961 char *buffer
, /* I - String buffer */
11962 int bufsize
) /* I - Size of buffer */
11964 char *bufptr
, /* Pointer into buffer */
11965 *bufend
; /* End of buffer */
11966 static const char *hex
= "0123456789ABCDEF";
11971 bufend
= buffer
+ bufsize
- 1;
11973 while (*s
&& bufptr
< bufend
)
11975 if (*s
== ' ' || *s
== '%' || *s
== '+')
11977 if (bufptr
>= (bufend
- 2))
11981 *bufptr
++ = hex
[(*s
>> 4) & 15];
11982 *bufptr
++ = hex
[*s
& 15];
11986 else if (*s
== '\'' || *s
== '\\')
11988 if (bufptr
>= (bufend
- 1))
12005 * 'user_allowed()' - See if a user is allowed to print to a queue.
12008 static int /* O - 0 if not allowed, 1 if allowed */
12009 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
12010 const char *username
) /* I - Username */
12012 struct passwd
*pw
; /* User password data */
12013 char baseuser
[256], /* Base username */
12014 *baseptr
, /* Pointer to "@" in base username */
12015 *name
; /* Current user name */
12018 if (cupsArrayCount(p
->users
) == 0)
12021 if (!strcmp(username
, "root"))
12024 if (strchr(username
, '@'))
12027 * Strip @REALM for username check...
12030 strlcpy(baseuser
, username
, sizeof(baseuser
));
12032 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
12035 username
= baseuser
;
12038 pw
= getpwnam(username
);
12041 for (name
= (char *)cupsArrayFirst(p
->users
);
12043 name
= (char *)cupsArrayNext(p
->users
))
12045 if (name
[0] == '@')
12048 * Check group membership...
12051 if (cupsdCheckGroup(username
, pw
, name
+ 1))
12054 else if (name
[0] == '#')
12060 if (cupsdCheckGroup(username
, pw
, name
))
12063 else if (!_cups_strcasecmp(username
, name
))
12067 return ((name
!= NULL
) != p
->deny_users
);
12072 * 'validate_job()' - Validate printer options and destination.
12076 validate_job(cupsd_client_t
*con
, /* I - Client connection */
12077 ipp_attribute_t
*uri
) /* I - Printer URI */
12079 http_status_t status
; /* Policy status */
12080 ipp_attribute_t
*attr
, /* Current attribute */
12081 *auth_info
; /* auth-info attribute */
12082 ipp_attribute_t
*format
; /* Document-format attribute */
12083 cups_ptype_t dtype
; /* Destination type (printer/class) */
12084 char super
[MIME_MAX_SUPER
],
12085 /* Supertype of file */
12086 type
[MIME_MAX_TYPE
];
12087 /* Subtype of file */
12088 cupsd_printer_t
*printer
; /* Printer */
12091 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
12092 con
->http
.fd
, uri
->values
[0].string
.text
);
12095 * OK, see if the client is sending the document compressed - CUPS
12096 * doesn't support compression yet...
12099 if ((attr
= ippFindAttribute(con
->request
, "compression",
12100 IPP_TAG_KEYWORD
)) != NULL
)
12102 if (strcmp(attr
->values
[0].string
.text
, "none")
12104 && strcmp(attr
->values
[0].string
.text
, "gzip")
12105 #endif /* HAVE_LIBZ */
12108 send_ipp_status(con
, IPP_ATTRIBUTES
,
12109 _("Unsupported compression \"%s\"."),
12110 attr
->values
[0].string
.text
);
12111 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
12112 "compression", NULL
, attr
->values
[0].string
.text
);
12118 * Is it a format we support?
12121 if ((format
= ippFindAttribute(con
->request
, "document-format",
12122 IPP_TAG_MIMETYPE
)) != NULL
)
12124 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
12127 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
12128 format
->values
[0].string
.text
);
12132 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
12133 !mimeType(MimeDatabase
, super
, type
))
12135 cupsdLogMessage(CUPSD_LOG_INFO
,
12136 "Hint: Do you have the raw file printing rules enabled?");
12137 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
12138 _("Unsupported document-format \"%s\"."),
12139 format
->values
[0].string
.text
);
12140 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
12141 "document-format", NULL
, format
->values
[0].string
.text
);
12147 * Is the destination valid?
12150 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
12156 send_ipp_status(con
, IPP_NOT_FOUND
,
12157 _("The printer or class does not exist."));
12165 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
12167 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
12169 send_http_error(con
, status
, printer
);
12172 else if (printer
->num_auth_info_required
== 1 &&
12173 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
12176 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
12180 else if (auth_info
&& !con
->http
.tls
&&
12181 !httpAddrLocalhost(con
->http
.hostaddr
))
12184 * Require encryption of auth-info over non-local connections...
12187 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
12190 #endif /* HAVE_SSL */
12193 * Everything was ok, so return OK status...
12196 con
->response
->request
.status
.status_code
= IPP_OK
;
12201 * 'validate_name()' - Make sure the printer name only contains valid chars.
12204 static int /* O - 0 if name is no good, 1 if good */
12205 validate_name(const char *name
) /* I - Name to check */
12207 const char *ptr
; /* Pointer into name */
12211 * Scan the whole name...
12214 for (ptr
= name
; *ptr
; ptr
++)
12215 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
12219 * All the characters are good; validate the length, too...
12222 return ((ptr
- name
) < 128);
12227 * 'validate_user()' - Validate the user for the request.
12230 static int /* O - 1 if permitted, 0 otherwise */
12231 validate_user(cupsd_job_t
*job
, /* I - Job */
12232 cupsd_client_t
*con
, /* I - Client connection */
12233 const char *owner
, /* I - Owner of job/resource */
12234 char *username
, /* O - Authenticated username */
12235 int userlen
) /* I - Length of username */
12237 cupsd_printer_t
*printer
; /* Printer for job */
12240 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
12241 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
12243 job
->id
, con
? con
->http
.fd
: 0,
12244 owner
? owner
: "(null)", username
, userlen
);
12247 * Validate input...
12250 if (!con
|| !owner
|| !username
|| userlen
<= 0)
12254 * Get the best authenticated username that is available.
12257 strlcpy(username
, get_username(con
), userlen
);
12260 * Check the username against the owner...
12263 printer
= cupsdFindDest(job
->dest
);
12265 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
12266 con
, owner
) == HTTP_OK
);
12271 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".